Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
35ea11ff HV |
2 | /* |
3 | * Video capture interface for Linux version 2 | |
4 | * | |
5 | * A generic framework to process V4L2 ioctl commands. | |
6 | * | |
d9b01449 | 7 | * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1) |
32590819 | 8 | * Mauro Carvalho Chehab <mchehab@kernel.org> (version 2) |
35ea11ff HV |
9 | */ |
10 | ||
8dbcc3fa | 11 | #include <linux/compat.h> |
758d90e1 | 12 | #include <linux/mm.h> |
35ea11ff | 13 | #include <linux/module.h> |
5a0e3ad6 | 14 | #include <linux/slab.h> |
35ea11ff HV |
15 | #include <linux/types.h> |
16 | #include <linux/kernel.h> | |
ae6db515 | 17 | #include <linux/version.h> |
35ea11ff | 18 | |
a418bb3f | 19 | #include <linux/v4l2-subdev.h> |
35ea11ff HV |
20 | #include <linux/videodev2.h> |
21 | ||
f2d8b691 | 22 | #include <media/media-device.h> /* for media_set_bus_info() */ |
35ea11ff HV |
23 | #include <media/v4l2-common.h> |
24 | #include <media/v4l2-ioctl.h> | |
11bbc1ca | 25 | #include <media/v4l2-ctrls.h> |
d3d7c963 SA |
26 | #include <media/v4l2-fh.h> |
27 | #include <media/v4l2-event.h> | |
99cd47bc | 28 | #include <media/v4l2-device.h> |
c139990e | 29 | #include <media/videobuf2-v4l2.h> |
77fa4e07 | 30 | #include <media/v4l2-mc.h> |
d862bc08 | 31 | #include <media/v4l2-mem2mem.h> |
35ea11ff | 32 | |
aa32f4c0 HV |
33 | #include <trace/events/v4l2.h> |
34 | ||
73f35418 HV |
35 | #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls) |
36 | ||
35ea11ff HV |
37 | struct std_descr { |
38 | v4l2_std_id std; | |
39 | const char *descr; | |
40 | }; | |
41 | ||
42 | static const struct std_descr standards[] = { | |
6e6a8b5a MCC |
43 | { V4L2_STD_NTSC, "NTSC" }, |
44 | { V4L2_STD_NTSC_M, "NTSC-M" }, | |
45 | { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" }, | |
35ea11ff | 46 | { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" }, |
6e6a8b5a MCC |
47 | { V4L2_STD_NTSC_443, "NTSC-443" }, |
48 | { V4L2_STD_PAL, "PAL" }, | |
49 | { V4L2_STD_PAL_BG, "PAL-BG" }, | |
50 | { V4L2_STD_PAL_B, "PAL-B" }, | |
51 | { V4L2_STD_PAL_B1, "PAL-B1" }, | |
52 | { V4L2_STD_PAL_G, "PAL-G" }, | |
53 | { V4L2_STD_PAL_H, "PAL-H" }, | |
54 | { V4L2_STD_PAL_I, "PAL-I" }, | |
55 | { V4L2_STD_PAL_DK, "PAL-DK" }, | |
56 | { V4L2_STD_PAL_D, "PAL-D" }, | |
57 | { V4L2_STD_PAL_D1, "PAL-D1" }, | |
58 | { V4L2_STD_PAL_K, "PAL-K" }, | |
59 | { V4L2_STD_PAL_M, "PAL-M" }, | |
60 | { V4L2_STD_PAL_N, "PAL-N" }, | |
61 | { V4L2_STD_PAL_Nc, "PAL-Nc" }, | |
62 | { V4L2_STD_PAL_60, "PAL-60" }, | |
63 | { V4L2_STD_SECAM, "SECAM" }, | |
64 | { V4L2_STD_SECAM_B, "SECAM-B" }, | |
65 | { V4L2_STD_SECAM_G, "SECAM-G" }, | |
66 | { V4L2_STD_SECAM_H, "SECAM-H" }, | |
67 | { V4L2_STD_SECAM_DK, "SECAM-DK" }, | |
68 | { V4L2_STD_SECAM_D, "SECAM-D" }, | |
69 | { V4L2_STD_SECAM_K, "SECAM-K" }, | |
70 | { V4L2_STD_SECAM_K1, "SECAM-K1" }, | |
71 | { V4L2_STD_SECAM_L, "SECAM-L" }, | |
72 | { V4L2_STD_SECAM_LC, "SECAM-Lc" }, | |
73 | { 0, "Unknown" } | |
35ea11ff HV |
74 | }; |
75 | ||
76 | /* video4linux standard ID conversion to standard name | |
77 | */ | |
78 | const char *v4l2_norm_to_name(v4l2_std_id id) | |
79 | { | |
80 | u32 myid = id; | |
81 | int i; | |
82 | ||
83 | /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle | |
4faf7066 | 84 | 64 bit comparisons. So, on that architecture, with some gcc |
35ea11ff HV |
85 | variants, compilation fails. Currently, the max value is 30bit wide. |
86 | */ | |
87 | BUG_ON(myid != id); | |
88 | ||
89 | for (i = 0; standards[i].std; i++) | |
90 | if (myid == standards[i].std) | |
91 | break; | |
92 | return standards[i].descr; | |
93 | } | |
94 | EXPORT_SYMBOL(v4l2_norm_to_name); | |
95 | ||
51f0b8d5 TP |
96 | /* Returns frame period for the given standard */ |
97 | void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod) | |
98 | { | |
99 | if (id & V4L2_STD_525_60) { | |
100 | frameperiod->numerator = 1001; | |
101 | frameperiod->denominator = 30000; | |
102 | } else { | |
103 | frameperiod->numerator = 1; | |
104 | frameperiod->denominator = 25; | |
105 | } | |
106 | } | |
107 | EXPORT_SYMBOL(v4l2_video_std_frame_period); | |
108 | ||
35ea11ff HV |
109 | /* Fill in the fields of a v4l2_standard structure according to the |
110 | 'id' and 'transmission' parameters. Returns negative on error. */ | |
111 | int v4l2_video_std_construct(struct v4l2_standard *vs, | |
112 | int id, const char *name) | |
113 | { | |
51f0b8d5 TP |
114 | vs->id = id; |
115 | v4l2_video_std_frame_period(id, &vs->frameperiod); | |
116 | vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625; | |
c0decac1 | 117 | strscpy(vs->name, name, sizeof(vs->name)); |
35ea11ff HV |
118 | return 0; |
119 | } | |
120 | EXPORT_SYMBOL(v4l2_video_std_construct); | |
121 | ||
aa2f8871 NS |
122 | /* Fill in the fields of a v4l2_standard structure according to the |
123 | * 'id' and 'vs->index' parameters. Returns negative on error. */ | |
124 | int v4l_video_std_enumstd(struct v4l2_standard *vs, v4l2_std_id id) | |
125 | { | |
126 | v4l2_std_id curr_id = 0; | |
127 | unsigned int index = vs->index, i, j = 0; | |
128 | const char *descr = ""; | |
129 | ||
130 | /* Return -ENODATA if the id for the current input | |
131 | or output is 0, meaning that it doesn't support this API. */ | |
132 | if (id == 0) | |
133 | return -ENODATA; | |
134 | ||
135 | /* Return norm array in a canonical way */ | |
136 | for (i = 0; i <= index && id; i++) { | |
137 | /* last std value in the standards array is 0, so this | |
138 | while always ends there since (id & 0) == 0. */ | |
139 | while ((id & standards[j].std) != standards[j].std) | |
140 | j++; | |
141 | curr_id = standards[j].std; | |
142 | descr = standards[j].descr; | |
143 | j++; | |
144 | if (curr_id == 0) | |
145 | break; | |
146 | if (curr_id != V4L2_STD_PAL && | |
147 | curr_id != V4L2_STD_SECAM && | |
148 | curr_id != V4L2_STD_NTSC) | |
149 | id &= ~curr_id; | |
150 | } | |
151 | if (i <= index) | |
152 | return -EINVAL; | |
153 | ||
154 | v4l2_video_std_construct(vs, curr_id, descr); | |
155 | return 0; | |
156 | } | |
157 | ||
35ea11ff HV |
158 | /* ----------------------------------------------------------------- */ |
159 | /* some arrays for pretty-printing debug messages of enum types */ | |
160 | ||
161 | const char *v4l2_field_names[] = { | |
162 | [V4L2_FIELD_ANY] = "any", | |
163 | [V4L2_FIELD_NONE] = "none", | |
164 | [V4L2_FIELD_TOP] = "top", | |
165 | [V4L2_FIELD_BOTTOM] = "bottom", | |
166 | [V4L2_FIELD_INTERLACED] = "interlaced", | |
167 | [V4L2_FIELD_SEQ_TB] = "seq-tb", | |
168 | [V4L2_FIELD_SEQ_BT] = "seq-bt", | |
169 | [V4L2_FIELD_ALTERNATE] = "alternate", | |
170 | [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb", | |
171 | [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt", | |
172 | }; | |
173 | EXPORT_SYMBOL(v4l2_field_names); | |
174 | ||
175 | const char *v4l2_type_names[] = { | |
839aa56d | 176 | [0] = "0", |
35ea11ff HV |
177 | [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap", |
178 | [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay", | |
179 | [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out", | |
180 | [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", | |
181 | [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", | |
182 | [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap", | |
183 | [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out", | |
184 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay", | |
f8f3914c PO |
185 | [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane", |
186 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane", | |
6f3073b8 | 187 | [V4L2_BUF_TYPE_SDR_CAPTURE] = "sdr-cap", |
9effc72f | 188 | [V4L2_BUF_TYPE_SDR_OUTPUT] = "sdr-out", |
fb9ffa6a | 189 | [V4L2_BUF_TYPE_META_CAPTURE] = "meta-cap", |
72148d1a | 190 | [V4L2_BUF_TYPE_META_OUTPUT] = "meta-out", |
35ea11ff HV |
191 | }; |
192 | EXPORT_SYMBOL(v4l2_type_names); | |
193 | ||
194 | static const char *v4l2_memory_names[] = { | |
195 | [V4L2_MEMORY_MMAP] = "mmap", | |
196 | [V4L2_MEMORY_USERPTR] = "userptr", | |
197 | [V4L2_MEMORY_OVERLAY] = "overlay", | |
051c7788 | 198 | [V4L2_MEMORY_DMABUF] = "dmabuf", |
35ea11ff HV |
199 | }; |
200 | ||
d9246240 | 201 | #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown") |
35ea11ff HV |
202 | |
203 | /* ------------------------------------------------------------------ */ | |
204 | /* debug help functions */ | |
8ab75e3e | 205 | |
59076122 HV |
206 | static void v4l_print_querycap(const void *arg, bool write_only) |
207 | { | |
208 | const struct v4l2_capability *p = arg; | |
209 | ||
8720427c | 210 | pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, capabilities=0x%08x, device_caps=0x%08x\n", |
27d5a87c HV |
211 | (int)sizeof(p->driver), p->driver, |
212 | (int)sizeof(p->card), p->card, | |
213 | (int)sizeof(p->bus_info), p->bus_info, | |
59076122 HV |
214 | p->version, p->capabilities, p->device_caps); |
215 | } | |
216 | ||
217 | static void v4l_print_enuminput(const void *arg, bool write_only) | |
218 | { | |
219 | const struct v4l2_input *p = arg; | |
220 | ||
8720427c | 221 | pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, std=0x%08Lx, status=0x%x, capabilities=0x%x\n", |
27d5a87c HV |
222 | p->index, (int)sizeof(p->name), p->name, p->type, p->audioset, |
223 | p->tuner, (unsigned long long)p->std, p->status, | |
224 | p->capabilities); | |
59076122 HV |
225 | } |
226 | ||
227 | static void v4l_print_enumoutput(const void *arg, bool write_only) | |
228 | { | |
229 | const struct v4l2_output *p = arg; | |
230 | ||
8720427c | 231 | pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, modulator=%u, std=0x%08Lx, capabilities=0x%x\n", |
27d5a87c HV |
232 | p->index, (int)sizeof(p->name), p->name, p->type, p->audioset, |
233 | p->modulator, (unsigned long long)p->std, p->capabilities); | |
59076122 HV |
234 | } |
235 | ||
236 | static void v4l_print_audio(const void *arg, bool write_only) | |
237 | { | |
238 | const struct v4l2_audio *p = arg; | |
239 | ||
240 | if (write_only) | |
241 | pr_cont("index=%u, mode=0x%x\n", p->index, p->mode); | |
242 | else | |
27d5a87c HV |
243 | pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n", |
244 | p->index, (int)sizeof(p->name), p->name, | |
245 | p->capability, p->mode); | |
59076122 HV |
246 | } |
247 | ||
248 | static void v4l_print_audioout(const void *arg, bool write_only) | |
249 | { | |
250 | const struct v4l2_audioout *p = arg; | |
251 | ||
252 | if (write_only) | |
253 | pr_cont("index=%u\n", p->index); | |
254 | else | |
27d5a87c HV |
255 | pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n", |
256 | p->index, (int)sizeof(p->name), p->name, | |
257 | p->capability, p->mode); | |
59076122 HV |
258 | } |
259 | ||
be6c64e4 HV |
260 | static void v4l_print_fmtdesc(const void *arg, bool write_only) |
261 | { | |
262 | const struct v4l2_fmtdesc *p = arg; | |
263 | ||
e927e1e0 | 264 | pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%p4cc, mbus_code=0x%04x, description='%.*s'\n", |
be6c64e4 | 265 | p->index, prt_names(p->type, v4l2_type_names), |
e927e1e0 | 266 | p->flags, &p->pixelformat, p->mbus_code, |
27d5a87c | 267 | (int)sizeof(p->description), p->description); |
be6c64e4 HV |
268 | } |
269 | ||
270 | static void v4l_print_format(const void *arg, bool write_only) | |
271 | { | |
272 | const struct v4l2_format *p = arg; | |
273 | const struct v4l2_pix_format *pix; | |
274 | const struct v4l2_pix_format_mplane *mp; | |
275 | const struct v4l2_vbi_format *vbi; | |
276 | const struct v4l2_sliced_vbi_format *sliced; | |
277 | const struct v4l2_window *win; | |
fb9ffa6a | 278 | const struct v4l2_meta_format *meta; |
24bb30c8 | 279 | u32 pixelformat; |
7fe9f01c | 280 | u32 planes; |
be6c64e4 HV |
281 | unsigned i; |
282 | ||
283 | pr_cont("type=%s", prt_names(p->type, v4l2_type_names)); | |
284 | switch (p->type) { | |
285 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
286 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | |
287 | pix = &p->fmt.pix; | |
e927e1e0 SA |
288 | pr_cont(", width=%u, height=%u, pixelformat=%p4cc, field=%s, bytesperline=%u, sizeimage=%u, colorspace=%d, flags=0x%x, ycbcr_enc=%u, quantization=%u, xfer_func=%u\n", |
289 | pix->width, pix->height, &pix->pixelformat, | |
be6c64e4 HV |
290 | prt_names(pix->field, v4l2_field_names), |
291 | pix->bytesperline, pix->sizeimage, | |
736d96b5 | 292 | pix->colorspace, pix->flags, pix->ycbcr_enc, |
74fdcb2e | 293 | pix->quantization, pix->xfer_func); |
be6c64e4 HV |
294 | break; |
295 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: | |
296 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: | |
297 | mp = &p->fmt.pix_mp; | |
24bb30c8 | 298 | pixelformat = mp->pixelformat; |
e927e1e0 | 299 | pr_cont(", width=%u, height=%u, format=%p4cc, field=%s, colorspace=%d, num_planes=%u, flags=0x%x, ycbcr_enc=%u, quantization=%u, xfer_func=%u\n", |
24bb30c8 | 300 | mp->width, mp->height, &pixelformat, |
be6c64e4 | 301 | prt_names(mp->field, v4l2_field_names), |
736d96b5 | 302 | mp->colorspace, mp->num_planes, mp->flags, |
74fdcb2e | 303 | mp->ycbcr_enc, mp->quantization, mp->xfer_func); |
7fe9f01c SA |
304 | planes = min_t(u32, mp->num_planes, VIDEO_MAX_PLANES); |
305 | for (i = 0; i < planes; i++) | |
be6c64e4 HV |
306 | printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i, |
307 | mp->plane_fmt[i].bytesperline, | |
308 | mp->plane_fmt[i].sizeimage); | |
309 | break; | |
310 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
311 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
312 | win = &p->fmt.win; | |
11340fbd HV |
313 | pr_cont(", (%d,%d)/%ux%u, field=%s, chromakey=0x%08x, global_alpha=0x%02x\n", |
314 | win->w.left, win->w.top, win->w.width, win->w.height, | |
be6c64e4 | 315 | prt_names(win->field, v4l2_field_names), |
99ba0703 | 316 | win->chromakey, win->global_alpha); |
be6c64e4 HV |
317 | break; |
318 | case V4L2_BUF_TYPE_VBI_CAPTURE: | |
319 | case V4L2_BUF_TYPE_VBI_OUTPUT: | |
320 | vbi = &p->fmt.vbi; | |
e927e1e0 | 321 | pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, sample_format=%p4cc, start=%u,%u, count=%u,%u\n", |
be6c64e4 | 322 | vbi->sampling_rate, vbi->offset, |
e927e1e0 | 323 | vbi->samples_per_line, &vbi->sample_format, |
be6c64e4 HV |
324 | vbi->start[0], vbi->start[1], |
325 | vbi->count[0], vbi->count[1]); | |
326 | break; | |
327 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
328 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: | |
329 | sliced = &p->fmt.sliced; | |
330 | pr_cont(", service_set=0x%08x, io_size=%d\n", | |
331 | sliced->service_set, sliced->io_size); | |
332 | for (i = 0; i < 24; i++) | |
333 | printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i, | |
334 | sliced->service_lines[0][i], | |
335 | sliced->service_lines[1][i]); | |
336 | break; | |
582c52cb | 337 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
9effc72f | 338 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
24bb30c8 SA |
339 | pixelformat = p->fmt.sdr.pixelformat; |
340 | pr_cont(", pixelformat=%p4cc\n", &pixelformat); | |
582c52cb | 341 | break; |
fb9ffa6a | 342 | case V4L2_BUF_TYPE_META_CAPTURE: |
72148d1a | 343 | case V4L2_BUF_TYPE_META_OUTPUT: |
fb9ffa6a | 344 | meta = &p->fmt.meta; |
24bb30c8 | 345 | pixelformat = meta->dataformat; |
89345c2a SA |
346 | pr_cont(", dataformat=%p4cc, buffersize=%u, width=%u, height=%u, bytesperline=%u\n", |
347 | &pixelformat, meta->buffersize, meta->width, | |
348 | meta->height, meta->bytesperline); | |
fb9ffa6a | 349 | break; |
be6c64e4 HV |
350 | } |
351 | } | |
352 | ||
353 | static void v4l_print_framebuffer(const void *arg, bool write_only) | |
354 | { | |
355 | const struct v4l2_framebuffer *p = arg; | |
356 | ||
e927e1e0 SA |
357 | pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, height=%u, pixelformat=%p4cc, bytesperline=%u, sizeimage=%u, colorspace=%d\n", |
358 | p->capability, p->flags, p->base, p->fmt.width, p->fmt.height, | |
359 | &p->fmt.pixelformat, p->fmt.bytesperline, p->fmt.sizeimage, | |
360 | p->fmt.colorspace); | |
be6c64e4 HV |
361 | } |
362 | ||
e325b244 HV |
363 | static void v4l_print_buftype(const void *arg, bool write_only) |
364 | { | |
365 | pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names)); | |
366 | } | |
367 | ||
4b1e2e4d HV |
368 | static void v4l_print_modulator(const void *arg, bool write_only) |
369 | { | |
370 | const struct v4l2_modulator *p = arg; | |
371 | ||
372 | if (write_only) | |
560dde24 | 373 | pr_cont("index=%u, txsubchans=0x%x\n", p->index, p->txsubchans); |
4b1e2e4d | 374 | else |
8720427c | 375 | pr_cont("index=%u, name=%.*s, capability=0x%x, rangelow=%u, rangehigh=%u, txsubchans=0x%x\n", |
27d5a87c | 376 | p->index, (int)sizeof(p->name), p->name, p->capability, |
4b1e2e4d HV |
377 | p->rangelow, p->rangehigh, p->txsubchans); |
378 | } | |
379 | ||
380 | static void v4l_print_tuner(const void *arg, bool write_only) | |
381 | { | |
382 | const struct v4l2_tuner *p = arg; | |
383 | ||
384 | if (write_only) | |
385 | pr_cont("index=%u, audmode=%u\n", p->index, p->audmode); | |
386 | else | |
8720427c | 387 | pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, rangelow=%u, rangehigh=%u, signal=%u, afc=%d, rxsubchans=0x%x, audmode=%u\n", |
27d5a87c | 388 | p->index, (int)sizeof(p->name), p->name, p->type, |
4b1e2e4d HV |
389 | p->capability, p->rangelow, |
390 | p->rangehigh, p->signal, p->afc, | |
391 | p->rxsubchans, p->audmode); | |
392 | } | |
393 | ||
394 | static void v4l_print_frequency(const void *arg, bool write_only) | |
395 | { | |
396 | const struct v4l2_frequency *p = arg; | |
397 | ||
398 | pr_cont("tuner=%u, type=%u, frequency=%u\n", | |
399 | p->tuner, p->type, p->frequency); | |
400 | } | |
401 | ||
402 | static void v4l_print_standard(const void *arg, bool write_only) | |
403 | { | |
404 | const struct v4l2_standard *p = arg; | |
405 | ||
8720427c MCC |
406 | pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, framelines=%u\n", |
407 | p->index, | |
27d5a87c | 408 | (unsigned long long)p->id, (int)sizeof(p->name), p->name, |
4b1e2e4d HV |
409 | p->frameperiod.numerator, |
410 | p->frameperiod.denominator, | |
411 | p->framelines); | |
412 | } | |
413 | ||
414 | static void v4l_print_std(const void *arg, bool write_only) | |
415 | { | |
416 | pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg); | |
417 | } | |
418 | ||
419 | static void v4l_print_hw_freq_seek(const void *arg, bool write_only) | |
420 | { | |
421 | const struct v4l2_hw_freq_seek *p = arg; | |
422 | ||
8720427c | 423 | pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, rangelow=%u, rangehigh=%u\n", |
5e788317 HV |
424 | p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing, |
425 | p->rangelow, p->rangehigh); | |
4b1e2e4d HV |
426 | } |
427 | ||
eb3728ed | 428 | static void v4l_print_requestbuffers(const void *arg, bool write_only) |
59076122 | 429 | { |
eb3728ed HV |
430 | const struct v4l2_requestbuffers *p = arg; |
431 | ||
432 | pr_cont("count=%d, type=%s, memory=%s\n", | |
433 | p->count, | |
434 | prt_names(p->type, v4l2_type_names), | |
435 | prt_names(p->memory, v4l2_memory_names)); | |
59076122 HV |
436 | } |
437 | ||
eb3728ed | 438 | static void v4l_print_buffer(const void *arg, bool write_only) |
35ea11ff | 439 | { |
eb3728ed HV |
440 | const struct v4l2_buffer *p = arg; |
441 | const struct v4l2_timecode *tc = &p->timecode; | |
442 | const struct v4l2_plane *plane; | |
d14e6d76 | 443 | int i; |
35ea11ff | 444 | |
48e15418 | 445 | pr_cont("%02d:%02d:%02d.%06ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s", |
577c89b0 AB |
446 | (int)p->timestamp.tv_sec / 3600, |
447 | ((int)p->timestamp.tv_sec / 60) % 60, | |
448 | ((int)p->timestamp.tv_sec % 60), | |
b045979d | 449 | (long)p->timestamp.tv_usec, |
35ea11ff | 450 | p->index, |
62fed26f | 451 | prt_names(p->type, v4l2_type_names), p->request_fd, |
eb3728ed HV |
452 | p->flags, prt_names(p->field, v4l2_field_names), |
453 | p->sequence, prt_names(p->memory, v4l2_memory_names)); | |
d14e6d76 PO |
454 | |
455 | if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) { | |
eb3728ed | 456 | pr_cont("\n"); |
d14e6d76 PO |
457 | for (i = 0; i < p->length; ++i) { |
458 | plane = &p->m.planes[i]; | |
eb3728ed | 459 | printk(KERN_DEBUG |
8720427c | 460 | "plane %d: bytesused=%d, data_offset=0x%08x, offset/userptr=0x%lx, length=%d\n", |
d14e6d76 PO |
461 | i, plane->bytesused, plane->data_offset, |
462 | plane->m.userptr, plane->length); | |
463 | } | |
464 | } else { | |
560dde24 | 465 | pr_cont(", bytesused=%d, offset/userptr=0x%lx, length=%d\n", |
d14e6d76 PO |
466 | p->bytesused, p->m.userptr, p->length); |
467 | } | |
468 | ||
8720427c | 469 | printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, flags=0x%08x, frames=%d, userbits=0x%08x\n", |
35ea11ff HV |
470 | tc->hours, tc->minutes, tc->seconds, |
471 | tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits); | |
472 | } | |
473 | ||
b799d09a TS |
474 | static void v4l_print_exportbuffer(const void *arg, bool write_only) |
475 | { | |
476 | const struct v4l2_exportbuffer *p = arg; | |
477 | ||
478 | pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n", | |
479 | p->fd, prt_names(p->type, v4l2_type_names), | |
480 | p->index, p->plane, p->flags); | |
481 | } | |
482 | ||
eb3728ed HV |
483 | static void v4l_print_create_buffers(const void *arg, bool write_only) |
484 | { | |
485 | const struct v4l2_create_buffers *p = arg; | |
486 | ||
2b9e6786 | 487 | pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, max num buffers=%u, ", |
319c4bd4 | 488 | p->index, p->count, prt_names(p->memory, v4l2_memory_names), |
d055a76c | 489 | p->capabilities, p->max_num_buffers); |
eb3728ed HV |
490 | v4l_print_format(&p->format, write_only); |
491 | } | |
492 | ||
a3293a85 BG |
493 | static void v4l_print_remove_buffers(const void *arg, bool write_only) |
494 | { | |
495 | const struct v4l2_remove_buffers *p = arg; | |
496 | ||
497 | pr_cont("type=%s, index=%u, count=%u\n", | |
498 | prt_names(p->type, v4l2_type_names), p->index, p->count); | |
499 | } | |
500 | ||
eb3728ed HV |
501 | static void v4l_print_streamparm(const void *arg, bool write_only) |
502 | { | |
503 | const struct v4l2_streamparm *p = arg; | |
504 | ||
505 | pr_cont("type=%s", prt_names(p->type, v4l2_type_names)); | |
506 | ||
507 | if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || | |
508 | p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { | |
509 | const struct v4l2_captureparm *c = &p->parm.capture; | |
510 | ||
8720427c | 511 | pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, extendedmode=%d, readbuffers=%d\n", |
eb3728ed HV |
512 | c->capability, c->capturemode, |
513 | c->timeperframe.numerator, c->timeperframe.denominator, | |
514 | c->extendedmode, c->readbuffers); | |
515 | } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT || | |
516 | p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { | |
517 | const struct v4l2_outputparm *c = &p->parm.output; | |
518 | ||
8720427c | 519 | pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, extendedmode=%d, writebuffers=%d\n", |
eb3728ed HV |
520 | c->capability, c->outputmode, |
521 | c->timeperframe.numerator, c->timeperframe.denominator, | |
522 | c->extendedmode, c->writebuffers); | |
560dde24 HV |
523 | } else { |
524 | pr_cont("\n"); | |
eb3728ed HV |
525 | } |
526 | } | |
527 | ||
efbceecd HV |
528 | static void v4l_print_queryctrl(const void *arg, bool write_only) |
529 | { | |
530 | const struct v4l2_queryctrl *p = arg; | |
531 | ||
8720427c | 532 | pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, step=%d, default=%d, flags=0x%08x\n", |
27d5a87c | 533 | p->id, p->type, (int)sizeof(p->name), p->name, |
efbceecd HV |
534 | p->minimum, p->maximum, |
535 | p->step, p->default_value, p->flags); | |
536 | } | |
537 | ||
e6bee368 HV |
538 | static void v4l_print_query_ext_ctrl(const void *arg, bool write_only) |
539 | { | |
540 | const struct v4l2_query_ext_ctrl *p = arg; | |
541 | ||
8720427c | 542 | pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, nr_of_dims=%u, dims=%u,%u,%u,%u\n", |
e6bee368 HV |
543 | p->id, p->type, (int)sizeof(p->name), p->name, |
544 | p->minimum, p->maximum, | |
545 | p->step, p->default_value, p->flags, | |
546 | p->elem_size, p->elems, p->nr_of_dims, | |
0176077a | 547 | p->dims[0], p->dims[1], p->dims[2], p->dims[3]); |
e6bee368 HV |
548 | } |
549 | ||
efbceecd HV |
550 | static void v4l_print_querymenu(const void *arg, bool write_only) |
551 | { | |
552 | const struct v4l2_querymenu *p = arg; | |
553 | ||
554 | pr_cont("id=0x%x, index=%d\n", p->id, p->index); | |
555 | } | |
556 | ||
557 | static void v4l_print_control(const void *arg, bool write_only) | |
558 | { | |
559 | const struct v4l2_control *p = arg; | |
a69a7a33 | 560 | const char *name = v4l2_ctrl_get_name(p->id); |
efbceecd | 561 | |
a69a7a33 EG |
562 | if (name) |
563 | pr_cont("name=%s, ", name); | |
efbceecd HV |
564 | pr_cont("id=0x%x, value=%d\n", p->id, p->value); |
565 | } | |
566 | ||
567 | static void v4l_print_ext_controls(const void *arg, bool write_only) | |
568 | { | |
569 | const struct v4l2_ext_controls *p = arg; | |
570 | int i; | |
571 | ||
f23317ad AC |
572 | pr_cont("which=0x%x, count=%d, error_idx=%d, request_fd=%d", |
573 | p->which, p->count, p->error_idx, p->request_fd); | |
efbceecd | 574 | for (i = 0; i < p->count; i++) { |
a69a7a33 EG |
575 | unsigned int id = p->controls[i].id; |
576 | const char *name = v4l2_ctrl_get_name(id); | |
577 | ||
578 | if (name) | |
579 | pr_cont(", name=%s", name); | |
017ab36a | 580 | if (!p->controls[i].size) |
a69a7a33 | 581 | pr_cont(", id/val=0x%x/0x%x", id, p->controls[i].value); |
efbceecd | 582 | else |
a69a7a33 | 583 | pr_cont(", id/size=0x%x/%u", id, p->controls[i].size); |
efbceecd HV |
584 | } |
585 | pr_cont("\n"); | |
586 | } | |
587 | ||
d84f2d94 | 588 | static void v4l_print_cropcap(const void *arg, bool write_only) |
eb3728ed | 589 | { |
d84f2d94 HV |
590 | const struct v4l2_cropcap *p = arg; |
591 | ||
11340fbd | 592 | pr_cont("type=%s, bounds (%d,%d)/%ux%u, defrect (%d,%d)/%ux%u, pixelaspect %d/%d\n", |
d84f2d94 | 593 | prt_names(p->type, v4l2_type_names), |
d84f2d94 | 594 | p->bounds.left, p->bounds.top, |
11340fbd | 595 | p->bounds.width, p->bounds.height, |
d84f2d94 | 596 | p->defrect.left, p->defrect.top, |
11340fbd | 597 | p->defrect.width, p->defrect.height, |
d84f2d94 | 598 | p->pixelaspect.numerator, p->pixelaspect.denominator); |
eb3728ed HV |
599 | } |
600 | ||
d84f2d94 | 601 | static void v4l_print_crop(const void *arg, bool write_only) |
35ea11ff | 602 | { |
d84f2d94 HV |
603 | const struct v4l2_crop *p = arg; |
604 | ||
11340fbd | 605 | pr_cont("type=%s, crop=(%d,%d)/%ux%u\n", |
d84f2d94 | 606 | prt_names(p->type, v4l2_type_names), |
11340fbd HV |
607 | p->c.left, p->c.top, |
608 | p->c.width, p->c.height); | |
d84f2d94 HV |
609 | } |
610 | ||
611 | static void v4l_print_selection(const void *arg, bool write_only) | |
612 | { | |
613 | const struct v4l2_selection *p = arg; | |
614 | ||
11340fbd | 615 | pr_cont("type=%s, target=%d, flags=0x%x, rect=(%d,%d)/%ux%u\n", |
d84f2d94 HV |
616 | prt_names(p->type, v4l2_type_names), |
617 | p->target, p->flags, | |
11340fbd | 618 | p->r.left, p->r.top, p->r.width, p->r.height); |
d84f2d94 HV |
619 | } |
620 | ||
d806f2df HV |
621 | static void v4l_print_jpegcompression(const void *arg, bool write_only) |
622 | { | |
623 | const struct v4l2_jpegcompression *p = arg; | |
624 | ||
8720427c | 625 | pr_cont("quality=%d, APPn=%d, APP_len=%d, COM_len=%d, jpeg_markers=0x%x\n", |
d806f2df HV |
626 | p->quality, p->APPn, p->APP_len, |
627 | p->COM_len, p->jpeg_markers); | |
628 | } | |
629 | ||
630 | static void v4l_print_enc_idx(const void *arg, bool write_only) | |
631 | { | |
632 | const struct v4l2_enc_idx *p = arg; | |
633 | ||
634 | pr_cont("entries=%d, entries_cap=%d\n", | |
635 | p->entries, p->entries_cap); | |
636 | } | |
637 | ||
638 | static void v4l_print_encoder_cmd(const void *arg, bool write_only) | |
639 | { | |
640 | const struct v4l2_encoder_cmd *p = arg; | |
641 | ||
642 | pr_cont("cmd=%d, flags=0x%x\n", | |
643 | p->cmd, p->flags); | |
644 | } | |
645 | ||
646 | static void v4l_print_decoder_cmd(const void *arg, bool write_only) | |
647 | { | |
648 | const struct v4l2_decoder_cmd *p = arg; | |
649 | ||
650 | pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags); | |
651 | ||
652 | if (p->cmd == V4L2_DEC_CMD_START) | |
653 | pr_info("speed=%d, format=%u\n", | |
654 | p->start.speed, p->start.format); | |
655 | else if (p->cmd == V4L2_DEC_CMD_STOP) | |
656 | pr_info("pts=%llu\n", p->stop.pts); | |
657 | } | |
658 | ||
96b03d2a | 659 | static void v4l_print_dbg_chip_info(const void *arg, bool write_only) |
79b0c640 | 660 | { |
96b03d2a | 661 | const struct v4l2_dbg_chip_info *p = arg; |
79b0c640 HV |
662 | |
663 | pr_cont("type=%u, ", p->match.type); | |
3eef2510 | 664 | if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) |
79b0c640 HV |
665 | pr_cont("name=%.*s, ", |
666 | (int)sizeof(p->match.name), p->match.name); | |
667 | else | |
668 | pr_cont("addr=%u, ", p->match.addr); | |
669 | pr_cont("name=%.*s\n", (int)sizeof(p->name), p->name); | |
670 | } | |
671 | ||
f16f77b0 HV |
672 | static void v4l_print_dbg_register(const void *arg, bool write_only) |
673 | { | |
674 | const struct v4l2_dbg_register *p = arg; | |
675 | ||
676 | pr_cont("type=%u, ", p->match.type); | |
3eef2510 | 677 | if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) |
27d5a87c HV |
678 | pr_cont("name=%.*s, ", |
679 | (int)sizeof(p->match.name), p->match.name); | |
f16f77b0 HV |
680 | else |
681 | pr_cont("addr=%u, ", p->match.addr); | |
682 | pr_cont("reg=0x%llx, val=0x%llx\n", | |
683 | p->reg, p->val); | |
684 | } | |
685 | ||
efc626b0 | 686 | static void v4l_print_dv_timings(const void *arg, bool write_only) |
5d7758ee | 687 | { |
efc626b0 HV |
688 | const struct v4l2_dv_timings *p = arg; |
689 | ||
5d7758ee HV |
690 | switch (p->type) { |
691 | case V4L2_DV_BT_656_1120: | |
8720427c | 692 | pr_cont("type=bt-656/1120, interlaced=%u, pixelclock=%llu, width=%u, height=%u, polarities=0x%x, hfrontporch=%u, hsync=%u, hbackporch=%u, vfrontporch=%u, vsync=%u, vbackporch=%u, il_vfrontporch=%u, il_vsync=%u, il_vbackporch=%u, standards=0x%x, flags=0x%x\n", |
5d7758ee HV |
693 | p->bt.interlaced, p->bt.pixelclock, |
694 | p->bt.width, p->bt.height, | |
695 | p->bt.polarities, p->bt.hfrontporch, | |
696 | p->bt.hsync, p->bt.hbackporch, | |
697 | p->bt.vfrontporch, p->bt.vsync, | |
698 | p->bt.vbackporch, p->bt.il_vfrontporch, | |
699 | p->bt.il_vsync, p->bt.il_vbackporch, | |
700 | p->bt.standards, p->bt.flags); | |
701 | break; | |
702 | default: | |
efc626b0 | 703 | pr_cont("type=%d\n", p->type); |
5d7758ee HV |
704 | break; |
705 | } | |
706 | } | |
707 | ||
efc626b0 HV |
708 | static void v4l_print_enum_dv_timings(const void *arg, bool write_only) |
709 | { | |
710 | const struct v4l2_enum_dv_timings *p = arg; | |
711 | ||
712 | pr_cont("index=%u, ", p->index); | |
713 | v4l_print_dv_timings(&p->timings, write_only); | |
714 | } | |
715 | ||
716 | static void v4l_print_dv_timings_cap(const void *arg, bool write_only) | |
717 | { | |
718 | const struct v4l2_dv_timings_cap *p = arg; | |
719 | ||
720 | switch (p->type) { | |
721 | case V4L2_DV_BT_656_1120: | |
8720427c | 722 | pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n", |
efc626b0 HV |
723 | p->bt.min_width, p->bt.max_width, |
724 | p->bt.min_height, p->bt.max_height, | |
725 | p->bt.min_pixelclock, p->bt.max_pixelclock, | |
726 | p->bt.standards, p->bt.capabilities); | |
727 | break; | |
728 | default: | |
729 | pr_cont("type=%u\n", p->type); | |
730 | break; | |
731 | } | |
732 | } | |
733 | ||
458aa4a6 HV |
734 | static void v4l_print_frmsizeenum(const void *arg, bool write_only) |
735 | { | |
736 | const struct v4l2_frmsizeenum *p = arg; | |
737 | ||
e927e1e0 SA |
738 | pr_cont("index=%u, pixelformat=%p4cc, type=%u", |
739 | p->index, &p->pixel_format, p->type); | |
458aa4a6 HV |
740 | switch (p->type) { |
741 | case V4L2_FRMSIZE_TYPE_DISCRETE: | |
560dde24 | 742 | pr_cont(", wxh=%ux%u\n", |
458aa4a6 HV |
743 | p->discrete.width, p->discrete.height); |
744 | break; | |
745 | case V4L2_FRMSIZE_TYPE_STEPWISE: | |
560dde24 | 746 | pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n", |
2489477e RR |
747 | p->stepwise.min_width, |
748 | p->stepwise.min_height, | |
749 | p->stepwise.max_width, | |
750 | p->stepwise.max_height, | |
751 | p->stepwise.step_width, | |
752 | p->stepwise.step_height); | |
458aa4a6 HV |
753 | break; |
754 | case V4L2_FRMSIZE_TYPE_CONTINUOUS: | |
458aa4a6 HV |
755 | default: |
756 | pr_cont("\n"); | |
757 | break; | |
758 | } | |
759 | } | |
760 | ||
761 | static void v4l_print_frmivalenum(const void *arg, bool write_only) | |
762 | { | |
763 | const struct v4l2_frmivalenum *p = arg; | |
764 | ||
e927e1e0 SA |
765 | pr_cont("index=%u, pixelformat=%p4cc, wxh=%ux%u, type=%u", |
766 | p->index, &p->pixel_format, p->width, p->height, p->type); | |
458aa4a6 HV |
767 | switch (p->type) { |
768 | case V4L2_FRMIVAL_TYPE_DISCRETE: | |
560dde24 | 769 | pr_cont(", fps=%d/%d\n", |
458aa4a6 HV |
770 | p->discrete.numerator, |
771 | p->discrete.denominator); | |
772 | break; | |
773 | case V4L2_FRMIVAL_TYPE_STEPWISE: | |
560dde24 | 774 | pr_cont(", min=%d/%d, max=%d/%d, step=%d/%d\n", |
458aa4a6 HV |
775 | p->stepwise.min.numerator, |
776 | p->stepwise.min.denominator, | |
777 | p->stepwise.max.numerator, | |
778 | p->stepwise.max.denominator, | |
779 | p->stepwise.step.numerator, | |
780 | p->stepwise.step.denominator); | |
781 | break; | |
782 | case V4L2_FRMIVAL_TYPE_CONTINUOUS: | |
458aa4a6 HV |
783 | default: |
784 | pr_cont("\n"); | |
785 | break; | |
786 | } | |
787 | } | |
788 | ||
789 | static void v4l_print_event(const void *arg, bool write_only) | |
790 | { | |
791 | const struct v4l2_event *p = arg; | |
792 | const struct v4l2_event_ctrl *c; | |
793 | ||
1a6c0b36 | 794 | pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%llu.%9.9llu\n", |
458aa4a6 HV |
795 | p->type, p->pending, p->sequence, p->id, |
796 | p->timestamp.tv_sec, p->timestamp.tv_nsec); | |
797 | switch (p->type) { | |
798 | case V4L2_EVENT_VSYNC: | |
799 | printk(KERN_DEBUG "field=%s\n", | |
800 | prt_names(p->u.vsync.field, v4l2_field_names)); | |
801 | break; | |
802 | case V4L2_EVENT_CTRL: | |
803 | c = &p->u.ctrl; | |
804 | printk(KERN_DEBUG "changes=0x%x, type=%u, ", | |
805 | c->changes, c->type); | |
806 | if (c->type == V4L2_CTRL_TYPE_INTEGER64) | |
807 | pr_cont("value64=%lld, ", c->value64); | |
808 | else | |
809 | pr_cont("value=%d, ", c->value); | |
8720427c | 810 | pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d, default_value=%d\n", |
458aa4a6 HV |
811 | c->flags, c->minimum, c->maximum, |
812 | c->step, c->default_value); | |
813 | break; | |
814 | case V4L2_EVENT_FRAME_SYNC: | |
815 | pr_cont("frame_sequence=%u\n", | |
816 | p->u.frame_sync.frame_sequence); | |
817 | break; | |
818 | } | |
819 | } | |
820 | ||
821 | static void v4l_print_event_subscription(const void *arg, bool write_only) | |
822 | { | |
823 | const struct v4l2_event_subscription *p = arg; | |
824 | ||
825 | pr_cont("type=0x%x, id=0x%x, flags=0x%x\n", | |
826 | p->type, p->id, p->flags); | |
827 | } | |
828 | ||
829 | static void v4l_print_sliced_vbi_cap(const void *arg, bool write_only) | |
830 | { | |
831 | const struct v4l2_sliced_vbi_cap *p = arg; | |
832 | int i; | |
833 | ||
834 | pr_cont("type=%s, service_set=0x%08x\n", | |
835 | prt_names(p->type, v4l2_type_names), p->service_set); | |
836 | for (i = 0; i < 24; i++) | |
837 | printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i, | |
838 | p->service_lines[0][i], | |
839 | p->service_lines[1][i]); | |
840 | } | |
841 | ||
82b655bf HV |
842 | static void v4l_print_freq_band(const void *arg, bool write_only) |
843 | { | |
844 | const struct v4l2_frequency_band *p = arg; | |
845 | ||
8720427c | 846 | pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, rangelow=%u, rangehigh=%u, modulation=0x%x\n", |
82b655bf HV |
847 | p->tuner, p->type, p->index, |
848 | p->capability, p->rangelow, | |
849 | p->rangehigh, p->modulation); | |
850 | } | |
851 | ||
dd519bb3 HV |
852 | static void v4l_print_edid(const void *arg, bool write_only) |
853 | { | |
854 | const struct v4l2_edid *p = arg; | |
855 | ||
856 | pr_cont("pad=%u, start_block=%u, blocks=%u\n", | |
857 | p->pad, p->start_block, p->blocks); | |
858 | } | |
859 | ||
efc626b0 HV |
860 | static void v4l_print_u32(const void *arg, bool write_only) |
861 | { | |
862 | pr_cont("value=%u\n", *(const u32 *)arg); | |
863 | } | |
864 | ||
865 | static void v4l_print_newline(const void *arg, bool write_only) | |
866 | { | |
867 | pr_cont("\n"); | |
868 | } | |
869 | ||
f18d8e07 HV |
870 | static void v4l_print_default(const void *arg, bool write_only) |
871 | { | |
872 | pr_cont("driver-specific ioctl\n"); | |
873 | } | |
874 | ||
861f92cb | 875 | static bool check_ext_ctrls(struct v4l2_ext_controls *c, unsigned long ioctl) |
35ea11ff HV |
876 | { |
877 | __u32 i; | |
878 | ||
879 | /* zero the reserved fields */ | |
f23317ad | 880 | c->reserved[0] = 0; |
6b5a9492 | 881 | for (i = 0; i < c->count; i++) |
35ea11ff | 882 | c->controls[i].reserved2[0] = 0; |
6b5a9492 | 883 | |
861f92cb RR |
884 | switch (c->which) { |
885 | case V4L2_CID_PRIVATE_BASE: | |
886 | /* | |
887 | * V4L2_CID_PRIVATE_BASE cannot be used as control class | |
888 | * when using extended controls. | |
889 | * Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL | |
890 | * is it allowed for backwards compatibility. | |
891 | */ | |
892 | if (ioctl == VIDIOC_G_CTRL || ioctl == VIDIOC_S_CTRL) | |
893 | return false; | |
894 | break; | |
895 | case V4L2_CTRL_WHICH_DEF_VAL: | |
a5bd42aa HV |
896 | case V4L2_CTRL_WHICH_MIN_VAL: |
897 | case V4L2_CTRL_WHICH_MAX_VAL: | |
898 | /* Default, minimum or maximum value cannot be changed */ | |
861f92cb RR |
899 | if (ioctl == VIDIOC_S_EXT_CTRLS || |
900 | ioctl == VIDIOC_TRY_EXT_CTRLS) { | |
901 | c->error_idx = c->count; | |
902 | return false; | |
903 | } | |
904 | return true; | |
905 | case V4L2_CTRL_WHICH_CUR_VAL: | |
906 | return true; | |
907 | case V4L2_CTRL_WHICH_REQUEST_VAL: | |
908 | c->error_idx = c->count; | |
909 | return false; | |
910 | } | |
911 | ||
35ea11ff HV |
912 | /* Check that all controls are from the same control class. */ |
913 | for (i = 0; i < c->count; i++) { | |
0f8017be | 914 | if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) { |
861f92cb RR |
915 | c->error_idx = ioctl == VIDIOC_TRY_EXT_CTRLS ? i : |
916 | c->count; | |
917 | return false; | |
35ea11ff HV |
918 | } |
919 | } | |
861f92cb | 920 | return true; |
35ea11ff HV |
921 | } |
922 | ||
4b20259f | 923 | static int check_fmt(struct file *file, enum v4l2_buf_type type) |
35ea11ff | 924 | { |
96f49c1a VB |
925 | const u32 vid_caps = V4L2_CAP_VIDEO_CAPTURE | |
926 | V4L2_CAP_VIDEO_CAPTURE_MPLANE | | |
927 | V4L2_CAP_VIDEO_OUTPUT | | |
928 | V4L2_CAP_VIDEO_OUTPUT_MPLANE | | |
929 | V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE; | |
930 | const u32 meta_caps = V4L2_CAP_META_CAPTURE | | |
931 | V4L2_CAP_META_OUTPUT; | |
4b20259f HV |
932 | struct video_device *vfd = video_devdata(file); |
933 | const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; | |
238e4a5b | 934 | bool is_vid = vfd->vfl_type == VFL_TYPE_VIDEO && |
96f49c1a | 935 | (vfd->device_caps & vid_caps); |
4b20259f | 936 | bool is_vbi = vfd->vfl_type == VFL_TYPE_VBI; |
582c52cb | 937 | bool is_sdr = vfd->vfl_type == VFL_TYPE_SDR; |
b2fe22d0 | 938 | bool is_tch = vfd->vfl_type == VFL_TYPE_TOUCH; |
238e4a5b | 939 | bool is_meta = vfd->vfl_type == VFL_TYPE_VIDEO && |
96f49c1a | 940 | (vfd->device_caps & meta_caps); |
4b20259f HV |
941 | bool is_rx = vfd->vfl_dir != VFL_DIR_TX; |
942 | bool is_tx = vfd->vfl_dir != VFL_DIR_RX; | |
943 | ||
a399810c HV |
944 | if (ops == NULL) |
945 | return -EINVAL; | |
946 | ||
35ea11ff HV |
947 | switch (type) { |
948 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
b2fe22d0 | 949 | if ((is_vid || is_tch) && is_rx && |
4b20259f | 950 | (ops->vidioc_g_fmt_vid_cap || ops->vidioc_g_fmt_vid_cap_mplane)) |
d14e6d76 PO |
951 | return 0; |
952 | break; | |
953 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: | |
095c21d3 | 954 | if ((is_vid || is_tch) && is_rx && ops->vidioc_g_fmt_vid_cap_mplane) |
35ea11ff HV |
955 | return 0; |
956 | break; | |
957 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
4b20259f | 958 | if (is_vid && is_rx && ops->vidioc_g_fmt_vid_overlay) |
35ea11ff HV |
959 | return 0; |
960 | break; | |
961 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | |
4b20259f HV |
962 | if (is_vid && is_tx && |
963 | (ops->vidioc_g_fmt_vid_out || ops->vidioc_g_fmt_vid_out_mplane)) | |
d14e6d76 PO |
964 | return 0; |
965 | break; | |
966 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: | |
4b20259f | 967 | if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_mplane) |
35ea11ff HV |
968 | return 0; |
969 | break; | |
970 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
4b20259f | 971 | if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_overlay) |
35ea11ff HV |
972 | return 0; |
973 | break; | |
974 | case V4L2_BUF_TYPE_VBI_CAPTURE: | |
4b20259f | 975 | if (is_vbi && is_rx && ops->vidioc_g_fmt_vbi_cap) |
35ea11ff HV |
976 | return 0; |
977 | break; | |
978 | case V4L2_BUF_TYPE_VBI_OUTPUT: | |
4b20259f | 979 | if (is_vbi && is_tx && ops->vidioc_g_fmt_vbi_out) |
35ea11ff HV |
980 | return 0; |
981 | break; | |
982 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
4b20259f | 983 | if (is_vbi && is_rx && ops->vidioc_g_fmt_sliced_vbi_cap) |
35ea11ff HV |
984 | return 0; |
985 | break; | |
986 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: | |
4b20259f | 987 | if (is_vbi && is_tx && ops->vidioc_g_fmt_sliced_vbi_out) |
35ea11ff HV |
988 | return 0; |
989 | break; | |
582c52cb AP |
990 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
991 | if (is_sdr && is_rx && ops->vidioc_g_fmt_sdr_cap) | |
992 | return 0; | |
993 | break; | |
9effc72f AP |
994 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
995 | if (is_sdr && is_tx && ops->vidioc_g_fmt_sdr_out) | |
996 | return 0; | |
997 | break; | |
fb9ffa6a | 998 | case V4L2_BUF_TYPE_META_CAPTURE: |
96f49c1a | 999 | if (is_meta && is_rx && ops->vidioc_g_fmt_meta_cap) |
fb9ffa6a LP |
1000 | return 0; |
1001 | break; | |
72148d1a | 1002 | case V4L2_BUF_TYPE_META_OUTPUT: |
96f49c1a | 1003 | if (is_meta && is_tx && ops->vidioc_g_fmt_meta_out) |
72148d1a SA |
1004 | return 0; |
1005 | break; | |
633c98e5 | 1006 | default: |
35ea11ff HV |
1007 | break; |
1008 | } | |
1009 | return -EINVAL; | |
1010 | } | |
1011 | ||
48e93b0c LP |
1012 | static void v4l_sanitize_colorspace(u32 pixelformat, u32 *colorspace, |
1013 | u32 *encoding, u32 *quantization, | |
1014 | u32 *xfer_func) | |
1015 | { | |
1016 | bool is_hsv = pixelformat == V4L2_PIX_FMT_HSV24 || | |
1017 | pixelformat == V4L2_PIX_FMT_HSV32; | |
1018 | ||
1019 | if (!v4l2_is_colorspace_valid(*colorspace)) { | |
1020 | *colorspace = V4L2_COLORSPACE_DEFAULT; | |
1021 | *encoding = V4L2_YCBCR_ENC_DEFAULT; | |
1022 | *quantization = V4L2_QUANTIZATION_DEFAULT; | |
1023 | *xfer_func = V4L2_XFER_FUNC_DEFAULT; | |
1024 | } | |
1025 | ||
1026 | if ((!is_hsv && !v4l2_is_ycbcr_enc_valid(*encoding)) || | |
1027 | (is_hsv && !v4l2_is_hsv_enc_valid(*encoding))) | |
1028 | *encoding = V4L2_YCBCR_ENC_DEFAULT; | |
1029 | ||
1030 | if (!v4l2_is_quant_valid(*quantization)) | |
1031 | *quantization = V4L2_QUANTIZATION_DEFAULT; | |
1032 | ||
1033 | if (!v4l2_is_xfer_func_valid(*xfer_func)) | |
1034 | *xfer_func = V4L2_XFER_FUNC_DEFAULT; | |
1035 | } | |
1036 | ||
d52e2381 LP |
1037 | static void v4l_sanitize_format(struct v4l2_format *fmt) |
1038 | { | |
1039 | unsigned int offset; | |
1040 | ||
14c8e80e EG |
1041 | /* Make sure num_planes is not bogus */ |
1042 | if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || | |
1043 | fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) | |
1044 | fmt->fmt.pix_mp.num_planes = min_t(u32, fmt->fmt.pix_mp.num_planes, | |
1045 | VIDEO_MAX_PLANES); | |
1046 | ||
d52e2381 LP |
1047 | /* |
1048 | * The v4l2_pix_format structure has been extended with fields that were | |
1049 | * not previously required to be set to zero by applications. The priv | |
fd3ed970 | 1050 | * field, when set to a magic value, indicates that the extended fields |
d52e2381 LP |
1051 | * are valid. Otherwise they will contain undefined values. To simplify |
1052 | * the API towards drivers zero the extended fields and set the priv | |
1053 | * field to the magic value when the extended pixel format structure | |
1054 | * isn't used by applications. | |
1055 | */ | |
48e93b0c LP |
1056 | if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || |
1057 | fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { | |
1058 | if (fmt->fmt.pix.priv != V4L2_PIX_FMT_PRIV_MAGIC) { | |
1059 | fmt->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; | |
1060 | ||
1061 | offset = offsetof(struct v4l2_pix_format, priv) | |
1062 | + sizeof(fmt->fmt.pix.priv); | |
1063 | memset(((void *)&fmt->fmt.pix) + offset, 0, | |
1064 | sizeof(fmt->fmt.pix) - offset); | |
1065 | } | |
1066 | } | |
d52e2381 | 1067 | |
48e93b0c LP |
1068 | /* Replace invalid colorspace values with defaults. */ |
1069 | if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || | |
1070 | fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { | |
1071 | v4l_sanitize_colorspace(fmt->fmt.pix.pixelformat, | |
1072 | &fmt->fmt.pix.colorspace, | |
1073 | &fmt->fmt.pix.ycbcr_enc, | |
1074 | &fmt->fmt.pix.quantization, | |
1075 | &fmt->fmt.pix.xfer_func); | |
1076 | } else if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || | |
1077 | fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { | |
1078 | u32 ycbcr_enc = fmt->fmt.pix_mp.ycbcr_enc; | |
1079 | u32 quantization = fmt->fmt.pix_mp.quantization; | |
1080 | u32 xfer_func = fmt->fmt.pix_mp.xfer_func; | |
1081 | ||
1082 | v4l_sanitize_colorspace(fmt->fmt.pix_mp.pixelformat, | |
1083 | &fmt->fmt.pix_mp.colorspace, &ycbcr_enc, | |
1084 | &quantization, &xfer_func); | |
1085 | ||
1086 | fmt->fmt.pix_mp.ycbcr_enc = ycbcr_enc; | |
1087 | fmt->fmt.pix_mp.quantization = quantization; | |
1088 | fmt->fmt.pix_mp.xfer_func = xfer_func; | |
1089 | } | |
d52e2381 LP |
1090 | } |
1091 | ||
59076122 HV |
1092 | static int v4l_querycap(const struct v4l2_ioctl_ops *ops, |
1093 | struct file *file, void *fh, void *arg) | |
1094 | { | |
1095 | struct v4l2_capability *cap = (struct v4l2_capability *)arg; | |
7bbe7813 | 1096 | struct video_device *vfd = video_devdata(file); |
d52e2381 | 1097 | int ret; |
59076122 HV |
1098 | |
1099 | cap->version = LINUX_VERSION_CODE; | |
7bbe7813 HV |
1100 | cap->device_caps = vfd->device_caps; |
1101 | cap->capabilities = vfd->device_caps | V4L2_CAP_DEVICE_CAPS; | |
d52e2381 | 1102 | |
f2d8b691 SA |
1103 | media_set_bus_info(cap->bus_info, sizeof(cap->bus_info), |
1104 | vfd->dev_parent); | |
1105 | ||
d52e2381 LP |
1106 | ret = ops->vidioc_querycap(file, fh, cap); |
1107 | ||
454a4e72 | 1108 | /* |
3c135050 HV |
1109 | * Drivers must not change device_caps, so check for this and |
1110 | * warn if this happened. | |
1111 | */ | |
1112 | WARN_ON(cap->device_caps != vfd->device_caps); | |
1113 | /* | |
1114 | * Check that capabilities is a superset of | |
1115 | * vfd->device_caps | V4L2_CAP_DEVICE_CAPS | |
454a4e72 | 1116 | */ |
3c135050 HV |
1117 | WARN_ON((cap->capabilities & |
1118 | (vfd->device_caps | V4L2_CAP_DEVICE_CAPS)) != | |
1119 | (vfd->device_caps | V4L2_CAP_DEVICE_CAPS)); | |
1120 | cap->capabilities |= V4L2_CAP_EXT_PIX_FORMAT; | |
796a2bd2 | 1121 | cap->device_caps |= V4L2_CAP_EXT_PIX_FORMAT; |
d52e2381 LP |
1122 | |
1123 | return ret; | |
59076122 HV |
1124 | } |
1125 | ||
f645e625 NS |
1126 | static int v4l_g_input(const struct v4l2_ioctl_ops *ops, |
1127 | struct file *file, void *fh, void *arg) | |
1128 | { | |
1129 | struct video_device *vfd = video_devdata(file); | |
1130 | ||
1131 | if (vfd->device_caps & V4L2_CAP_IO_MC) { | |
1132 | *(int *)arg = 0; | |
1133 | return 0; | |
1134 | } | |
1135 | ||
1136 | return ops->vidioc_g_input(file, fh, arg); | |
1137 | } | |
1138 | ||
1139 | static int v4l_g_output(const struct v4l2_ioctl_ops *ops, | |
1140 | struct file *file, void *fh, void *arg) | |
1141 | { | |
1142 | struct video_device *vfd = video_devdata(file); | |
1143 | ||
1144 | if (vfd->device_caps & V4L2_CAP_IO_MC) { | |
1145 | *(int *)arg = 0; | |
1146 | return 0; | |
1147 | } | |
1148 | ||
1149 | return ops->vidioc_g_output(file, fh, arg); | |
1150 | } | |
1151 | ||
59076122 HV |
1152 | static int v4l_s_input(const struct v4l2_ioctl_ops *ops, |
1153 | struct file *file, void *fh, void *arg) | |
1154 | { | |
77fa4e07 SK |
1155 | struct video_device *vfd = video_devdata(file); |
1156 | int ret; | |
1157 | ||
1158 | ret = v4l_enable_media_source(vfd); | |
1159 | if (ret) | |
1160 | return ret; | |
f645e625 NS |
1161 | |
1162 | if (vfd->device_caps & V4L2_CAP_IO_MC) | |
1163 | return *(int *)arg ? -EINVAL : 0; | |
1164 | ||
59076122 HV |
1165 | return ops->vidioc_s_input(file, fh, *(unsigned int *)arg); |
1166 | } | |
1167 | ||
1168 | static int v4l_s_output(const struct v4l2_ioctl_ops *ops, | |
1169 | struct file *file, void *fh, void *arg) | |
1170 | { | |
f645e625 NS |
1171 | struct video_device *vfd = video_devdata(file); |
1172 | ||
1173 | if (vfd->device_caps & V4L2_CAP_IO_MC) | |
1174 | return *(int *)arg ? -EINVAL : 0; | |
1175 | ||
59076122 HV |
1176 | return ops->vidioc_s_output(file, fh, *(unsigned int *)arg); |
1177 | } | |
1178 | ||
d0547cba HV |
1179 | static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, |
1180 | struct file *file, void *fh, void *arg) | |
1181 | { | |
1182 | struct video_device *vfd; | |
1183 | u32 *p = arg; | |
1184 | ||
d0547cba | 1185 | vfd = video_devdata(file); |
59b702ea | 1186 | *p = v4l2_prio_max(vfd->prio); |
d0547cba HV |
1187 | return 0; |
1188 | } | |
1189 | ||
1190 | static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, | |
1191 | struct file *file, void *fh, void *arg) | |
1192 | { | |
1193 | struct video_device *vfd; | |
1194 | struct v4l2_fh *vfh; | |
1195 | u32 *p = arg; | |
1196 | ||
d0547cba | 1197 | vfd = video_devdata(file); |
2438e78a HV |
1198 | if (!test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) |
1199 | return -ENOTTY; | |
d0547cba | 1200 | vfh = file->private_data; |
59b702ea | 1201 | return v4l2_prio_change(vfd->prio, &vfh->prio, *p); |
d0547cba HV |
1202 | } |
1203 | ||
59076122 HV |
1204 | static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, |
1205 | struct file *file, void *fh, void *arg) | |
1206 | { | |
73f35418 | 1207 | struct video_device *vfd = video_devdata(file); |
59076122 HV |
1208 | struct v4l2_input *p = arg; |
1209 | ||
1210 | /* | |
02fa6282 | 1211 | * We set the flags for CAP_DV_TIMINGS & |
59076122 HV |
1212 | * CAP_STD here based on ioctl handler provided by the |
1213 | * driver. If the driver doesn't support these | |
1214 | * for a specific input, it must override these flags. | |
1215 | */ | |
73f35418 | 1216 | if (is_valid_ioctl(vfd, VIDIOC_S_STD)) |
59076122 | 1217 | p->capabilities |= V4L2_IN_CAP_STD; |
59076122 | 1218 | |
f645e625 NS |
1219 | if (vfd->device_caps & V4L2_CAP_IO_MC) { |
1220 | if (p->index) | |
1221 | return -EINVAL; | |
1222 | strscpy(p->name, vfd->name, sizeof(p->name)); | |
1223 | p->type = V4L2_INPUT_TYPE_CAMERA; | |
1224 | return 0; | |
1225 | } | |
1226 | ||
59076122 HV |
1227 | return ops->vidioc_enum_input(file, fh, p); |
1228 | } | |
1229 | ||
1230 | static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, | |
1231 | struct file *file, void *fh, void *arg) | |
1232 | { | |
73f35418 | 1233 | struct video_device *vfd = video_devdata(file); |
59076122 HV |
1234 | struct v4l2_output *p = arg; |
1235 | ||
1236 | /* | |
02fa6282 | 1237 | * We set the flags for CAP_DV_TIMINGS & |
59076122 HV |
1238 | * CAP_STD here based on ioctl handler provided by the |
1239 | * driver. If the driver doesn't support these | |
1240 | * for a specific output, it must override these flags. | |
1241 | */ | |
73f35418 | 1242 | if (is_valid_ioctl(vfd, VIDIOC_S_STD)) |
59076122 | 1243 | p->capabilities |= V4L2_OUT_CAP_STD; |
59076122 | 1244 | |
f645e625 NS |
1245 | if (vfd->device_caps & V4L2_CAP_IO_MC) { |
1246 | if (p->index) | |
1247 | return -EINVAL; | |
1248 | strscpy(p->name, vfd->name, sizeof(p->name)); | |
1249 | p->type = V4L2_OUTPUT_TYPE_ANALOG; | |
1250 | return 0; | |
1251 | } | |
1252 | ||
59076122 HV |
1253 | return ops->vidioc_enum_output(file, fh, p); |
1254 | } | |
1255 | ||
ba300204 HV |
1256 | static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) |
1257 | { | |
1258 | const unsigned sz = sizeof(fmt->description); | |
1259 | const char *descr = NULL; | |
1260 | u32 flags = 0; | |
1261 | ||
1262 | /* | |
1263 | * We depart from the normal coding style here since the descriptions | |
1264 | * should be aligned so it is easy to see which descriptions will be | |
1265 | * longer than 31 characters (the max length for a description). | |
1266 | * And frankly, this is easier to read anyway. | |
1267 | * | |
1268 | * Note that gcc will use O(log N) comparisons to find the right case. | |
1269 | */ | |
1270 | switch (fmt->pixelformat) { | |
1271 | /* Max description length mask: descr = "0123456789012345678901234567890" */ | |
1272 | case V4L2_PIX_FMT_RGB332: descr = "8-bit RGB 3-3-2"; break; | |
1273 | case V4L2_PIX_FMT_RGB444: descr = "16-bit A/XRGB 4-4-4-4"; break; | |
1274 | case V4L2_PIX_FMT_ARGB444: descr = "16-bit ARGB 4-4-4-4"; break; | |
1275 | case V4L2_PIX_FMT_XRGB444: descr = "16-bit XRGB 4-4-4-4"; break; | |
4747bd0f HV |
1276 | case V4L2_PIX_FMT_RGBA444: descr = "16-bit RGBA 4-4-4-4"; break; |
1277 | case V4L2_PIX_FMT_RGBX444: descr = "16-bit RGBX 4-4-4-4"; break; | |
1278 | case V4L2_PIX_FMT_ABGR444: descr = "16-bit ABGR 4-4-4-4"; break; | |
1279 | case V4L2_PIX_FMT_XBGR444: descr = "16-bit XBGR 4-4-4-4"; break; | |
1280 | case V4L2_PIX_FMT_BGRA444: descr = "16-bit BGRA 4-4-4-4"; break; | |
1281 | case V4L2_PIX_FMT_BGRX444: descr = "16-bit BGRX 4-4-4-4"; break; | |
ba300204 HV |
1282 | case V4L2_PIX_FMT_RGB555: descr = "16-bit A/XRGB 1-5-5-5"; break; |
1283 | case V4L2_PIX_FMT_ARGB555: descr = "16-bit ARGB 1-5-5-5"; break; | |
1284 | case V4L2_PIX_FMT_XRGB555: descr = "16-bit XRGB 1-5-5-5"; break; | |
4747bd0f HV |
1285 | case V4L2_PIX_FMT_ABGR555: descr = "16-bit ABGR 1-5-5-5"; break; |
1286 | case V4L2_PIX_FMT_XBGR555: descr = "16-bit XBGR 1-5-5-5"; break; | |
1287 | case V4L2_PIX_FMT_RGBA555: descr = "16-bit RGBA 5-5-5-1"; break; | |
1288 | case V4L2_PIX_FMT_RGBX555: descr = "16-bit RGBX 5-5-5-1"; break; | |
1289 | case V4L2_PIX_FMT_BGRA555: descr = "16-bit BGRA 5-5-5-1"; break; | |
1290 | case V4L2_PIX_FMT_BGRX555: descr = "16-bit BGRX 5-5-5-1"; break; | |
ba300204 HV |
1291 | case V4L2_PIX_FMT_RGB565: descr = "16-bit RGB 5-6-5"; break; |
1292 | case V4L2_PIX_FMT_RGB555X: descr = "16-bit A/XRGB 1-5-5-5 BE"; break; | |
1293 | case V4L2_PIX_FMT_ARGB555X: descr = "16-bit ARGB 1-5-5-5 BE"; break; | |
1294 | case V4L2_PIX_FMT_XRGB555X: descr = "16-bit XRGB 1-5-5-5 BE"; break; | |
1295 | case V4L2_PIX_FMT_RGB565X: descr = "16-bit RGB 5-6-5 BE"; break; | |
1296 | case V4L2_PIX_FMT_BGR666: descr = "18-bit BGRX 6-6-6-14"; break; | |
1297 | case V4L2_PIX_FMT_BGR24: descr = "24-bit BGR 8-8-8"; break; | |
1298 | case V4L2_PIX_FMT_RGB24: descr = "24-bit RGB 8-8-8"; break; | |
1299 | case V4L2_PIX_FMT_BGR32: descr = "32-bit BGRA/X 8-8-8-8"; break; | |
1300 | case V4L2_PIX_FMT_ABGR32: descr = "32-bit BGRA 8-8-8-8"; break; | |
1301 | case V4L2_PIX_FMT_XBGR32: descr = "32-bit BGRX 8-8-8-8"; break; | |
1302 | case V4L2_PIX_FMT_RGB32: descr = "32-bit A/XRGB 8-8-8-8"; break; | |
1303 | case V4L2_PIX_FMT_ARGB32: descr = "32-bit ARGB 8-8-8-8"; break; | |
1304 | case V4L2_PIX_FMT_XRGB32: descr = "32-bit XRGB 8-8-8-8"; break; | |
4747bd0f HV |
1305 | case V4L2_PIX_FMT_BGRA32: descr = "32-bit ABGR 8-8-8-8"; break; |
1306 | case V4L2_PIX_FMT_BGRX32: descr = "32-bit XBGR 8-8-8-8"; break; | |
1307 | case V4L2_PIX_FMT_RGBA32: descr = "32-bit RGBA 8-8-8-8"; break; | |
1308 | case V4L2_PIX_FMT_RGBX32: descr = "32-bit RGBX 8-8-8-8"; break; | |
8d0e3fc6 TV |
1309 | case V4L2_PIX_FMT_RGBX1010102: descr = "32-bit RGBX 10-10-10-2"; break; |
1310 | case V4L2_PIX_FMT_RGBA1010102: descr = "32-bit RGBA 10-10-10-2"; break; | |
1311 | case V4L2_PIX_FMT_ARGB2101010: descr = "32-bit ARGB 2-10-10-10"; break; | |
d1741141 JM |
1312 | case V4L2_PIX_FMT_BGR48: descr = "48-bit BGR 16-16-16"; break; |
1313 | case V4L2_PIX_FMT_RGB48: descr = "48-bit RGB 16-16-16"; break; | |
da0b7a40 | 1314 | case V4L2_PIX_FMT_BGR48_12: descr = "12-bit Depth BGR"; break; |
302b988c | 1315 | case V4L2_PIX_FMT_ABGR64_12: descr = "12-bit Depth BGRA"; break; |
ba300204 HV |
1316 | case V4L2_PIX_FMT_GREY: descr = "8-bit Greyscale"; break; |
1317 | case V4L2_PIX_FMT_Y4: descr = "4-bit Greyscale"; break; | |
1318 | case V4L2_PIX_FMT_Y6: descr = "6-bit Greyscale"; break; | |
1319 | case V4L2_PIX_FMT_Y10: descr = "10-bit Greyscale"; break; | |
1320 | case V4L2_PIX_FMT_Y12: descr = "12-bit Greyscale"; break; | |
a490ea68 | 1321 | case V4L2_PIX_FMT_Y012: descr = "12-bit Greyscale (bits 15-4)"; break; |
ae9753a0 | 1322 | case V4L2_PIX_FMT_Y14: descr = "14-bit Greyscale"; break; |
ba300204 | 1323 | case V4L2_PIX_FMT_Y16: descr = "16-bit Greyscale"; break; |
2e5e435f | 1324 | case V4L2_PIX_FMT_Y16_BE: descr = "16-bit Greyscale BE"; break; |
ba300204 | 1325 | case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; break; |
6e15bec4 | 1326 | case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI Packed)"; break; |
b87f5e25 | 1327 | case V4L2_PIX_FMT_IPU3_Y10: descr = "10-bit greyscale (IPU3 Packed)"; break; |
18104776 | 1328 | case V4L2_PIX_FMT_Y12P: descr = "12-bit Greyscale (MIPI Packed)"; break; |
adb1d465 | 1329 | case V4L2_PIX_FMT_Y14P: descr = "14-bit Greyscale (MIPI Packed)"; break; |
5b382290 LP |
1330 | case V4L2_PIX_FMT_Y8I: descr = "Interleaved 8-bit Greyscale"; break; |
1331 | case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; break; | |
a8f2cdd2 | 1332 | case V4L2_PIX_FMT_Y16I: descr = "Interleaved 16-bit Greyscale"; break; |
5b382290 | 1333 | case V4L2_PIX_FMT_Z16: descr = "16-bit Depth"; break; |
5df082e2 | 1334 | case V4L2_PIX_FMT_INZI: descr = "Planar 10:16 Greyscale Depth"; break; |
92799ef7 | 1335 | case V4L2_PIX_FMT_CNF4: descr = "4-bit Depth Confidence (Packed)"; break; |
ba300204 HV |
1336 | case V4L2_PIX_FMT_PAL8: descr = "8-bit Palette"; break; |
1337 | case V4L2_PIX_FMT_UV8: descr = "8-bit Chrominance UV 4-4"; break; | |
1338 | case V4L2_PIX_FMT_YVU410: descr = "Planar YVU 4:1:0"; break; | |
1339 | case V4L2_PIX_FMT_YVU420: descr = "Planar YVU 4:2:0"; break; | |
1340 | case V4L2_PIX_FMT_YUYV: descr = "YUYV 4:2:2"; break; | |
1341 | case V4L2_PIX_FMT_YYUV: descr = "YYUV 4:2:2"; break; | |
1342 | case V4L2_PIX_FMT_YVYU: descr = "YVYU 4:2:2"; break; | |
1343 | case V4L2_PIX_FMT_UYVY: descr = "UYVY 4:2:2"; break; | |
1344 | case V4L2_PIX_FMT_VYUY: descr = "VYUY 4:2:2"; break; | |
fcbafafb | 1345 | case V4L2_PIX_FMT_YUV422P: descr = "Planar YUV 4:2:2"; break; |
ba300204 HV |
1346 | case V4L2_PIX_FMT_YUV411P: descr = "Planar YUV 4:1:1"; break; |
1347 | case V4L2_PIX_FMT_Y41P: descr = "YUV 4:1:1 (Packed)"; break; | |
1348 | case V4L2_PIX_FMT_YUV444: descr = "16-bit A/XYUV 4-4-4-4"; break; | |
1349 | case V4L2_PIX_FMT_YUV555: descr = "16-bit A/XYUV 1-5-5-5"; break; | |
1350 | case V4L2_PIX_FMT_YUV565: descr = "16-bit YUV 5-6-5"; break; | |
0376a51f | 1351 | case V4L2_PIX_FMT_YUV24: descr = "24-bit YUV 4:4:4 8-8-8"; break; |
ba300204 | 1352 | case V4L2_PIX_FMT_YUV32: descr = "32-bit A/XYUV 8-8-8-8"; break; |
a7fe4ca7 VK |
1353 | case V4L2_PIX_FMT_AYUV32: descr = "32-bit AYUV 8-8-8-8"; break; |
1354 | case V4L2_PIX_FMT_XYUV32: descr = "32-bit XYUV 8-8-8-8"; break; | |
1355 | case V4L2_PIX_FMT_VUYA32: descr = "32-bit VUYA 8-8-8-8"; break; | |
1356 | case V4L2_PIX_FMT_VUYX32: descr = "32-bit VUYX 8-8-8-8"; break; | |
00f6842e LP |
1357 | case V4L2_PIX_FMT_YUVA32: descr = "32-bit YUVA 8-8-8-8"; break; |
1358 | case V4L2_PIX_FMT_YUVX32: descr = "32-bit YUVX 8-8-8-8"; break; | |
ba300204 HV |
1359 | case V4L2_PIX_FMT_YUV410: descr = "Planar YUV 4:1:0"; break; |
1360 | case V4L2_PIX_FMT_YUV420: descr = "Planar YUV 4:2:0"; break; | |
1361 | case V4L2_PIX_FMT_HI240: descr = "8-bit Dithered RGB (BTTV)"; break; | |
ba300204 | 1362 | case V4L2_PIX_FMT_M420: descr = "YUV 4:2:0 (M420)"; break; |
99c95496 | 1363 | case V4L2_PIX_FMT_YUV48_12: descr = "12-bit YUV 4:4:4 Packed"; break; |
6a394d56 JS |
1364 | case V4L2_PIX_FMT_NV12: descr = "Y/UV 4:2:0"; break; |
1365 | case V4L2_PIX_FMT_NV21: descr = "Y/VU 4:2:0"; break; | |
dcbe2aed | 1366 | case V4L2_PIX_FMT_NV15: descr = "10-bit Y/UV 4:2:0 (Packed)"; break; |
6a394d56 JS |
1367 | case V4L2_PIX_FMT_NV16: descr = "Y/UV 4:2:2"; break; |
1368 | case V4L2_PIX_FMT_NV61: descr = "Y/VU 4:2:2"; break; | |
dcbe2aed | 1369 | case V4L2_PIX_FMT_NV20: descr = "10-bit Y/UV 4:2:2 (Packed)"; break; |
6a394d56 JS |
1370 | case V4L2_PIX_FMT_NV24: descr = "Y/UV 4:4:4"; break; |
1371 | case V4L2_PIX_FMT_NV42: descr = "Y/VU 4:4:4"; break; | |
1372 | case V4L2_PIX_FMT_P010: descr = "10-bit Y/UV 4:2:0"; break; | |
aa108040 | 1373 | case V4L2_PIX_FMT_P012: descr = "12-bit Y/UV 4:2:0"; break; |
6a394d56 JS |
1374 | case V4L2_PIX_FMT_NV12_4L4: descr = "Y/UV 4:2:0 (4x4 Linear)"; break; |
1375 | case V4L2_PIX_FMT_NV12_16L16: descr = "Y/UV 4:2:0 (16x16 Linear)"; break; | |
1376 | case V4L2_PIX_FMT_NV12_32L32: descr = "Y/UV 4:2:0 (32x32 Linear)"; break; | |
fc91af07 | 1377 | case V4L2_PIX_FMT_NV15_4L4: descr = "10-bit Y/UV 4:2:0 (4x4 Linear)"; break; |
6a394d56 JS |
1378 | case V4L2_PIX_FMT_P010_4L4: descr = "10-bit Y/UV 4:2:0 (4x4 Linear)"; break; |
1379 | case V4L2_PIX_FMT_NV12M: descr = "Y/UV 4:2:0 (N-C)"; break; | |
1380 | case V4L2_PIX_FMT_NV21M: descr = "Y/VU 4:2:0 (N-C)"; break; | |
1381 | case V4L2_PIX_FMT_NV16M: descr = "Y/UV 4:2:2 (N-C)"; break; | |
1382 | case V4L2_PIX_FMT_NV61M: descr = "Y/VU 4:2:2 (N-C)"; break; | |
1383 | case V4L2_PIX_FMT_NV12MT: descr = "Y/UV 4:2:0 (64x32 MB, N-C)"; break; | |
1384 | case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/UV 4:2:0 (16x16 MB, N-C)"; break; | |
aa108040 | 1385 | case V4L2_PIX_FMT_P012M: descr = "12-bit Y/UV 4:2:0 (N-C)"; break; |
ba300204 HV |
1386 | case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break; |
1387 | case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break; | |
d65fae92 LP |
1388 | case V4L2_PIX_FMT_YUV422M: descr = "Planar YUV 4:2:2 (N-C)"; break; |
1389 | case V4L2_PIX_FMT_YVU422M: descr = "Planar YVU 4:2:2 (N-C)"; break; | |
1390 | case V4L2_PIX_FMT_YUV444M: descr = "Planar YUV 4:4:4 (N-C)"; break; | |
1391 | case V4L2_PIX_FMT_YVU444M: descr = "Planar YVU 4:4:4 (N-C)"; break; | |
ba300204 HV |
1392 | case V4L2_PIX_FMT_SBGGR8: descr = "8-bit Bayer BGBG/GRGR"; break; |
1393 | case V4L2_PIX_FMT_SGBRG8: descr = "8-bit Bayer GBGB/RGRG"; break; | |
1394 | case V4L2_PIX_FMT_SGRBG8: descr = "8-bit Bayer GRGR/BGBG"; break; | |
1395 | case V4L2_PIX_FMT_SRGGB8: descr = "8-bit Bayer RGRG/GBGB"; break; | |
1396 | case V4L2_PIX_FMT_SBGGR10: descr = "10-bit Bayer BGBG/GRGR"; break; | |
1397 | case V4L2_PIX_FMT_SGBRG10: descr = "10-bit Bayer GBGB/RGRG"; break; | |
1398 | case V4L2_PIX_FMT_SGRBG10: descr = "10-bit Bayer GRGR/BGBG"; break; | |
1399 | case V4L2_PIX_FMT_SRGGB10: descr = "10-bit Bayer RGRG/GBGB"; break; | |
ba300204 HV |
1400 | case V4L2_PIX_FMT_SBGGR10P: descr = "10-bit Bayer BGBG/GRGR Packed"; break; |
1401 | case V4L2_PIX_FMT_SGBRG10P: descr = "10-bit Bayer GBGB/RGRG Packed"; break; | |
1402 | case V4L2_PIX_FMT_SGRBG10P: descr = "10-bit Bayer GRGR/BGBG Packed"; break; | |
1403 | case V4L2_PIX_FMT_SRGGB10P: descr = "10-bit Bayer RGRG/GBGB Packed"; break; | |
e8391b76 YZ |
1404 | case V4L2_PIX_FMT_IPU3_SBGGR10: descr = "10-bit bayer BGGR IPU3 Packed"; break; |
1405 | case V4L2_PIX_FMT_IPU3_SGBRG10: descr = "10-bit bayer GBRG IPU3 Packed"; break; | |
1406 | case V4L2_PIX_FMT_IPU3_SGRBG10: descr = "10-bit bayer GRBG IPU3 Packed"; break; | |
1407 | case V4L2_PIX_FMT_IPU3_SRGGB10: descr = "10-bit bayer RGGB IPU3 Packed"; break; | |
ba300204 HV |
1408 | case V4L2_PIX_FMT_SBGGR10ALAW8: descr = "8-bit Bayer BGBG/GRGR (A-law)"; break; |
1409 | case V4L2_PIX_FMT_SGBRG10ALAW8: descr = "8-bit Bayer GBGB/RGRG (A-law)"; break; | |
1410 | case V4L2_PIX_FMT_SGRBG10ALAW8: descr = "8-bit Bayer GRGR/BGBG (A-law)"; break; | |
1411 | case V4L2_PIX_FMT_SRGGB10ALAW8: descr = "8-bit Bayer RGRG/GBGB (A-law)"; break; | |
1412 | case V4L2_PIX_FMT_SBGGR10DPCM8: descr = "8-bit Bayer BGBG/GRGR (DPCM)"; break; | |
1413 | case V4L2_PIX_FMT_SGBRG10DPCM8: descr = "8-bit Bayer GBGB/RGRG (DPCM)"; break; | |
1414 | case V4L2_PIX_FMT_SGRBG10DPCM8: descr = "8-bit Bayer GRGR/BGBG (DPCM)"; break; | |
1415 | case V4L2_PIX_FMT_SRGGB10DPCM8: descr = "8-bit Bayer RGRG/GBGB (DPCM)"; break; | |
d1b3437e SA |
1416 | case V4L2_PIX_FMT_SBGGR12: descr = "12-bit Bayer BGBG/GRGR"; break; |
1417 | case V4L2_PIX_FMT_SGBRG12: descr = "12-bit Bayer GBGB/RGRG"; break; | |
1418 | case V4L2_PIX_FMT_SGRBG12: descr = "12-bit Bayer GRGR/BGBG"; break; | |
1419 | case V4L2_PIX_FMT_SRGGB12: descr = "12-bit Bayer RGRG/GBGB"; break; | |
1420 | case V4L2_PIX_FMT_SBGGR12P: descr = "12-bit Bayer BGBG/GRGR Packed"; break; | |
1421 | case V4L2_PIX_FMT_SGBRG12P: descr = "12-bit Bayer GBGB/RGRG Packed"; break; | |
1422 | case V4L2_PIX_FMT_SGRBG12P: descr = "12-bit Bayer GRGR/BGBG Packed"; break; | |
1423 | case V4L2_PIX_FMT_SRGGB12P: descr = "12-bit Bayer RGRG/GBGB Packed"; break; | |
d12127ed SA |
1424 | case V4L2_PIX_FMT_SBGGR14: descr = "14-bit Bayer BGBG/GRGR"; break; |
1425 | case V4L2_PIX_FMT_SGBRG14: descr = "14-bit Bayer GBGB/RGRG"; break; | |
1426 | case V4L2_PIX_FMT_SGRBG14: descr = "14-bit Bayer GRGR/BGBG"; break; | |
1427 | case V4L2_PIX_FMT_SRGGB14: descr = "14-bit Bayer RGRG/GBGB"; break; | |
83b15832 SA |
1428 | case V4L2_PIX_FMT_SBGGR14P: descr = "14-bit Bayer BGBG/GRGR Packed"; break; |
1429 | case V4L2_PIX_FMT_SGBRG14P: descr = "14-bit Bayer GBGB/RGRG Packed"; break; | |
1430 | case V4L2_PIX_FMT_SGRBG14P: descr = "14-bit Bayer GRGR/BGBG Packed"; break; | |
1431 | case V4L2_PIX_FMT_SRGGB14P: descr = "14-bit Bayer RGRG/GBGB Packed"; break; | |
b9a4b13c SA |
1432 | case V4L2_PIX_FMT_SBGGR16: descr = "16-bit Bayer BGBG/GRGR"; break; |
1433 | case V4L2_PIX_FMT_SGBRG16: descr = "16-bit Bayer GBGB/RGRG"; break; | |
1434 | case V4L2_PIX_FMT_SGRBG16: descr = "16-bit Bayer GRGR/BGBG"; break; | |
1435 | case V4L2_PIX_FMT_SRGGB16: descr = "16-bit Bayer RGRG/GBGB"; break; | |
99b74277 | 1436 | case V4L2_PIX_FMT_SN9C20X_I420: descr = "GSPCA SN9C20X I420"; break; |
ba300204 HV |
1437 | case V4L2_PIX_FMT_SPCA501: descr = "GSPCA SPCA501"; break; |
1438 | case V4L2_PIX_FMT_SPCA505: descr = "GSPCA SPCA505"; break; | |
1439 | case V4L2_PIX_FMT_SPCA508: descr = "GSPCA SPCA508"; break; | |
1440 | case V4L2_PIX_FMT_STV0680: descr = "GSPCA STV0680"; break; | |
1441 | case V4L2_PIX_FMT_TM6000: descr = "A/V + VBI Mux Packet"; break; | |
1442 | case V4L2_PIX_FMT_CIT_YYVYUY: descr = "GSPCA CIT YYVYUY"; break; | |
1443 | case V4L2_PIX_FMT_KONICA420: descr = "GSPCA KONICA420"; break; | |
ffe5350c | 1444 | case V4L2_PIX_FMT_MM21: descr = "Mediatek 8-bit Block Format"; break; |
66b2ab27 RRD |
1445 | case V4L2_PIX_FMT_HSV24: descr = "24-bit HSV 8-8-8"; break; |
1446 | case V4L2_PIX_FMT_HSV32: descr = "32-bit XHSV 8-8-8-8"; break; | |
48fc10aa AP |
1447 | case V4L2_SDR_FMT_CU8: descr = "Complex U8"; break; |
1448 | case V4L2_SDR_FMT_CU16LE: descr = "Complex U16LE"; break; | |
ba300204 HV |
1449 | case V4L2_SDR_FMT_CS8: descr = "Complex S8"; break; |
1450 | case V4L2_SDR_FMT_CS14LE: descr = "Complex S14LE"; break; | |
1451 | case V4L2_SDR_FMT_RU12LE: descr = "Real U12LE"; break; | |
c28f2118 RS |
1452 | case V4L2_SDR_FMT_PCU16BE: descr = "Planar Complex U16BE"; break; |
1453 | case V4L2_SDR_FMT_PCU18BE: descr = "Planar Complex U18BE"; break; | |
1454 | case V4L2_SDR_FMT_PCU20BE: descr = "Planar Complex U20BE"; break; | |
4747bd0f HV |
1455 | case V4L2_TCH_FMT_DELTA_TD16: descr = "16-bit Signed Deltas"; break; |
1456 | case V4L2_TCH_FMT_DELTA_TD08: descr = "8-bit Signed Deltas"; break; | |
1457 | case V4L2_TCH_FMT_TU16: descr = "16-bit Unsigned Touch Data"; break; | |
1458 | case V4L2_TCH_FMT_TU08: descr = "8-bit Unsigned Touch Data"; break; | |
14d66538 | 1459 | case V4L2_META_FMT_VSP1_HGO: descr = "R-Car VSP1 1-D Histogram"; break; |
5deb1c04 | 1460 | case V4L2_META_FMT_VSP1_HGT: descr = "R-Car VSP1 2-D Histogram"; break; |
4747bd0f HV |
1461 | case V4L2_META_FMT_UVC: descr = "UVC Payload Header Metadata"; break; |
1462 | case V4L2_META_FMT_D4XX: descr = "Intel D4xx UVC Metadata"; break; | |
78892b6b | 1463 | case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break; |
df22026a SZ |
1464 | case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break; |
1465 | case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A Statistics"; break; | |
1fc379f6 | 1466 | case V4L2_META_FMT_RK_ISP1_EXT_PARAMS: descr = "Rockchip ISP1 Ext 3A Params"; break; |
a3aa115a KL |
1467 | case V4L2_META_FMT_C3ISP_PARAMS: descr = "Amlogic C3 ISP Parameters"; break; |
1468 | case V4L2_META_FMT_C3ISP_STATS: descr = "Amlogic C3 ISP Statistics"; break; | |
5b8bb216 | 1469 | case V4L2_PIX_FMT_NV12_8L128: descr = "NV12 (8x128 Linear)"; break; |
72a74c8f | 1470 | case V4L2_PIX_FMT_NV12M_8L128: descr = "NV12M (8x128 Linear)"; break; |
5b8bb216 | 1471 | case V4L2_PIX_FMT_NV12_10BE_8L128: descr = "10-bit NV12 (8x128 Linear, BE)"; break; |
72a74c8f | 1472 | case V4L2_PIX_FMT_NV12M_10BE_8L128: descr = "10-bit NV12M (8x128 Linear, BE)"; break; |
0dc1d7a7 TV |
1473 | case V4L2_PIX_FMT_Y210: descr = "10-bit YUYV Packed"; break; |
1474 | case V4L2_PIX_FMT_Y212: descr = "12-bit YUYV Packed"; break; | |
1475 | case V4L2_PIX_FMT_Y216: descr = "16-bit YUYV Packed"; break; | |
8f6c2202 | 1476 | case V4L2_META_FMT_RPI_BE_CFG: descr = "RPi PiSP BE Config format"; break; |
6390834c TV |
1477 | case V4L2_META_FMT_RPI_FE_CFG: descr = "RPi PiSP FE Config format"; break; |
1478 | case V4L2_META_FMT_RPI_FE_STATS: descr = "RPi PiSP FE Statistics format"; break; | |
1d921523 SA |
1479 | case V4L2_META_FMT_GENERIC_8: descr = "8-bit Generic Metadata"; break; |
1480 | case V4L2_META_FMT_GENERIC_CSI2_10: descr = "8-bit Generic Meta, 10b CSI-2"; break; | |
1481 | case V4L2_META_FMT_GENERIC_CSI2_12: descr = "8-bit Generic Meta, 12b CSI-2"; break; | |
1482 | case V4L2_META_FMT_GENERIC_CSI2_14: descr = "8-bit Generic Meta, 14b CSI-2"; break; | |
1483 | case V4L2_META_FMT_GENERIC_CSI2_16: descr = "8-bit Generic Meta, 16b CSI-2"; break; | |
1484 | case V4L2_META_FMT_GENERIC_CSI2_20: descr = "8-bit Generic Meta, 20b CSI-2"; break; | |
1485 | case V4L2_META_FMT_GENERIC_CSI2_24: descr = "8-bit Generic Meta, 24b CSI-2"; break; | |
ba300204 HV |
1486 | |
1487 | default: | |
1488 | /* Compressed formats */ | |
1489 | flags = V4L2_FMT_FLAG_COMPRESSED; | |
1490 | switch (fmt->pixelformat) { | |
1491 | /* Max description length mask: descr = "0123456789012345678901234567890" */ | |
1492 | case V4L2_PIX_FMT_MJPEG: descr = "Motion-JPEG"; break; | |
1493 | case V4L2_PIX_FMT_JPEG: descr = "JFIF JPEG"; break; | |
1494 | case V4L2_PIX_FMT_DV: descr = "1394"; break; | |
1495 | case V4L2_PIX_FMT_MPEG: descr = "MPEG-1/2/4"; break; | |
1496 | case V4L2_PIX_FMT_H264: descr = "H.264"; break; | |
1497 | case V4L2_PIX_FMT_H264_NO_SC: descr = "H.264 (No Start Codes)"; break; | |
1498 | case V4L2_PIX_FMT_H264_MVC: descr = "H.264 MVC"; break; | |
7bb3c32a | 1499 | case V4L2_PIX_FMT_H264_SLICE: descr = "H.264 Parsed Slice Data"; break; |
ba300204 HV |
1500 | case V4L2_PIX_FMT_H263: descr = "H.263"; break; |
1501 | case V4L2_PIX_FMT_MPEG1: descr = "MPEG-1 ES"; break; | |
1502 | case V4L2_PIX_FMT_MPEG2: descr = "MPEG-2 ES"; break; | |
c27bb30e | 1503 | case V4L2_PIX_FMT_MPEG2_SLICE: descr = "MPEG-2 Parsed Slice Data"; break; |
4747bd0f | 1504 | case V4L2_PIX_FMT_MPEG4: descr = "MPEG-4 Part 2 ES"; break; |
ba300204 HV |
1505 | case V4L2_PIX_FMT_XVID: descr = "Xvid"; break; |
1506 | case V4L2_PIX_FMT_VC1_ANNEX_G: descr = "VC-1 (SMPTE 412M Annex G)"; break; | |
1507 | case V4L2_PIX_FMT_VC1_ANNEX_L: descr = "VC-1 (SMPTE 412M Annex L)"; break; | |
1508 | case V4L2_PIX_FMT_VP8: descr = "VP8"; break; | |
a57d6aca | 1509 | case V4L2_PIX_FMT_VP8_FRAME: descr = "VP8 Frame"; break; |
fa14a564 | 1510 | case V4L2_PIX_FMT_VP9: descr = "VP9"; break; |
b88dbe38 | 1511 | case V4L2_PIX_FMT_VP9_FRAME: descr = "VP9 Frame"; break; |
1c791727 | 1512 | case V4L2_PIX_FMT_HEVC: descr = "HEVC"; break; /* aka H.265 */ |
256fa392 | 1513 | case V4L2_PIX_FMT_HEVC_SLICE: descr = "HEVC Parsed Slice Data"; break; |
62c3fce0 | 1514 | case V4L2_PIX_FMT_FWHT: descr = "FWHT"; break; /* used in vicodec */ |
f05a51b9 | 1515 | case V4L2_PIX_FMT_FWHT_STATELESS: descr = "FWHT Stateless"; break; /* used in vicodec */ |
ae77d139 | 1516 | case V4L2_PIX_FMT_SPK: descr = "Sorenson Spark"; break; |
ec9aa62a MQ |
1517 | case V4L2_PIX_FMT_RV30: descr = "RealVideo 8"; break; |
1518 | case V4L2_PIX_FMT_RV40: descr = "RealVideo 9 & 10"; break; | |
ba300204 HV |
1519 | case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break; |
1520 | case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break; | |
1521 | case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break; | |
1522 | case V4L2_PIX_FMT_PWC1: descr = "Raw Philips Webcam Type (Old)"; break; | |
1523 | case V4L2_PIX_FMT_PWC2: descr = "Raw Philips Webcam Type (New)"; break; | |
1524 | case V4L2_PIX_FMT_ET61X251: descr = "GSPCA ET61X251"; break; | |
1525 | case V4L2_PIX_FMT_SPCA561: descr = "GSPCA SPCA561"; break; | |
1526 | case V4L2_PIX_FMT_PAC207: descr = "GSPCA PAC207"; break; | |
1527 | case V4L2_PIX_FMT_MR97310A: descr = "GSPCA MR97310A"; break; | |
1528 | case V4L2_PIX_FMT_JL2005BCD: descr = "GSPCA JL2005BCD"; break; | |
1529 | case V4L2_PIX_FMT_SN9C2028: descr = "GSPCA SN9C2028"; break; | |
1530 | case V4L2_PIX_FMT_SQ905C: descr = "GSPCA SQ905C"; break; | |
1531 | case V4L2_PIX_FMT_PJPG: descr = "GSPCA PJPG"; break; | |
1532 | case V4L2_PIX_FMT_OV511: descr = "GSPCA OV511"; break; | |
1533 | case V4L2_PIX_FMT_OV518: descr = "GSPCA OV518"; break; | |
1534 | case V4L2_PIX_FMT_JPGL: descr = "JPEG Lite"; break; | |
1535 | case V4L2_PIX_FMT_SE401: descr = "GSPCA SE401"; break; | |
1536 | case V4L2_PIX_FMT_S5C_UYVY_JPG: descr = "S5C73MX interleaved UYVY/JPEG"; break; | |
d4de6634 | 1537 | case V4L2_PIX_FMT_MT21C: descr = "Mediatek Compressed Format"; break; |
2308d5af SV |
1538 | case V4L2_PIX_FMT_QC08C: descr = "QCOM Compressed 8-bit Format"; break; |
1539 | case V4L2_PIX_FMT_QC10C: descr = "QCOM Compressed 10-bit Format"; break; | |
7a4b3770 | 1540 | case V4L2_PIX_FMT_AJPG: descr = "Aspeed JPEG"; break; |
9de30f57 | 1541 | case V4L2_PIX_FMT_AV1_FRAME: descr = "AV1 Frame"; break; |
6afcc2b0 | 1542 | case V4L2_PIX_FMT_MT2110T: descr = "Mediatek 10bit Tile Mode"; break; |
1dff2beb | 1543 | case V4L2_PIX_FMT_MT2110R: descr = "Mediatek 10bit Raster Mode"; break; |
d62d8e7b | 1544 | case V4L2_PIX_FMT_HEXTILE: descr = "Hextile Compressed Format"; break; |
d260c122 JM |
1545 | case V4L2_PIX_FMT_PISP_COMP1_RGGB: descr = "PiSP 8b RGRG/GBGB mode1 compr"; break; |
1546 | case V4L2_PIX_FMT_PISP_COMP1_GRBG: descr = "PiSP 8b GRGR/BGBG mode1 compr"; break; | |
1547 | case V4L2_PIX_FMT_PISP_COMP1_GBRG: descr = "PiSP 8b GBGB/RGRG mode1 compr"; break; | |
1548 | case V4L2_PIX_FMT_PISP_COMP1_BGGR: descr = "PiSP 8b BGBG/GRGR mode1 compr"; break; | |
1549 | case V4L2_PIX_FMT_PISP_COMP1_MONO: descr = "PiSP 8b monochrome mode1 compr"; break; | |
1550 | case V4L2_PIX_FMT_PISP_COMP2_RGGB: descr = "PiSP 8b RGRG/GBGB mode2 compr"; break; | |
1551 | case V4L2_PIX_FMT_PISP_COMP2_GRBG: descr = "PiSP 8b GRGR/BGBG mode2 compr"; break; | |
1552 | case V4L2_PIX_FMT_PISP_COMP2_GBRG: descr = "PiSP 8b GBGB/RGRG mode2 compr"; break; | |
1553 | case V4L2_PIX_FMT_PISP_COMP2_BGGR: descr = "PiSP 8b BGBG/GRGR mode2 compr"; break; | |
1554 | case V4L2_PIX_FMT_PISP_COMP2_MONO: descr = "PiSP 8b monochrome mode2 compr"; break; | |
ba300204 | 1555 | default: |
ba300204 HV |
1556 | if (fmt->description[0]) |
1557 | return; | |
c2286cc0 | 1558 | WARN(1, "Unknown pixelformat 0x%08x\n", fmt->pixelformat); |
ba300204 | 1559 | flags = 0; |
e927e1e0 SA |
1560 | snprintf(fmt->description, sz, "%p4cc", |
1561 | &fmt->pixelformat); | |
ba300204 HV |
1562 | break; |
1563 | } | |
1564 | } | |
1565 | ||
21828609 SA |
1566 | if (fmt->type == V4L2_BUF_TYPE_META_CAPTURE) { |
1567 | switch (fmt->pixelformat) { | |
1568 | case V4L2_META_FMT_GENERIC_8: | |
1569 | case V4L2_META_FMT_GENERIC_CSI2_10: | |
1570 | case V4L2_META_FMT_GENERIC_CSI2_12: | |
1571 | case V4L2_META_FMT_GENERIC_CSI2_14: | |
1572 | case V4L2_META_FMT_GENERIC_CSI2_16: | |
1573 | case V4L2_META_FMT_GENERIC_CSI2_20: | |
1574 | case V4L2_META_FMT_GENERIC_CSI2_24: | |
1575 | fmt->flags |= V4L2_FMT_FLAG_META_LINE_BASED; | |
1576 | break; | |
1577 | default: | |
1578 | fmt->flags &= ~V4L2_FMT_FLAG_META_LINE_BASED; | |
1579 | } | |
1580 | } | |
1581 | ||
ba300204 | 1582 | if (descr) |
e7dd89ce | 1583 | WARN_ON(strscpy(fmt->description, descr, sz) < 0); |
7c490e25 | 1584 | fmt->flags |= flags; |
ba300204 HV |
1585 | } |
1586 | ||
be6c64e4 HV |
1587 | static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, |
1588 | struct file *file, void *fh, void *arg) | |
1589 | { | |
7e98b7b5 | 1590 | struct video_device *vdev = video_devdata(file); |
be6c64e4 | 1591 | struct v4l2_fmtdesc *p = arg; |
b2469c81 | 1592 | int ret = check_fmt(file, p->type); |
e5b6b07a | 1593 | u32 mbus_code; |
f0d2b7a8 | 1594 | u32 cap_mask; |
b2469c81 HV |
1595 | |
1596 | if (ret) | |
1597 | return ret; | |
1598 | ret = -EINVAL; | |
be6c64e4 | 1599 | |
e5b6b07a LP |
1600 | if (!(vdev->device_caps & V4L2_CAP_IO_MC)) |
1601 | p->mbus_code = 0; | |
1602 | ||
1603 | mbus_code = p->mbus_code; | |
0625b6b8 | 1604 | memset_after(p, 0, type); |
e5b6b07a LP |
1605 | p->mbus_code = mbus_code; |
1606 | ||
be6c64e4 HV |
1607 | switch (p->type) { |
1608 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
7e98b7b5 | 1609 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
f0d2b7a8 BB |
1610 | cap_mask = V4L2_CAP_VIDEO_CAPTURE_MPLANE | |
1611 | V4L2_CAP_VIDEO_M2M_MPLANE; | |
1612 | if (!!(vdev->device_caps & cap_mask) != | |
7e98b7b5 BB |
1613 | (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) |
1614 | break; | |
1615 | ||
b2469c81 | 1616 | if (unlikely(!ops->vidioc_enum_fmt_vid_cap)) |
be6c64e4 | 1617 | break; |
ba300204 HV |
1618 | ret = ops->vidioc_enum_fmt_vid_cap(file, fh, arg); |
1619 | break; | |
be6c64e4 | 1620 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
b2469c81 | 1621 | if (unlikely(!ops->vidioc_enum_fmt_vid_overlay)) |
be6c64e4 | 1622 | break; |
ba300204 HV |
1623 | ret = ops->vidioc_enum_fmt_vid_overlay(file, fh, arg); |
1624 | break; | |
be6c64e4 | 1625 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
7e98b7b5 | 1626 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
f0d2b7a8 BB |
1627 | cap_mask = V4L2_CAP_VIDEO_OUTPUT_MPLANE | |
1628 | V4L2_CAP_VIDEO_M2M_MPLANE; | |
1629 | if (!!(vdev->device_caps & cap_mask) != | |
7e98b7b5 BB |
1630 | (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)) |
1631 | break; | |
1632 | ||
b2469c81 | 1633 | if (unlikely(!ops->vidioc_enum_fmt_vid_out)) |
be6c64e4 | 1634 | break; |
ba300204 HV |
1635 | ret = ops->vidioc_enum_fmt_vid_out(file, fh, arg); |
1636 | break; | |
582c52cb | 1637 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
b2469c81 | 1638 | if (unlikely(!ops->vidioc_enum_fmt_sdr_cap)) |
582c52cb | 1639 | break; |
ba300204 HV |
1640 | ret = ops->vidioc_enum_fmt_sdr_cap(file, fh, arg); |
1641 | break; | |
9effc72f | 1642 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
b2469c81 | 1643 | if (unlikely(!ops->vidioc_enum_fmt_sdr_out)) |
9effc72f AP |
1644 | break; |
1645 | ret = ops->vidioc_enum_fmt_sdr_out(file, fh, arg); | |
1646 | break; | |
fb9ffa6a | 1647 | case V4L2_BUF_TYPE_META_CAPTURE: |
b2469c81 | 1648 | if (unlikely(!ops->vidioc_enum_fmt_meta_cap)) |
fb9ffa6a LP |
1649 | break; |
1650 | ret = ops->vidioc_enum_fmt_meta_cap(file, fh, arg); | |
1651 | break; | |
72148d1a SA |
1652 | case V4L2_BUF_TYPE_META_OUTPUT: |
1653 | if (unlikely(!ops->vidioc_enum_fmt_meta_out)) | |
1654 | break; | |
1655 | ret = ops->vidioc_enum_fmt_meta_out(file, fh, arg); | |
1656 | break; | |
be6c64e4 | 1657 | } |
ba300204 HV |
1658 | if (ret == 0) |
1659 | v4l_fill_fmtdesc(p); | |
1660 | return ret; | |
be6c64e4 HV |
1661 | } |
1662 | ||
545b618c VB |
1663 | static void v4l_pix_format_touch(struct v4l2_pix_format *p) |
1664 | { | |
1665 | /* | |
1666 | * The v4l2_pix_format structure contains fields that make no sense for | |
1667 | * touch. Set them to default values in this case. | |
1668 | */ | |
1669 | ||
1670 | p->field = V4L2_FIELD_NONE; | |
1671 | p->colorspace = V4L2_COLORSPACE_RAW; | |
1672 | p->flags = 0; | |
1673 | p->ycbcr_enc = 0; | |
1674 | p->quantization = 0; | |
1675 | p->xfer_func = 0; | |
1676 | } | |
1677 | ||
be6c64e4 HV |
1678 | static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, |
1679 | struct file *file, void *fh, void *arg) | |
1680 | { | |
1681 | struct v4l2_format *p = arg; | |
545b618c | 1682 | struct video_device *vfd = video_devdata(file); |
b2469c81 HV |
1683 | int ret = check_fmt(file, p->type); |
1684 | ||
1685 | if (ret) | |
1686 | return ret; | |
d52e2381 | 1687 | |
99ba0703 | 1688 | memset(&p->fmt, 0, sizeof(p->fmt)); |
e5ce558a | 1689 | |
be6c64e4 HV |
1690 | switch (p->type) { |
1691 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
b2469c81 | 1692 | if (unlikely(!ops->vidioc_g_fmt_vid_cap)) |
be6c64e4 | 1693 | break; |
48f2650a | 1694 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; |
d52e2381 | 1695 | ret = ops->vidioc_g_fmt_vid_cap(file, fh, arg); |
48f2650a | 1696 | /* just in case the driver zeroed it again */ |
d52e2381 | 1697 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; |
545b618c VB |
1698 | if (vfd->vfl_type == VFL_TYPE_TOUCH) |
1699 | v4l_pix_format_touch(&p->fmt.pix); | |
d52e2381 | 1700 | return ret; |
be6c64e4 | 1701 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
be6c64e4 HV |
1702 | return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg); |
1703 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
be6c64e4 | 1704 | return ops->vidioc_g_fmt_vid_overlay(file, fh, arg); |
4b20259f | 1705 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
4b20259f HV |
1706 | return ops->vidioc_g_fmt_vbi_cap(file, fh, arg); |
1707 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
4b20259f | 1708 | return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg); |
be6c64e4 | 1709 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
b2469c81 | 1710 | if (unlikely(!ops->vidioc_g_fmt_vid_out)) |
be6c64e4 | 1711 | break; |
48f2650a | 1712 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; |
d52e2381 | 1713 | ret = ops->vidioc_g_fmt_vid_out(file, fh, arg); |
48f2650a | 1714 | /* just in case the driver zeroed it again */ |
d52e2381 LP |
1715 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; |
1716 | return ret; | |
be6c64e4 | 1717 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
be6c64e4 HV |
1718 | return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg); |
1719 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
be6c64e4 | 1720 | return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg); |
be6c64e4 | 1721 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
be6c64e4 | 1722 | return ops->vidioc_g_fmt_vbi_out(file, fh, arg); |
be6c64e4 | 1723 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
be6c64e4 | 1724 | return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg); |
582c52cb | 1725 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
582c52cb | 1726 | return ops->vidioc_g_fmt_sdr_cap(file, fh, arg); |
9effc72f | 1727 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
9effc72f | 1728 | return ops->vidioc_g_fmt_sdr_out(file, fh, arg); |
fb9ffa6a | 1729 | case V4L2_BUF_TYPE_META_CAPTURE: |
fb9ffa6a | 1730 | return ops->vidioc_g_fmt_meta_cap(file, fh, arg); |
72148d1a SA |
1731 | case V4L2_BUF_TYPE_META_OUTPUT: |
1732 | return ops->vidioc_g_fmt_meta_out(file, fh, arg); | |
be6c64e4 HV |
1733 | } |
1734 | return -EINVAL; | |
1735 | } | |
1736 | ||
1737 | static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, | |
1738 | struct file *file, void *fh, void *arg) | |
1739 | { | |
1740 | struct v4l2_format *p = arg; | |
4b20259f | 1741 | struct video_device *vfd = video_devdata(file); |
b2469c81 | 1742 | int ret = check_fmt(file, p->type); |
4e1e0eb0 | 1743 | unsigned int i; |
b2469c81 HV |
1744 | |
1745 | if (ret) | |
1746 | return ret; | |
be6c64e4 | 1747 | |
77fa4e07 SK |
1748 | ret = v4l_enable_media_source(vfd); |
1749 | if (ret) | |
1750 | return ret; | |
d52e2381 LP |
1751 | v4l_sanitize_format(p); |
1752 | ||
be6c64e4 HV |
1753 | switch (p->type) { |
1754 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
b2469c81 | 1755 | if (unlikely(!ops->vidioc_s_fmt_vid_cap)) |
be6c64e4 | 1756 | break; |
0625b6b8 | 1757 | memset_after(p, 0, fmt.pix); |
48f2650a HV |
1758 | ret = ops->vidioc_s_fmt_vid_cap(file, fh, arg); |
1759 | /* just in case the driver zeroed it again */ | |
1760 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; | |
b2469c81 | 1761 | if (vfd->vfl_type == VFL_TYPE_TOUCH) |
b2fe22d0 | 1762 | v4l_pix_format_touch(&p->fmt.pix); |
48f2650a | 1763 | return ret; |
be6c64e4 | 1764 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
b2469c81 | 1765 | if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane)) |
be6c64e4 | 1766 | break; |
0625b6b8 | 1767 | memset_after(p, 0, fmt.pix_mp.xfer_func); |
4e1e0eb0 | 1768 | for (i = 0; i < p->fmt.pix_mp.num_planes; i++) |
0625b6b8 XJ |
1769 | memset_after(&p->fmt.pix_mp.plane_fmt[i], |
1770 | 0, bytesperline); | |
be6c64e4 HV |
1771 | return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg); |
1772 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
b2469c81 | 1773 | if (unlikely(!ops->vidioc_s_fmt_vid_overlay)) |
be6c64e4 | 1774 | break; |
0625b6b8 | 1775 | memset_after(p, 0, fmt.win); |
99ba0703 HV |
1776 | p->fmt.win.clips = NULL; |
1777 | p->fmt.win.clipcount = 0; | |
1778 | p->fmt.win.bitmap = NULL; | |
be6c64e4 | 1779 | return ops->vidioc_s_fmt_vid_overlay(file, fh, arg); |
4b20259f | 1780 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
b2469c81 | 1781 | if (unlikely(!ops->vidioc_s_fmt_vbi_cap)) |
4b20259f | 1782 | break; |
0625b6b8 | 1783 | memset_after(p, 0, fmt.vbi.flags); |
4b20259f HV |
1784 | return ops->vidioc_s_fmt_vbi_cap(file, fh, arg); |
1785 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
b2469c81 | 1786 | if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap)) |
4b20259f | 1787 | break; |
0625b6b8 | 1788 | memset_after(p, 0, fmt.sliced.io_size); |
4b20259f | 1789 | return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg); |
be6c64e4 | 1790 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
b2469c81 | 1791 | if (unlikely(!ops->vidioc_s_fmt_vid_out)) |
be6c64e4 | 1792 | break; |
0625b6b8 | 1793 | memset_after(p, 0, fmt.pix); |
48f2650a HV |
1794 | ret = ops->vidioc_s_fmt_vid_out(file, fh, arg); |
1795 | /* just in case the driver zeroed it again */ | |
1796 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; | |
1797 | return ret; | |
be6c64e4 | 1798 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
b2469c81 | 1799 | if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane)) |
be6c64e4 | 1800 | break; |
0625b6b8 | 1801 | memset_after(p, 0, fmt.pix_mp.xfer_func); |
4e1e0eb0 | 1802 | for (i = 0; i < p->fmt.pix_mp.num_planes; i++) |
0625b6b8 XJ |
1803 | memset_after(&p->fmt.pix_mp.plane_fmt[i], |
1804 | 0, bytesperline); | |
be6c64e4 HV |
1805 | return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg); |
1806 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
b2469c81 | 1807 | if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay)) |
be6c64e4 | 1808 | break; |
0625b6b8 | 1809 | memset_after(p, 0, fmt.win); |
99ba0703 HV |
1810 | p->fmt.win.clips = NULL; |
1811 | p->fmt.win.clipcount = 0; | |
1812 | p->fmt.win.bitmap = NULL; | |
be6c64e4 | 1813 | return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg); |
be6c64e4 | 1814 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
b2469c81 | 1815 | if (unlikely(!ops->vidioc_s_fmt_vbi_out)) |
be6c64e4 | 1816 | break; |
0625b6b8 | 1817 | memset_after(p, 0, fmt.vbi.flags); |
be6c64e4 | 1818 | return ops->vidioc_s_fmt_vbi_out(file, fh, arg); |
be6c64e4 | 1819 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
b2469c81 | 1820 | if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out)) |
be6c64e4 | 1821 | break; |
0625b6b8 | 1822 | memset_after(p, 0, fmt.sliced.io_size); |
be6c64e4 | 1823 | return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg); |
582c52cb | 1824 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
b2469c81 | 1825 | if (unlikely(!ops->vidioc_s_fmt_sdr_cap)) |
582c52cb | 1826 | break; |
0625b6b8 | 1827 | memset_after(p, 0, fmt.sdr.buffersize); |
582c52cb | 1828 | return ops->vidioc_s_fmt_sdr_cap(file, fh, arg); |
9effc72f | 1829 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
b2469c81 | 1830 | if (unlikely(!ops->vidioc_s_fmt_sdr_out)) |
9effc72f | 1831 | break; |
0625b6b8 | 1832 | memset_after(p, 0, fmt.sdr.buffersize); |
9effc72f | 1833 | return ops->vidioc_s_fmt_sdr_out(file, fh, arg); |
fb9ffa6a | 1834 | case V4L2_BUF_TYPE_META_CAPTURE: |
b2469c81 | 1835 | if (unlikely(!ops->vidioc_s_fmt_meta_cap)) |
fb9ffa6a | 1836 | break; |
0625b6b8 | 1837 | memset_after(p, 0, fmt.meta); |
fb9ffa6a | 1838 | return ops->vidioc_s_fmt_meta_cap(file, fh, arg); |
72148d1a SA |
1839 | case V4L2_BUF_TYPE_META_OUTPUT: |
1840 | if (unlikely(!ops->vidioc_s_fmt_meta_out)) | |
1841 | break; | |
0625b6b8 | 1842 | memset_after(p, 0, fmt.meta); |
72148d1a | 1843 | return ops->vidioc_s_fmt_meta_out(file, fh, arg); |
be6c64e4 HV |
1844 | } |
1845 | return -EINVAL; | |
1846 | } | |
1847 | ||
1848 | static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, | |
1849 | struct file *file, void *fh, void *arg) | |
1850 | { | |
1851 | struct v4l2_format *p = arg; | |
999a4312 | 1852 | struct video_device *vfd = video_devdata(file); |
b2469c81 | 1853 | int ret = check_fmt(file, p->type); |
4e1e0eb0 | 1854 | unsigned int i; |
b2469c81 HV |
1855 | |
1856 | if (ret) | |
1857 | return ret; | |
be6c64e4 | 1858 | |
d52e2381 LP |
1859 | v4l_sanitize_format(p); |
1860 | ||
be6c64e4 HV |
1861 | switch (p->type) { |
1862 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
b2469c81 | 1863 | if (unlikely(!ops->vidioc_try_fmt_vid_cap)) |
be6c64e4 | 1864 | break; |
0625b6b8 | 1865 | memset_after(p, 0, fmt.pix); |
48f2650a HV |
1866 | ret = ops->vidioc_try_fmt_vid_cap(file, fh, arg); |
1867 | /* just in case the driver zeroed it again */ | |
1868 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; | |
999a4312 HV |
1869 | if (vfd->vfl_type == VFL_TYPE_TOUCH) |
1870 | v4l_pix_format_touch(&p->fmt.pix); | |
48f2650a | 1871 | return ret; |
be6c64e4 | 1872 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
b2469c81 | 1873 | if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane)) |
be6c64e4 | 1874 | break; |
0625b6b8 | 1875 | memset_after(p, 0, fmt.pix_mp.xfer_func); |
4e1e0eb0 | 1876 | for (i = 0; i < p->fmt.pix_mp.num_planes; i++) |
0625b6b8 XJ |
1877 | memset_after(&p->fmt.pix_mp.plane_fmt[i], |
1878 | 0, bytesperline); | |
be6c64e4 HV |
1879 | return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg); |
1880 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
b2469c81 | 1881 | if (unlikely(!ops->vidioc_try_fmt_vid_overlay)) |
be6c64e4 | 1882 | break; |
0625b6b8 | 1883 | memset_after(p, 0, fmt.win); |
99ba0703 HV |
1884 | p->fmt.win.clips = NULL; |
1885 | p->fmt.win.clipcount = 0; | |
1886 | p->fmt.win.bitmap = NULL; | |
be6c64e4 | 1887 | return ops->vidioc_try_fmt_vid_overlay(file, fh, arg); |
4b20259f | 1888 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
b2469c81 | 1889 | if (unlikely(!ops->vidioc_try_fmt_vbi_cap)) |
4b20259f | 1890 | break; |
0625b6b8 | 1891 | memset_after(p, 0, fmt.vbi.flags); |
4b20259f HV |
1892 | return ops->vidioc_try_fmt_vbi_cap(file, fh, arg); |
1893 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
b2469c81 | 1894 | if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap)) |
4b20259f | 1895 | break; |
0625b6b8 | 1896 | memset_after(p, 0, fmt.sliced.io_size); |
4b20259f | 1897 | return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg); |
be6c64e4 | 1898 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
b2469c81 | 1899 | if (unlikely(!ops->vidioc_try_fmt_vid_out)) |
be6c64e4 | 1900 | break; |
0625b6b8 | 1901 | memset_after(p, 0, fmt.pix); |
48f2650a HV |
1902 | ret = ops->vidioc_try_fmt_vid_out(file, fh, arg); |
1903 | /* just in case the driver zeroed it again */ | |
1904 | p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; | |
1905 | return ret; | |
be6c64e4 | 1906 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
b2469c81 | 1907 | if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane)) |
be6c64e4 | 1908 | break; |
0625b6b8 | 1909 | memset_after(p, 0, fmt.pix_mp.xfer_func); |
4e1e0eb0 | 1910 | for (i = 0; i < p->fmt.pix_mp.num_planes; i++) |
0625b6b8 XJ |
1911 | memset_after(&p->fmt.pix_mp.plane_fmt[i], |
1912 | 0, bytesperline); | |
be6c64e4 HV |
1913 | return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg); |
1914 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
b2469c81 | 1915 | if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay)) |
be6c64e4 | 1916 | break; |
0625b6b8 | 1917 | memset_after(p, 0, fmt.win); |
99ba0703 HV |
1918 | p->fmt.win.clips = NULL; |
1919 | p->fmt.win.clipcount = 0; | |
1920 | p->fmt.win.bitmap = NULL; | |
be6c64e4 | 1921 | return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg); |
be6c64e4 | 1922 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
b2469c81 | 1923 | if (unlikely(!ops->vidioc_try_fmt_vbi_out)) |
be6c64e4 | 1924 | break; |
0625b6b8 | 1925 | memset_after(p, 0, fmt.vbi.flags); |
be6c64e4 | 1926 | return ops->vidioc_try_fmt_vbi_out(file, fh, arg); |
be6c64e4 | 1927 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
b2469c81 | 1928 | if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out)) |
be6c64e4 | 1929 | break; |
0625b6b8 | 1930 | memset_after(p, 0, fmt.sliced.io_size); |
be6c64e4 | 1931 | return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg); |
582c52cb | 1932 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
b2469c81 | 1933 | if (unlikely(!ops->vidioc_try_fmt_sdr_cap)) |
582c52cb | 1934 | break; |
0625b6b8 | 1935 | memset_after(p, 0, fmt.sdr.buffersize); |
582c52cb | 1936 | return ops->vidioc_try_fmt_sdr_cap(file, fh, arg); |
9effc72f | 1937 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
b2469c81 | 1938 | if (unlikely(!ops->vidioc_try_fmt_sdr_out)) |
9effc72f | 1939 | break; |
0625b6b8 | 1940 | memset_after(p, 0, fmt.sdr.buffersize); |
9effc72f | 1941 | return ops->vidioc_try_fmt_sdr_out(file, fh, arg); |
fb9ffa6a | 1942 | case V4L2_BUF_TYPE_META_CAPTURE: |
b2469c81 | 1943 | if (unlikely(!ops->vidioc_try_fmt_meta_cap)) |
fb9ffa6a | 1944 | break; |
0625b6b8 | 1945 | memset_after(p, 0, fmt.meta); |
fb9ffa6a | 1946 | return ops->vidioc_try_fmt_meta_cap(file, fh, arg); |
72148d1a SA |
1947 | case V4L2_BUF_TYPE_META_OUTPUT: |
1948 | if (unlikely(!ops->vidioc_try_fmt_meta_out)) | |
1949 | break; | |
0625b6b8 | 1950 | memset_after(p, 0, fmt.meta); |
72148d1a | 1951 | return ops->vidioc_try_fmt_meta_out(file, fh, arg); |
be6c64e4 HV |
1952 | } |
1953 | return -EINVAL; | |
1954 | } | |
1955 | ||
e325b244 HV |
1956 | static int v4l_streamon(const struct v4l2_ioctl_ops *ops, |
1957 | struct file *file, void *fh, void *arg) | |
1958 | { | |
1959 | return ops->vidioc_streamon(file, fh, *(unsigned int *)arg); | |
1960 | } | |
1961 | ||
1962 | static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, | |
1963 | struct file *file, void *fh, void *arg) | |
1964 | { | |
1965 | return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg); | |
1966 | } | |
1967 | ||
4b1e2e4d HV |
1968 | static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, |
1969 | struct file *file, void *fh, void *arg) | |
1970 | { | |
1971 | struct video_device *vfd = video_devdata(file); | |
1972 | struct v4l2_tuner *p = arg; | |
82b655bf | 1973 | int err; |
4b1e2e4d HV |
1974 | |
1975 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? | |
1976 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
82b655bf HV |
1977 | err = ops->vidioc_g_tuner(file, fh, p); |
1978 | if (!err) | |
1979 | p->capability |= V4L2_TUNER_CAP_FREQ_BANDS; | |
1980 | return err; | |
4b1e2e4d HV |
1981 | } |
1982 | ||
1983 | static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, | |
1984 | struct file *file, void *fh, void *arg) | |
1985 | { | |
1986 | struct video_device *vfd = video_devdata(file); | |
1987 | struct v4l2_tuner *p = arg; | |
77fa4e07 | 1988 | int ret; |
4b1e2e4d | 1989 | |
77fa4e07 SK |
1990 | ret = v4l_enable_media_source(vfd); |
1991 | if (ret) | |
1992 | return ret; | |
4b1e2e4d HV |
1993 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
1994 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
1995 | return ops->vidioc_s_tuner(file, fh, p); | |
1996 | } | |
1997 | ||
82b655bf HV |
1998 | static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops, |
1999 | struct file *file, void *fh, void *arg) | |
2000 | { | |
4124a3c4 | 2001 | struct video_device *vfd = video_devdata(file); |
82b655bf HV |
2002 | struct v4l2_modulator *p = arg; |
2003 | int err; | |
2004 | ||
4124a3c4 AP |
2005 | if (vfd->vfl_type == VFL_TYPE_RADIO) |
2006 | p->type = V4L2_TUNER_RADIO; | |
2007 | ||
82b655bf HV |
2008 | err = ops->vidioc_g_modulator(file, fh, p); |
2009 | if (!err) | |
2010 | p->capability |= V4L2_TUNER_CAP_FREQ_BANDS; | |
2011 | return err; | |
2012 | } | |
2013 | ||
4124a3c4 AP |
2014 | static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops, |
2015 | struct file *file, void *fh, void *arg) | |
2016 | { | |
2017 | struct video_device *vfd = video_devdata(file); | |
2018 | struct v4l2_modulator *p = arg; | |
2019 | ||
2020 | if (vfd->vfl_type == VFL_TYPE_RADIO) | |
2021 | p->type = V4L2_TUNER_RADIO; | |
2022 | ||
2023 | return ops->vidioc_s_modulator(file, fh, p); | |
2024 | } | |
2025 | ||
4b1e2e4d HV |
2026 | static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops, |
2027 | struct file *file, void *fh, void *arg) | |
2028 | { | |
2029 | struct video_device *vfd = video_devdata(file); | |
2030 | struct v4l2_frequency *p = arg; | |
2031 | ||
84099a28 | 2032 | if (vfd->vfl_type == VFL_TYPE_SDR) |
f3c3ecec | 2033 | p->type = V4L2_TUNER_SDR; |
84099a28 AP |
2034 | else |
2035 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? | |
2036 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
4b1e2e4d HV |
2037 | return ops->vidioc_g_frequency(file, fh, p); |
2038 | } | |
2039 | ||
2040 | static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops, | |
2041 | struct file *file, void *fh, void *arg) | |
2042 | { | |
2043 | struct video_device *vfd = video_devdata(file); | |
b530a447 | 2044 | const struct v4l2_frequency *p = arg; |
4b1e2e4d | 2045 | enum v4l2_tuner_type type; |
77fa4e07 | 2046 | int ret; |
4b1e2e4d | 2047 | |
77fa4e07 SK |
2048 | ret = v4l_enable_media_source(vfd); |
2049 | if (ret) | |
2050 | return ret; | |
84099a28 | 2051 | if (vfd->vfl_type == VFL_TYPE_SDR) { |
f3c3ecec | 2052 | if (p->type != V4L2_TUNER_SDR && p->type != V4L2_TUNER_RF) |
84099a28 AP |
2053 | return -EINVAL; |
2054 | } else { | |
2055 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? | |
2056 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
2057 | if (type != p->type) | |
2058 | return -EINVAL; | |
2059 | } | |
4b1e2e4d HV |
2060 | return ops->vidioc_s_frequency(file, fh, p); |
2061 | } | |
2062 | ||
2063 | static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, | |
2064 | struct file *file, void *fh, void *arg) | |
2065 | { | |
2066 | struct video_device *vfd = video_devdata(file); | |
2067 | struct v4l2_standard *p = arg; | |
a5338190 | 2068 | |
aa2f8871 | 2069 | return v4l_video_std_enumstd(p, vfd->tvnorms); |
4b1e2e4d HV |
2070 | } |
2071 | ||
4b1e2e4d HV |
2072 | static int v4l_s_std(const struct v4l2_ioctl_ops *ops, |
2073 | struct file *file, void *fh, void *arg) | |
2074 | { | |
2075 | struct video_device *vfd = video_devdata(file); | |
314527ac | 2076 | v4l2_std_id id = *(v4l2_std_id *)arg, norm; |
77fa4e07 | 2077 | int ret; |
4b1e2e4d | 2078 | |
77fa4e07 SK |
2079 | ret = v4l_enable_media_source(vfd); |
2080 | if (ret) | |
2081 | return ret; | |
314527ac | 2082 | norm = id & vfd->tvnorms; |
4b1e2e4d HV |
2083 | if (vfd->tvnorms && !norm) /* Check if std is supported */ |
2084 | return -EINVAL; | |
2085 | ||
2086 | /* Calls the specific handler */ | |
ca371575 | 2087 | return ops->vidioc_s_std(file, fh, norm); |
4b1e2e4d HV |
2088 | } |
2089 | ||
2090 | static int v4l_querystd(const struct v4l2_ioctl_ops *ops, | |
2091 | struct file *file, void *fh, void *arg) | |
2092 | { | |
2093 | struct video_device *vfd = video_devdata(file); | |
2094 | v4l2_std_id *p = arg; | |
77fa4e07 | 2095 | int ret; |
4b1e2e4d | 2096 | |
77fa4e07 SK |
2097 | ret = v4l_enable_media_source(vfd); |
2098 | if (ret) | |
2099 | return ret; | |
4b1e2e4d | 2100 | /* |
1a2c6866 HV |
2101 | * If no signal is detected, then the driver should return |
2102 | * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with | |
2103 | * any standards that do not apply removed. | |
2104 | * | |
4b1e2e4d HV |
2105 | * This means that tuners, audio and video decoders can join |
2106 | * their efforts to improve the standards detection. | |
2107 | */ | |
2108 | *p = vfd->tvnorms; | |
2109 | return ops->vidioc_querystd(file, fh, arg); | |
2110 | } | |
2111 | ||
2112 | static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops, | |
2113 | struct file *file, void *fh, void *arg) | |
2114 | { | |
2115 | struct video_device *vfd = video_devdata(file); | |
2116 | struct v4l2_hw_freq_seek *p = arg; | |
2117 | enum v4l2_tuner_type type; | |
77fa4e07 | 2118 | int ret; |
4b1e2e4d | 2119 | |
77fa4e07 SK |
2120 | ret = v4l_enable_media_source(vfd); |
2121 | if (ret) | |
2122 | return ret; | |
84099a28 AP |
2123 | /* s_hw_freq_seek is not supported for SDR for now */ |
2124 | if (vfd->vfl_type == VFL_TYPE_SDR) | |
2125 | return -EINVAL; | |
2126 | ||
4b1e2e4d HV |
2127 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
2128 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
2129 | if (p->type != type) | |
2130 | return -EINVAL; | |
2131 | return ops->vidioc_s_hw_freq_seek(file, fh, p); | |
2132 | } | |
2133 | ||
d04794da HV |
2134 | static int v4l_s_fbuf(const struct v4l2_ioctl_ops *ops, |
2135 | struct file *file, void *fh, void *arg) | |
2136 | { | |
2137 | struct v4l2_framebuffer *p = arg; | |
2138 | ||
2139 | p->base = NULL; | |
2140 | return ops->vidioc_s_fbuf(file, fh, p); | |
2141 | } | |
2142 | ||
737c097b HV |
2143 | static int v4l_overlay(const struct v4l2_ioctl_ops *ops, |
2144 | struct file *file, void *fh, void *arg) | |
2145 | { | |
2146 | return ops->vidioc_overlay(file, fh, *(unsigned int *)arg); | |
2147 | } | |
2148 | ||
eb3728ed HV |
2149 | static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, |
2150 | struct file *file, void *fh, void *arg) | |
2151 | { | |
a3293a85 | 2152 | struct video_device *vfd = video_devdata(file); |
eb3728ed | 2153 | struct v4l2_requestbuffers *p = arg; |
4b20259f | 2154 | int ret = check_fmt(file, p->type); |
eb3728ed HV |
2155 | |
2156 | if (ret) | |
2157 | return ret; | |
129134e5 | 2158 | |
0625b6b8 | 2159 | memset_after(p, 0, flags); |
129134e5 | 2160 | |
a3293a85 BG |
2161 | p->capabilities = 0; |
2162 | if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS)) | |
2163 | p->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS; | |
2164 | ||
eb3728ed HV |
2165 | return ops->vidioc_reqbufs(file, fh, p); |
2166 | } | |
2167 | ||
2168 | static int v4l_querybuf(const struct v4l2_ioctl_ops *ops, | |
2169 | struct file *file, void *fh, void *arg) | |
2170 | { | |
2171 | struct v4l2_buffer *p = arg; | |
4b20259f | 2172 | int ret = check_fmt(file, p->type); |
eb3728ed HV |
2173 | |
2174 | return ret ? ret : ops->vidioc_querybuf(file, fh, p); | |
2175 | } | |
2176 | ||
2177 | static int v4l_qbuf(const struct v4l2_ioctl_ops *ops, | |
2178 | struct file *file, void *fh, void *arg) | |
2179 | { | |
2180 | struct v4l2_buffer *p = arg; | |
4b20259f | 2181 | int ret = check_fmt(file, p->type); |
eb3728ed HV |
2182 | |
2183 | return ret ? ret : ops->vidioc_qbuf(file, fh, p); | |
2184 | } | |
2185 | ||
2186 | static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, | |
2187 | struct file *file, void *fh, void *arg) | |
2188 | { | |
2189 | struct v4l2_buffer *p = arg; | |
4b20259f | 2190 | int ret = check_fmt(file, p->type); |
eb3728ed HV |
2191 | |
2192 | return ret ? ret : ops->vidioc_dqbuf(file, fh, p); | |
2193 | } | |
2194 | ||
2195 | static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, | |
2196 | struct file *file, void *fh, void *arg) | |
2197 | { | |
a3293a85 | 2198 | struct video_device *vfd = video_devdata(file); |
eb3728ed | 2199 | struct v4l2_create_buffers *create = arg; |
4b20259f | 2200 | int ret = check_fmt(file, create->format.type); |
eb3728ed | 2201 | |
d52e2381 LP |
2202 | if (ret) |
2203 | return ret; | |
2204 | ||
0625b6b8 | 2205 | memset_after(create, 0, flags); |
5d351251 | 2206 | |
d52e2381 LP |
2207 | v4l_sanitize_format(&create->format); |
2208 | ||
a3293a85 BG |
2209 | create->capabilities = 0; |
2210 | if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS)) | |
2211 | create->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS; | |
2212 | ||
d52e2381 LP |
2213 | ret = ops->vidioc_create_bufs(file, fh, create); |
2214 | ||
2215 | if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE || | |
2216 | create->format.type == V4L2_BUF_TYPE_VIDEO_OUTPUT) | |
2217 | create->format.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; | |
2218 | ||
2219 | return ret; | |
eb3728ed HV |
2220 | } |
2221 | ||
2222 | static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, | |
2223 | struct file *file, void *fh, void *arg) | |
2224 | { | |
2225 | struct v4l2_buffer *b = arg; | |
4b20259f | 2226 | int ret = check_fmt(file, b->type); |
eb3728ed HV |
2227 | |
2228 | return ret ? ret : ops->vidioc_prepare_buf(file, fh, b); | |
2229 | } | |
2230 | ||
a3293a85 BG |
2231 | static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops, |
2232 | struct file *file, void *fh, void *arg) | |
2233 | { | |
2234 | struct v4l2_remove_buffers *remove = arg; | |
2235 | ||
2236 | if (ops->vidioc_remove_bufs) | |
2237 | return ops->vidioc_remove_bufs(file, fh, remove); | |
2238 | ||
2239 | return -ENOTTY; | |
2240 | } | |
2241 | ||
eb3728ed HV |
2242 | static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, |
2243 | struct file *file, void *fh, void *arg) | |
2244 | { | |
cd9d9377 | 2245 | struct video_device *vfd = video_devdata(file); |
eb3728ed HV |
2246 | struct v4l2_streamparm *p = arg; |
2247 | v4l2_std_id std; | |
4b20259f | 2248 | int ret = check_fmt(file, p->type); |
eb3728ed HV |
2249 | |
2250 | if (ret) | |
2251 | return ret; | |
2252 | if (ops->vidioc_g_parm) | |
2253 | return ops->vidioc_g_parm(file, fh, p); | |
eb3728ed HV |
2254 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
2255 | p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | |
2256 | return -EINVAL; | |
cd9d9377 HV |
2257 | if (vfd->device_caps & V4L2_CAP_READWRITE) |
2258 | p->parm.capture.readbuffers = 2; | |
ca371575 | 2259 | ret = ops->vidioc_g_std(file, fh, &std); |
eb3728ed | 2260 | if (ret == 0) |
ca371575 | 2261 | v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe); |
eb3728ed HV |
2262 | return ret; |
2263 | } | |
2264 | ||
2265 | static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, | |
2266 | struct file *file, void *fh, void *arg) | |
2267 | { | |
2268 | struct v4l2_streamparm *p = arg; | |
4b20259f | 2269 | int ret = check_fmt(file, p->type); |
eb3728ed | 2270 | |
8a7c5594 HV |
2271 | if (ret) |
2272 | return ret; | |
2273 | ||
4f62e840 | 2274 | /* Note: extendedmode is never used in drivers */ |
8a7c5594 HV |
2275 | if (V4L2_TYPE_IS_OUTPUT(p->type)) { |
2276 | memset(p->parm.output.reserved, 0, | |
2277 | sizeof(p->parm.output.reserved)); | |
2278 | p->parm.output.extendedmode = 0; | |
2279 | p->parm.output.outputmode &= V4L2_MODE_HIGHQUALITY; | |
2280 | } else { | |
2281 | memset(p->parm.capture.reserved, 0, | |
2282 | sizeof(p->parm.capture.reserved)); | |
4f62e840 | 2283 | p->parm.capture.extendedmode = 0; |
8a7c5594 HV |
2284 | p->parm.capture.capturemode &= V4L2_MODE_HIGHQUALITY; |
2285 | } | |
2286 | return ops->vidioc_s_parm(file, fh, p); | |
eb3728ed HV |
2287 | } |
2288 | ||
efbceecd HV |
2289 | static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, |
2290 | struct file *file, void *fh, void *arg) | |
2291 | { | |
2292 | struct video_device *vfd = video_devdata(file); | |
46108b41 | 2293 | struct v4l2_query_ext_ctrl qec = {}; |
efbceecd | 2294 | struct v4l2_queryctrl *p = arg; |
7a3ed2d9 HV |
2295 | struct v4l2_fh *vfh = |
2296 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
46108b41 | 2297 | int ret; |
efbceecd HV |
2298 | |
2299 | if (vfh && vfh->ctrl_handler) | |
2300 | return v4l2_queryctrl(vfh->ctrl_handler, p); | |
2301 | if (vfd->ctrl_handler) | |
2302 | return v4l2_queryctrl(vfd->ctrl_handler, p); | |
46108b41 RR |
2303 | if (!ops->vidioc_query_ext_ctrl) |
2304 | return -ENOTTY; | |
2305 | ||
2306 | /* Simulate query_ext_ctr using query_ctrl. */ | |
2307 | qec.id = p->id; | |
2308 | ret = ops->vidioc_query_ext_ctrl(file, fh, &qec); | |
2309 | if (ret) | |
2310 | return ret; | |
6494d350 RR |
2311 | v4l2_query_ext_ctrl_to_v4l2_queryctrl(p, &qec); |
2312 | return ret; | |
efbceecd HV |
2313 | } |
2314 | ||
e6bee368 HV |
2315 | static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops, |
2316 | struct file *file, void *fh, void *arg) | |
2317 | { | |
2318 | struct video_device *vfd = video_devdata(file); | |
2319 | struct v4l2_query_ext_ctrl *p = arg; | |
2320 | struct v4l2_fh *vfh = | |
2321 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
2322 | ||
2323 | if (vfh && vfh->ctrl_handler) | |
2324 | return v4l2_query_ext_ctrl(vfh->ctrl_handler, p); | |
2325 | if (vfd->ctrl_handler) | |
2326 | return v4l2_query_ext_ctrl(vfd->ctrl_handler, p); | |
2327 | if (ops->vidioc_query_ext_ctrl) | |
2328 | return ops->vidioc_query_ext_ctrl(file, fh, p); | |
2329 | return -ENOTTY; | |
2330 | } | |
2331 | ||
efbceecd HV |
2332 | static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, |
2333 | struct file *file, void *fh, void *arg) | |
2334 | { | |
2335 | struct video_device *vfd = video_devdata(file); | |
2336 | struct v4l2_querymenu *p = arg; | |
7a3ed2d9 HV |
2337 | struct v4l2_fh *vfh = |
2338 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
efbceecd HV |
2339 | |
2340 | if (vfh && vfh->ctrl_handler) | |
2341 | return v4l2_querymenu(vfh->ctrl_handler, p); | |
2342 | if (vfd->ctrl_handler) | |
2343 | return v4l2_querymenu(vfd->ctrl_handler, p); | |
2344 | if (ops->vidioc_querymenu) | |
2345 | return ops->vidioc_querymenu(file, fh, p); | |
2346 | return -ENOTTY; | |
2347 | } | |
2348 | ||
2349 | static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, | |
2350 | struct file *file, void *fh, void *arg) | |
2351 | { | |
2352 | struct video_device *vfd = video_devdata(file); | |
2353 | struct v4l2_control *p = arg; | |
7a3ed2d9 HV |
2354 | struct v4l2_fh *vfh = |
2355 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
efbceecd HV |
2356 | struct v4l2_ext_controls ctrls; |
2357 | struct v4l2_ext_control ctrl; | |
2358 | ||
2359 | if (vfh && vfh->ctrl_handler) | |
2360 | return v4l2_g_ctrl(vfh->ctrl_handler, p); | |
2361 | if (vfd->ctrl_handler) | |
2362 | return v4l2_g_ctrl(vfd->ctrl_handler, p); | |
efbceecd HV |
2363 | if (ops->vidioc_g_ext_ctrls == NULL) |
2364 | return -ENOTTY; | |
2365 | ||
0f8017be | 2366 | ctrls.which = V4L2_CTRL_ID2WHICH(p->id); |
efbceecd HV |
2367 | ctrls.count = 1; |
2368 | ctrls.controls = &ctrl; | |
2369 | ctrl.id = p->id; | |
2370 | ctrl.value = p->value; | |
861f92cb | 2371 | if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) { |
efbceecd HV |
2372 | int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); |
2373 | ||
2374 | if (ret == 0) | |
2375 | p->value = ctrl.value; | |
2376 | return ret; | |
2377 | } | |
2378 | return -EINVAL; | |
2379 | } | |
2380 | ||
2381 | static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, | |
2382 | struct file *file, void *fh, void *arg) | |
2383 | { | |
2384 | struct video_device *vfd = video_devdata(file); | |
2385 | struct v4l2_control *p = arg; | |
7a3ed2d9 HV |
2386 | struct v4l2_fh *vfh = |
2387 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
efbceecd HV |
2388 | struct v4l2_ext_controls ctrls; |
2389 | struct v4l2_ext_control ctrl; | |
c87ed935 | 2390 | int ret; |
efbceecd HV |
2391 | |
2392 | if (vfh && vfh->ctrl_handler) | |
2393 | return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p); | |
2394 | if (vfd->ctrl_handler) | |
2395 | return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p); | |
efbceecd HV |
2396 | if (ops->vidioc_s_ext_ctrls == NULL) |
2397 | return -ENOTTY; | |
2398 | ||
0f8017be | 2399 | ctrls.which = V4L2_CTRL_ID2WHICH(p->id); |
efbceecd HV |
2400 | ctrls.count = 1; |
2401 | ctrls.controls = &ctrl; | |
2402 | ctrl.id = p->id; | |
2403 | ctrl.value = p->value; | |
c87ed935 RR |
2404 | if (!check_ext_ctrls(&ctrls, VIDIOC_S_CTRL)) |
2405 | return -EINVAL; | |
2406 | ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls); | |
2407 | p->value = ctrl.value; | |
2408 | return ret; | |
efbceecd HV |
2409 | } |
2410 | ||
2411 | static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, | |
2412 | struct file *file, void *fh, void *arg) | |
2413 | { | |
2414 | struct video_device *vfd = video_devdata(file); | |
2415 | struct v4l2_ext_controls *p = arg; | |
7a3ed2d9 HV |
2416 | struct v4l2_fh *vfh = |
2417 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
efbceecd HV |
2418 | |
2419 | p->error_idx = p->count; | |
2420 | if (vfh && vfh->ctrl_handler) | |
173f6eac EG |
2421 | return v4l2_g_ext_ctrls(vfh->ctrl_handler, |
2422 | vfd, vfd->v4l2_dev->mdev, p); | |
efbceecd | 2423 | if (vfd->ctrl_handler) |
173f6eac EG |
2424 | return v4l2_g_ext_ctrls(vfd->ctrl_handler, |
2425 | vfd, vfd->v4l2_dev->mdev, p); | |
efbceecd HV |
2426 | if (ops->vidioc_g_ext_ctrls == NULL) |
2427 | return -ENOTTY; | |
861f92cb RR |
2428 | return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ? |
2429 | ops->vidioc_g_ext_ctrls(file, fh, p) : -EINVAL; | |
efbceecd HV |
2430 | } |
2431 | ||
2432 | static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, | |
2433 | struct file *file, void *fh, void *arg) | |
2434 | { | |
2435 | struct video_device *vfd = video_devdata(file); | |
2436 | struct v4l2_ext_controls *p = arg; | |
7a3ed2d9 HV |
2437 | struct v4l2_fh *vfh = |
2438 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
efbceecd HV |
2439 | |
2440 | p->error_idx = p->count; | |
2441 | if (vfh && vfh->ctrl_handler) | |
173f6eac EG |
2442 | return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, |
2443 | vfd, vfd->v4l2_dev->mdev, p); | |
efbceecd | 2444 | if (vfd->ctrl_handler) |
173f6eac EG |
2445 | return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, |
2446 | vfd, vfd->v4l2_dev->mdev, p); | |
efbceecd HV |
2447 | if (ops->vidioc_s_ext_ctrls == NULL) |
2448 | return -ENOTTY; | |
861f92cb RR |
2449 | return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ? |
2450 | ops->vidioc_s_ext_ctrls(file, fh, p) : -EINVAL; | |
efbceecd HV |
2451 | } |
2452 | ||
2453 | static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, | |
2454 | struct file *file, void *fh, void *arg) | |
2455 | { | |
2456 | struct video_device *vfd = video_devdata(file); | |
2457 | struct v4l2_ext_controls *p = arg; | |
7a3ed2d9 HV |
2458 | struct v4l2_fh *vfh = |
2459 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; | |
efbceecd HV |
2460 | |
2461 | p->error_idx = p->count; | |
2462 | if (vfh && vfh->ctrl_handler) | |
173f6eac EG |
2463 | return v4l2_try_ext_ctrls(vfh->ctrl_handler, |
2464 | vfd, vfd->v4l2_dev->mdev, p); | |
efbceecd | 2465 | if (vfd->ctrl_handler) |
173f6eac EG |
2466 | return v4l2_try_ext_ctrls(vfd->ctrl_handler, |
2467 | vfd, vfd->v4l2_dev->mdev, p); | |
efbceecd HV |
2468 | if (ops->vidioc_try_ext_ctrls == NULL) |
2469 | return -ENOTTY; | |
861f92cb RR |
2470 | return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ? |
2471 | ops->vidioc_try_ext_ctrls(file, fh, p) : -EINVAL; | |
efbceecd HV |
2472 | } |
2473 | ||
eaec420f HV |
2474 | /* |
2475 | * The selection API specified originally that the _MPLANE buffer types | |
2476 | * shouldn't be used. The reasons for this are lost in the mists of time | |
2477 | * (or just really crappy memories). Regardless, this is really annoying | |
2478 | * for userspace. So to keep things simple we map _MPLANE buffer types | |
2479 | * to their 'regular' counterparts before calling the driver. And we | |
2480 | * restore it afterwards. This way applications can use either buffer | |
2481 | * type and drivers don't need to check for both. | |
2482 | */ | |
2483 | static int v4l_g_selection(const struct v4l2_ioctl_ops *ops, | |
2484 | struct file *file, void *fh, void *arg) | |
2485 | { | |
2486 | struct v4l2_selection *p = arg; | |
2487 | u32 old_type = p->type; | |
2488 | int ret; | |
2489 | ||
2490 | if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | |
2491 | p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
2492 | else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) | |
2493 | p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | |
2494 | ret = ops->vidioc_g_selection(file, fh, p); | |
2495 | p->type = old_type; | |
2496 | return ret; | |
2497 | } | |
2498 | ||
2499 | static int v4l_s_selection(const struct v4l2_ioctl_ops *ops, | |
2500 | struct file *file, void *fh, void *arg) | |
2501 | { | |
2502 | struct v4l2_selection *p = arg; | |
2503 | u32 old_type = p->type; | |
2504 | int ret; | |
2505 | ||
2506 | if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | |
2507 | p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
2508 | else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) | |
2509 | p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | |
2510 | ret = ops->vidioc_s_selection(file, fh, p); | |
2511 | p->type = old_type; | |
2512 | return ret; | |
2513 | } | |
2514 | ||
d84f2d94 HV |
2515 | static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, |
2516 | struct file *file, void *fh, void *arg) | |
2517 | { | |
8cbd94bd | 2518 | struct video_device *vfd = video_devdata(file); |
d84f2d94 HV |
2519 | struct v4l2_crop *p = arg; |
2520 | struct v4l2_selection s = { | |
2521 | .type = p->type, | |
2522 | }; | |
2523 | int ret; | |
2524 | ||
d84f2d94 HV |
2525 | /* simulate capture crop using selection api */ |
2526 | ||
2527 | /* crop means compose for output devices */ | |
2528 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
5b79da06 | 2529 | s.target = V4L2_SEL_TGT_COMPOSE; |
d84f2d94 | 2530 | else |
5b79da06 | 2531 | s.target = V4L2_SEL_TGT_CROP; |
d84f2d94 | 2532 | |
8cbd94bd HV |
2533 | if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags)) |
2534 | s.target = s.target == V4L2_SEL_TGT_COMPOSE ? | |
2535 | V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE; | |
2536 | ||
eaec420f | 2537 | ret = v4l_g_selection(ops, file, fh, &s); |
d84f2d94 HV |
2538 | |
2539 | /* copying results to old structure on success */ | |
2540 | if (!ret) | |
2541 | p->c = s.r; | |
2542 | return ret; | |
2543 | } | |
2544 | ||
2545 | static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, | |
2546 | struct file *file, void *fh, void *arg) | |
2547 | { | |
8cbd94bd | 2548 | struct video_device *vfd = video_devdata(file); |
d84f2d94 HV |
2549 | struct v4l2_crop *p = arg; |
2550 | struct v4l2_selection s = { | |
2551 | .type = p->type, | |
2552 | .r = p->c, | |
2553 | }; | |
2554 | ||
d84f2d94 HV |
2555 | /* simulate capture crop using selection api */ |
2556 | ||
2557 | /* crop means compose for output devices */ | |
2558 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
5b79da06 | 2559 | s.target = V4L2_SEL_TGT_COMPOSE; |
d84f2d94 | 2560 | else |
5b79da06 | 2561 | s.target = V4L2_SEL_TGT_CROP; |
d84f2d94 | 2562 | |
8cbd94bd HV |
2563 | if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags)) |
2564 | s.target = s.target == V4L2_SEL_TGT_COMPOSE ? | |
2565 | V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE; | |
2566 | ||
eaec420f | 2567 | return v4l_s_selection(ops, file, fh, &s); |
d84f2d94 HV |
2568 | } |
2569 | ||
2570 | static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, | |
2571 | struct file *file, void *fh, void *arg) | |
2572 | { | |
8cbd94bd | 2573 | struct video_device *vfd = video_devdata(file); |
d84f2d94 | 2574 | struct v4l2_cropcap *p = arg; |
95dd7b7e HV |
2575 | struct v4l2_selection s = { .type = p->type }; |
2576 | int ret = 0; | |
d84f2d94 | 2577 | |
95dd7b7e HV |
2578 | /* setting trivial pixelaspect */ |
2579 | p->pixelaspect.numerator = 1; | |
2580 | p->pixelaspect.denominator = 1; | |
d84f2d94 | 2581 | |
5200ab6a HV |
2582 | if (s.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
2583 | s.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
2584 | else if (s.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) | |
2585 | s.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | |
2586 | ||
95dd7b7e HV |
2587 | /* |
2588 | * The determine_valid_ioctls() call already should ensure | |
2589 | * that this can never happen, but just in case... | |
2590 | */ | |
5200ab6a | 2591 | if (WARN_ON(!ops->vidioc_g_selection)) |
95dd7b7e | 2592 | return -ENOTTY; |
d84f2d94 | 2593 | |
5200ab6a HV |
2594 | if (ops->vidioc_g_pixelaspect) |
2595 | ret = ops->vidioc_g_pixelaspect(file, fh, s.type, | |
2596 | &p->pixelaspect); | |
d84f2d94 | 2597 | |
95dd7b7e HV |
2598 | /* |
2599 | * Ignore ENOTTY or ENOIOCTLCMD error returns, just use the | |
2600 | * square pixel aspect ratio in that case. | |
2601 | */ | |
2602 | if (ret && ret != -ENOTTY && ret != -ENOIOCTLCMD) | |
2603 | return ret; | |
d84f2d94 | 2604 | |
95dd7b7e | 2605 | /* Use g_selection() to fill in the bounds and defrect rectangles */ |
9409945c | 2606 | |
95dd7b7e HV |
2607 | /* obtaining bounds */ |
2608 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
2609 | s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS; | |
2610 | else | |
2611 | s.target = V4L2_SEL_TGT_CROP_BOUNDS; | |
2612 | ||
8cbd94bd HV |
2613 | if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags)) |
2614 | s.target = s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS ? | |
2615 | V4L2_SEL_TGT_CROP_BOUNDS : V4L2_SEL_TGT_COMPOSE_BOUNDS; | |
2616 | ||
eaec420f | 2617 | ret = v4l_g_selection(ops, file, fh, &s); |
95dd7b7e HV |
2618 | if (ret) |
2619 | return ret; | |
2620 | p->bounds = s.r; | |
2621 | ||
2622 | /* obtaining defrect */ | |
8cbd94bd | 2623 | if (s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS) |
95dd7b7e HV |
2624 | s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT; |
2625 | else | |
2626 | s.target = V4L2_SEL_TGT_CROP_DEFAULT; | |
2627 | ||
eaec420f | 2628 | ret = v4l_g_selection(ops, file, fh, &s); |
95dd7b7e HV |
2629 | if (ret) |
2630 | return ret; | |
2631 | p->defrect = s.r; | |
9409945c | 2632 | |
d84f2d94 HV |
2633 | return 0; |
2634 | } | |
2635 | ||
f16f77b0 HV |
2636 | static int v4l_log_status(const struct v4l2_ioctl_ops *ops, |
2637 | struct file *file, void *fh, void *arg) | |
2638 | { | |
2639 | struct video_device *vfd = video_devdata(file); | |
2640 | int ret; | |
2641 | ||
2642 | if (vfd->v4l2_dev) | |
2643 | pr_info("%s: ================= START STATUS =================\n", | |
2644 | vfd->v4l2_dev->name); | |
2645 | ret = ops->vidioc_log_status(file, fh); | |
2646 | if (vfd->v4l2_dev) | |
2647 | pr_info("%s: ================== END STATUS ==================\n", | |
2648 | vfd->v4l2_dev->name); | |
2649 | return ret; | |
2650 | } | |
2651 | ||
2652 | static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops, | |
2653 | struct file *file, void *fh, void *arg) | |
2654 | { | |
2655 | #ifdef CONFIG_VIDEO_ADV_DEBUG | |
2656 | struct v4l2_dbg_register *p = arg; | |
79b0c640 HV |
2657 | struct video_device *vfd = video_devdata(file); |
2658 | struct v4l2_subdev *sd; | |
2659 | int idx = 0; | |
f16f77b0 HV |
2660 | |
2661 | if (!capable(CAP_SYS_ADMIN)) | |
2662 | return -EPERM; | |
3eef2510 | 2663 | if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) { |
79b0c640 HV |
2664 | if (vfd->v4l2_dev == NULL) |
2665 | return -EINVAL; | |
3eef2510 HV |
2666 | v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) |
2667 | if (p->match.addr == idx++) | |
79b0c640 | 2668 | return v4l2_subdev_call(sd, core, g_register, p); |
79b0c640 HV |
2669 | return -EINVAL; |
2670 | } | |
191b79b0 HV |
2671 | if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE && |
2672 | (ops->vidioc_g_chip_info || p->match.addr == 0)) | |
79b0c640 HV |
2673 | return ops->vidioc_g_register(file, fh, p); |
2674 | return -EINVAL; | |
f16f77b0 HV |
2675 | #else |
2676 | return -ENOTTY; | |
2677 | #endif | |
2678 | } | |
2679 | ||
2680 | static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops, | |
2681 | struct file *file, void *fh, void *arg) | |
2682 | { | |
2683 | #ifdef CONFIG_VIDEO_ADV_DEBUG | |
977ba3b1 | 2684 | const struct v4l2_dbg_register *p = arg; |
79b0c640 HV |
2685 | struct video_device *vfd = video_devdata(file); |
2686 | struct v4l2_subdev *sd; | |
2687 | int idx = 0; | |
f16f77b0 HV |
2688 | |
2689 | if (!capable(CAP_SYS_ADMIN)) | |
2690 | return -EPERM; | |
3eef2510 | 2691 | if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) { |
79b0c640 HV |
2692 | if (vfd->v4l2_dev == NULL) |
2693 | return -EINVAL; | |
3eef2510 HV |
2694 | v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) |
2695 | if (p->match.addr == idx++) | |
79b0c640 | 2696 | return v4l2_subdev_call(sd, core, s_register, p); |
79b0c640 HV |
2697 | return -EINVAL; |
2698 | } | |
191b79b0 HV |
2699 | if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE && |
2700 | (ops->vidioc_g_chip_info || p->match.addr == 0)) | |
79b0c640 HV |
2701 | return ops->vidioc_s_register(file, fh, p); |
2702 | return -EINVAL; | |
f16f77b0 HV |
2703 | #else |
2704 | return -ENOTTY; | |
2705 | #endif | |
2706 | } | |
2707 | ||
96b03d2a | 2708 | static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops, |
79b0c640 HV |
2709 | struct file *file, void *fh, void *arg) |
2710 | { | |
cd634f1b | 2711 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
79b0c640 | 2712 | struct video_device *vfd = video_devdata(file); |
96b03d2a | 2713 | struct v4l2_dbg_chip_info *p = arg; |
79b0c640 HV |
2714 | struct v4l2_subdev *sd; |
2715 | int idx = 0; | |
2716 | ||
2717 | switch (p->match.type) { | |
2718 | case V4L2_CHIP_MATCH_BRIDGE: | |
79b0c640 HV |
2719 | if (ops->vidioc_s_register) |
2720 | p->flags |= V4L2_CHIP_FL_WRITABLE; | |
2721 | if (ops->vidioc_g_register) | |
2722 | p->flags |= V4L2_CHIP_FL_READABLE; | |
c0decac1 | 2723 | strscpy(p->name, vfd->v4l2_dev->name, sizeof(p->name)); |
96b03d2a HV |
2724 | if (ops->vidioc_g_chip_info) |
2725 | return ops->vidioc_g_chip_info(file, fh, arg); | |
0f0fe4b9 HV |
2726 | if (p->match.addr) |
2727 | return -EINVAL; | |
79b0c640 HV |
2728 | return 0; |
2729 | ||
3eef2510 | 2730 | case V4L2_CHIP_MATCH_SUBDEV: |
79b0c640 HV |
2731 | if (vfd->v4l2_dev == NULL) |
2732 | break; | |
2733 | v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) { | |
3eef2510 HV |
2734 | if (p->match.addr != idx++) |
2735 | continue; | |
2736 | if (sd->ops->core && sd->ops->core->s_register) | |
2737 | p->flags |= V4L2_CHIP_FL_WRITABLE; | |
2738 | if (sd->ops->core && sd->ops->core->g_register) | |
2739 | p->flags |= V4L2_CHIP_FL_READABLE; | |
c0decac1 | 2740 | strscpy(p->name, sd->name, sizeof(p->name)); |
3eef2510 | 2741 | return 0; |
79b0c640 HV |
2742 | } |
2743 | break; | |
2744 | } | |
2745 | return -EINVAL; | |
cd634f1b HV |
2746 | #else |
2747 | return -ENOTTY; | |
2748 | #endif | |
79b0c640 HV |
2749 | } |
2750 | ||
458aa4a6 HV |
2751 | static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, |
2752 | struct file *file, void *fh, void *arg) | |
2753 | { | |
2754 | return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK); | |
2755 | } | |
2756 | ||
2757 | static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops, | |
2758 | struct file *file, void *fh, void *arg) | |
2759 | { | |
2760 | return ops->vidioc_subscribe_event(fh, arg); | |
2761 | } | |
2762 | ||
2763 | static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops, | |
2764 | struct file *file, void *fh, void *arg) | |
2765 | { | |
2766 | return ops->vidioc_unsubscribe_event(fh, arg); | |
2767 | } | |
2768 | ||
2769 | static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops, | |
2770 | struct file *file, void *fh, void *arg) | |
2771 | { | |
2772 | struct v4l2_sliced_vbi_cap *p = arg; | |
4b20259f HV |
2773 | int ret = check_fmt(file, p->type); |
2774 | ||
2775 | if (ret) | |
2776 | return ret; | |
458aa4a6 HV |
2777 | |
2778 | /* Clear up to type, everything after type is zeroed already */ | |
2779 | memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type)); | |
2780 | ||
2781 | return ops->vidioc_g_sliced_vbi_cap(file, fh, p); | |
2782 | } | |
2783 | ||
82b655bf HV |
2784 | static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops, |
2785 | struct file *file, void *fh, void *arg) | |
2786 | { | |
2787 | struct video_device *vfd = video_devdata(file); | |
2788 | struct v4l2_frequency_band *p = arg; | |
2789 | enum v4l2_tuner_type type; | |
2790 | int err; | |
2791 | ||
84099a28 | 2792 | if (vfd->vfl_type == VFL_TYPE_SDR) { |
f3c3ecec | 2793 | if (p->type != V4L2_TUNER_SDR && p->type != V4L2_TUNER_RF) |
84099a28 AP |
2794 | return -EINVAL; |
2795 | type = p->type; | |
2796 | } else { | |
2797 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? | |
2798 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
2799 | if (type != p->type) | |
2800 | return -EINVAL; | |
2801 | } | |
a7f404af HV |
2802 | if (ops->vidioc_enum_freq_bands) { |
2803 | err = ops->vidioc_enum_freq_bands(file, fh, p); | |
2804 | if (err != -ENOTTY) | |
2805 | return err; | |
2806 | } | |
73f35418 | 2807 | if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) { |
82b655bf HV |
2808 | struct v4l2_tuner t = { |
2809 | .index = p->tuner, | |
2810 | .type = type, | |
2811 | }; | |
2812 | ||
aa4d9b53 HV |
2813 | if (p->index) |
2814 | return -EINVAL; | |
82b655bf HV |
2815 | err = ops->vidioc_g_tuner(file, fh, &t); |
2816 | if (err) | |
2817 | return err; | |
2818 | p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS; | |
2819 | p->rangelow = t.rangelow; | |
2820 | p->rangehigh = t.rangehigh; | |
2821 | p->modulation = (type == V4L2_TUNER_RADIO) ? | |
2822 | V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB; | |
2823 | return 0; | |
2824 | } | |
73f35418 | 2825 | if (is_valid_ioctl(vfd, VIDIOC_G_MODULATOR)) { |
82b655bf HV |
2826 | struct v4l2_modulator m = { |
2827 | .index = p->tuner, | |
2828 | }; | |
2829 | ||
2830 | if (type != V4L2_TUNER_RADIO) | |
2831 | return -EINVAL; | |
aa4d9b53 HV |
2832 | if (p->index) |
2833 | return -EINVAL; | |
82b655bf HV |
2834 | err = ops->vidioc_g_modulator(file, fh, &m); |
2835 | if (err) | |
2836 | return err; | |
2837 | p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS; | |
2838 | p->rangelow = m.rangelow; | |
2839 | p->rangehigh = m.rangehigh; | |
fdc33c5f | 2840 | p->modulation = V4L2_BAND_MODULATION_FM; |
82b655bf HV |
2841 | return 0; |
2842 | } | |
2843 | return -ENOTTY; | |
2844 | } | |
2845 | ||
4839e6c2 HV |
2846 | struct v4l2_ioctl_info { |
2847 | unsigned int ioctl; | |
27cd2aba | 2848 | u32 flags; |
4839e6c2 | 2849 | const char * const name; |
3ad3b7a2 ST |
2850 | int (*func)(const struct v4l2_ioctl_ops *ops, struct file *file, |
2851 | void *fh, void *p); | |
86748f35 | 2852 | void (*debug)(const void *arg, bool write_only); |
4839e6c2 HV |
2853 | }; |
2854 | ||
2855 | /* This control needs a priority check */ | |
043f77ed | 2856 | #define INFO_FL_PRIO (1 << 0) |
4839e6c2 | 2857 | /* This control can be valid if the filehandle passes a control handler. */ |
043f77ed | 2858 | #define INFO_FL_CTRL (1 << 1) |
5a5adf6b | 2859 | /* Queuing ioctl */ |
3ad3b7a2 | 2860 | #define INFO_FL_QUEUE (1 << 2) |
043f77ed | 2861 | /* Always copy back result, even on error */ |
3ad3b7a2 | 2862 | #define INFO_FL_ALWAYS_COPY (1 << 3) |
27cd2aba HV |
2863 | /* Zero struct from after the field to the end */ |
2864 | #define INFO_FL_CLEAR(v4l2_struct, field) \ | |
2865 | ((offsetof(struct v4l2_struct, field) + \ | |
c593642c | 2866 | sizeof_field(struct v4l2_struct, field)) << 16) |
6e6a8b5a | 2867 | #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16) |
4839e6c2 | 2868 | |
3ad3b7a2 ST |
2869 | #define DEFINE_V4L_STUB_FUNC(_vidioc) \ |
2870 | static int v4l_stub_ ## _vidioc( \ | |
2871 | const struct v4l2_ioctl_ops *ops, \ | |
2872 | struct file *file, void *fh, void *p) \ | |
2873 | { \ | |
2874 | return ops->vidioc_ ## _vidioc(file, fh, p); \ | |
86748f35 HV |
2875 | } |
2876 | ||
3ad3b7a2 ST |
2877 | #define IOCTL_INFO(_ioctl, _func, _debug, _flags) \ |
2878 | [_IOC_NR(_ioctl)] = { \ | |
2879 | .ioctl = _ioctl, \ | |
2880 | .flags = _flags, \ | |
2881 | .name = #_ioctl, \ | |
2882 | .func = _func, \ | |
2883 | .debug = _debug, \ | |
86748f35 HV |
2884 | } |
2885 | ||
3ad3b7a2 | 2886 | DEFINE_V4L_STUB_FUNC(g_fbuf) |
3ad3b7a2 ST |
2887 | DEFINE_V4L_STUB_FUNC(expbuf) |
2888 | DEFINE_V4L_STUB_FUNC(g_std) | |
2889 | DEFINE_V4L_STUB_FUNC(g_audio) | |
2890 | DEFINE_V4L_STUB_FUNC(s_audio) | |
3ad3b7a2 ST |
2891 | DEFINE_V4L_STUB_FUNC(g_edid) |
2892 | DEFINE_V4L_STUB_FUNC(s_edid) | |
3ad3b7a2 ST |
2893 | DEFINE_V4L_STUB_FUNC(g_audout) |
2894 | DEFINE_V4L_STUB_FUNC(s_audout) | |
2895 | DEFINE_V4L_STUB_FUNC(g_jpegcomp) | |
2896 | DEFINE_V4L_STUB_FUNC(s_jpegcomp) | |
2897 | DEFINE_V4L_STUB_FUNC(enumaudio) | |
2898 | DEFINE_V4L_STUB_FUNC(enumaudout) | |
2899 | DEFINE_V4L_STUB_FUNC(enum_framesizes) | |
2900 | DEFINE_V4L_STUB_FUNC(enum_frameintervals) | |
2901 | DEFINE_V4L_STUB_FUNC(g_enc_index) | |
2902 | DEFINE_V4L_STUB_FUNC(encoder_cmd) | |
2903 | DEFINE_V4L_STUB_FUNC(try_encoder_cmd) | |
2904 | DEFINE_V4L_STUB_FUNC(decoder_cmd) | |
2905 | DEFINE_V4L_STUB_FUNC(try_decoder_cmd) | |
2906 | DEFINE_V4L_STUB_FUNC(s_dv_timings) | |
2907 | DEFINE_V4L_STUB_FUNC(g_dv_timings) | |
2908 | DEFINE_V4L_STUB_FUNC(enum_dv_timings) | |
2909 | DEFINE_V4L_STUB_FUNC(query_dv_timings) | |
2910 | DEFINE_V4L_STUB_FUNC(dv_timings_cap) | |
2911 | ||
7c91d0a4 | 2912 | static const struct v4l2_ioctl_info v4l2_ioctls[] = { |
3ad3b7a2 | 2913 | IOCTL_INFO(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0), |
e5b6b07a | 2914 | IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, 0), |
3ad3b7a2 ST |
2915 | IOCTL_INFO(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, 0), |
2916 | IOCTL_INFO(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO), | |
2917 | IOCTL_INFO(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE), | |
2918 | IOCTL_INFO(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)), | |
2919 | IOCTL_INFO(VIDIOC_G_FBUF, v4l_stub_g_fbuf, v4l_print_framebuffer, 0), | |
d04794da | 2920 | IOCTL_INFO(VIDIOC_S_FBUF, v4l_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO), |
3ad3b7a2 ST |
2921 | IOCTL_INFO(VIDIOC_OVERLAY, v4l_overlay, v4l_print_u32, INFO_FL_PRIO), |
2922 | IOCTL_INFO(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE), | |
2923 | IOCTL_INFO(VIDIOC_EXPBUF, v4l_stub_expbuf, v4l_print_exportbuffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_exportbuffer, flags)), | |
2924 | IOCTL_INFO(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE), | |
2925 | IOCTL_INFO(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), | |
2926 | IOCTL_INFO(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), | |
2927 | IOCTL_INFO(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)), | |
2928 | IOCTL_INFO(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO), | |
2929 | IOCTL_INFO(VIDIOC_G_STD, v4l_stub_g_std, v4l_print_std, 0), | |
2930 | IOCTL_INFO(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO), | |
2931 | IOCTL_INFO(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)), | |
2932 | IOCTL_INFO(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)), | |
2933 | IOCTL_INFO(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)), | |
2934 | IOCTL_INFO(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL), | |
2935 | IOCTL_INFO(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)), | |
2936 | IOCTL_INFO(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO), | |
2937 | IOCTL_INFO(VIDIOC_G_AUDIO, v4l_stub_g_audio, v4l_print_audio, 0), | |
2938 | IOCTL_INFO(VIDIOC_S_AUDIO, v4l_stub_s_audio, v4l_print_audio, INFO_FL_PRIO), | |
2939 | IOCTL_INFO(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)), | |
2940 | IOCTL_INFO(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)), | |
f645e625 | 2941 | IOCTL_INFO(VIDIOC_G_INPUT, v4l_g_input, v4l_print_u32, 0), |
3ad3b7a2 ST |
2942 | IOCTL_INFO(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO), |
2943 | IOCTL_INFO(VIDIOC_G_EDID, v4l_stub_g_edid, v4l_print_edid, INFO_FL_ALWAYS_COPY), | |
2944 | IOCTL_INFO(VIDIOC_S_EDID, v4l_stub_s_edid, v4l_print_edid, INFO_FL_PRIO | INFO_FL_ALWAYS_COPY), | |
f645e625 | 2945 | IOCTL_INFO(VIDIOC_G_OUTPUT, v4l_g_output, v4l_print_u32, 0), |
3ad3b7a2 ST |
2946 | IOCTL_INFO(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO), |
2947 | IOCTL_INFO(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)), | |
2948 | IOCTL_INFO(VIDIOC_G_AUDOUT, v4l_stub_g_audout, v4l_print_audioout, 0), | |
2949 | IOCTL_INFO(VIDIOC_S_AUDOUT, v4l_stub_s_audout, v4l_print_audioout, INFO_FL_PRIO), | |
2950 | IOCTL_INFO(VIDIOC_G_MODULATOR, v4l_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)), | |
2951 | IOCTL_INFO(VIDIOC_S_MODULATOR, v4l_s_modulator, v4l_print_modulator, INFO_FL_PRIO), | |
2952 | IOCTL_INFO(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)), | |
2953 | IOCTL_INFO(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO), | |
2954 | IOCTL_INFO(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)), | |
2955 | IOCTL_INFO(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)), | |
2956 | IOCTL_INFO(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO), | |
2957 | IOCTL_INFO(VIDIOC_G_SELECTION, v4l_g_selection, v4l_print_selection, INFO_FL_CLEAR(v4l2_selection, r)), | |
2958 | IOCTL_INFO(VIDIOC_S_SELECTION, v4l_s_selection, v4l_print_selection, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_selection, r)), | |
2959 | IOCTL_INFO(VIDIOC_G_JPEGCOMP, v4l_stub_g_jpegcomp, v4l_print_jpegcompression, 0), | |
2960 | IOCTL_INFO(VIDIOC_S_JPEGCOMP, v4l_stub_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO), | |
2961 | IOCTL_INFO(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0), | |
2962 | IOCTL_INFO(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0), | |
2963 | IOCTL_INFO(VIDIOC_ENUMAUDIO, v4l_stub_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)), | |
2964 | IOCTL_INFO(VIDIOC_ENUMAUDOUT, v4l_stub_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)), | |
2965 | IOCTL_INFO(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0), | |
2966 | IOCTL_INFO(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO), | |
2967 | IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)), | |
2968 | IOCTL_INFO(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0), | |
f0da34f3 HV |
2969 | IOCTL_INFO(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL | INFO_FL_ALWAYS_COPY), |
2970 | IOCTL_INFO(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL | INFO_FL_ALWAYS_COPY), | |
2971 | IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL | INFO_FL_ALWAYS_COPY), | |
3ad3b7a2 ST |
2972 | IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, v4l_stub_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)), |
2973 | IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, v4l_stub_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)), | |
2974 | IOCTL_INFO(VIDIOC_G_ENC_INDEX, v4l_stub_g_enc_index, v4l_print_enc_idx, 0), | |
2975 | IOCTL_INFO(VIDIOC_ENCODER_CMD, v4l_stub_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), | |
2976 | IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, v4l_stub_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), | |
2977 | IOCTL_INFO(VIDIOC_DECODER_CMD, v4l_stub_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO), | |
2978 | IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, v4l_stub_try_decoder_cmd, v4l_print_decoder_cmd, 0), | |
2979 | IOCTL_INFO(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0), | |
2980 | IOCTL_INFO(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0), | |
2981 | IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO), | |
2982 | IOCTL_INFO(VIDIOC_S_DV_TIMINGS, v4l_stub_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_dv_timings, bt.flags)), | |
2983 | IOCTL_INFO(VIDIOC_G_DV_TIMINGS, v4l_stub_g_dv_timings, v4l_print_dv_timings, 0), | |
2984 | IOCTL_INFO(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0), | |
2985 | IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0), | |
2986 | IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0), | |
2987 | IOCTL_INFO(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE), | |
2988 | IOCTL_INFO(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE), | |
2989 | IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, v4l_stub_enum_dv_timings, v4l_print_enum_dv_timings, INFO_FL_CLEAR(v4l2_enum_dv_timings, pad)), | |
2990 | IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, v4l_stub_query_dv_timings, v4l_print_dv_timings, INFO_FL_ALWAYS_COPY), | |
2991 | IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, v4l_stub_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, pad)), | |
2992 | IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0), | |
2993 | IOCTL_INFO(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)), | |
2994 | IOCTL_INFO(VIDIOC_QUERY_EXT_CTRL, v4l_query_ext_ctrl, v4l_print_query_ext_ctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_query_ext_ctrl, id)), | |
a3293a85 | 2995 | IOCTL_INFO(VIDIOC_REMOVE_BUFS, v4l_remove_bufs, v4l_print_remove_buffers, INFO_FL_PRIO | INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_remove_buffers, type)), |
4839e6c2 HV |
2996 | }; |
2997 | #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) | |
2998 | ||
73a11062 | 2999 | static bool v4l2_is_known_ioctl(unsigned int cmd) |
4839e6c2 HV |
3000 | { |
3001 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) | |
3002 | return false; | |
3003 | return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd; | |
3004 | } | |
3005 | ||
73a11062 | 3006 | static struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, |
d862bc08 HV |
3007 | struct v4l2_fh *vfh, unsigned int cmd, |
3008 | void *arg) | |
5a5adf6b HV |
3009 | { |
3010 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) | |
3011 | return vdev->lock; | |
d862bc08 HV |
3012 | if (vfh && vfh->m2m_ctx && |
3013 | (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE)) { | |
542a522d EG |
3014 | if (vfh->m2m_ctx->q_lock) |
3015 | return vfh->m2m_ctx->q_lock; | |
d862bc08 | 3016 | } |
5a5adf6b HV |
3017 | if (vdev->queue && vdev->queue->lock && |
3018 | (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE)) | |
3019 | return vdev->queue->lock; | |
3020 | return vdev->lock; | |
3021 | } | |
3022 | ||
4839e6c2 HV |
3023 | /* Common ioctl debug function. This function can be used by |
3024 | external ioctl messages as well as internal V4L ioctl */ | |
4a085168 | 3025 | void v4l_printk_ioctl(const char *prefix, unsigned int cmd) |
4839e6c2 | 3026 | { |
86748f35 | 3027 | const char *dir, *type; |
4839e6c2 | 3028 | |
4a085168 HV |
3029 | if (prefix) |
3030 | printk(KERN_DEBUG "%s: ", prefix); | |
3031 | ||
4839e6c2 HV |
3032 | switch (_IOC_TYPE(cmd)) { |
3033 | case 'd': | |
3034 | type = "v4l2_int"; | |
3035 | break; | |
3036 | case 'V': | |
6aa210d2 | 3037 | if (!v4l2_is_known_ioctl(cmd)) { |
4839e6c2 HV |
3038 | type = "v4l2"; |
3039 | break; | |
3040 | } | |
86748f35 | 3041 | pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name); |
4839e6c2 HV |
3042 | return; |
3043 | default: | |
3044 | type = "unknown"; | |
86748f35 | 3045 | break; |
4839e6c2 HV |
3046 | } |
3047 | ||
3048 | switch (_IOC_DIR(cmd)) { | |
3049 | case _IOC_NONE: dir = "--"; break; | |
3050 | case _IOC_READ: dir = "r-"; break; | |
3051 | case _IOC_WRITE: dir = "-w"; break; | |
3052 | case _IOC_READ | _IOC_WRITE: dir = "rw"; break; | |
3053 | default: dir = "*ERR*"; break; | |
3054 | } | |
86748f35 | 3055 | pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)", |
4839e6c2 HV |
3056 | type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd); |
3057 | } | |
3058 | EXPORT_SYMBOL(v4l_printk_ioctl); | |
3059 | ||
069b7479 | 3060 | static long __video_do_ioctl(struct file *file, |
35ea11ff HV |
3061 | unsigned int cmd, void *arg) |
3062 | { | |
3063 | struct video_device *vfd = video_devdata(file); | |
cc6eddcd | 3064 | struct mutex *req_queue_lock = NULL; |
73a11062 | 3065 | struct mutex *lock; /* ioctl serialization mutex */ |
a399810c | 3066 | const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; |
86748f35 HV |
3067 | bool write_only = false; |
3068 | struct v4l2_ioctl_info default_info; | |
3069 | const struct v4l2_ioctl_info *info; | |
d5fbf32f | 3070 | void *fh = file->private_data; |
99cd47bc | 3071 | struct v4l2_fh *vfh = NULL; |
17028cdb | 3072 | int dev_debug = vfd->dev_debug; |
9190d191 | 3073 | long ret = -ENOTTY; |
35ea11ff | 3074 | |
6a717883 | 3075 | if (ops == NULL) { |
4a085168 HV |
3076 | pr_warn("%s: has no ioctl_ops.\n", |
3077 | video_device_node_name(vfd)); | |
9190d191 | 3078 | return ret; |
6a717883 HV |
3079 | } |
3080 | ||
b7284bb0 | 3081 | if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) |
99cd47bc HV |
3082 | vfh = file->private_data; |
3083 | ||
cc6eddcd HV |
3084 | /* |
3085 | * We need to serialize streamon/off with queueing new requests. | |
3086 | * These ioctls may trigger the cancellation of a streaming | |
3087 | * operation, and that should not be mixed with queueing a new | |
3088 | * request at the same time. | |
3089 | */ | |
3090 | if (v4l2_device_supports_requests(vfd->v4l2_dev) && | |
3091 | (cmd == VIDIOC_STREAMON || cmd == VIDIOC_STREAMOFF)) { | |
3092 | req_queue_lock = &vfd->v4l2_dev->mdev->req_queue_mutex; | |
3093 | ||
3094 | if (mutex_lock_interruptible(req_queue_lock)) | |
3095 | return -ERESTARTSYS; | |
3096 | } | |
3097 | ||
d862bc08 | 3098 | lock = v4l2_ioctl_get_lock(vfd, vfh, cmd, arg); |
73a11062 | 3099 | |
cc6eddcd HV |
3100 | if (lock && mutex_lock_interruptible(lock)) { |
3101 | if (req_queue_lock) | |
3102 | mutex_unlock(req_queue_lock); | |
73a11062 | 3103 | return -ERESTARTSYS; |
cc6eddcd | 3104 | } |
73a11062 HV |
3105 | |
3106 | if (!video_is_registered(vfd)) { | |
3107 | ret = -ENODEV; | |
3108 | goto unlock; | |
3109 | } | |
3110 | ||
48ea0be0 | 3111 | if (v4l2_is_known_ioctl(cmd)) { |
86748f35 | 3112 | info = &v4l2_ioctls[_IOC_NR(cmd)]; |
48ea0be0 | 3113 | |
c464c2e3 | 3114 | if (!is_valid_ioctl(vfd, cmd) && |
48ea0be0 | 3115 | !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler)) |
86748f35 | 3116 | goto done; |
4b902fec | 3117 | |
b7284bb0 | 3118 | if (vfh && (info->flags & INFO_FL_PRIO)) { |
4b902fec HV |
3119 | ret = v4l2_prio_check(vfd->prio, vfh->prio); |
3120 | if (ret) | |
86748f35 | 3121 | goto done; |
4b902fec | 3122 | } |
86748f35 HV |
3123 | } else { |
3124 | default_info.ioctl = cmd; | |
3125 | default_info.flags = 0; | |
f18d8e07 | 3126 | default_info.debug = v4l_print_default; |
86748f35 | 3127 | info = &default_info; |
48ea0be0 HV |
3128 | } |
3129 | ||
86748f35 | 3130 | write_only = _IOC_DIR(cmd) == _IOC_WRITE; |
3ad3b7a2 ST |
3131 | if (info != &default_info) { |
3132 | ret = info->func(ops, file, fh, arg); | |
f18d8e07 HV |
3133 | } else if (!ops->vidioc_default) { |
3134 | ret = -ENOTTY; | |
3135 | } else { | |
3136 | ret = ops->vidioc_default(file, fh, | |
b7284bb0 | 3137 | vfh ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0, |
f18d8e07 | 3138 | cmd, arg); |
48ea0be0 | 3139 | } |
99cd47bc | 3140 | |
86748f35 | 3141 | done: |
17028cdb HV |
3142 | if (dev_debug & (V4L2_DEV_DEBUG_IOCTL | V4L2_DEV_DEBUG_IOCTL_ARG)) { |
3143 | if (!(dev_debug & V4L2_DEV_DEBUG_STREAMING) && | |
3144 | (cmd == VIDIOC_QBUF || cmd == VIDIOC_DQBUF)) | |
5983d3bc | 3145 | goto unlock; |
17028cdb | 3146 | |
4a085168 | 3147 | v4l_printk_ioctl(video_device_node_name(vfd), cmd); |
86748f35 | 3148 | if (ret < 0) |
505d04bd | 3149 | pr_cont(": error %ld", ret); |
17028cdb | 3150 | if (!(dev_debug & V4L2_DEV_DEBUG_IOCTL_ARG)) |
86748f35 | 3151 | pr_cont("\n"); |
86748f35 HV |
3152 | else if (_IOC_DIR(cmd) == _IOC_NONE) |
3153 | info->debug(arg, write_only); | |
3154 | else { | |
3155 | pr_cont(": "); | |
3156 | info->debug(arg, write_only); | |
35ea11ff HV |
3157 | } |
3158 | } | |
3159 | ||
73a11062 HV |
3160 | unlock: |
3161 | if (lock) | |
3162 | mutex_unlock(lock); | |
cc6eddcd HV |
3163 | if (req_queue_lock) |
3164 | mutex_unlock(req_queue_lock); | |
35ea11ff HV |
3165 | return ret; |
3166 | } | |
3167 | ||
d14e6d76 | 3168 | static int check_array_args(unsigned int cmd, void *parg, size_t *array_size, |
ba2d35c1 | 3169 | void __user **user_ptr, void ***kernel_ptr) |
d14e6d76 PO |
3170 | { |
3171 | int ret = 0; | |
3172 | ||
3173 | switch (cmd) { | |
96b1a702 | 3174 | case VIDIOC_PREPARE_BUF: |
d14e6d76 PO |
3175 | case VIDIOC_QUERYBUF: |
3176 | case VIDIOC_QBUF: | |
3177 | case VIDIOC_DQBUF: { | |
3178 | struct v4l2_buffer *buf = parg; | |
3179 | ||
3180 | if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) { | |
3181 | if (buf->length > VIDEO_MAX_PLANES) { | |
3182 | ret = -EINVAL; | |
3183 | break; | |
3184 | } | |
3185 | *user_ptr = (void __user *)buf->m.planes; | |
ba2d35c1 | 3186 | *kernel_ptr = (void **)&buf->m.planes; |
d14e6d76 PO |
3187 | *array_size = sizeof(struct v4l2_plane) * buf->length; |
3188 | ret = 1; | |
3189 | } | |
3190 | break; | |
3191 | } | |
3192 | ||
dd519bb3 HV |
3193 | case VIDIOC_G_EDID: |
3194 | case VIDIOC_S_EDID: { | |
3195 | struct v4l2_edid *edid = parg; | |
ed45ce2c HV |
3196 | |
3197 | if (edid->blocks) { | |
1b8b10cc HV |
3198 | if (edid->blocks > 256) { |
3199 | ret = -EINVAL; | |
3200 | break; | |
3201 | } | |
ed45ce2c | 3202 | *user_ptr = (void __user *)edid->edid; |
ba2d35c1 | 3203 | *kernel_ptr = (void **)&edid->edid; |
ed45ce2c HV |
3204 | *array_size = edid->blocks * 128; |
3205 | ret = 1; | |
3206 | } | |
3207 | break; | |
3208 | } | |
3209 | ||
d14e6d76 PO |
3210 | case VIDIOC_S_EXT_CTRLS: |
3211 | case VIDIOC_G_EXT_CTRLS: | |
3212 | case VIDIOC_TRY_EXT_CTRLS: { | |
3213 | struct v4l2_ext_controls *ctrls = parg; | |
3214 | ||
3215 | if (ctrls->count != 0) { | |
6c06108b DC |
3216 | if (ctrls->count > V4L2_CID_MAX_CTRLS) { |
3217 | ret = -EINVAL; | |
3218 | break; | |
3219 | } | |
d14e6d76 | 3220 | *user_ptr = (void __user *)ctrls->controls; |
ba2d35c1 | 3221 | *kernel_ptr = (void **)&ctrls->controls; |
d14e6d76 PO |
3222 | *array_size = sizeof(struct v4l2_ext_control) |
3223 | * ctrls->count; | |
3224 | ret = 1; | |
3225 | } | |
3226 | break; | |
3227 | } | |
a418bb3f LP |
3228 | |
3229 | case VIDIOC_SUBDEV_G_ROUTING: | |
3230 | case VIDIOC_SUBDEV_S_ROUTING: { | |
3231 | struct v4l2_subdev_routing *routing = parg; | |
3232 | ||
83a22a07 | 3233 | if (routing->len_routes > 256) |
a418bb3f LP |
3234 | return -E2BIG; |
3235 | ||
3236 | *user_ptr = u64_to_user_ptr(routing->routes); | |
3237 | *kernel_ptr = (void **)&routing->routes; | |
3238 | *array_size = sizeof(struct v4l2_subdev_route) | |
83a22a07 | 3239 | * routing->len_routes; |
a418bb3f LP |
3240 | ret = 1; |
3241 | break; | |
3242 | } | |
d14e6d76 PO |
3243 | } |
3244 | ||
3245 | return ret; | |
3246 | } | |
3247 | ||
c8ef1a60 AB |
3248 | static unsigned int video_translate_cmd(unsigned int cmd) |
3249 | { | |
c344f07a | 3250 | #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) |
1a6c0b36 | 3251 | switch (cmd) { |
1a6c0b36 AB |
3252 | case VIDIOC_DQEVENT_TIME32: |
3253 | return VIDIOC_DQEVENT; | |
577c89b0 AB |
3254 | case VIDIOC_QUERYBUF_TIME32: |
3255 | return VIDIOC_QUERYBUF; | |
3256 | case VIDIOC_QBUF_TIME32: | |
3257 | return VIDIOC_QBUF; | |
3258 | case VIDIOC_DQBUF_TIME32: | |
3259 | return VIDIOC_DQBUF; | |
3260 | case VIDIOC_PREPARE_BUF_TIME32: | |
3261 | return VIDIOC_PREPARE_BUF; | |
1a6c0b36 | 3262 | } |
c344f07a | 3263 | #endif |
8dbcc3fa AB |
3264 | if (in_compat_syscall()) |
3265 | return v4l2_compat_translate_cmd(cmd); | |
1a6c0b36 | 3266 | |
c8ef1a60 AB |
3267 | return cmd; |
3268 | } | |
3269 | ||
8dbcc3fa AB |
3270 | static int video_get_user(void __user *arg, void *parg, |
3271 | unsigned int real_cmd, unsigned int cmd, | |
c8ef1a60 AB |
3272 | bool *always_copy) |
3273 | { | |
8dbcc3fa AB |
3274 | unsigned int n = _IOC_SIZE(real_cmd); |
3275 | int err = 0; | |
c8ef1a60 AB |
3276 | |
3277 | if (!(_IOC_DIR(cmd) & _IOC_WRITE)) { | |
3278 | /* read-only ioctl */ | |
3279 | memset(parg, 0, n); | |
3280 | return 0; | |
3281 | } | |
3282 | ||
8dbcc3fa AB |
3283 | /* |
3284 | * In some cases, only a few fields are used as input, | |
3285 | * i.e. when the app sets "index" and then the driver | |
3286 | * fills in the rest of the structure for the thing | |
3287 | * with that index. We only need to copy up the first | |
3288 | * non-input field. | |
3289 | */ | |
3290 | if (v4l2_is_known_ioctl(real_cmd)) { | |
3291 | u32 flags = v4l2_ioctls[_IOC_NR(real_cmd)].flags; | |
577c89b0 | 3292 | |
8dbcc3fa AB |
3293 | if (flags & INFO_FL_CLEAR_MASK) |
3294 | n = (flags & INFO_FL_CLEAR_MASK) >> 16; | |
3295 | *always_copy = flags & INFO_FL_ALWAYS_COPY; | |
577c89b0 | 3296 | } |
c8ef1a60 | 3297 | |
8dbcc3fa | 3298 | if (cmd == real_cmd) { |
c8ef1a60 | 3299 | if (copy_from_user(parg, (void __user *)arg, n)) |
8dbcc3fa AB |
3300 | err = -EFAULT; |
3301 | } else if (in_compat_syscall()) { | |
7b53cca7 | 3302 | memset(parg, 0, n); |
8dbcc3fa AB |
3303 | err = v4l2_compat_get_user(arg, parg, cmd); |
3304 | } else { | |
7b53cca7 | 3305 | memset(parg, 0, n); |
c344f07a | 3306 | #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) |
8dbcc3fa | 3307 | switch (cmd) { |
8dbcc3fa AB |
3308 | case VIDIOC_QUERYBUF_TIME32: |
3309 | case VIDIOC_QBUF_TIME32: | |
3310 | case VIDIOC_DQBUF_TIME32: | |
3311 | case VIDIOC_PREPARE_BUF_TIME32: { | |
3312 | struct v4l2_buffer_time32 vb32; | |
3313 | struct v4l2_buffer *vb = parg; | |
3314 | ||
3315 | if (copy_from_user(&vb32, arg, sizeof(vb32))) | |
3316 | return -EFAULT; | |
3317 | ||
3318 | *vb = (struct v4l2_buffer) { | |
3319 | .index = vb32.index, | |
e84c8932 AB |
3320 | .type = vb32.type, |
3321 | .bytesused = vb32.bytesused, | |
3322 | .flags = vb32.flags, | |
3323 | .field = vb32.field, | |
3324 | .timestamp.tv_sec = vb32.timestamp.tv_sec, | |
3325 | .timestamp.tv_usec = vb32.timestamp.tv_usec, | |
3326 | .timecode = vb32.timecode, | |
3327 | .sequence = vb32.sequence, | |
3328 | .memory = vb32.memory, | |
3329 | .m.userptr = vb32.m.userptr, | |
3330 | .length = vb32.length, | |
3331 | .request_fd = vb32.request_fd, | |
8dbcc3fa AB |
3332 | }; |
3333 | break; | |
3334 | } | |
8dbcc3fa | 3335 | } |
c344f07a | 3336 | #endif |
c8ef1a60 AB |
3337 | } |
3338 | ||
8dbcc3fa AB |
3339 | /* zero out anything we don't copy from userspace */ |
3340 | if (!err && n < _IOC_SIZE(real_cmd)) | |
3341 | memset((u8 *)parg + n, 0, _IOC_SIZE(real_cmd) - n); | |
3342 | return err; | |
c8ef1a60 AB |
3343 | } |
3344 | ||
8dbcc3fa AB |
3345 | static int video_put_user(void __user *arg, void *parg, |
3346 | unsigned int real_cmd, unsigned int cmd) | |
c8ef1a60 AB |
3347 | { |
3348 | if (!(_IOC_DIR(cmd) & _IOC_READ)) | |
3349 | return 0; | |
3350 | ||
8dbcc3fa AB |
3351 | if (cmd == real_cmd) { |
3352 | /* Copy results into user buffer */ | |
3353 | if (copy_to_user(arg, parg, _IOC_SIZE(cmd))) | |
3354 | return -EFAULT; | |
3355 | return 0; | |
3356 | } | |
3357 | ||
3358 | if (in_compat_syscall()) | |
3359 | return v4l2_compat_put_user(arg, parg, cmd); | |
3360 | ||
c344f07a | 3361 | #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) |
c8ef1a60 | 3362 | switch (cmd) { |
1a6c0b36 AB |
3363 | case VIDIOC_DQEVENT_TIME32: { |
3364 | struct v4l2_event *ev = parg; | |
4ffb879e PY |
3365 | struct v4l2_event_time32 ev32; |
3366 | ||
3367 | memset(&ev32, 0, sizeof(ev32)); | |
3368 | ||
3369 | ev32.type = ev->type; | |
3370 | ev32.pending = ev->pending; | |
3371 | ev32.sequence = ev->sequence; | |
3372 | ev32.timestamp.tv_sec = ev->timestamp.tv_sec; | |
3373 | ev32.timestamp.tv_nsec = ev->timestamp.tv_nsec; | |
3374 | ev32.id = ev->id; | |
1a6c0b36 AB |
3375 | |
3376 | memcpy(&ev32.u, &ev->u, sizeof(ev->u)); | |
3377 | memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved)); | |
3378 | ||
3379 | if (copy_to_user(arg, &ev32, sizeof(ev32))) | |
3380 | return -EFAULT; | |
3381 | break; | |
3382 | } | |
577c89b0 AB |
3383 | case VIDIOC_QUERYBUF_TIME32: |
3384 | case VIDIOC_QBUF_TIME32: | |
3385 | case VIDIOC_DQBUF_TIME32: | |
3386 | case VIDIOC_PREPARE_BUF_TIME32: { | |
3387 | struct v4l2_buffer *vb = parg; | |
4ffb879e PY |
3388 | struct v4l2_buffer_time32 vb32; |
3389 | ||
3390 | memset(&vb32, 0, sizeof(vb32)); | |
3391 | ||
3392 | vb32.index = vb->index; | |
3393 | vb32.type = vb->type; | |
3394 | vb32.bytesused = vb->bytesused; | |
3395 | vb32.flags = vb->flags; | |
3396 | vb32.field = vb->field; | |
3397 | vb32.timestamp.tv_sec = vb->timestamp.tv_sec; | |
3398 | vb32.timestamp.tv_usec = vb->timestamp.tv_usec; | |
3399 | vb32.timecode = vb->timecode; | |
3400 | vb32.sequence = vb->sequence; | |
3401 | vb32.memory = vb->memory; | |
3402 | vb32.m.userptr = vb->m.userptr; | |
3403 | vb32.length = vb->length; | |
3404 | vb32.request_fd = vb->request_fd; | |
577c89b0 AB |
3405 | |
3406 | if (copy_to_user(arg, &vb32, sizeof(vb32))) | |
3407 | return -EFAULT; | |
3408 | break; | |
3409 | } | |
c8ef1a60 | 3410 | } |
c344f07a | 3411 | #endif |
c8ef1a60 AB |
3412 | |
3413 | return 0; | |
3414 | } | |
3415 | ||
fc0a8079 | 3416 | long |
c8ef1a60 | 3417 | video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg, |
fc0a8079 | 3418 | v4l2_kioctl func) |
35ea11ff HV |
3419 | { |
3420 | char sbuf[128]; | |
fb18802a | 3421 | void *mbuf = NULL, *array_buf = NULL; |
1d94aa36 | 3422 | void *parg = (void *)arg; |
069b7479 | 3423 | long err = -EINVAL; |
d14e6d76 | 3424 | bool has_array_args; |
043f77ed | 3425 | bool always_copy = false; |
d14e6d76 | 3426 | size_t array_size = 0; |
35ea11ff | 3427 | void __user *user_ptr = NULL; |
d14e6d76 | 3428 | void **kernel_ptr = NULL; |
c8ef1a60 | 3429 | unsigned int cmd = video_translate_cmd(orig_cmd); |
f8a695c4 | 3430 | const size_t ioc_size = _IOC_SIZE(cmd); |
35ea11ff | 3431 | |
35ea11ff | 3432 | /* Copy arguments into temp kernel buffer */ |
337f9d20 | 3433 | if (_IOC_DIR(cmd) != _IOC_NONE) { |
f8a695c4 | 3434 | if (ioc_size <= sizeof(sbuf)) { |
35ea11ff HV |
3435 | parg = sbuf; |
3436 | } else { | |
3437 | /* too big to allocate from stack */ | |
62a12551 | 3438 | mbuf = kmalloc(ioc_size, GFP_KERNEL); |
35ea11ff HV |
3439 | if (NULL == mbuf) |
3440 | return -ENOMEM; | |
3441 | parg = mbuf; | |
3442 | } | |
3443 | ||
8dbcc3fa AB |
3444 | err = video_get_user((void __user *)arg, parg, cmd, |
3445 | orig_cmd, &always_copy); | |
1dc8b65c AB |
3446 | if (err) |
3447 | goto out; | |
35ea11ff HV |
3448 | } |
3449 | ||
d14e6d76 PO |
3450 | err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr); |
3451 | if (err < 0) | |
3452 | goto out; | |
3453 | has_array_args = err; | |
35ea11ff | 3454 | |
d14e6d76 | 3455 | if (has_array_args) { |
fb18802a | 3456 | array_buf = kvmalloc(array_size, GFP_KERNEL); |
d14e6d76 | 3457 | err = -ENOMEM; |
fb18802a | 3458 | if (array_buf == NULL) |
f0da34f3 | 3459 | goto out; |
8dbcc3fa | 3460 | if (in_compat_syscall()) |
fb18802a SA |
3461 | err = v4l2_compat_get_array_args(file, array_buf, |
3462 | user_ptr, array_size, | |
3463 | orig_cmd, parg); | |
8dbcc3fa | 3464 | else |
fb18802a | 3465 | err = copy_from_user(array_buf, user_ptr, array_size) ? |
8dbcc3fa AB |
3466 | -EFAULT : 0; |
3467 | if (err) | |
f0da34f3 | 3468 | goto out; |
fb18802a | 3469 | *kernel_ptr = array_buf; |
35ea11ff HV |
3470 | } |
3471 | ||
3472 | /* Handles IOCTL */ | |
fc0a8079 | 3473 | err = func(file, cmd, parg); |
181a4a2d | 3474 | if (err == -ENOTTY || err == -ENOIOCTLCMD) { |
02bbb814 | 3475 | err = -ENOTTY; |
181a4a2d HV |
3476 | goto out; |
3477 | } | |
3478 | ||
aa32f4c0 HV |
3479 | if (err == 0) { |
3480 | if (cmd == VIDIOC_DQBUF) | |
3481 | trace_v4l2_dqbuf(video_devdata(file)->minor, parg); | |
3482 | else if (cmd == VIDIOC_QBUF) | |
3483 | trace_v4l2_qbuf(video_devdata(file)->minor, parg); | |
3484 | } | |
35ea11ff | 3485 | |
f0da34f3 HV |
3486 | /* |
3487 | * Some ioctls can return an error, but still have valid | |
3488 | * results that must be returned. | |
a418bb3f LP |
3489 | * |
3490 | * FIXME: subdev IOCTLS are partially handled here and partially in | |
3491 | * v4l2-subdev.c and the 'always_copy' flag can only be set for IOCTLS | |
3492 | * defined here as part of the 'v4l2_ioctls' array. As | |
38c84932 SA |
3493 | * VIDIOC_SUBDEV_[GS]_ROUTING needs to return results to applications |
3494 | * even in case of failure, but it is not defined here as part of the | |
a418bb3f | 3495 | * 'v4l2_ioctls' array, insert an ad-hoc check to address that. |
f0da34f3 | 3496 | */ |
38c84932 SA |
3497 | if (cmd == VIDIOC_SUBDEV_G_ROUTING || cmd == VIDIOC_SUBDEV_S_ROUTING) |
3498 | always_copy = true; | |
3499 | ||
3500 | if (err < 0 && !always_copy) | |
f0da34f3 HV |
3501 | goto out; |
3502 | ||
d14e6d76 | 3503 | if (has_array_args) { |
ba2d35c1 | 3504 | *kernel_ptr = (void __force *)user_ptr; |
8dbcc3fa AB |
3505 | if (in_compat_syscall()) { |
3506 | int put_err; | |
3507 | ||
fb18802a SA |
3508 | put_err = v4l2_compat_put_array_args(file, user_ptr, |
3509 | array_buf, | |
3510 | array_size, | |
3511 | orig_cmd, parg); | |
8dbcc3fa AB |
3512 | if (put_err) |
3513 | err = put_err; | |
fb18802a | 3514 | } else if (copy_to_user(user_ptr, array_buf, array_size)) { |
35ea11ff | 3515 | err = -EFAULT; |
8dbcc3fa | 3516 | } |
35ea11ff | 3517 | } |
35ea11ff | 3518 | |
8dbcc3fa | 3519 | if (video_put_user((void __user *)arg, parg, cmd, orig_cmd)) |
c8ef1a60 | 3520 | err = -EFAULT; |
35ea11ff | 3521 | out: |
fb18802a | 3522 | kvfree(array_buf); |
62a12551 | 3523 | kfree(mbuf); |
35ea11ff HV |
3524 | return err; |
3525 | } | |
fc0a8079 LP |
3526 | |
3527 | long video_ioctl2(struct file *file, | |
3528 | unsigned int cmd, unsigned long arg) | |
3529 | { | |
3530 | return video_usercopy(file, cmd, arg, __video_do_ioctl); | |
3531 | } | |
8a522c91 | 3532 | EXPORT_SYMBOL(video_ioctl2); |