xref: /openbmc/linux/include/media/v4l2-dev.h (revision 545e4006)
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 #define OBSOLETE_DEVDATA 1 /* to be removed soon */
14 
15 #include <linux/poll.h>
16 #include <linux/fs.h>
17 #include <linux/device.h>
18 #include <linux/mutex.h>
19 #include <linux/compiler.h> /* need __user */
20 #ifdef CONFIG_VIDEO_V4L1_COMPAT
21 #include <linux/videodev.h>
22 #else
23 #include <linux/videodev2.h>
24 #endif
25 
26 #define VIDEO_MAJOR	81
27 /* Minor device allocation */
28 #define MINOR_VFL_TYPE_GRABBER_MIN   0
29 #define MINOR_VFL_TYPE_GRABBER_MAX  63
30 #define MINOR_VFL_TYPE_RADIO_MIN    64
31 #define MINOR_VFL_TYPE_RADIO_MAX   127
32 #define MINOR_VFL_TYPE_VTX_MIN     192
33 #define MINOR_VFL_TYPE_VTX_MAX     223
34 #define MINOR_VFL_TYPE_VBI_MIN     224
35 #define MINOR_VFL_TYPE_VBI_MAX     255
36 
37 #define VFL_TYPE_GRABBER	0
38 #define VFL_TYPE_VBI		1
39 #define VFL_TYPE_RADIO		2
40 #define VFL_TYPE_VTX		3
41 
42 /*  Video standard functions  */
43 extern const char *v4l2_norm_to_name(v4l2_std_id id);
44 extern int v4l2_video_std_construct(struct v4l2_standard *vs,
45 				    int id, const char *name);
46 /* Prints the ioctl in a human-readable format */
47 extern void v4l_printk_ioctl(unsigned int cmd);
48 
49 /* prority handling */
50 struct v4l2_prio_state {
51 	atomic_t prios[4];
52 };
53 int v4l2_prio_init(struct v4l2_prio_state *global);
54 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
55 		     enum v4l2_priority new);
56 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
57 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
58 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
59 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
60 
61 /* names for fancy debug output */
62 extern const char *v4l2_field_names[];
63 extern const char *v4l2_type_names[];
64 
65 /*  Compatibility layer interface  --  v4l1-compat module */
66 typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
67 			   unsigned int cmd, void *arg);
68 #ifdef CONFIG_VIDEO_V4L1_COMPAT
69 int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
70 			       int cmd, void *arg, v4l2_kioctl driver_ioctl);
71 #else
72 #define v4l_compat_translate_ioctl(inode,file,cmd,arg,ioctl) -EINVAL
73 #endif
74 
75 /* 32 Bits compatibility layer for 64 bits processors */
76 extern long v4l_compat_ioctl32(struct file *file, unsigned int cmd,
77 				unsigned long arg);
78 
79 /*
80  * Newer version of video_device, handled by videodev2.c
81  * 	This version moves redundant code from video device code to
82  *	the common handler
83  */
84 
85 struct video_device
86 {
87 	/* device ops */
88 	const struct file_operations *fops;
89 
90 	/* sysfs */
91 	struct device class_dev;	/* v4l device */
92 	struct device *dev;		/* device parent */
93 
94 	/* device info */
95 	char name[32];
96 	int type;       /* v4l1 */
97 	int type2;      /* v4l2 */
98 	int minor;
99 	/* attribute to diferentiate multiple indexs on one physical device */
100 	int index;
101 
102 	int debug;	/* Activates debug level*/
103 
104 	/* Video standard vars */
105 	v4l2_std_id tvnorms;		/* Supported tv norms */
106 	v4l2_std_id current_norm;	/* Current tvnorm */
107 
108 	/* callbacks */
109 	void (*release)(struct video_device *vfd);
110 
111 	/* ioctl callbacks */
112 
113 	/* VIDIOC_QUERYCAP handler */
114 	int (*vidioc_querycap)(struct file *file, void *fh, struct v4l2_capability *cap);
115 
116 	/* Priority handling */
117 	int (*vidioc_g_priority)   (struct file *file, void *fh,
118 				    enum v4l2_priority *p);
119 	int (*vidioc_s_priority)   (struct file *file, void *fh,
120 				    enum v4l2_priority p);
121 
122 	/* VIDIOC_ENUM_FMT handlers */
123 	int (*vidioc_enum_fmt_vid_cap)     (struct file *file, void *fh,
124 					    struct v4l2_fmtdesc *f);
125 	int (*vidioc_enum_fmt_vid_overlay) (struct file *file, void *fh,
126 					    struct v4l2_fmtdesc *f);
127 	int (*vidioc_enum_fmt_vid_out)     (struct file *file, void *fh,
128 					    struct v4l2_fmtdesc *f);
129 #if 1
130 	/* deprecated, will be removed in 2.6.28 */
131 	int (*vidioc_enum_fmt_vbi_cap)     (struct file *file, void *fh,
132 					    struct v4l2_fmtdesc *f);
133 #endif
134 	int (*vidioc_enum_fmt_type_private)(struct file *file, void *fh,
135 					    struct v4l2_fmtdesc *f);
136 
137 	/* VIDIOC_G_FMT handlers */
138 	int (*vidioc_g_fmt_vid_cap)    (struct file *file, void *fh,
139 					struct v4l2_format *f);
140 	int (*vidioc_g_fmt_vid_overlay)(struct file *file, void *fh,
141 					struct v4l2_format *f);
142 	int (*vidioc_g_fmt_vid_out)    (struct file *file, void *fh,
143 					struct v4l2_format *f);
144 	int (*vidioc_g_fmt_vid_out_overlay)(struct file *file, void *fh,
145 					struct v4l2_format *f);
146 	int (*vidioc_g_fmt_vbi_cap)    (struct file *file, void *fh,
147 					struct v4l2_format *f);
148 	int (*vidioc_g_fmt_vbi_out)    (struct file *file, void *fh,
149 					struct v4l2_format *f);
150 	int (*vidioc_g_fmt_sliced_vbi_cap)(struct file *file, void *fh,
151 					struct v4l2_format *f);
152 	int (*vidioc_g_fmt_sliced_vbi_out)(struct file *file, void *fh,
153 					struct v4l2_format *f);
154 	int (*vidioc_g_fmt_type_private)(struct file *file, void *fh,
155 					struct v4l2_format *f);
156 
157 	/* VIDIOC_S_FMT handlers */
158 	int (*vidioc_s_fmt_vid_cap)    (struct file *file, void *fh,
159 					struct v4l2_format *f);
160 	int (*vidioc_s_fmt_vid_overlay)(struct file *file, void *fh,
161 					struct v4l2_format *f);
162 	int (*vidioc_s_fmt_vid_out)    (struct file *file, void *fh,
163 					struct v4l2_format *f);
164 	int (*vidioc_s_fmt_vid_out_overlay)(struct file *file, void *fh,
165 					struct v4l2_format *f);
166 	int (*vidioc_s_fmt_vbi_cap)    (struct file *file, void *fh,
167 					struct v4l2_format *f);
168 	int (*vidioc_s_fmt_vbi_out)    (struct file *file, void *fh,
169 					struct v4l2_format *f);
170 	int (*vidioc_s_fmt_sliced_vbi_cap)(struct file *file, void *fh,
171 					struct v4l2_format *f);
172 	int (*vidioc_s_fmt_sliced_vbi_out)(struct file *file, void *fh,
173 					struct v4l2_format *f);
174 	int (*vidioc_s_fmt_type_private)(struct file *file, void *fh,
175 					struct v4l2_format *f);
176 
177 	/* VIDIOC_TRY_FMT handlers */
178 	int (*vidioc_try_fmt_vid_cap)    (struct file *file, void *fh,
179 					  struct v4l2_format *f);
180 	int (*vidioc_try_fmt_vid_overlay)(struct file *file, void *fh,
181 					  struct v4l2_format *f);
182 	int (*vidioc_try_fmt_vid_out)    (struct file *file, void *fh,
183 					  struct v4l2_format *f);
184 	int (*vidioc_try_fmt_vid_out_overlay)(struct file *file, void *fh,
185 					  struct v4l2_format *f);
186 	int (*vidioc_try_fmt_vbi_cap)    (struct file *file, void *fh,
187 					  struct v4l2_format *f);
188 	int (*vidioc_try_fmt_vbi_out)    (struct file *file, void *fh,
189 					  struct v4l2_format *f);
190 	int (*vidioc_try_fmt_sliced_vbi_cap)(struct file *file, void *fh,
191 					  struct v4l2_format *f);
192 	int (*vidioc_try_fmt_sliced_vbi_out)(struct file *file, void *fh,
193 					  struct v4l2_format *f);
194 	int (*vidioc_try_fmt_type_private)(struct file *file, void *fh,
195 					  struct v4l2_format *f);
196 
197 	/* Buffer handlers */
198 	int (*vidioc_reqbufs) (struct file *file, void *fh, struct v4l2_requestbuffers *b);
199 	int (*vidioc_querybuf)(struct file *file, void *fh, struct v4l2_buffer *b);
200 	int (*vidioc_qbuf)    (struct file *file, void *fh, struct v4l2_buffer *b);
201 	int (*vidioc_dqbuf)   (struct file *file, void *fh, struct v4l2_buffer *b);
202 
203 
204 	int (*vidioc_overlay) (struct file *file, void *fh, unsigned int i);
205 #ifdef CONFIG_VIDEO_V4L1_COMPAT
206 			/* buffer type is struct vidio_mbuf * */
207 	int (*vidiocgmbuf)  (struct file *file, void *fh, struct video_mbuf *p);
208 #endif
209 	int (*vidioc_g_fbuf)   (struct file *file, void *fh,
210 				struct v4l2_framebuffer *a);
211 	int (*vidioc_s_fbuf)   (struct file *file, void *fh,
212 				struct v4l2_framebuffer *a);
213 
214 		/* Stream on/off */
215 	int (*vidioc_streamon) (struct file *file, void *fh, enum v4l2_buf_type i);
216 	int (*vidioc_streamoff)(struct file *file, void *fh, enum v4l2_buf_type i);
217 
218 		/* Standard handling
219 			ENUMSTD is handled by videodev.c
220 		 */
221 	int (*vidioc_g_std) (struct file *file, void *fh, v4l2_std_id *norm);
222 	int (*vidioc_s_std) (struct file *file, void *fh, v4l2_std_id *norm);
223 	int (*vidioc_querystd) (struct file *file, void *fh, v4l2_std_id *a);
224 
225 		/* Input handling */
226 	int (*vidioc_enum_input)(struct file *file, void *fh,
227 				 struct v4l2_input *inp);
228 	int (*vidioc_g_input)   (struct file *file, void *fh, unsigned int *i);
229 	int (*vidioc_s_input)   (struct file *file, void *fh, unsigned int i);
230 
231 		/* Output handling */
232 	int (*vidioc_enum_output) (struct file *file, void *fh,
233 				  struct v4l2_output *a);
234 	int (*vidioc_g_output)   (struct file *file, void *fh, unsigned int *i);
235 	int (*vidioc_s_output)   (struct file *file, void *fh, unsigned int i);
236 
237 		/* Control handling */
238 	int (*vidioc_queryctrl)        (struct file *file, void *fh,
239 					struct v4l2_queryctrl *a);
240 	int (*vidioc_g_ctrl)           (struct file *file, void *fh,
241 					struct v4l2_control *a);
242 	int (*vidioc_s_ctrl)           (struct file *file, void *fh,
243 					struct v4l2_control *a);
244 	int (*vidioc_g_ext_ctrls)      (struct file *file, void *fh,
245 					struct v4l2_ext_controls *a);
246 	int (*vidioc_s_ext_ctrls)      (struct file *file, void *fh,
247 					struct v4l2_ext_controls *a);
248 	int (*vidioc_try_ext_ctrls)    (struct file *file, void *fh,
249 					struct v4l2_ext_controls *a);
250 	int (*vidioc_querymenu)        (struct file *file, void *fh,
251 					struct v4l2_querymenu *a);
252 
253 	/* Audio ioctls */
254 	int (*vidioc_enumaudio)        (struct file *file, void *fh,
255 					struct v4l2_audio *a);
256 	int (*vidioc_g_audio)          (struct file *file, void *fh,
257 					struct v4l2_audio *a);
258 	int (*vidioc_s_audio)          (struct file *file, void *fh,
259 					struct v4l2_audio *a);
260 
261 	/* Audio out ioctls */
262 	int (*vidioc_enumaudout)       (struct file *file, void *fh,
263 					struct v4l2_audioout *a);
264 	int (*vidioc_g_audout)         (struct file *file, void *fh,
265 					struct v4l2_audioout *a);
266 	int (*vidioc_s_audout)         (struct file *file, void *fh,
267 					struct v4l2_audioout *a);
268 	int (*vidioc_g_modulator)      (struct file *file, void *fh,
269 					struct v4l2_modulator *a);
270 	int (*vidioc_s_modulator)      (struct file *file, void *fh,
271 					struct v4l2_modulator *a);
272 	/* Crop ioctls */
273 	int (*vidioc_cropcap)          (struct file *file, void *fh,
274 					struct v4l2_cropcap *a);
275 	int (*vidioc_g_crop)           (struct file *file, void *fh,
276 					struct v4l2_crop *a);
277 	int (*vidioc_s_crop)           (struct file *file, void *fh,
278 					struct v4l2_crop *a);
279 	/* Compression ioctls */
280 	int (*vidioc_g_jpegcomp)       (struct file *file, void *fh,
281 					struct v4l2_jpegcompression *a);
282 	int (*vidioc_s_jpegcomp)       (struct file *file, void *fh,
283 					struct v4l2_jpegcompression *a);
284 	int (*vidioc_g_enc_index)      (struct file *file, void *fh,
285 					struct v4l2_enc_idx *a);
286 	int (*vidioc_encoder_cmd)      (struct file *file, void *fh,
287 					struct v4l2_encoder_cmd *a);
288 	int (*vidioc_try_encoder_cmd)  (struct file *file, void *fh,
289 					struct v4l2_encoder_cmd *a);
290 
291 	/* Stream type-dependent parameter ioctls */
292 	int (*vidioc_g_parm)           (struct file *file, void *fh,
293 					struct v4l2_streamparm *a);
294 	int (*vidioc_s_parm)           (struct file *file, void *fh,
295 					struct v4l2_streamparm *a);
296 
297 	/* Tuner ioctls */
298 	int (*vidioc_g_tuner)          (struct file *file, void *fh,
299 					struct v4l2_tuner *a);
300 	int (*vidioc_s_tuner)          (struct file *file, void *fh,
301 					struct v4l2_tuner *a);
302 	int (*vidioc_g_frequency)      (struct file *file, void *fh,
303 					struct v4l2_frequency *a);
304 	int (*vidioc_s_frequency)      (struct file *file, void *fh,
305 					struct v4l2_frequency *a);
306 
307 	/* Sliced VBI cap */
308 	int (*vidioc_g_sliced_vbi_cap) (struct file *file, void *fh,
309 					struct v4l2_sliced_vbi_cap *a);
310 
311 	/* Log status ioctl */
312 	int (*vidioc_log_status)       (struct file *file, void *fh);
313 
314 	int (*vidioc_s_hw_freq_seek)   (struct file *file, void *fh,
315 					struct v4l2_hw_freq_seek *a);
316 
317 	/* Debugging ioctls */
318 #ifdef CONFIG_VIDEO_ADV_DEBUG
319 	int (*vidioc_g_register)       (struct file *file, void *fh,
320 					struct v4l2_register *reg);
321 	int (*vidioc_s_register)       (struct file *file, void *fh,
322 					struct v4l2_register *reg);
323 #endif
324 	int (*vidioc_g_chip_ident)     (struct file *file, void *fh,
325 					struct v4l2_chip_ident *chip);
326 
327 	/* For other private ioctls */
328 	int (*vidioc_default)	       (struct file *file, void *fh,
329 					int cmd, void *arg);
330 
331 
332 #ifdef OBSOLETE_OWNER /* to be removed soon */
333 /* obsolete -- fops->owner is used instead */
334 struct module *owner;
335 /* dev->driver_data will be used instead some day.
336 	* Use the video_{get|set}_drvdata() helper functions,
337 	* so the switch over will be transparent for you.
338 	* Or use {pci|usb}_{get|set}_drvdata() directly. */
339 void *priv;
340 #endif
341 
342 	/* for videodev.c intenal usage -- please don't touch */
343 	int users;                     /* video_exclusive_{open|close} ... */
344 	struct mutex lock;             /* ... helper function uses these   */
345 };
346 
347 /* Class-dev to video-device */
348 #define to_video_device(cd) container_of(cd, struct video_device, class_dev)
349 
350 /* Version 2 functions */
351 extern int video_register_device(struct video_device *vfd, int type, int nr);
352 int video_register_device_index(struct video_device *vfd, int type, int nr,
353 					int index);
354 void video_unregister_device(struct video_device *);
355 extern int video_ioctl2(struct inode *inode, struct file *file,
356 			  unsigned int cmd, unsigned long arg);
357 
358 /* helper functions to alloc / release struct video_device, the
359    later can be used for video_device->release() */
360 struct video_device *video_device_alloc(void);
361 void video_device_release(struct video_device *vfd);
362 
363 /* Include support for obsoleted stuff */
364 extern int video_usercopy(struct inode *inode, struct file *file,
365 			  unsigned int cmd, unsigned long arg,
366 			  int (*func)(struct inode *inode, struct file *file,
367 				      unsigned int cmd, void *arg));
368 
369 #ifdef CONFIG_VIDEO_V4L1_COMPAT
370 #include <linux/mm.h>
371 
372 static inline int __must_check
373 video_device_create_file(struct video_device *vfd,
374 			 struct device_attribute *attr)
375 {
376 	int ret = device_create_file(&vfd->class_dev, attr);
377 	if (ret < 0)
378 		printk(KERN_WARNING "%s error: %d\n", __func__, ret);
379 	return ret;
380 }
381 static inline void
382 video_device_remove_file(struct video_device *vfd,
383 			 struct device_attribute *attr)
384 {
385 	device_remove_file(&vfd->class_dev, attr);
386 }
387 
388 #endif /* CONFIG_VIDEO_V4L1_COMPAT */
389 
390 #ifdef OBSOLETE_OWNER /* to be removed soon */
391 /* helper functions to access driver private data. */
392 static inline void *video_get_drvdata(struct video_device *dev)
393 {
394 	return dev->priv;
395 }
396 
397 static inline void video_set_drvdata(struct video_device *dev, void *data)
398 {
399 	dev->priv = data;
400 }
401 
402 #endif
403 
404 #ifdef OBSOLETE_DEVDATA /* to be removed soon */
405 /* Obsolete stuff - Still needed for radio devices and obsolete drivers */
406 extern struct video_device* video_devdata(struct file*);
407 extern int video_exclusive_open(struct inode *inode, struct file *file);
408 extern int video_exclusive_release(struct inode *inode, struct file *file);
409 #endif
410 
411 #endif /* _V4L2_DEV_H */
412