Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * V 4 L 2 D R I V E R H E L P E R A P I |
| 4 | * |
| 5 | * Moved from videodev2.h |
| 6 | * |
| 7 | * Some commonly needed functions for drivers (v4l2-common.o module) |
| 8 | */ |
| 9 | #ifndef _V4L2_DEV_H |
| 10 | #define _V4L2_DEV_H |
| 11 | |
Mauro Carvalho Chehab | 38ee04f | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 12 | #define OBSOLETE_DEVDATA 1 /* to be removed soon */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 13 | |
| 14 | #include <linux/poll.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/mutex.h> |
| 18 | #include <linux/compiler.h> /* need __user */ |
Mauro Carvalho Chehab | 487206f | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 19 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 20 | #include <linux/videodev.h> |
| 21 | #else |
| 22 | #include <linux/videodev2.h> |
| 23 | #endif |
| 24 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 25 | #define VIDEO_MAJOR 81 |
| 26 | /* Minor device allocation */ |
| 27 | #define MINOR_VFL_TYPE_GRABBER_MIN 0 |
| 28 | #define MINOR_VFL_TYPE_GRABBER_MAX 63 |
| 29 | #define MINOR_VFL_TYPE_RADIO_MIN 64 |
| 30 | #define MINOR_VFL_TYPE_RADIO_MAX 127 |
| 31 | #define MINOR_VFL_TYPE_VTX_MIN 192 |
| 32 | #define MINOR_VFL_TYPE_VTX_MAX 223 |
| 33 | #define MINOR_VFL_TYPE_VBI_MIN 224 |
| 34 | #define MINOR_VFL_TYPE_VBI_MAX 255 |
| 35 | |
| 36 | #define VFL_TYPE_GRABBER 0 |
| 37 | #define VFL_TYPE_VBI 1 |
| 38 | #define VFL_TYPE_RADIO 2 |
| 39 | #define VFL_TYPE_VTX 3 |
| 40 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 41 | struct v4l2_ioctl_callbacks; |
| 42 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 43 | /* |
| 44 | * Newer version of video_device, handled by videodev2.c |
| 45 | * This version moves redundant code from video device code to |
| 46 | * the common handler |
| 47 | */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 48 | |
| 49 | struct video_device |
| 50 | { |
| 51 | /* device ops */ |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 52 | const struct file_operations *fops; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 53 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 54 | /* sysfs */ |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 55 | struct device dev; /* v4l device */ |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 56 | struct device *parent; /* device parent */ |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 57 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 58 | /* device info */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 59 | char name[32]; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 60 | int type; /* v4l1 */ |
| 61 | int type2; /* v4l2 */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 62 | int minor; |
brandon@ifup.org | 539a755 | 2008-06-20 22:58:53 -0300 | [diff] [blame] | 63 | /* attribute to diferentiate multiple indexs on one physical device */ |
| 64 | int index; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 65 | |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 66 | int debug; /* Activates debug level*/ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 67 | |
| 68 | /* Video standard vars */ |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 69 | v4l2_std_id tvnorms; /* Supported tv norms */ |
| 70 | v4l2_std_id current_norm; /* Current tvnorm */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 71 | |
| 72 | /* callbacks */ |
| 73 | void (*release)(struct video_device *vfd); |
| 74 | |
| 75 | /* ioctl callbacks */ |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 76 | const struct v4l2_ioctl_ops *ioctl_ops; |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 77 | |
Hans Verkuil | 9c39d7e | 2008-07-21 07:51:45 -0300 | [diff] [blame^] | 78 | #ifdef OBSOLETE_DEVDATA /* to be removed soon */ |
| 79 | /* dev->driver_data will be used instead some day. |
| 80 | * Use the video_{get|set}_drvdata() helper functions, |
| 81 | * so the switch over will be transparent for you. |
| 82 | * Or use {pci|usb}_{get|set}_drvdata() directly. */ |
| 83 | void *priv; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | /* for videodev.c intenal usage -- please don't touch */ |
| 87 | int users; /* video_exclusive_{open|close} ... */ |
| 88 | struct mutex lock; /* ... helper function uses these */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 89 | }; |
| 90 | |
Linus Torvalds | e90ff92 | 2007-09-13 21:09:01 -0300 | [diff] [blame] | 91 | /* Class-dev to video-device */ |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 92 | #define to_video_device(cd) container_of(cd, struct video_device, dev) |
Linus Torvalds | e90ff92 | 2007-09-13 21:09:01 -0300 | [diff] [blame] | 93 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 94 | /* Version 2 functions */ |
| 95 | extern int video_register_device(struct video_device *vfd, int type, int nr); |
brandon@ifup.org | 539a755 | 2008-06-20 22:58:53 -0300 | [diff] [blame] | 96 | int video_register_device_index(struct video_device *vfd, int type, int nr, |
| 97 | int index); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 98 | void video_unregister_device(struct video_device *); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 99 | |
| 100 | /* helper functions to alloc / release struct video_device, the |
| 101 | later can be used for video_device->release() */ |
| 102 | struct video_device *video_device_alloc(void); |
| 103 | void video_device_release(struct video_device *vfd); |
| 104 | |
Mauro Carvalho Chehab | 8a90516 | 2006-09-10 12:01:19 -0300 | [diff] [blame] | 105 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 106 | #include <linux/mm.h> |
| 107 | |
Andrew Morton | 8a6914a | 2006-08-14 22:43:19 -0700 | [diff] [blame] | 108 | static inline int __must_check |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 109 | video_device_create_file(struct video_device *vfd, |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 110 | struct device_attribute *attr) |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 111 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 112 | int ret = device_create_file(&vfd->dev, attr); |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 113 | if (ret < 0) |
Hans Verkuil | 2bc93aa | 2008-07-17 16:45:00 -0300 | [diff] [blame] | 114 | printk(KERN_WARNING "%s error: %d\n", __func__, ret); |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 115 | return ret; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 116 | } |
| 117 | static inline void |
| 118 | video_device_remove_file(struct video_device *vfd, |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 119 | struct device_attribute *attr) |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 120 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 121 | device_remove_file(&vfd->dev, attr); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 122 | } |
| 123 | |
Mauro Carvalho Chehab | 8a90516 | 2006-09-10 12:01:19 -0300 | [diff] [blame] | 124 | #endif /* CONFIG_VIDEO_V4L1_COMPAT */ |
| 125 | |
Hans Verkuil | 9c39d7e | 2008-07-21 07:51:45 -0300 | [diff] [blame^] | 126 | #ifdef OBSOLETE_DEVDATA /* to be removed soon */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 127 | /* helper functions to access driver private data. */ |
| 128 | static inline void *video_get_drvdata(struct video_device *dev) |
| 129 | { |
| 130 | return dev->priv; |
| 131 | } |
| 132 | |
| 133 | static inline void video_set_drvdata(struct video_device *dev, void *data) |
| 134 | { |
| 135 | dev->priv = data; |
| 136 | } |
Mauro Carvalho Chehab | 38ee04f | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 137 | |
Mauro Carvalho Chehab | 38ee04f | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 138 | /* Obsolete stuff - Still needed for radio devices and obsolete drivers */ |
| 139 | extern struct video_device* video_devdata(struct file*); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 140 | extern int video_exclusive_open(struct inode *inode, struct file *file); |
| 141 | extern int video_exclusive_release(struct inode *inode, struct file *file); |
Mauro Carvalho Chehab | 38ee04f | 2006-08-08 09:10:01 -0300 | [diff] [blame] | 142 | #endif |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 143 | |
| 144 | #endif /* _V4L2_DEV_H */ |