xref: /linux/include/media/v4l2-ioctl.h (revision b43ab901d671e3e3cad425ea5e9a3c74e266dcdd)
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_IOCTL_H
10 #define _V4L2_IOCTL_H
11 
12 #include <linux/poll.h>
13 #include <linux/fs.h>
14 #include <linux/device.h>
15 #include <linux/mutex.h>
16 #include <linux/compiler.h> /* need __user */
17 #include <linux/videodev2.h>
18 
19 struct v4l2_fh;
20 
21 struct v4l2_ioctl_ops {
22 	/* ioctl callbacks */
23 
24 	/* VIDIOC_QUERYCAP handler */
25 	int (*vidioc_querycap)(struct file *file, void *fh, struct v4l2_capability *cap);
26 
27 	/* Priority handling */
28 	int (*vidioc_g_priority)   (struct file *file, void *fh,
29 				    enum v4l2_priority *p);
30 	int (*vidioc_s_priority)   (struct file *file, void *fh,
31 				    enum v4l2_priority p);
32 
33 	/* VIDIOC_ENUM_FMT handlers */
34 	int (*vidioc_enum_fmt_vid_cap)     (struct file *file, void *fh,
35 					    struct v4l2_fmtdesc *f);
36 	int (*vidioc_enum_fmt_vid_overlay) (struct file *file, void *fh,
37 					    struct v4l2_fmtdesc *f);
38 	int (*vidioc_enum_fmt_vid_out)     (struct file *file, void *fh,
39 					    struct v4l2_fmtdesc *f);
40 	int (*vidioc_enum_fmt_vid_cap_mplane)(struct file *file, void *fh,
41 					      struct v4l2_fmtdesc *f);
42 	int (*vidioc_enum_fmt_vid_out_mplane)(struct file *file, void *fh,
43 					      struct v4l2_fmtdesc *f);
44 	int (*vidioc_enum_fmt_type_private)(struct file *file, void *fh,
45 					    struct v4l2_fmtdesc *f);
46 
47 	/* VIDIOC_G_FMT handlers */
48 	int (*vidioc_g_fmt_vid_cap)    (struct file *file, void *fh,
49 					struct v4l2_format *f);
50 	int (*vidioc_g_fmt_vid_overlay)(struct file *file, void *fh,
51 					struct v4l2_format *f);
52 	int (*vidioc_g_fmt_vid_out)    (struct file *file, void *fh,
53 					struct v4l2_format *f);
54 	int (*vidioc_g_fmt_vid_out_overlay)(struct file *file, void *fh,
55 					struct v4l2_format *f);
56 	int (*vidioc_g_fmt_vbi_cap)    (struct file *file, void *fh,
57 					struct v4l2_format *f);
58 	int (*vidioc_g_fmt_vbi_out)    (struct file *file, void *fh,
59 					struct v4l2_format *f);
60 	int (*vidioc_g_fmt_sliced_vbi_cap)(struct file *file, void *fh,
61 					struct v4l2_format *f);
62 	int (*vidioc_g_fmt_sliced_vbi_out)(struct file *file, void *fh,
63 					struct v4l2_format *f);
64 	int (*vidioc_g_fmt_vid_cap_mplane)(struct file *file, void *fh,
65 					   struct v4l2_format *f);
66 	int (*vidioc_g_fmt_vid_out_mplane)(struct file *file, void *fh,
67 					   struct v4l2_format *f);
68 	int (*vidioc_g_fmt_type_private)(struct file *file, void *fh,
69 					struct v4l2_format *f);
70 
71 	/* VIDIOC_S_FMT handlers */
72 	int (*vidioc_s_fmt_vid_cap)    (struct file *file, void *fh,
73 					struct v4l2_format *f);
74 	int (*vidioc_s_fmt_vid_overlay)(struct file *file, void *fh,
75 					struct v4l2_format *f);
76 	int (*vidioc_s_fmt_vid_out)    (struct file *file, void *fh,
77 					struct v4l2_format *f);
78 	int (*vidioc_s_fmt_vid_out_overlay)(struct file *file, void *fh,
79 					struct v4l2_format *f);
80 	int (*vidioc_s_fmt_vbi_cap)    (struct file *file, void *fh,
81 					struct v4l2_format *f);
82 	int (*vidioc_s_fmt_vbi_out)    (struct file *file, void *fh,
83 					struct v4l2_format *f);
84 	int (*vidioc_s_fmt_sliced_vbi_cap)(struct file *file, void *fh,
85 					struct v4l2_format *f);
86 	int (*vidioc_s_fmt_sliced_vbi_out)(struct file *file, void *fh,
87 					struct v4l2_format *f);
88 	int (*vidioc_s_fmt_vid_cap_mplane)(struct file *file, void *fh,
89 					   struct v4l2_format *f);
90 	int (*vidioc_s_fmt_vid_out_mplane)(struct file *file, void *fh,
91 					   struct v4l2_format *f);
92 	int (*vidioc_s_fmt_type_private)(struct file *file, void *fh,
93 					struct v4l2_format *f);
94 
95 	/* VIDIOC_TRY_FMT handlers */
96 	int (*vidioc_try_fmt_vid_cap)    (struct file *file, void *fh,
97 					  struct v4l2_format *f);
98 	int (*vidioc_try_fmt_vid_overlay)(struct file *file, void *fh,
99 					  struct v4l2_format *f);
100 	int (*vidioc_try_fmt_vid_out)    (struct file *file, void *fh,
101 					  struct v4l2_format *f);
102 	int (*vidioc_try_fmt_vid_out_overlay)(struct file *file, void *fh,
103 					  struct v4l2_format *f);
104 	int (*vidioc_try_fmt_vbi_cap)    (struct file *file, void *fh,
105 					  struct v4l2_format *f);
106 	int (*vidioc_try_fmt_vbi_out)    (struct file *file, void *fh,
107 					  struct v4l2_format *f);
108 	int (*vidioc_try_fmt_sliced_vbi_cap)(struct file *file, void *fh,
109 					  struct v4l2_format *f);
110 	int (*vidioc_try_fmt_sliced_vbi_out)(struct file *file, void *fh,
111 					  struct v4l2_format *f);
112 	int (*vidioc_try_fmt_vid_cap_mplane)(struct file *file, void *fh,
113 					     struct v4l2_format *f);
114 	int (*vidioc_try_fmt_vid_out_mplane)(struct file *file, void *fh,
115 					     struct v4l2_format *f);
116 	int (*vidioc_try_fmt_type_private)(struct file *file, void *fh,
117 					  struct v4l2_format *f);
118 
119 	/* Buffer handlers */
120 	int (*vidioc_reqbufs) (struct file *file, void *fh, struct v4l2_requestbuffers *b);
121 	int (*vidioc_querybuf)(struct file *file, void *fh, struct v4l2_buffer *b);
122 	int (*vidioc_qbuf)    (struct file *file, void *fh, struct v4l2_buffer *b);
123 	int (*vidioc_dqbuf)   (struct file *file, void *fh, struct v4l2_buffer *b);
124 
125 	int (*vidioc_create_bufs)(struct file *file, void *fh, struct v4l2_create_buffers *b);
126 	int (*vidioc_prepare_buf)(struct file *file, void *fh, struct v4l2_buffer *b);
127 
128 	int (*vidioc_overlay) (struct file *file, void *fh, unsigned int i);
129 	int (*vidioc_g_fbuf)   (struct file *file, void *fh,
130 				struct v4l2_framebuffer *a);
131 	int (*vidioc_s_fbuf)   (struct file *file, void *fh,
132 				struct v4l2_framebuffer *a);
133 
134 		/* Stream on/off */
135 	int (*vidioc_streamon) (struct file *file, void *fh, enum v4l2_buf_type i);
136 	int (*vidioc_streamoff)(struct file *file, void *fh, enum v4l2_buf_type i);
137 
138 		/* Standard handling
139 			ENUMSTD is handled by videodev.c
140 		 */
141 	int (*vidioc_g_std) (struct file *file, void *fh, v4l2_std_id *norm);
142 	int (*vidioc_s_std) (struct file *file, void *fh, v4l2_std_id *norm);
143 	int (*vidioc_querystd) (struct file *file, void *fh, v4l2_std_id *a);
144 
145 		/* Input handling */
146 	int (*vidioc_enum_input)(struct file *file, void *fh,
147 				 struct v4l2_input *inp);
148 	int (*vidioc_g_input)   (struct file *file, void *fh, unsigned int *i);
149 	int (*vidioc_s_input)   (struct file *file, void *fh, unsigned int i);
150 
151 		/* Output handling */
152 	int (*vidioc_enum_output) (struct file *file, void *fh,
153 				  struct v4l2_output *a);
154 	int (*vidioc_g_output)   (struct file *file, void *fh, unsigned int *i);
155 	int (*vidioc_s_output)   (struct file *file, void *fh, unsigned int i);
156 
157 		/* Control handling */
158 	int (*vidioc_queryctrl)        (struct file *file, void *fh,
159 					struct v4l2_queryctrl *a);
160 	int (*vidioc_g_ctrl)           (struct file *file, void *fh,
161 					struct v4l2_control *a);
162 	int (*vidioc_s_ctrl)           (struct file *file, void *fh,
163 					struct v4l2_control *a);
164 	int (*vidioc_g_ext_ctrls)      (struct file *file, void *fh,
165 					struct v4l2_ext_controls *a);
166 	int (*vidioc_s_ext_ctrls)      (struct file *file, void *fh,
167 					struct v4l2_ext_controls *a);
168 	int (*vidioc_try_ext_ctrls)    (struct file *file, void *fh,
169 					struct v4l2_ext_controls *a);
170 	int (*vidioc_querymenu)        (struct file *file, void *fh,
171 					struct v4l2_querymenu *a);
172 
173 	/* Audio ioctls */
174 	int (*vidioc_enumaudio)        (struct file *file, void *fh,
175 					struct v4l2_audio *a);
176 	int (*vidioc_g_audio)          (struct file *file, void *fh,
177 					struct v4l2_audio *a);
178 	int (*vidioc_s_audio)          (struct file *file, void *fh,
179 					struct v4l2_audio *a);
180 
181 	/* Audio out ioctls */
182 	int (*vidioc_enumaudout)       (struct file *file, void *fh,
183 					struct v4l2_audioout *a);
184 	int (*vidioc_g_audout)         (struct file *file, void *fh,
185 					struct v4l2_audioout *a);
186 	int (*vidioc_s_audout)         (struct file *file, void *fh,
187 					struct v4l2_audioout *a);
188 	int (*vidioc_g_modulator)      (struct file *file, void *fh,
189 					struct v4l2_modulator *a);
190 	int (*vidioc_s_modulator)      (struct file *file, void *fh,
191 					struct v4l2_modulator *a);
192 	/* Crop ioctls */
193 	int (*vidioc_cropcap)          (struct file *file, void *fh,
194 					struct v4l2_cropcap *a);
195 	int (*vidioc_g_crop)           (struct file *file, void *fh,
196 					struct v4l2_crop *a);
197 	int (*vidioc_s_crop)           (struct file *file, void *fh,
198 					struct v4l2_crop *a);
199 	int (*vidioc_g_selection)      (struct file *file, void *fh,
200 					struct v4l2_selection *s);
201 	int (*vidioc_s_selection)      (struct file *file, void *fh,
202 					struct v4l2_selection *s);
203 	/* Compression ioctls */
204 	int (*vidioc_g_jpegcomp)       (struct file *file, void *fh,
205 					struct v4l2_jpegcompression *a);
206 	int (*vidioc_s_jpegcomp)       (struct file *file, void *fh,
207 					struct v4l2_jpegcompression *a);
208 	int (*vidioc_g_enc_index)      (struct file *file, void *fh,
209 					struct v4l2_enc_idx *a);
210 	int (*vidioc_encoder_cmd)      (struct file *file, void *fh,
211 					struct v4l2_encoder_cmd *a);
212 	int (*vidioc_try_encoder_cmd)  (struct file *file, void *fh,
213 					struct v4l2_encoder_cmd *a);
214 
215 	/* Stream type-dependent parameter ioctls */
216 	int (*vidioc_g_parm)           (struct file *file, void *fh,
217 					struct v4l2_streamparm *a);
218 	int (*vidioc_s_parm)           (struct file *file, void *fh,
219 					struct v4l2_streamparm *a);
220 
221 	/* Tuner ioctls */
222 	int (*vidioc_g_tuner)          (struct file *file, void *fh,
223 					struct v4l2_tuner *a);
224 	int (*vidioc_s_tuner)          (struct file *file, void *fh,
225 					struct v4l2_tuner *a);
226 	int (*vidioc_g_frequency)      (struct file *file, void *fh,
227 					struct v4l2_frequency *a);
228 	int (*vidioc_s_frequency)      (struct file *file, void *fh,
229 					struct v4l2_frequency *a);
230 
231 	/* Sliced VBI cap */
232 	int (*vidioc_g_sliced_vbi_cap) (struct file *file, void *fh,
233 					struct v4l2_sliced_vbi_cap *a);
234 
235 	/* Log status ioctl */
236 	int (*vidioc_log_status)       (struct file *file, void *fh);
237 
238 	int (*vidioc_s_hw_freq_seek)   (struct file *file, void *fh,
239 					struct v4l2_hw_freq_seek *a);
240 
241 	/* Debugging ioctls */
242 #ifdef CONFIG_VIDEO_ADV_DEBUG
243 	int (*vidioc_g_register)       (struct file *file, void *fh,
244 					struct v4l2_dbg_register *reg);
245 	int (*vidioc_s_register)       (struct file *file, void *fh,
246 					struct v4l2_dbg_register *reg);
247 #endif
248 	int (*vidioc_g_chip_ident)     (struct file *file, void *fh,
249 					struct v4l2_dbg_chip_ident *chip);
250 
251 	int (*vidioc_enum_framesizes)   (struct file *file, void *fh,
252 					 struct v4l2_frmsizeenum *fsize);
253 
254 	int (*vidioc_enum_frameintervals) (struct file *file, void *fh,
255 					   struct v4l2_frmivalenum *fival);
256 
257 	/* DV Timings IOCTLs */
258 	int (*vidioc_enum_dv_presets) (struct file *file, void *fh,
259 				       struct v4l2_dv_enum_preset *preset);
260 
261 	int (*vidioc_s_dv_preset) (struct file *file, void *fh,
262 				   struct v4l2_dv_preset *preset);
263 	int (*vidioc_g_dv_preset) (struct file *file, void *fh,
264 				   struct v4l2_dv_preset *preset);
265 	int (*vidioc_query_dv_preset) (struct file *file, void *fh,
266 					struct v4l2_dv_preset *qpreset);
267 	int (*vidioc_s_dv_timings) (struct file *file, void *fh,
268 				    struct v4l2_dv_timings *timings);
269 	int (*vidioc_g_dv_timings) (struct file *file, void *fh,
270 				    struct v4l2_dv_timings *timings);
271 
272 	int (*vidioc_subscribe_event)  (struct v4l2_fh *fh,
273 					struct v4l2_event_subscription *sub);
274 	int (*vidioc_unsubscribe_event)(struct v4l2_fh *fh,
275 					struct v4l2_event_subscription *sub);
276 
277 	/* For other private ioctls */
278 	long (*vidioc_default)	       (struct file *file, void *fh,
279 					bool valid_prio, int cmd, void *arg);
280 };
281 
282 
283 /* v4l debugging and diagnostics */
284 
285 /* Debug bitmask flags to be used on V4L2 */
286 #define V4L2_DEBUG_IOCTL     0x01
287 #define V4L2_DEBUG_IOCTL_ARG 0x02
288 
289 /* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
290 #define v4l_print_ioctl(name, cmd)  		 \
291 	do {  					 \
292 		printk(KERN_DEBUG "%s: ", name); \
293 		v4l_printk_ioctl(cmd);		 \
294 	} while (0)
295 
296 /* Use this macro in I2C drivers where 'client' is the struct i2c_client
297    pointer */
298 #define v4l_i2c_print_ioctl(client, cmd) 		   \
299 	do {      					   \
300 		v4l_client_printk(KERN_DEBUG, client, ""); \
301 		v4l_printk_ioctl(cmd);			   \
302 	} while (0)
303 
304 /*  Video standard functions  */
305 extern const char *v4l2_norm_to_name(v4l2_std_id id);
306 extern void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod);
307 extern int v4l2_video_std_construct(struct v4l2_standard *vs,
308 				    int id, const char *name);
309 /* Prints the ioctl in a human-readable format */
310 extern void v4l_printk_ioctl(unsigned int cmd);
311 
312 /* names for fancy debug output */
313 extern const char *v4l2_field_names[];
314 extern const char *v4l2_type_names[];
315 
316 #ifdef CONFIG_COMPAT
317 /* 32 Bits compatibility layer for 64 bits processors */
318 extern long v4l2_compat_ioctl32(struct file *file, unsigned int cmd,
319 				unsigned long arg);
320 #endif
321 
322 typedef long (*v4l2_kioctl)(struct file *file,
323 		unsigned int cmd, void *arg);
324 
325 /* Include support for obsoleted stuff */
326 extern long video_usercopy(struct file *file, unsigned int cmd,
327 				unsigned long arg, v4l2_kioctl func);
328 
329 /* Standard handlers for V4L ioctl's */
330 extern long video_ioctl2(struct file *file,
331 			unsigned int cmd, unsigned long arg);
332 
333 #endif /* _V4L2_IOCTL_H */
334