diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-04 09:06:18 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-25 01:05:04 -0400 |
commit | 401998fa96fe18b057af3f906527196522dd2d9d (patch) | |
tree | 32d656e18410ab05204c83b57969db23665e4fe9 /include/media/v4l2-dev.h | |
parent | 7565ab082de88ec274283d6b83980144e520a2fc (diff) |
V4L/DVB (4065): Several improvements at videodev.c
Videodev now is capable of better handling V4L2 api, by
processing V4L2 ioctls and using callbacks to the driver.
The drivers should be migrated to the newer way and the older
one will be obsoleted soon.
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'include/media/v4l2-dev.h')
-rw-r--r-- | include/media/v4l2-dev.h | 371 |
1 files changed, 371 insertions, 0 deletions
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h new file mode 100644 index 000000000000..c2f54d2c9a4c --- /dev/null +++ b/include/media/v4l2-dev.h | |||
@@ -0,0 +1,371 @@ | |||
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 | |||
12 | #define OBSOLETE_OWNER 1 /* to be removed soon */ | ||
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 */ | ||
19 | #ifdef CONFIG_VIDEO_V4L1 | ||
20 | #include <linux/videodev.h> | ||
21 | #else | ||
22 | #include <linux/videodev2.h> | ||
23 | #endif | ||
24 | |||
25 | #include <linux/fs.h> | ||
26 | |||
27 | #define VIDEO_MAJOR 81 | ||
28 | /* Minor device allocation */ | ||
29 | #define MINOR_VFL_TYPE_GRABBER_MIN 0 | ||
30 | #define MINOR_VFL_TYPE_GRABBER_MAX 63 | ||
31 | #define MINOR_VFL_TYPE_RADIO_MIN 64 | ||
32 | #define MINOR_VFL_TYPE_RADIO_MAX 127 | ||
33 | #define MINOR_VFL_TYPE_VTX_MIN 192 | ||
34 | #define MINOR_VFL_TYPE_VTX_MAX 223 | ||
35 | #define MINOR_VFL_TYPE_VBI_MIN 224 | ||
36 | #define MINOR_VFL_TYPE_VBI_MAX 255 | ||
37 | |||
38 | #define VFL_TYPE_GRABBER 0 | ||
39 | #define VFL_TYPE_VBI 1 | ||
40 | #define VFL_TYPE_RADIO 2 | ||
41 | #define VFL_TYPE_VTX 3 | ||
42 | |||
43 | const struct file_operations *fops; | ||
44 | |||
45 | /* Video standard functions */ | ||
46 | extern unsigned int v4l2_video_std_fps(struct v4l2_standard *vs); | ||
47 | extern int v4l2_video_std_construct(struct v4l2_standard *vs, | ||
48 | int id, char *name); | ||
49 | |||
50 | /* prority handling */ | ||
51 | struct v4l2_prio_state { | ||
52 | atomic_t prios[4]; | ||
53 | }; | ||
54 | int v4l2_prio_init(struct v4l2_prio_state *global); | ||
55 | int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local, | ||
56 | enum v4l2_priority new); | ||
57 | int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local); | ||
58 | int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local); | ||
59 | enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global); | ||
60 | int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local); | ||
61 | |||
62 | /* names for fancy debug output */ | ||
63 | extern char *v4l2_field_names[]; | ||
64 | extern char *v4l2_type_names[]; | ||
65 | |||
66 | /* Compatibility layer interface -- v4l1-compat module */ | ||
67 | typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file, | ||
68 | unsigned int cmd, void *arg); | ||
69 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | ||
70 | int v4l_compat_translate_ioctl(struct inode *inode, struct file *file, | ||
71 | int cmd, void *arg, v4l2_kioctl driver_ioctl); | ||
72 | #else | ||
73 | #define v4l_compat_translate_ioctl(inode,file,cmd,arg,ioctl) -EINVAL | ||
74 | #endif | ||
75 | |||
76 | /* 32 Bits compatibility layer for 64 bits processors */ | ||
77 | extern long v4l_compat_ioctl32(struct file *file, unsigned int cmd, | ||
78 | unsigned long arg); | ||
79 | |||
80 | /* | ||
81 | * Newer version of video_device, handled by videodev2.c | ||
82 | * This version moves redundant code from video device code to | ||
83 | * the common handler | ||
84 | */ | ||
85 | struct v4l2_tvnorm { | ||
86 | char *name; | ||
87 | v4l2_std_id id; | ||
88 | |||
89 | void *priv_data; | ||
90 | }; | ||
91 | |||
92 | struct video_device | ||
93 | { | ||
94 | /* device ops */ | ||
95 | struct file_operations *fops; | ||
96 | |||
97 | /* device info */ | ||
98 | struct device *dev; | ||
99 | char name[32]; | ||
100 | int type; /* v4l1 */ | ||
101 | int type2; /* v4l2 */ | ||
102 | int hardware; | ||
103 | int minor; | ||
104 | |||
105 | int debug; /* Activates debug level*/ | ||
106 | |||
107 | /* Video standard vars */ | ||
108 | int tvnormsize; /* Size of tvnorm array */ | ||
109 | v4l2_std_id current_norm; /* Current tvnorm */ | ||
110 | struct v4l2_tvnorm *tvnorms; | ||
111 | |||
112 | /* callbacks */ | ||
113 | void (*release)(struct video_device *vfd); | ||
114 | |||
115 | /* ioctl callbacks */ | ||
116 | |||
117 | /* VIDIOC_QUERYCAP handler */ | ||
118 | int (*vidioc_querycap)(struct file *file, void *fh, struct v4l2_capability *cap); | ||
119 | |||
120 | /* Priority handling */ | ||
121 | int (*vidioc_g_priority) (struct file *file, void *fh, | ||
122 | enum v4l2_priority *p); | ||
123 | int (*vidioc_s_priority) (struct file *file, void *fh, | ||
124 | enum v4l2_priority p); | ||
125 | |||
126 | /* VIDIOC_ENUM_FMT handlers */ | ||
127 | int (*vidioc_enum_fmt_cap) (struct file *file, void *fh, | ||
128 | struct v4l2_fmtdesc *f); | ||
129 | int (*vidioc_enum_fmt_overlay) (struct file *file, void *fh, | ||
130 | struct v4l2_fmtdesc *f); | ||
131 | int (*vidioc_enum_fmt_vbi) (struct file *file, void *fh, | ||
132 | struct v4l2_fmtdesc *f); | ||
133 | int (*vidioc_enum_fmt_vbi_capture) (struct file *file, void *fh, | ||
134 | struct v4l2_fmtdesc *f); | ||
135 | int (*vidioc_enum_fmt_video_output)(struct file *file, void *fh, | ||
136 | struct v4l2_fmtdesc *f); | ||
137 | int (*vidioc_enum_fmt_vbi_output) (struct file *file, void *fh, | ||
138 | struct v4l2_fmtdesc *f); | ||
139 | int (*vidioc_enum_fmt_type_private)(struct file *file, void *fh, | ||
140 | struct v4l2_fmtdesc *f); | ||
141 | |||
142 | /* VIDIOC_G_FMT handlers */ | ||
143 | int (*vidioc_g_fmt_cap) (struct file *file, void *fh, | ||
144 | struct v4l2_format *f); | ||
145 | int (*vidioc_g_fmt_overlay) (struct file *file, void *fh, | ||
146 | struct v4l2_format *f); | ||
147 | int (*vidioc_g_fmt_vbi) (struct file *file, void *fh, | ||
148 | struct v4l2_format *f); | ||
149 | int (*vidioc_g_fmt_vbi_output) (struct file *file, void *fh, | ||
150 | struct v4l2_format *f); | ||
151 | int (*vidioc_g_fmt_vbi_capture)(struct file *file, void *fh, | ||
152 | struct v4l2_format *f); | ||
153 | int (*vidioc_g_fmt_video_output)(struct file *file, void *fh, | ||
154 | struct v4l2_format *f); | ||
155 | int (*vidioc_g_fmt_type_private)(struct file *file, void *fh, | ||
156 | struct v4l2_format *f); | ||
157 | |||
158 | /* VIDIOC_S_FMT handlers */ | ||
159 | int (*vidioc_s_fmt_cap) (struct file *file, void *fh, | ||
160 | struct v4l2_format *f); | ||
161 | |||
162 | int (*vidioc_s_fmt_overlay) (struct file *file, void *fh, | ||
163 | struct v4l2_format *f); | ||
164 | int (*vidioc_s_fmt_vbi) (struct file *file, void *fh, | ||
165 | struct v4l2_format *f); | ||
166 | int (*vidioc_s_fmt_vbi_output) (struct file *file, void *fh, | ||
167 | struct v4l2_format *f); | ||
168 | int (*vidioc_s_fmt_vbi_capture)(struct file *file, void *fh, | ||
169 | struct v4l2_format *f); | ||
170 | int (*vidioc_s_fmt_video_output)(struct file *file, void *fh, | ||
171 | struct v4l2_format *f); | ||
172 | int (*vidioc_s_fmt_type_private)(struct file *file, void *fh, | ||
173 | struct v4l2_format *f); | ||
174 | |||
175 | /* VIDIOC_TRY_FMT handlers */ | ||
176 | int (*vidioc_try_fmt_cap) (struct file *file, void *fh, | ||
177 | struct v4l2_format *f); | ||
178 | int (*vidioc_try_fmt_overlay) (struct file *file, void *fh, | ||
179 | struct v4l2_format *f); | ||
180 | int (*vidioc_try_fmt_vbi) (struct file *file, void *fh, | ||
181 | struct v4l2_format *f); | ||
182 | int (*vidioc_try_fmt_vbi_output) (struct file *file, void *fh, | ||
183 | struct v4l2_format *f); | ||
184 | int (*vidioc_try_fmt_vbi_capture)(struct file *file, void *fh, | ||
185 | struct v4l2_format *f); | ||
186 | int (*vidioc_try_fmt_video_output)(struct file *file, void *fh, | ||
187 | struct v4l2_format *f); | ||
188 | int (*vidioc_try_fmt_type_private)(struct file *file, void *fh, | ||
189 | struct v4l2_format *f); | ||
190 | |||
191 | /* Buffer handlers */ | ||
192 | int (*vidioc_reqbufs) (struct file *file, void *fh, struct v4l2_requestbuffers *b); | ||
193 | int (*vidioc_querybuf)(struct file *file, void *fh, struct v4l2_buffer *b); | ||
194 | int (*vidioc_qbuf) (struct file *file, void *fh, struct v4l2_buffer *b); | ||
195 | int (*vidioc_dqbuf) (struct file *file, void *fh, struct v4l2_buffer *b); | ||
196 | |||
197 | |||
198 | int (*vidioc_overlay) (struct file *file, void *fh, unsigned int i); | ||
199 | #ifdef HAVE_V4L1 | ||
200 | /* buffer type is struct vidio_mbuf * */ | ||
201 | int (*vidiocgmbuf) (struct file *file, void *fh, struct video_mbuf *p); | ||
202 | #endif | ||
203 | int (*vidioc_g_fbuf) (struct file *file, void *fh, | ||
204 | struct v4l2_framebuffer *a); | ||
205 | int (*vidioc_s_fbuf) (struct file *file, void *fh, | ||
206 | struct v4l2_framebuffer *a); | ||
207 | |||
208 | /* Stream on/off */ | ||
209 | int (*vidioc_streamon) (struct file *file, void *fh, enum v4l2_buf_type i); | ||
210 | int (*vidioc_streamoff)(struct file *file, void *fh, enum v4l2_buf_type i); | ||
211 | |||
212 | /* Standard handling | ||
213 | G_STD and ENUMSTD are handled by videodev.c | ||
214 | */ | ||
215 | int (*vidioc_s_std) (struct file *file, void *fh, v4l2_std_id a); | ||
216 | int (*vidioc_querystd) (struct file *file, void *fh, v4l2_std_id *a); | ||
217 | |||
218 | /* Input handling */ | ||
219 | int (*vidioc_enum_input)(struct file *file, void *fh, | ||
220 | struct v4l2_input *inp); | ||
221 | int (*vidioc_g_input) (struct file *file, void *fh, unsigned int *i); | ||
222 | int (*vidioc_s_input) (struct file *file, void *fh, unsigned int i); | ||
223 | |||
224 | /* Output handling */ | ||
225 | int (*vidioc_enumoutput) (struct file *file, void *fh, | ||
226 | struct v4l2_output *a); | ||
227 | int (*vidioc_g_output) (struct file *file, void *fh, unsigned int *i); | ||
228 | int (*vidioc_s_output) (struct file *file, void *fh, unsigned int i); | ||
229 | |||
230 | /* Control handling */ | ||
231 | int (*vidioc_queryctrl) (struct file *file, void *fh, | ||
232 | struct v4l2_queryctrl *a); | ||
233 | int (*vidioc_g_ctrl) (struct file *file, void *fh, | ||
234 | struct v4l2_control *a); | ||
235 | int (*vidioc_s_ctrl) (struct file *file, void *fh, | ||
236 | struct v4l2_control *a); | ||
237 | int (*vidioc_querymenu) (struct file *file, void *fh, | ||
238 | struct v4l2_querymenu *a); | ||
239 | |||
240 | /* Audio ioctls */ | ||
241 | int (*vidioc_enumaudio) (struct file *file, void *fh, | ||
242 | struct v4l2_audio *a); | ||
243 | int (*vidioc_g_audio) (struct file *file, void *fh, | ||
244 | struct v4l2_audio *a); | ||
245 | int (*vidioc_s_audio) (struct file *file, void *fh, | ||
246 | struct v4l2_audio *a); | ||
247 | |||
248 | /* Audio out ioctls */ | ||
249 | int (*vidioc_enumaudout) (struct file *file, void *fh, | ||
250 | struct v4l2_audioout *a); | ||
251 | int (*vidioc_g_audout) (struct file *file, void *fh, | ||
252 | struct v4l2_audioout *a); | ||
253 | int (*vidioc_s_audout) (struct file *file, void *fh, | ||
254 | struct v4l2_audioout *a); | ||
255 | int (*vidioc_g_modulator) (struct file *file, void *fh, | ||
256 | struct v4l2_modulator *a); | ||
257 | int (*vidioc_s_modulator) (struct file *file, void *fh, | ||
258 | struct v4l2_modulator *a); | ||
259 | /* Crop ioctls */ | ||
260 | int (*vidioc_cropcap) (struct file *file, void *fh, | ||
261 | struct v4l2_cropcap *a); | ||
262 | int (*vidioc_g_crop) (struct file *file, void *fh, | ||
263 | struct v4l2_crop *a); | ||
264 | int (*vidioc_s_crop) (struct file *file, void *fh, | ||
265 | struct v4l2_crop *a); | ||
266 | /* Compression ioctls */ | ||
267 | int (*vidioc_g_mpegcomp) (struct file *file, void *fh, | ||
268 | struct v4l2_mpeg_compression *a); | ||
269 | int (*vidioc_s_mpegcomp) (struct file *file, void *fh, | ||
270 | struct v4l2_mpeg_compression *a); | ||
271 | int (*vidioc_g_jpegcomp) (struct file *file, void *fh, | ||
272 | struct v4l2_jpegcompression *a); | ||
273 | int (*vidioc_s_jpegcomp) (struct file *file, void *fh, | ||
274 | struct v4l2_jpegcompression *a); | ||
275 | |||
276 | /* Stream type-dependent parameter ioctls */ | ||
277 | int (*vidioc_g_parm) (struct file *file, void *fh, | ||
278 | struct v4l2_streamparm *a); | ||
279 | int (*vidioc_s_parm) (struct file *file, void *fh, | ||
280 | struct v4l2_streamparm *a); | ||
281 | |||
282 | /* Tuner ioctls */ | ||
283 | int (*vidioc_g_tuner) (struct file *file, void *fh, | ||
284 | struct v4l2_tuner *a); | ||
285 | int (*vidioc_s_tuner) (struct file *file, void *fh, | ||
286 | struct v4l2_tuner *a); | ||
287 | int (*vidioc_g_frequency) (struct file *file, void *fh, | ||
288 | struct v4l2_frequency *a); | ||
289 | int (*vidioc_s_frequency) (struct file *file, void *fh, | ||
290 | struct v4l2_frequency *a); | ||
291 | |||
292 | /* Sliced VBI cap */ | ||
293 | int (*vidioc_g_sliced_vbi_cap) (struct file *file, void *fh, | ||
294 | struct v4l2_sliced_vbi_cap *a); | ||
295 | |||
296 | /* Log status ioctl */ | ||
297 | int (*vidioc_log_status) (struct file *file, void *fh); | ||
298 | |||
299 | |||
300 | #if OBSOLETE_OWNER /* to be removed soon */ | ||
301 | /* obsolete -- fops->owner is used instead */ | ||
302 | struct module *owner; | ||
303 | /* dev->driver_data will be used instead some day. | ||
304 | * Use the video_{get|set}_drvdata() helper functions, | ||
305 | * so the switch over will be transparent for you. | ||
306 | * Or use {pci|usb}_{get|set}_drvdata() directly. */ | ||
307 | void *priv; | ||
308 | #endif | ||
309 | |||
310 | /* for videodev.c intenal usage -- please don't touch */ | ||
311 | int users; /* video_exclusive_{open|close} ... */ | ||
312 | struct mutex lock; /* ... helper function uses these */ | ||
313 | char devfs_name[64]; /* devfs */ | ||
314 | struct class_device class_dev; /* sysfs */ | ||
315 | }; | ||
316 | |||
317 | /* Version 2 functions */ | ||
318 | extern int video_register_device(struct video_device *vfd, int type, int nr); | ||
319 | void video_unregister_device(struct video_device *); | ||
320 | extern int video_ioctl2(struct inode *inode, struct file *file, | ||
321 | unsigned int cmd, unsigned long arg); | ||
322 | |||
323 | /* helper functions to alloc / release struct video_device, the | ||
324 | later can be used for video_device->release() */ | ||
325 | struct video_device *video_device_alloc(void); | ||
326 | void video_device_release(struct video_device *vfd); | ||
327 | |||
328 | /* Include support for obsoleted stuff */ | ||
329 | extern int video_usercopy(struct inode *inode, struct file *file, | ||
330 | unsigned int cmd, unsigned long arg, | ||
331 | int (*func)(struct inode *inode, struct file *file, | ||
332 | unsigned int cmd, void *arg)); | ||
333 | |||
334 | |||
335 | #ifdef HAVE_V4L1 | ||
336 | #include <linux/mm.h> | ||
337 | |||
338 | extern struct video_device* video_devdata(struct file*); | ||
339 | |||
340 | #define to_video_device(cd) container_of(cd, struct video_device, class_dev) | ||
341 | static inline void | ||
342 | video_device_create_file(struct video_device *vfd, | ||
343 | struct class_device_attribute *attr) | ||
344 | { | ||
345 | class_device_create_file(&vfd->class_dev, attr); | ||
346 | } | ||
347 | static inline void | ||
348 | video_device_remove_file(struct video_device *vfd, | ||
349 | struct class_device_attribute *attr) | ||
350 | { | ||
351 | class_device_remove_file(&vfd->class_dev, attr); | ||
352 | } | ||
353 | |||
354 | #if OBSOLETE_OWNER /* to be removed soon */ | ||
355 | /* helper functions to access driver private data. */ | ||
356 | static inline void *video_get_drvdata(struct video_device *dev) | ||
357 | { | ||
358 | return dev->priv; | ||
359 | } | ||
360 | |||
361 | static inline void video_set_drvdata(struct video_device *dev, void *data) | ||
362 | { | ||
363 | dev->priv = data; | ||
364 | } | ||
365 | #endif | ||
366 | |||
367 | extern int video_exclusive_open(struct inode *inode, struct file *file); | ||
368 | extern int video_exclusive_release(struct inode *inode, struct file *file); | ||
369 | #endif /* HAVE_V4L1 */ | ||
370 | |||
371 | #endif /* _V4L2_DEV_H */ | ||