Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Video capture interface for Linux version 2 |
| 3 | * |
| 4 | * A generic framework to process V4L2 ioctl commands. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 11 | * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 12 | * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2) |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 17 | #include <linux/types.h> |
| 18 | #include <linux/kernel.h> |
Mauro Carvalho Chehab | ae6db51 | 2011-06-24 13:14:14 -0300 | [diff] [blame] | 19 | #include <linux/version.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 20 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 21 | #include <linux/videodev2.h> |
| 22 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 23 | #include <media/v4l2-common.h> |
| 24 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 11bbc1c | 2010-05-16 09:24:06 -0300 | [diff] [blame] | 25 | #include <media/v4l2-ctrls.h> |
Sakari Ailus | d3d7c96 | 2010-03-27 11:02:10 -0300 | [diff] [blame] | 26 | #include <media/v4l2-fh.h> |
| 27 | #include <media/v4l2-event.h> |
Hans Verkuil | 99cd47bc | 2011-03-11 19:00:56 -0300 | [diff] [blame] | 28 | #include <media/v4l2-device.h> |
Hans Verkuil | 80b36e0 | 2009-02-07 11:00:02 -0300 | [diff] [blame] | 29 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 30 | #include <media/videobuf2-core.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 31 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 32 | /* Zero out the end of the struct pointed to by p. Everything after, but |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 33 | * not including, the specified field is cleared. */ |
| 34 | #define CLEAR_AFTER_FIELD(p, field) \ |
| 35 | memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \ |
| 36 | 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field)) |
| 37 | |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 38 | #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls) |
| 39 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 40 | struct std_descr { |
| 41 | v4l2_std_id std; |
| 42 | const char *descr; |
| 43 | }; |
| 44 | |
| 45 | static const struct std_descr standards[] = { |
| 46 | { V4L2_STD_NTSC, "NTSC" }, |
| 47 | { V4L2_STD_NTSC_M, "NTSC-M" }, |
| 48 | { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" }, |
| 49 | { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" }, |
| 50 | { V4L2_STD_NTSC_443, "NTSC-443" }, |
| 51 | { V4L2_STD_PAL, "PAL" }, |
| 52 | { V4L2_STD_PAL_BG, "PAL-BG" }, |
| 53 | { V4L2_STD_PAL_B, "PAL-B" }, |
| 54 | { V4L2_STD_PAL_B1, "PAL-B1" }, |
| 55 | { V4L2_STD_PAL_G, "PAL-G" }, |
| 56 | { V4L2_STD_PAL_H, "PAL-H" }, |
| 57 | { V4L2_STD_PAL_I, "PAL-I" }, |
| 58 | { V4L2_STD_PAL_DK, "PAL-DK" }, |
| 59 | { V4L2_STD_PAL_D, "PAL-D" }, |
| 60 | { V4L2_STD_PAL_D1, "PAL-D1" }, |
| 61 | { V4L2_STD_PAL_K, "PAL-K" }, |
| 62 | { V4L2_STD_PAL_M, "PAL-M" }, |
| 63 | { V4L2_STD_PAL_N, "PAL-N" }, |
| 64 | { V4L2_STD_PAL_Nc, "PAL-Nc" }, |
| 65 | { V4L2_STD_PAL_60, "PAL-60" }, |
| 66 | { V4L2_STD_SECAM, "SECAM" }, |
| 67 | { V4L2_STD_SECAM_B, "SECAM-B" }, |
| 68 | { V4L2_STD_SECAM_G, "SECAM-G" }, |
| 69 | { V4L2_STD_SECAM_H, "SECAM-H" }, |
| 70 | { V4L2_STD_SECAM_DK, "SECAM-DK" }, |
| 71 | { V4L2_STD_SECAM_D, "SECAM-D" }, |
| 72 | { V4L2_STD_SECAM_K, "SECAM-K" }, |
| 73 | { V4L2_STD_SECAM_K1, "SECAM-K1" }, |
| 74 | { V4L2_STD_SECAM_L, "SECAM-L" }, |
| 75 | { V4L2_STD_SECAM_LC, "SECAM-Lc" }, |
| 76 | { 0, "Unknown" } |
| 77 | }; |
| 78 | |
| 79 | /* video4linux standard ID conversion to standard name |
| 80 | */ |
| 81 | const char *v4l2_norm_to_name(v4l2_std_id id) |
| 82 | { |
| 83 | u32 myid = id; |
| 84 | int i; |
| 85 | |
| 86 | /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle |
| 87 | 64 bit comparations. So, on that architecture, with some gcc |
| 88 | variants, compilation fails. Currently, the max value is 30bit wide. |
| 89 | */ |
| 90 | BUG_ON(myid != id); |
| 91 | |
| 92 | for (i = 0; standards[i].std; i++) |
| 93 | if (myid == standards[i].std) |
| 94 | break; |
| 95 | return standards[i].descr; |
| 96 | } |
| 97 | EXPORT_SYMBOL(v4l2_norm_to_name); |
| 98 | |
Trent Piepho | 51f0b8d5 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 99 | /* Returns frame period for the given standard */ |
| 100 | void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod) |
| 101 | { |
| 102 | if (id & V4L2_STD_525_60) { |
| 103 | frameperiod->numerator = 1001; |
| 104 | frameperiod->denominator = 30000; |
| 105 | } else { |
| 106 | frameperiod->numerator = 1; |
| 107 | frameperiod->denominator = 25; |
| 108 | } |
| 109 | } |
| 110 | EXPORT_SYMBOL(v4l2_video_std_frame_period); |
| 111 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 112 | /* Fill in the fields of a v4l2_standard structure according to the |
| 113 | 'id' and 'transmission' parameters. Returns negative on error. */ |
| 114 | int v4l2_video_std_construct(struct v4l2_standard *vs, |
| 115 | int id, const char *name) |
| 116 | { |
Trent Piepho | 51f0b8d5 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 117 | vs->id = id; |
| 118 | v4l2_video_std_frame_period(id, &vs->frameperiod); |
| 119 | vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 120 | strlcpy(vs->name, name, sizeof(vs->name)); |
| 121 | return 0; |
| 122 | } |
| 123 | EXPORT_SYMBOL(v4l2_video_std_construct); |
| 124 | |
| 125 | /* ----------------------------------------------------------------- */ |
| 126 | /* some arrays for pretty-printing debug messages of enum types */ |
| 127 | |
| 128 | const char *v4l2_field_names[] = { |
| 129 | [V4L2_FIELD_ANY] = "any", |
| 130 | [V4L2_FIELD_NONE] = "none", |
| 131 | [V4L2_FIELD_TOP] = "top", |
| 132 | [V4L2_FIELD_BOTTOM] = "bottom", |
| 133 | [V4L2_FIELD_INTERLACED] = "interlaced", |
| 134 | [V4L2_FIELD_SEQ_TB] = "seq-tb", |
| 135 | [V4L2_FIELD_SEQ_BT] = "seq-bt", |
| 136 | [V4L2_FIELD_ALTERNATE] = "alternate", |
| 137 | [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb", |
| 138 | [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt", |
| 139 | }; |
| 140 | EXPORT_SYMBOL(v4l2_field_names); |
| 141 | |
| 142 | const char *v4l2_type_names[] = { |
| 143 | [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap", |
| 144 | [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay", |
| 145 | [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out", |
| 146 | [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", |
| 147 | [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", |
| 148 | [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap", |
| 149 | [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out", |
| 150 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay", |
Pawel Osciak | f8f3914 | 2010-07-29 14:44:25 -0300 | [diff] [blame] | 151 | [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane", |
| 152 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane", |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 153 | }; |
| 154 | EXPORT_SYMBOL(v4l2_type_names); |
| 155 | |
| 156 | static const char *v4l2_memory_names[] = { |
| 157 | [V4L2_MEMORY_MMAP] = "mmap", |
| 158 | [V4L2_MEMORY_USERPTR] = "userptr", |
| 159 | [V4L2_MEMORY_OVERLAY] = "overlay", |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 160 | [V4L2_MEMORY_DMABUF] = "dmabuf", |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 161 | }; |
| 162 | |
Hans Verkuil | d924624 | 2012-10-02 02:47:59 -0300 | [diff] [blame] | 163 | #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown") |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 164 | |
| 165 | /* ------------------------------------------------------------------ */ |
| 166 | /* debug help functions */ |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 167 | |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 168 | static void v4l_print_querycap(const void *arg, bool write_only) |
| 169 | { |
| 170 | const struct v4l2_capability *p = arg; |
| 171 | |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 172 | pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, " |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 173 | "capabilities=0x%08x, device_caps=0x%08x\n", |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 174 | (int)sizeof(p->driver), p->driver, |
| 175 | (int)sizeof(p->card), p->card, |
| 176 | (int)sizeof(p->bus_info), p->bus_info, |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 177 | p->version, p->capabilities, p->device_caps); |
| 178 | } |
| 179 | |
| 180 | static void v4l_print_enuminput(const void *arg, bool write_only) |
| 181 | { |
| 182 | const struct v4l2_input *p = arg; |
| 183 | |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 184 | pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, " |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 185 | "std=0x%08Lx, status=0x%x, capabilities=0x%x\n", |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 186 | p->index, (int)sizeof(p->name), p->name, p->type, p->audioset, |
| 187 | p->tuner, (unsigned long long)p->std, p->status, |
| 188 | p->capabilities); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static void v4l_print_enumoutput(const void *arg, bool write_only) |
| 192 | { |
| 193 | const struct v4l2_output *p = arg; |
| 194 | |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 195 | pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, " |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 196 | "modulator=%u, std=0x%08Lx, capabilities=0x%x\n", |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 197 | p->index, (int)sizeof(p->name), p->name, p->type, p->audioset, |
| 198 | p->modulator, (unsigned long long)p->std, p->capabilities); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static void v4l_print_audio(const void *arg, bool write_only) |
| 202 | { |
| 203 | const struct v4l2_audio *p = arg; |
| 204 | |
| 205 | if (write_only) |
| 206 | pr_cont("index=%u, mode=0x%x\n", p->index, p->mode); |
| 207 | else |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 208 | pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n", |
| 209 | p->index, (int)sizeof(p->name), p->name, |
| 210 | p->capability, p->mode); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static void v4l_print_audioout(const void *arg, bool write_only) |
| 214 | { |
| 215 | const struct v4l2_audioout *p = arg; |
| 216 | |
| 217 | if (write_only) |
| 218 | pr_cont("index=%u\n", p->index); |
| 219 | else |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 220 | pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n", |
| 221 | p->index, (int)sizeof(p->name), p->name, |
| 222 | p->capability, p->mode); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 223 | } |
| 224 | |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 225 | static void v4l_print_fmtdesc(const void *arg, bool write_only) |
| 226 | { |
| 227 | const struct v4l2_fmtdesc *p = arg; |
| 228 | |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 229 | pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n", |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 230 | p->index, prt_names(p->type, v4l2_type_names), |
| 231 | p->flags, (p->pixelformat & 0xff), |
| 232 | (p->pixelformat >> 8) & 0xff, |
| 233 | (p->pixelformat >> 16) & 0xff, |
| 234 | (p->pixelformat >> 24) & 0xff, |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 235 | (int)sizeof(p->description), p->description); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static void v4l_print_format(const void *arg, bool write_only) |
| 239 | { |
| 240 | const struct v4l2_format *p = arg; |
| 241 | const struct v4l2_pix_format *pix; |
| 242 | const struct v4l2_pix_format_mplane *mp; |
| 243 | const struct v4l2_vbi_format *vbi; |
| 244 | const struct v4l2_sliced_vbi_format *sliced; |
| 245 | const struct v4l2_window *win; |
| 246 | const struct v4l2_clip *clip; |
| 247 | unsigned i; |
| 248 | |
| 249 | pr_cont("type=%s", prt_names(p->type, v4l2_type_names)); |
| 250 | switch (p->type) { |
| 251 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 252 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 253 | pix = &p->fmt.pix; |
| 254 | pr_cont(", width=%u, height=%u, " |
| 255 | "pixelformat=%c%c%c%c, field=%s, " |
| 256 | "bytesperline=%u sizeimage=%u, colorspace=%d\n", |
| 257 | pix->width, pix->height, |
| 258 | (pix->pixelformat & 0xff), |
| 259 | (pix->pixelformat >> 8) & 0xff, |
| 260 | (pix->pixelformat >> 16) & 0xff, |
| 261 | (pix->pixelformat >> 24) & 0xff, |
| 262 | prt_names(pix->field, v4l2_field_names), |
| 263 | pix->bytesperline, pix->sizeimage, |
| 264 | pix->colorspace); |
| 265 | break; |
| 266 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
| 267 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
| 268 | mp = &p->fmt.pix_mp; |
| 269 | pr_cont(", width=%u, height=%u, " |
| 270 | "format=%c%c%c%c, field=%s, " |
| 271 | "colorspace=%d, num_planes=%u\n", |
| 272 | mp->width, mp->height, |
| 273 | (mp->pixelformat & 0xff), |
| 274 | (mp->pixelformat >> 8) & 0xff, |
| 275 | (mp->pixelformat >> 16) & 0xff, |
| 276 | (mp->pixelformat >> 24) & 0xff, |
| 277 | prt_names(mp->field, v4l2_field_names), |
| 278 | mp->colorspace, mp->num_planes); |
| 279 | for (i = 0; i < mp->num_planes; i++) |
| 280 | printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i, |
| 281 | mp->plane_fmt[i].bytesperline, |
| 282 | mp->plane_fmt[i].sizeimage); |
| 283 | break; |
| 284 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 285 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
| 286 | win = &p->fmt.win; |
| 287 | pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, " |
| 288 | "chromakey=0x%08x, bitmap=%p, " |
| 289 | "global_alpha=0x%02x\n", |
| 290 | win->w.width, win->w.height, |
| 291 | win->w.left, win->w.top, |
| 292 | prt_names(win->field, v4l2_field_names), |
| 293 | win->chromakey, win->bitmap, win->global_alpha); |
| 294 | clip = win->clips; |
| 295 | for (i = 0; i < win->clipcount; i++) { |
| 296 | printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n", |
| 297 | i, clip->c.width, clip->c.height, |
| 298 | clip->c.left, clip->c.top); |
| 299 | clip = clip->next; |
| 300 | } |
| 301 | break; |
| 302 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 303 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
| 304 | vbi = &p->fmt.vbi; |
| 305 | pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, " |
| 306 | "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n", |
| 307 | vbi->sampling_rate, vbi->offset, |
| 308 | vbi->samples_per_line, |
| 309 | (vbi->sample_format & 0xff), |
| 310 | (vbi->sample_format >> 8) & 0xff, |
| 311 | (vbi->sample_format >> 16) & 0xff, |
| 312 | (vbi->sample_format >> 24) & 0xff, |
| 313 | vbi->start[0], vbi->start[1], |
| 314 | vbi->count[0], vbi->count[1]); |
| 315 | break; |
| 316 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 317 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 318 | sliced = &p->fmt.sliced; |
| 319 | pr_cont(", service_set=0x%08x, io_size=%d\n", |
| 320 | sliced->service_set, sliced->io_size); |
| 321 | for (i = 0; i < 24; i++) |
| 322 | printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i, |
| 323 | sliced->service_lines[0][i], |
| 324 | sliced->service_lines[1][i]); |
| 325 | break; |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
| 329 | static void v4l_print_framebuffer(const void *arg, bool write_only) |
| 330 | { |
| 331 | const struct v4l2_framebuffer *p = arg; |
| 332 | |
| 333 | pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, " |
| 334 | "height=%u, pixelformat=%c%c%c%c, " |
| 335 | "bytesperline=%u sizeimage=%u, colorspace=%d\n", |
| 336 | p->capability, p->flags, p->base, |
| 337 | p->fmt.width, p->fmt.height, |
| 338 | (p->fmt.pixelformat & 0xff), |
| 339 | (p->fmt.pixelformat >> 8) & 0xff, |
| 340 | (p->fmt.pixelformat >> 16) & 0xff, |
| 341 | (p->fmt.pixelformat >> 24) & 0xff, |
| 342 | p->fmt.bytesperline, p->fmt.sizeimage, |
| 343 | p->fmt.colorspace); |
| 344 | } |
| 345 | |
Hans Verkuil | e325b24 | 2012-06-09 12:50:15 -0300 | [diff] [blame] | 346 | static void v4l_print_buftype(const void *arg, bool write_only) |
| 347 | { |
| 348 | pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names)); |
| 349 | } |
| 350 | |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 351 | static void v4l_print_modulator(const void *arg, bool write_only) |
| 352 | { |
| 353 | const struct v4l2_modulator *p = arg; |
| 354 | |
| 355 | if (write_only) |
| 356 | pr_cont("index=%u, txsubchans=0x%x", p->index, p->txsubchans); |
| 357 | else |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 358 | pr_cont("index=%u, name=%.*s, capability=0x%x, " |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 359 | "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n", |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 360 | p->index, (int)sizeof(p->name), p->name, p->capability, |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 361 | p->rangelow, p->rangehigh, p->txsubchans); |
| 362 | } |
| 363 | |
| 364 | static void v4l_print_tuner(const void *arg, bool write_only) |
| 365 | { |
| 366 | const struct v4l2_tuner *p = arg; |
| 367 | |
| 368 | if (write_only) |
| 369 | pr_cont("index=%u, audmode=%u\n", p->index, p->audmode); |
| 370 | else |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 371 | pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, " |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 372 | "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, " |
| 373 | "rxsubchans=0x%x, audmode=%u\n", |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 374 | p->index, (int)sizeof(p->name), p->name, p->type, |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 375 | p->capability, p->rangelow, |
| 376 | p->rangehigh, p->signal, p->afc, |
| 377 | p->rxsubchans, p->audmode); |
| 378 | } |
| 379 | |
| 380 | static void v4l_print_frequency(const void *arg, bool write_only) |
| 381 | { |
| 382 | const struct v4l2_frequency *p = arg; |
| 383 | |
| 384 | pr_cont("tuner=%u, type=%u, frequency=%u\n", |
| 385 | p->tuner, p->type, p->frequency); |
| 386 | } |
| 387 | |
| 388 | static void v4l_print_standard(const void *arg, bool write_only) |
| 389 | { |
| 390 | const struct v4l2_standard *p = arg; |
| 391 | |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 392 | pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, " |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 393 | "framelines=%u\n", p->index, |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 394 | (unsigned long long)p->id, (int)sizeof(p->name), p->name, |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 395 | p->frameperiod.numerator, |
| 396 | p->frameperiod.denominator, |
| 397 | p->framelines); |
| 398 | } |
| 399 | |
| 400 | static void v4l_print_std(const void *arg, bool write_only) |
| 401 | { |
| 402 | pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg); |
| 403 | } |
| 404 | |
| 405 | static void v4l_print_hw_freq_seek(const void *arg, bool write_only) |
| 406 | { |
| 407 | const struct v4l2_hw_freq_seek *p = arg; |
| 408 | |
Hans Verkuil | 5e788317 | 2012-08-01 16:18:41 -0300 | [diff] [blame] | 409 | pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, " |
| 410 | "rangelow=%u, rangehigh=%u\n", |
| 411 | p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing, |
| 412 | p->rangelow, p->rangehigh); |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 413 | } |
| 414 | |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 415 | static void v4l_print_requestbuffers(const void *arg, bool write_only) |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 416 | { |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 417 | const struct v4l2_requestbuffers *p = arg; |
| 418 | |
| 419 | pr_cont("count=%d, type=%s, memory=%s\n", |
| 420 | p->count, |
| 421 | prt_names(p->type, v4l2_type_names), |
| 422 | prt_names(p->memory, v4l2_memory_names)); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 423 | } |
| 424 | |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 425 | static void v4l_print_buffer(const void *arg, bool write_only) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 426 | { |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 427 | const struct v4l2_buffer *p = arg; |
| 428 | const struct v4l2_timecode *tc = &p->timecode; |
| 429 | const struct v4l2_plane *plane; |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 430 | int i; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 431 | |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 432 | pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, " |
| 433 | "flags=0x%08x, field=%s, sequence=%d, memory=%s", |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 434 | p->timestamp.tv_sec / 3600, |
| 435 | (int)(p->timestamp.tv_sec / 60) % 60, |
| 436 | (int)(p->timestamp.tv_sec % 60), |
Alexander Beregalov | b045979 | 2008-09-03 16:47:38 -0300 | [diff] [blame] | 437 | (long)p->timestamp.tv_usec, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 438 | p->index, |
| 439 | prt_names(p->type, v4l2_type_names), |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 440 | p->flags, prt_names(p->field, v4l2_field_names), |
| 441 | p->sequence, prt_names(p->memory, v4l2_memory_names)); |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 442 | |
| 443 | if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) { |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 444 | pr_cont("\n"); |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 445 | for (i = 0; i < p->length; ++i) { |
| 446 | plane = &p->m.planes[i]; |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 447 | printk(KERN_DEBUG |
| 448 | "plane %d: bytesused=%d, data_offset=0x%08x " |
| 449 | "offset/userptr=0x%lx, length=%d\n", |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 450 | i, plane->bytesused, plane->data_offset, |
| 451 | plane->m.userptr, plane->length); |
| 452 | } |
| 453 | } else { |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 454 | pr_cont("bytesused=%d, offset/userptr=0x%lx, length=%d\n", |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 455 | p->bytesused, p->m.userptr, p->length); |
| 456 | } |
| 457 | |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 458 | printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, " |
| 459 | "flags=0x%08x, frames=%d, userbits=0x%08x\n", |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 460 | tc->hours, tc->minutes, tc->seconds, |
| 461 | tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits); |
| 462 | } |
| 463 | |
Tomasz Stanislawski | b799d09a | 2012-06-14 11:32:23 -0300 | [diff] [blame] | 464 | static void v4l_print_exportbuffer(const void *arg, bool write_only) |
| 465 | { |
| 466 | const struct v4l2_exportbuffer *p = arg; |
| 467 | |
| 468 | pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n", |
| 469 | p->fd, prt_names(p->type, v4l2_type_names), |
| 470 | p->index, p->plane, p->flags); |
| 471 | } |
| 472 | |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 473 | static void v4l_print_create_buffers(const void *arg, bool write_only) |
| 474 | { |
| 475 | const struct v4l2_create_buffers *p = arg; |
| 476 | |
| 477 | pr_cont("index=%d, count=%d, memory=%s, ", |
| 478 | p->index, p->count, |
| 479 | prt_names(p->memory, v4l2_memory_names)); |
| 480 | v4l_print_format(&p->format, write_only); |
| 481 | } |
| 482 | |
| 483 | static void v4l_print_streamparm(const void *arg, bool write_only) |
| 484 | { |
| 485 | const struct v4l2_streamparm *p = arg; |
| 486 | |
| 487 | pr_cont("type=%s", prt_names(p->type, v4l2_type_names)); |
| 488 | |
| 489 | if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || |
| 490 | p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { |
| 491 | const struct v4l2_captureparm *c = &p->parm.capture; |
| 492 | |
| 493 | pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, " |
| 494 | "extendedmode=%d, readbuffers=%d\n", |
| 495 | c->capability, c->capturemode, |
| 496 | c->timeperframe.numerator, c->timeperframe.denominator, |
| 497 | c->extendedmode, c->readbuffers); |
| 498 | } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT || |
| 499 | p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { |
| 500 | const struct v4l2_outputparm *c = &p->parm.output; |
| 501 | |
| 502 | pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, " |
| 503 | "extendedmode=%d, writebuffers=%d\n", |
| 504 | c->capability, c->outputmode, |
| 505 | c->timeperframe.numerator, c->timeperframe.denominator, |
| 506 | c->extendedmode, c->writebuffers); |
| 507 | } |
| 508 | } |
| 509 | |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 510 | static void v4l_print_queryctrl(const void *arg, bool write_only) |
| 511 | { |
| 512 | const struct v4l2_queryctrl *p = arg; |
| 513 | |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 514 | pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, " |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 515 | "step=%d, default=%d, flags=0x%08x\n", |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 516 | p->id, p->type, (int)sizeof(p->name), p->name, |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 517 | p->minimum, p->maximum, |
| 518 | p->step, p->default_value, p->flags); |
| 519 | } |
| 520 | |
| 521 | static void v4l_print_querymenu(const void *arg, bool write_only) |
| 522 | { |
| 523 | const struct v4l2_querymenu *p = arg; |
| 524 | |
| 525 | pr_cont("id=0x%x, index=%d\n", p->id, p->index); |
| 526 | } |
| 527 | |
| 528 | static void v4l_print_control(const void *arg, bool write_only) |
| 529 | { |
| 530 | const struct v4l2_control *p = arg; |
| 531 | |
| 532 | pr_cont("id=0x%x, value=%d\n", p->id, p->value); |
| 533 | } |
| 534 | |
| 535 | static void v4l_print_ext_controls(const void *arg, bool write_only) |
| 536 | { |
| 537 | const struct v4l2_ext_controls *p = arg; |
| 538 | int i; |
| 539 | |
| 540 | pr_cont("class=0x%x, count=%d, error_idx=%d", |
| 541 | p->ctrl_class, p->count, p->error_idx); |
| 542 | for (i = 0; i < p->count; i++) { |
| 543 | if (p->controls[i].size) |
| 544 | pr_cont(", id/val=0x%x/0x%x", |
| 545 | p->controls[i].id, p->controls[i].value); |
| 546 | else |
| 547 | pr_cont(", id/size=0x%x/%u", |
| 548 | p->controls[i].id, p->controls[i].size); |
| 549 | } |
| 550 | pr_cont("\n"); |
| 551 | } |
| 552 | |
Hans Verkuil | d84f2d94 | 2012-06-09 11:57:46 -0300 | [diff] [blame] | 553 | static void v4l_print_cropcap(const void *arg, bool write_only) |
| 554 | { |
| 555 | const struct v4l2_cropcap *p = arg; |
| 556 | |
| 557 | pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, " |
| 558 | "defrect wxh=%dx%d, x,y=%d,%d\n, " |
| 559 | "pixelaspect %d/%d\n", |
| 560 | prt_names(p->type, v4l2_type_names), |
| 561 | p->bounds.width, p->bounds.height, |
| 562 | p->bounds.left, p->bounds.top, |
| 563 | p->defrect.width, p->defrect.height, |
| 564 | p->defrect.left, p->defrect.top, |
| 565 | p->pixelaspect.numerator, p->pixelaspect.denominator); |
| 566 | } |
| 567 | |
| 568 | static void v4l_print_crop(const void *arg, bool write_only) |
| 569 | { |
| 570 | const struct v4l2_crop *p = arg; |
| 571 | |
| 572 | pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n", |
| 573 | prt_names(p->type, v4l2_type_names), |
| 574 | p->c.width, p->c.height, |
| 575 | p->c.left, p->c.top); |
| 576 | } |
| 577 | |
| 578 | static void v4l_print_selection(const void *arg, bool write_only) |
| 579 | { |
| 580 | const struct v4l2_selection *p = arg; |
| 581 | |
| 582 | pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n", |
| 583 | prt_names(p->type, v4l2_type_names), |
| 584 | p->target, p->flags, |
| 585 | p->r.width, p->r.height, p->r.left, p->r.top); |
| 586 | } |
| 587 | |
Hans Verkuil | d806f2d | 2012-06-09 10:02:49 -0300 | [diff] [blame] | 588 | static void v4l_print_jpegcompression(const void *arg, bool write_only) |
| 589 | { |
| 590 | const struct v4l2_jpegcompression *p = arg; |
| 591 | |
| 592 | pr_cont("quality=%d, APPn=%d, APP_len=%d, " |
| 593 | "COM_len=%d, jpeg_markers=0x%x\n", |
| 594 | p->quality, p->APPn, p->APP_len, |
| 595 | p->COM_len, p->jpeg_markers); |
| 596 | } |
| 597 | |
| 598 | static void v4l_print_enc_idx(const void *arg, bool write_only) |
| 599 | { |
| 600 | const struct v4l2_enc_idx *p = arg; |
| 601 | |
| 602 | pr_cont("entries=%d, entries_cap=%d\n", |
| 603 | p->entries, p->entries_cap); |
| 604 | } |
| 605 | |
| 606 | static void v4l_print_encoder_cmd(const void *arg, bool write_only) |
| 607 | { |
| 608 | const struct v4l2_encoder_cmd *p = arg; |
| 609 | |
| 610 | pr_cont("cmd=%d, flags=0x%x\n", |
| 611 | p->cmd, p->flags); |
| 612 | } |
| 613 | |
| 614 | static void v4l_print_decoder_cmd(const void *arg, bool write_only) |
| 615 | { |
| 616 | const struct v4l2_decoder_cmd *p = arg; |
| 617 | |
| 618 | pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags); |
| 619 | |
| 620 | if (p->cmd == V4L2_DEC_CMD_START) |
| 621 | pr_info("speed=%d, format=%u\n", |
| 622 | p->start.speed, p->start.format); |
| 623 | else if (p->cmd == V4L2_DEC_CMD_STOP) |
| 624 | pr_info("pts=%llu\n", p->stop.pts); |
| 625 | } |
| 626 | |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 627 | static void v4l_print_dbg_chip_ident(const void *arg, bool write_only) |
| 628 | { |
| 629 | const struct v4l2_dbg_chip_ident *p = arg; |
| 630 | |
| 631 | pr_cont("type=%u, ", p->match.type); |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 632 | if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 633 | pr_cont("name=%.*s, ", |
| 634 | (int)sizeof(p->match.name), p->match.name); |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 635 | else |
| 636 | pr_cont("addr=%u, ", p->match.addr); |
| 637 | pr_cont("chip_ident=%u, revision=0x%x\n", |
| 638 | p->ident, p->revision); |
| 639 | } |
| 640 | |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 641 | static void v4l_print_dbg_chip_name(const void *arg, bool write_only) |
| 642 | { |
| 643 | const struct v4l2_dbg_chip_name *p = arg; |
| 644 | |
| 645 | pr_cont("type=%u, ", p->match.type); |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 646 | if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 647 | pr_cont("name=%.*s, ", |
| 648 | (int)sizeof(p->match.name), p->match.name); |
| 649 | else |
| 650 | pr_cont("addr=%u, ", p->match.addr); |
| 651 | pr_cont("name=%.*s\n", (int)sizeof(p->name), p->name); |
| 652 | } |
| 653 | |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 654 | static void v4l_print_dbg_register(const void *arg, bool write_only) |
| 655 | { |
| 656 | const struct v4l2_dbg_register *p = arg; |
| 657 | |
| 658 | pr_cont("type=%u, ", p->match.type); |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 659 | if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) |
Hans Verkuil | 27d5a87 | 2013-03-18 11:02:22 -0300 | [diff] [blame] | 660 | pr_cont("name=%.*s, ", |
| 661 | (int)sizeof(p->match.name), p->match.name); |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 662 | else |
| 663 | pr_cont("addr=%u, ", p->match.addr); |
| 664 | pr_cont("reg=0x%llx, val=0x%llx\n", |
| 665 | p->reg, p->val); |
| 666 | } |
| 667 | |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 668 | static void v4l_print_dv_timings(const void *arg, bool write_only) |
Hans Verkuil | 5d7758e | 2012-05-15 08:06:44 -0300 | [diff] [blame] | 669 | { |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 670 | const struct v4l2_dv_timings *p = arg; |
| 671 | |
Hans Verkuil | 5d7758e | 2012-05-15 08:06:44 -0300 | [diff] [blame] | 672 | switch (p->type) { |
| 673 | case V4L2_DV_BT_656_1120: |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 674 | pr_cont("type=bt-656/1120, interlaced=%u, " |
| 675 | "pixelclock=%llu, " |
| 676 | "width=%u, height=%u, polarities=0x%x, " |
| 677 | "hfrontporch=%u, hsync=%u, " |
| 678 | "hbackporch=%u, vfrontporch=%u, " |
| 679 | "vsync=%u, vbackporch=%u, " |
| 680 | "il_vfrontporch=%u, il_vsync=%u, " |
| 681 | "il_vbackporch=%u, standards=0x%x, flags=0x%x\n", |
Hans Verkuil | 5d7758e | 2012-05-15 08:06:44 -0300 | [diff] [blame] | 682 | p->bt.interlaced, p->bt.pixelclock, |
| 683 | p->bt.width, p->bt.height, |
| 684 | p->bt.polarities, p->bt.hfrontporch, |
| 685 | p->bt.hsync, p->bt.hbackporch, |
| 686 | p->bt.vfrontporch, p->bt.vsync, |
| 687 | p->bt.vbackporch, p->bt.il_vfrontporch, |
| 688 | p->bt.il_vsync, p->bt.il_vbackporch, |
| 689 | p->bt.standards, p->bt.flags); |
| 690 | break; |
| 691 | default: |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 692 | pr_cont("type=%d\n", p->type); |
Hans Verkuil | 5d7758e | 2012-05-15 08:06:44 -0300 | [diff] [blame] | 693 | break; |
| 694 | } |
| 695 | } |
| 696 | |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 697 | static void v4l_print_enum_dv_timings(const void *arg, bool write_only) |
| 698 | { |
| 699 | const struct v4l2_enum_dv_timings *p = arg; |
| 700 | |
| 701 | pr_cont("index=%u, ", p->index); |
| 702 | v4l_print_dv_timings(&p->timings, write_only); |
| 703 | } |
| 704 | |
| 705 | static void v4l_print_dv_timings_cap(const void *arg, bool write_only) |
| 706 | { |
| 707 | const struct v4l2_dv_timings_cap *p = arg; |
| 708 | |
| 709 | switch (p->type) { |
| 710 | case V4L2_DV_BT_656_1120: |
| 711 | pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, " |
| 712 | "pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n", |
| 713 | p->bt.min_width, p->bt.max_width, |
| 714 | p->bt.min_height, p->bt.max_height, |
| 715 | p->bt.min_pixelclock, p->bt.max_pixelclock, |
| 716 | p->bt.standards, p->bt.capabilities); |
| 717 | break; |
| 718 | default: |
| 719 | pr_cont("type=%u\n", p->type); |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | |
Hans Verkuil | 458aa4a | 2012-06-09 12:55:52 -0300 | [diff] [blame] | 724 | static void v4l_print_frmsizeenum(const void *arg, bool write_only) |
| 725 | { |
| 726 | const struct v4l2_frmsizeenum *p = arg; |
| 727 | |
| 728 | pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u", |
| 729 | p->index, |
| 730 | (p->pixel_format & 0xff), |
| 731 | (p->pixel_format >> 8) & 0xff, |
| 732 | (p->pixel_format >> 16) & 0xff, |
| 733 | (p->pixel_format >> 24) & 0xff, |
| 734 | p->type); |
| 735 | switch (p->type) { |
| 736 | case V4L2_FRMSIZE_TYPE_DISCRETE: |
| 737 | pr_cont(" wxh=%ux%u\n", |
| 738 | p->discrete.width, p->discrete.height); |
| 739 | break; |
| 740 | case V4L2_FRMSIZE_TYPE_STEPWISE: |
| 741 | pr_cont(" min=%ux%u, max=%ux%u, step=%ux%u\n", |
| 742 | p->stepwise.min_width, p->stepwise.min_height, |
| 743 | p->stepwise.step_width, p->stepwise.step_height, |
| 744 | p->stepwise.max_width, p->stepwise.max_height); |
| 745 | break; |
| 746 | case V4L2_FRMSIZE_TYPE_CONTINUOUS: |
| 747 | /* fall through */ |
| 748 | default: |
| 749 | pr_cont("\n"); |
| 750 | break; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | static void v4l_print_frmivalenum(const void *arg, bool write_only) |
| 755 | { |
| 756 | const struct v4l2_frmivalenum *p = arg; |
| 757 | |
| 758 | pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u", |
| 759 | p->index, |
| 760 | (p->pixel_format & 0xff), |
| 761 | (p->pixel_format >> 8) & 0xff, |
| 762 | (p->pixel_format >> 16) & 0xff, |
| 763 | (p->pixel_format >> 24) & 0xff, |
| 764 | p->width, p->height, p->type); |
| 765 | switch (p->type) { |
| 766 | case V4L2_FRMIVAL_TYPE_DISCRETE: |
| 767 | pr_cont(" fps=%d/%d\n", |
| 768 | p->discrete.numerator, |
| 769 | p->discrete.denominator); |
| 770 | break; |
| 771 | case V4L2_FRMIVAL_TYPE_STEPWISE: |
| 772 | pr_cont(" min=%d/%d, max=%d/%d, step=%d/%d\n", |
| 773 | p->stepwise.min.numerator, |
| 774 | p->stepwise.min.denominator, |
| 775 | p->stepwise.max.numerator, |
| 776 | p->stepwise.max.denominator, |
| 777 | p->stepwise.step.numerator, |
| 778 | p->stepwise.step.denominator); |
| 779 | break; |
| 780 | case V4L2_FRMIVAL_TYPE_CONTINUOUS: |
| 781 | /* fall through */ |
| 782 | default: |
| 783 | pr_cont("\n"); |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | static void v4l_print_event(const void *arg, bool write_only) |
| 789 | { |
| 790 | const struct v4l2_event *p = arg; |
| 791 | const struct v4l2_event_ctrl *c; |
| 792 | |
| 793 | pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, " |
| 794 | "timestamp=%lu.%9.9lu\n", |
| 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); |
| 810 | pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d," |
| 811 | " default_value=%d\n", |
| 812 | c->flags, c->minimum, c->maximum, |
| 813 | c->step, c->default_value); |
| 814 | break; |
| 815 | case V4L2_EVENT_FRAME_SYNC: |
| 816 | pr_cont("frame_sequence=%u\n", |
| 817 | p->u.frame_sync.frame_sequence); |
| 818 | break; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | static void v4l_print_event_subscription(const void *arg, bool write_only) |
| 823 | { |
| 824 | const struct v4l2_event_subscription *p = arg; |
| 825 | |
| 826 | pr_cont("type=0x%x, id=0x%x, flags=0x%x\n", |
| 827 | p->type, p->id, p->flags); |
| 828 | } |
| 829 | |
| 830 | static void v4l_print_sliced_vbi_cap(const void *arg, bool write_only) |
| 831 | { |
| 832 | const struct v4l2_sliced_vbi_cap *p = arg; |
| 833 | int i; |
| 834 | |
| 835 | pr_cont("type=%s, service_set=0x%08x\n", |
| 836 | prt_names(p->type, v4l2_type_names), p->service_set); |
| 837 | for (i = 0; i < 24; i++) |
| 838 | printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i, |
| 839 | p->service_lines[0][i], |
| 840 | p->service_lines[1][i]); |
| 841 | } |
| 842 | |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 843 | static void v4l_print_freq_band(const void *arg, bool write_only) |
| 844 | { |
| 845 | const struct v4l2_frequency_band *p = arg; |
| 846 | |
| 847 | pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, " |
| 848 | "rangelow=%u, rangehigh=%u, modulation=0x%x\n", |
| 849 | p->tuner, p->type, p->index, |
| 850 | p->capability, p->rangelow, |
| 851 | p->rangehigh, p->modulation); |
| 852 | } |
| 853 | |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 854 | static void v4l_print_u32(const void *arg, bool write_only) |
| 855 | { |
| 856 | pr_cont("value=%u\n", *(const u32 *)arg); |
| 857 | } |
| 858 | |
| 859 | static void v4l_print_newline(const void *arg, bool write_only) |
| 860 | { |
| 861 | pr_cont("\n"); |
| 862 | } |
| 863 | |
Hans Verkuil | f18d8e0 | 2012-06-22 06:35:01 -0300 | [diff] [blame] | 864 | static void v4l_print_default(const void *arg, bool write_only) |
| 865 | { |
| 866 | pr_cont("driver-specific ioctl\n"); |
| 867 | } |
| 868 | |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 869 | static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 870 | { |
| 871 | __u32 i; |
| 872 | |
| 873 | /* zero the reserved fields */ |
| 874 | c->reserved[0] = c->reserved[1] = 0; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 875 | for (i = 0; i < c->count; i++) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 876 | c->controls[i].reserved2[0] = 0; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 877 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 878 | /* V4L2_CID_PRIVATE_BASE cannot be used as control class |
| 879 | when using extended controls. |
| 880 | Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL |
| 881 | is it allowed for backwards compatibility. |
| 882 | */ |
| 883 | if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE) |
| 884 | return 0; |
| 885 | /* Check that all controls are from the same control class. */ |
| 886 | for (i = 0; i < c->count; i++) { |
| 887 | if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) { |
| 888 | c->error_idx = i; |
| 889 | return 0; |
| 890 | } |
| 891 | } |
| 892 | return 1; |
| 893 | } |
| 894 | |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 895 | static int check_fmt(struct file *file, enum v4l2_buf_type type) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 896 | { |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 897 | struct video_device *vfd = video_devdata(file); |
| 898 | const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; |
| 899 | bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER; |
| 900 | bool is_vbi = vfd->vfl_type == VFL_TYPE_VBI; |
| 901 | bool is_rx = vfd->vfl_dir != VFL_DIR_TX; |
| 902 | bool is_tx = vfd->vfl_dir != VFL_DIR_RX; |
| 903 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 904 | if (ops == NULL) |
| 905 | return -EINVAL; |
| 906 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 907 | switch (type) { |
| 908 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 909 | if (is_vid && is_rx && |
| 910 | (ops->vidioc_g_fmt_vid_cap || ops->vidioc_g_fmt_vid_cap_mplane)) |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 911 | return 0; |
| 912 | break; |
| 913 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 914 | if (is_vid && is_rx && ops->vidioc_g_fmt_vid_cap_mplane) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 915 | return 0; |
| 916 | break; |
| 917 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 918 | if (is_vid && is_rx && ops->vidioc_g_fmt_vid_overlay) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 919 | return 0; |
| 920 | break; |
| 921 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 922 | if (is_vid && is_tx && |
| 923 | (ops->vidioc_g_fmt_vid_out || ops->vidioc_g_fmt_vid_out_mplane)) |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 924 | return 0; |
| 925 | break; |
| 926 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 927 | if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_mplane) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 928 | return 0; |
| 929 | break; |
| 930 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 931 | if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_overlay) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 932 | return 0; |
| 933 | break; |
| 934 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 935 | if (is_vbi && is_rx && ops->vidioc_g_fmt_vbi_cap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 936 | return 0; |
| 937 | break; |
| 938 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 939 | if (is_vbi && is_tx && ops->vidioc_g_fmt_vbi_out) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 940 | return 0; |
| 941 | break; |
| 942 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 943 | if (is_vbi && is_rx && ops->vidioc_g_fmt_sliced_vbi_cap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 944 | return 0; |
| 945 | break; |
| 946 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 947 | if (is_vbi && is_tx && ops->vidioc_g_fmt_sliced_vbi_out) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 948 | return 0; |
| 949 | break; |
Hans Verkuil | 633c98e | 2012-09-17 05:02:26 -0300 | [diff] [blame] | 950 | default: |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 951 | break; |
| 952 | } |
| 953 | return -EINVAL; |
| 954 | } |
| 955 | |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 956 | static int v4l_querycap(const struct v4l2_ioctl_ops *ops, |
| 957 | struct file *file, void *fh, void *arg) |
| 958 | { |
| 959 | struct v4l2_capability *cap = (struct v4l2_capability *)arg; |
| 960 | |
| 961 | cap->version = LINUX_VERSION_CODE; |
| 962 | return ops->vidioc_querycap(file, fh, cap); |
| 963 | } |
| 964 | |
| 965 | static int v4l_s_input(const struct v4l2_ioctl_ops *ops, |
| 966 | struct file *file, void *fh, void *arg) |
| 967 | { |
| 968 | return ops->vidioc_s_input(file, fh, *(unsigned int *)arg); |
| 969 | } |
| 970 | |
| 971 | static int v4l_s_output(const struct v4l2_ioctl_ops *ops, |
| 972 | struct file *file, void *fh, void *arg) |
| 973 | { |
| 974 | return ops->vidioc_s_output(file, fh, *(unsigned int *)arg); |
| 975 | } |
| 976 | |
Hans Verkuil | d0547cb | 2012-06-09 09:27:10 -0300 | [diff] [blame] | 977 | static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, |
| 978 | struct file *file, void *fh, void *arg) |
| 979 | { |
| 980 | struct video_device *vfd; |
| 981 | u32 *p = arg; |
| 982 | |
| 983 | if (ops->vidioc_g_priority) |
| 984 | return ops->vidioc_g_priority(file, fh, arg); |
| 985 | vfd = video_devdata(file); |
| 986 | *p = v4l2_prio_max(&vfd->v4l2_dev->prio); |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, |
| 991 | struct file *file, void *fh, void *arg) |
| 992 | { |
| 993 | struct video_device *vfd; |
| 994 | struct v4l2_fh *vfh; |
| 995 | u32 *p = arg; |
| 996 | |
| 997 | if (ops->vidioc_s_priority) |
| 998 | return ops->vidioc_s_priority(file, fh, *p); |
| 999 | vfd = video_devdata(file); |
| 1000 | vfh = file->private_data; |
| 1001 | return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p); |
| 1002 | } |
| 1003 | |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1004 | static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, |
| 1005 | struct file *file, void *fh, void *arg) |
| 1006 | { |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1007 | struct video_device *vfd = video_devdata(file); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1008 | struct v4l2_input *p = arg; |
| 1009 | |
| 1010 | /* |
Hans Verkuil | 02fa628 | 2013-02-15 15:21:06 -0300 | [diff] [blame] | 1011 | * We set the flags for CAP_DV_TIMINGS & |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1012 | * CAP_STD here based on ioctl handler provided by the |
| 1013 | * driver. If the driver doesn't support these |
| 1014 | * for a specific input, it must override these flags. |
| 1015 | */ |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1016 | if (is_valid_ioctl(vfd, VIDIOC_S_STD)) |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1017 | p->capabilities |= V4L2_IN_CAP_STD; |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1018 | |
| 1019 | return ops->vidioc_enum_input(file, fh, p); |
| 1020 | } |
| 1021 | |
| 1022 | static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, |
| 1023 | struct file *file, void *fh, void *arg) |
| 1024 | { |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1025 | struct video_device *vfd = video_devdata(file); |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1026 | struct v4l2_output *p = arg; |
| 1027 | |
| 1028 | /* |
Hans Verkuil | 02fa628 | 2013-02-15 15:21:06 -0300 | [diff] [blame] | 1029 | * We set the flags for CAP_DV_TIMINGS & |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1030 | * CAP_STD here based on ioctl handler provided by the |
| 1031 | * driver. If the driver doesn't support these |
| 1032 | * for a specific output, it must override these flags. |
| 1033 | */ |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1034 | if (is_valid_ioctl(vfd, VIDIOC_S_STD)) |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1035 | p->capabilities |= V4L2_OUT_CAP_STD; |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 1036 | |
| 1037 | return ops->vidioc_enum_output(file, fh, p); |
| 1038 | } |
| 1039 | |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1040 | static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, |
| 1041 | struct file *file, void *fh, void *arg) |
| 1042 | { |
| 1043 | struct v4l2_fmtdesc *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1044 | struct video_device *vfd = video_devdata(file); |
| 1045 | bool is_rx = vfd->vfl_dir != VFL_DIR_TX; |
| 1046 | bool is_tx = vfd->vfl_dir != VFL_DIR_RX; |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1047 | |
| 1048 | switch (p->type) { |
| 1049 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1050 | if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_cap)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1051 | break; |
| 1052 | return ops->vidioc_enum_fmt_vid_cap(file, fh, arg); |
| 1053 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1054 | if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_cap_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1055 | break; |
| 1056 | return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg); |
| 1057 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1058 | if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1059 | break; |
| 1060 | return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg); |
| 1061 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1062 | if (unlikely(!is_tx || !ops->vidioc_enum_fmt_vid_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1063 | break; |
| 1064 | return ops->vidioc_enum_fmt_vid_out(file, fh, arg); |
| 1065 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1066 | if (unlikely(!is_tx || !ops->vidioc_enum_fmt_vid_out_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1067 | break; |
| 1068 | return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1069 | } |
| 1070 | return -EINVAL; |
| 1071 | } |
| 1072 | |
| 1073 | static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, |
| 1074 | struct file *file, void *fh, void *arg) |
| 1075 | { |
| 1076 | struct v4l2_format *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1077 | struct video_device *vfd = video_devdata(file); |
| 1078 | bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER; |
| 1079 | bool is_rx = vfd->vfl_dir != VFL_DIR_TX; |
| 1080 | bool is_tx = vfd->vfl_dir != VFL_DIR_RX; |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1081 | |
| 1082 | switch (p->type) { |
| 1083 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1084 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1085 | break; |
| 1086 | return ops->vidioc_g_fmt_vid_cap(file, fh, arg); |
| 1087 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1088 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1089 | break; |
| 1090 | return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg); |
| 1091 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1092 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1093 | break; |
| 1094 | return ops->vidioc_g_fmt_vid_overlay(file, fh, arg); |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1095 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 1096 | if (unlikely(!is_rx || is_vid || !ops->vidioc_g_fmt_vbi_cap)) |
| 1097 | break; |
| 1098 | return ops->vidioc_g_fmt_vbi_cap(file, fh, arg); |
| 1099 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 1100 | if (unlikely(!is_rx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_cap)) |
| 1101 | break; |
| 1102 | return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1103 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1104 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1105 | break; |
| 1106 | return ops->vidioc_g_fmt_vid_out(file, fh, arg); |
| 1107 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1108 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1109 | break; |
| 1110 | return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg); |
| 1111 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1112 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1113 | break; |
| 1114 | return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1115 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1116 | if (unlikely(!is_tx || is_vid || !ops->vidioc_g_fmt_vbi_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1117 | break; |
| 1118 | return ops->vidioc_g_fmt_vbi_out(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1119 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1120 | if (unlikely(!is_tx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1121 | break; |
| 1122 | return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1123 | } |
| 1124 | return -EINVAL; |
| 1125 | } |
| 1126 | |
| 1127 | static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, |
| 1128 | struct file *file, void *fh, void *arg) |
| 1129 | { |
| 1130 | struct v4l2_format *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1131 | struct video_device *vfd = video_devdata(file); |
| 1132 | bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER; |
| 1133 | bool is_rx = vfd->vfl_dir != VFL_DIR_TX; |
| 1134 | bool is_tx = vfd->vfl_dir != VFL_DIR_RX; |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1135 | |
| 1136 | switch (p->type) { |
| 1137 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1138 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1139 | break; |
| 1140 | CLEAR_AFTER_FIELD(p, fmt.pix); |
| 1141 | return ops->vidioc_s_fmt_vid_cap(file, fh, arg); |
| 1142 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1143 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1144 | break; |
| 1145 | CLEAR_AFTER_FIELD(p, fmt.pix_mp); |
| 1146 | return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg); |
| 1147 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1148 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1149 | break; |
| 1150 | CLEAR_AFTER_FIELD(p, fmt.win); |
| 1151 | return ops->vidioc_s_fmt_vid_overlay(file, fh, arg); |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1152 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 1153 | if (unlikely(!is_rx || is_vid || !ops->vidioc_s_fmt_vbi_cap)) |
| 1154 | break; |
| 1155 | CLEAR_AFTER_FIELD(p, fmt.vbi); |
| 1156 | return ops->vidioc_s_fmt_vbi_cap(file, fh, arg); |
| 1157 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 1158 | if (unlikely(!is_rx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_cap)) |
| 1159 | break; |
| 1160 | CLEAR_AFTER_FIELD(p, fmt.sliced); |
| 1161 | return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1162 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1163 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1164 | break; |
| 1165 | CLEAR_AFTER_FIELD(p, fmt.pix); |
| 1166 | return ops->vidioc_s_fmt_vid_out(file, fh, arg); |
| 1167 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1168 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1169 | break; |
| 1170 | CLEAR_AFTER_FIELD(p, fmt.pix_mp); |
| 1171 | return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg); |
| 1172 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1173 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1174 | break; |
| 1175 | CLEAR_AFTER_FIELD(p, fmt.win); |
| 1176 | return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1177 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1178 | if (unlikely(!is_tx || is_vid || !ops->vidioc_s_fmt_vbi_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1179 | break; |
| 1180 | CLEAR_AFTER_FIELD(p, fmt.vbi); |
| 1181 | return ops->vidioc_s_fmt_vbi_out(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1182 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1183 | if (unlikely(!is_tx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1184 | break; |
| 1185 | CLEAR_AFTER_FIELD(p, fmt.sliced); |
| 1186 | return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1187 | } |
| 1188 | return -EINVAL; |
| 1189 | } |
| 1190 | |
| 1191 | static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, |
| 1192 | struct file *file, void *fh, void *arg) |
| 1193 | { |
| 1194 | struct v4l2_format *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1195 | struct video_device *vfd = video_devdata(file); |
| 1196 | bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER; |
| 1197 | bool is_rx = vfd->vfl_dir != VFL_DIR_TX; |
| 1198 | bool is_tx = vfd->vfl_dir != VFL_DIR_RX; |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1199 | |
| 1200 | switch (p->type) { |
| 1201 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1202 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1203 | break; |
| 1204 | CLEAR_AFTER_FIELD(p, fmt.pix); |
| 1205 | return ops->vidioc_try_fmt_vid_cap(file, fh, arg); |
| 1206 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1207 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1208 | break; |
| 1209 | CLEAR_AFTER_FIELD(p, fmt.pix_mp); |
| 1210 | return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg); |
| 1211 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1212 | if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1213 | break; |
| 1214 | CLEAR_AFTER_FIELD(p, fmt.win); |
| 1215 | return ops->vidioc_try_fmt_vid_overlay(file, fh, arg); |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1216 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 1217 | if (unlikely(!is_rx || is_vid || !ops->vidioc_try_fmt_vbi_cap)) |
| 1218 | break; |
| 1219 | CLEAR_AFTER_FIELD(p, fmt.vbi); |
| 1220 | return ops->vidioc_try_fmt_vbi_cap(file, fh, arg); |
| 1221 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 1222 | if (unlikely(!is_rx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_cap)) |
| 1223 | break; |
| 1224 | CLEAR_AFTER_FIELD(p, fmt.sliced); |
| 1225 | return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1226 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1227 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1228 | break; |
| 1229 | CLEAR_AFTER_FIELD(p, fmt.pix); |
| 1230 | return ops->vidioc_try_fmt_vid_out(file, fh, arg); |
| 1231 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1232 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_mplane)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1233 | break; |
| 1234 | CLEAR_AFTER_FIELD(p, fmt.pix_mp); |
| 1235 | return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg); |
| 1236 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1237 | if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_overlay)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1238 | break; |
| 1239 | CLEAR_AFTER_FIELD(p, fmt.win); |
| 1240 | return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1241 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1242 | if (unlikely(!is_tx || is_vid || !ops->vidioc_try_fmt_vbi_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1243 | break; |
| 1244 | CLEAR_AFTER_FIELD(p, fmt.vbi); |
| 1245 | return ops->vidioc_try_fmt_vbi_out(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1246 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1247 | if (unlikely(!is_tx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_out)) |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1248 | break; |
| 1249 | CLEAR_AFTER_FIELD(p, fmt.sliced); |
| 1250 | return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg); |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 1251 | } |
| 1252 | return -EINVAL; |
| 1253 | } |
| 1254 | |
Hans Verkuil | e325b24 | 2012-06-09 12:50:15 -0300 | [diff] [blame] | 1255 | static int v4l_streamon(const struct v4l2_ioctl_ops *ops, |
| 1256 | struct file *file, void *fh, void *arg) |
| 1257 | { |
| 1258 | return ops->vidioc_streamon(file, fh, *(unsigned int *)arg); |
| 1259 | } |
| 1260 | |
| 1261 | static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, |
| 1262 | struct file *file, void *fh, void *arg) |
| 1263 | { |
| 1264 | return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg); |
| 1265 | } |
| 1266 | |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1267 | static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, |
| 1268 | struct file *file, void *fh, void *arg) |
| 1269 | { |
| 1270 | struct video_device *vfd = video_devdata(file); |
| 1271 | struct v4l2_tuner *p = arg; |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1272 | int err; |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1273 | |
| 1274 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
| 1275 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1276 | err = ops->vidioc_g_tuner(file, fh, p); |
| 1277 | if (!err) |
| 1278 | p->capability |= V4L2_TUNER_CAP_FREQ_BANDS; |
| 1279 | return err; |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, |
| 1283 | struct file *file, void *fh, void *arg) |
| 1284 | { |
| 1285 | struct video_device *vfd = video_devdata(file); |
| 1286 | struct v4l2_tuner *p = arg; |
| 1287 | |
| 1288 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
| 1289 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1290 | return ops->vidioc_s_tuner(file, fh, p); |
| 1291 | } |
| 1292 | |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1293 | static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops, |
| 1294 | struct file *file, void *fh, void *arg) |
| 1295 | { |
| 1296 | struct v4l2_modulator *p = arg; |
| 1297 | int err; |
| 1298 | |
| 1299 | err = ops->vidioc_g_modulator(file, fh, p); |
| 1300 | if (!err) |
| 1301 | p->capability |= V4L2_TUNER_CAP_FREQ_BANDS; |
| 1302 | return err; |
| 1303 | } |
| 1304 | |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1305 | static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops, |
| 1306 | struct file *file, void *fh, void *arg) |
| 1307 | { |
| 1308 | struct video_device *vfd = video_devdata(file); |
| 1309 | struct v4l2_frequency *p = arg; |
| 1310 | |
| 1311 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
| 1312 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1313 | return ops->vidioc_g_frequency(file, fh, p); |
| 1314 | } |
| 1315 | |
| 1316 | static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops, |
| 1317 | struct file *file, void *fh, void *arg) |
| 1318 | { |
| 1319 | struct video_device *vfd = video_devdata(file); |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 1320 | const struct v4l2_frequency *p = arg; |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1321 | enum v4l2_tuner_type type; |
| 1322 | |
| 1323 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
| 1324 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1325 | if (p->type != type) |
| 1326 | return -EINVAL; |
| 1327 | return ops->vidioc_s_frequency(file, fh, p); |
| 1328 | } |
| 1329 | |
| 1330 | static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, |
| 1331 | struct file *file, void *fh, void *arg) |
| 1332 | { |
| 1333 | struct video_device *vfd = video_devdata(file); |
| 1334 | struct v4l2_standard *p = arg; |
| 1335 | v4l2_std_id id = vfd->tvnorms, curr_id = 0; |
| 1336 | unsigned int index = p->index, i, j = 0; |
| 1337 | const char *descr = ""; |
| 1338 | |
Hans Verkuil | a533819 | 2012-09-14 06:45:43 -0300 | [diff] [blame] | 1339 | /* Return -ENODATA if the tvnorms for the current input |
| 1340 | or output is 0, meaning that it doesn't support this API. */ |
| 1341 | if (id == 0) |
| 1342 | return -ENODATA; |
| 1343 | |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1344 | /* Return norm array in a canonical way */ |
| 1345 | for (i = 0; i <= index && id; i++) { |
| 1346 | /* last std value in the standards array is 0, so this |
| 1347 | while always ends there since (id & 0) == 0. */ |
| 1348 | while ((id & standards[j].std) != standards[j].std) |
| 1349 | j++; |
| 1350 | curr_id = standards[j].std; |
| 1351 | descr = standards[j].descr; |
| 1352 | j++; |
| 1353 | if (curr_id == 0) |
| 1354 | break; |
| 1355 | if (curr_id != V4L2_STD_PAL && |
| 1356 | curr_id != V4L2_STD_SECAM && |
| 1357 | curr_id != V4L2_STD_NTSC) |
| 1358 | id &= ~curr_id; |
| 1359 | } |
| 1360 | if (i <= index) |
| 1361 | return -EINVAL; |
| 1362 | |
| 1363 | v4l2_video_std_construct(p, curr_id, descr); |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
| 1367 | static int v4l_g_std(const struct v4l2_ioctl_ops *ops, |
| 1368 | struct file *file, void *fh, void *arg) |
| 1369 | { |
| 1370 | struct video_device *vfd = video_devdata(file); |
| 1371 | v4l2_std_id *id = arg; |
| 1372 | |
| 1373 | /* Calls the specific handler */ |
| 1374 | if (ops->vidioc_g_std) |
| 1375 | return ops->vidioc_g_std(file, fh, arg); |
| 1376 | if (vfd->current_norm) { |
| 1377 | *id = vfd->current_norm; |
| 1378 | return 0; |
| 1379 | } |
| 1380 | return -ENOTTY; |
| 1381 | } |
| 1382 | |
| 1383 | static int v4l_s_std(const struct v4l2_ioctl_ops *ops, |
| 1384 | struct file *file, void *fh, void *arg) |
| 1385 | { |
| 1386 | struct video_device *vfd = video_devdata(file); |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1387 | v4l2_std_id id = *(v4l2_std_id *)arg, norm; |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1388 | int ret; |
| 1389 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1390 | norm = id & vfd->tvnorms; |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1391 | if (vfd->tvnorms && !norm) /* Check if std is supported */ |
| 1392 | return -EINVAL; |
| 1393 | |
| 1394 | /* Calls the specific handler */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1395 | ret = ops->vidioc_s_std(file, fh, norm); |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 1396 | |
| 1397 | /* Updates standard information */ |
| 1398 | if (ret >= 0) |
| 1399 | vfd->current_norm = norm; |
| 1400 | return ret; |
| 1401 | } |
| 1402 | |
| 1403 | static int v4l_querystd(const struct v4l2_ioctl_ops *ops, |
| 1404 | struct file *file, void *fh, void *arg) |
| 1405 | { |
| 1406 | struct video_device *vfd = video_devdata(file); |
| 1407 | v4l2_std_id *p = arg; |
| 1408 | |
| 1409 | /* |
| 1410 | * If nothing detected, it should return all supported |
| 1411 | * standard. |
| 1412 | * Drivers just need to mask the std argument, in order |
| 1413 | * to remove the standards that don't apply from the mask. |
| 1414 | * This means that tuners, audio and video decoders can join |
| 1415 | * their efforts to improve the standards detection. |
| 1416 | */ |
| 1417 | *p = vfd->tvnorms; |
| 1418 | return ops->vidioc_querystd(file, fh, arg); |
| 1419 | } |
| 1420 | |
| 1421 | static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops, |
| 1422 | struct file *file, void *fh, void *arg) |
| 1423 | { |
| 1424 | struct video_device *vfd = video_devdata(file); |
| 1425 | struct v4l2_hw_freq_seek *p = arg; |
| 1426 | enum v4l2_tuner_type type; |
| 1427 | |
| 1428 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
| 1429 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1430 | if (p->type != type) |
| 1431 | return -EINVAL; |
| 1432 | return ops->vidioc_s_hw_freq_seek(file, fh, p); |
| 1433 | } |
| 1434 | |
Hans Verkuil | 737c097 | 2012-09-04 10:08:01 -0300 | [diff] [blame] | 1435 | static int v4l_overlay(const struct v4l2_ioctl_ops *ops, |
| 1436 | struct file *file, void *fh, void *arg) |
| 1437 | { |
| 1438 | return ops->vidioc_overlay(file, fh, *(unsigned int *)arg); |
| 1439 | } |
| 1440 | |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1441 | static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, |
| 1442 | struct file *file, void *fh, void *arg) |
| 1443 | { |
| 1444 | struct v4l2_requestbuffers *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1445 | int ret = check_fmt(file, p->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1446 | |
| 1447 | if (ret) |
| 1448 | return ret; |
| 1449 | |
Hans Verkuil | 633c98e | 2012-09-17 05:02:26 -0300 | [diff] [blame] | 1450 | CLEAR_AFTER_FIELD(p, memory); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1451 | |
| 1452 | return ops->vidioc_reqbufs(file, fh, p); |
| 1453 | } |
| 1454 | |
| 1455 | static int v4l_querybuf(const struct v4l2_ioctl_ops *ops, |
| 1456 | struct file *file, void *fh, void *arg) |
| 1457 | { |
| 1458 | struct v4l2_buffer *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1459 | int ret = check_fmt(file, p->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1460 | |
| 1461 | return ret ? ret : ops->vidioc_querybuf(file, fh, p); |
| 1462 | } |
| 1463 | |
| 1464 | static int v4l_qbuf(const struct v4l2_ioctl_ops *ops, |
| 1465 | struct file *file, void *fh, void *arg) |
| 1466 | { |
| 1467 | struct v4l2_buffer *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1468 | int ret = check_fmt(file, p->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1469 | |
| 1470 | return ret ? ret : ops->vidioc_qbuf(file, fh, p); |
| 1471 | } |
| 1472 | |
| 1473 | static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, |
| 1474 | struct file *file, void *fh, void *arg) |
| 1475 | { |
| 1476 | struct v4l2_buffer *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1477 | int ret = check_fmt(file, p->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1478 | |
| 1479 | return ret ? ret : ops->vidioc_dqbuf(file, fh, p); |
| 1480 | } |
| 1481 | |
| 1482 | static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, |
| 1483 | struct file *file, void *fh, void *arg) |
| 1484 | { |
| 1485 | struct v4l2_create_buffers *create = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1486 | int ret = check_fmt(file, create->format.type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1487 | |
| 1488 | return ret ? ret : ops->vidioc_create_bufs(file, fh, create); |
| 1489 | } |
| 1490 | |
| 1491 | static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, |
| 1492 | struct file *file, void *fh, void *arg) |
| 1493 | { |
| 1494 | struct v4l2_buffer *b = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1495 | int ret = check_fmt(file, b->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1496 | |
| 1497 | return ret ? ret : ops->vidioc_prepare_buf(file, fh, b); |
| 1498 | } |
| 1499 | |
| 1500 | static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, |
| 1501 | struct file *file, void *fh, void *arg) |
| 1502 | { |
| 1503 | struct video_device *vfd = video_devdata(file); |
| 1504 | struct v4l2_streamparm *p = arg; |
| 1505 | v4l2_std_id std; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1506 | int ret = check_fmt(file, p->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1507 | |
| 1508 | if (ret) |
| 1509 | return ret; |
| 1510 | if (ops->vidioc_g_parm) |
| 1511 | return ops->vidioc_g_parm(file, fh, p); |
| 1512 | std = vfd->current_norm; |
| 1513 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 1514 | p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 1515 | return -EINVAL; |
| 1516 | p->parm.capture.readbuffers = 2; |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1517 | if (is_valid_ioctl(vfd, VIDIOC_G_STD) && ops->vidioc_g_std) |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1518 | ret = ops->vidioc_g_std(file, fh, &std); |
| 1519 | if (ret == 0) |
| 1520 | v4l2_video_std_frame_period(std, |
| 1521 | &p->parm.capture.timeperframe); |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
| 1525 | static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, |
| 1526 | struct file *file, void *fh, void *arg) |
| 1527 | { |
| 1528 | struct v4l2_streamparm *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1529 | int ret = check_fmt(file, p->type); |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 1530 | |
| 1531 | return ret ? ret : ops->vidioc_s_parm(file, fh, p); |
| 1532 | } |
| 1533 | |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1534 | static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, |
| 1535 | struct file *file, void *fh, void *arg) |
| 1536 | { |
| 1537 | struct video_device *vfd = video_devdata(file); |
| 1538 | struct v4l2_queryctrl *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1539 | struct v4l2_fh *vfh = |
| 1540 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1541 | |
| 1542 | if (vfh && vfh->ctrl_handler) |
| 1543 | return v4l2_queryctrl(vfh->ctrl_handler, p); |
| 1544 | if (vfd->ctrl_handler) |
| 1545 | return v4l2_queryctrl(vfd->ctrl_handler, p); |
| 1546 | if (ops->vidioc_queryctrl) |
| 1547 | return ops->vidioc_queryctrl(file, fh, p); |
| 1548 | return -ENOTTY; |
| 1549 | } |
| 1550 | |
| 1551 | static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, |
| 1552 | struct file *file, void *fh, void *arg) |
| 1553 | { |
| 1554 | struct video_device *vfd = video_devdata(file); |
| 1555 | struct v4l2_querymenu *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1556 | struct v4l2_fh *vfh = |
| 1557 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1558 | |
| 1559 | if (vfh && vfh->ctrl_handler) |
| 1560 | return v4l2_querymenu(vfh->ctrl_handler, p); |
| 1561 | if (vfd->ctrl_handler) |
| 1562 | return v4l2_querymenu(vfd->ctrl_handler, p); |
| 1563 | if (ops->vidioc_querymenu) |
| 1564 | return ops->vidioc_querymenu(file, fh, p); |
| 1565 | return -ENOTTY; |
| 1566 | } |
| 1567 | |
| 1568 | static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, |
| 1569 | struct file *file, void *fh, void *arg) |
| 1570 | { |
| 1571 | struct video_device *vfd = video_devdata(file); |
| 1572 | struct v4l2_control *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1573 | struct v4l2_fh *vfh = |
| 1574 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1575 | struct v4l2_ext_controls ctrls; |
| 1576 | struct v4l2_ext_control ctrl; |
| 1577 | |
| 1578 | if (vfh && vfh->ctrl_handler) |
| 1579 | return v4l2_g_ctrl(vfh->ctrl_handler, p); |
| 1580 | if (vfd->ctrl_handler) |
| 1581 | return v4l2_g_ctrl(vfd->ctrl_handler, p); |
| 1582 | if (ops->vidioc_g_ctrl) |
| 1583 | return ops->vidioc_g_ctrl(file, fh, p); |
| 1584 | if (ops->vidioc_g_ext_ctrls == NULL) |
| 1585 | return -ENOTTY; |
| 1586 | |
| 1587 | ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id); |
| 1588 | ctrls.count = 1; |
| 1589 | ctrls.controls = &ctrl; |
| 1590 | ctrl.id = p->id; |
| 1591 | ctrl.value = p->value; |
| 1592 | if (check_ext_ctrls(&ctrls, 1)) { |
| 1593 | int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); |
| 1594 | |
| 1595 | if (ret == 0) |
| 1596 | p->value = ctrl.value; |
| 1597 | return ret; |
| 1598 | } |
| 1599 | return -EINVAL; |
| 1600 | } |
| 1601 | |
| 1602 | static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, |
| 1603 | struct file *file, void *fh, void *arg) |
| 1604 | { |
| 1605 | struct video_device *vfd = video_devdata(file); |
| 1606 | struct v4l2_control *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1607 | struct v4l2_fh *vfh = |
| 1608 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1609 | struct v4l2_ext_controls ctrls; |
| 1610 | struct v4l2_ext_control ctrl; |
| 1611 | |
| 1612 | if (vfh && vfh->ctrl_handler) |
| 1613 | return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p); |
| 1614 | if (vfd->ctrl_handler) |
| 1615 | return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p); |
| 1616 | if (ops->vidioc_s_ctrl) |
| 1617 | return ops->vidioc_s_ctrl(file, fh, p); |
| 1618 | if (ops->vidioc_s_ext_ctrls == NULL) |
| 1619 | return -ENOTTY; |
| 1620 | |
| 1621 | ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id); |
| 1622 | ctrls.count = 1; |
| 1623 | ctrls.controls = &ctrl; |
| 1624 | ctrl.id = p->id; |
| 1625 | ctrl.value = p->value; |
| 1626 | if (check_ext_ctrls(&ctrls, 1)) |
| 1627 | return ops->vidioc_s_ext_ctrls(file, fh, &ctrls); |
| 1628 | return -EINVAL; |
| 1629 | } |
| 1630 | |
| 1631 | static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, |
| 1632 | struct file *file, void *fh, void *arg) |
| 1633 | { |
| 1634 | struct video_device *vfd = video_devdata(file); |
| 1635 | struct v4l2_ext_controls *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1636 | struct v4l2_fh *vfh = |
| 1637 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1638 | |
| 1639 | p->error_idx = p->count; |
| 1640 | if (vfh && vfh->ctrl_handler) |
| 1641 | return v4l2_g_ext_ctrls(vfh->ctrl_handler, p); |
| 1642 | if (vfd->ctrl_handler) |
| 1643 | return v4l2_g_ext_ctrls(vfd->ctrl_handler, p); |
| 1644 | if (ops->vidioc_g_ext_ctrls == NULL) |
| 1645 | return -ENOTTY; |
| 1646 | return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) : |
| 1647 | -EINVAL; |
| 1648 | } |
| 1649 | |
| 1650 | static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, |
| 1651 | struct file *file, void *fh, void *arg) |
| 1652 | { |
| 1653 | struct video_device *vfd = video_devdata(file); |
| 1654 | struct v4l2_ext_controls *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1655 | struct v4l2_fh *vfh = |
| 1656 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1657 | |
| 1658 | p->error_idx = p->count; |
| 1659 | if (vfh && vfh->ctrl_handler) |
| 1660 | return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p); |
| 1661 | if (vfd->ctrl_handler) |
| 1662 | return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p); |
| 1663 | if (ops->vidioc_s_ext_ctrls == NULL) |
| 1664 | return -ENOTTY; |
| 1665 | return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) : |
| 1666 | -EINVAL; |
| 1667 | } |
| 1668 | |
| 1669 | static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, |
| 1670 | struct file *file, void *fh, void *arg) |
| 1671 | { |
| 1672 | struct video_device *vfd = video_devdata(file); |
| 1673 | struct v4l2_ext_controls *p = arg; |
Hans Verkuil | 7a3ed2d | 2012-07-07 16:11:11 -0300 | [diff] [blame] | 1674 | struct v4l2_fh *vfh = |
| 1675 | test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 1676 | |
| 1677 | p->error_idx = p->count; |
| 1678 | if (vfh && vfh->ctrl_handler) |
| 1679 | return v4l2_try_ext_ctrls(vfh->ctrl_handler, p); |
| 1680 | if (vfd->ctrl_handler) |
| 1681 | return v4l2_try_ext_ctrls(vfd->ctrl_handler, p); |
| 1682 | if (ops->vidioc_try_ext_ctrls == NULL) |
| 1683 | return -ENOTTY; |
| 1684 | return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) : |
| 1685 | -EINVAL; |
| 1686 | } |
| 1687 | |
Hans Verkuil | d84f2d94 | 2012-06-09 11:57:46 -0300 | [diff] [blame] | 1688 | static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, |
| 1689 | struct file *file, void *fh, void *arg) |
| 1690 | { |
| 1691 | struct v4l2_crop *p = arg; |
| 1692 | struct v4l2_selection s = { |
| 1693 | .type = p->type, |
| 1694 | }; |
| 1695 | int ret; |
| 1696 | |
| 1697 | if (ops->vidioc_g_crop) |
| 1698 | return ops->vidioc_g_crop(file, fh, p); |
| 1699 | /* simulate capture crop using selection api */ |
| 1700 | |
| 1701 | /* crop means compose for output devices */ |
| 1702 | if (V4L2_TYPE_IS_OUTPUT(p->type)) |
| 1703 | s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE; |
| 1704 | else |
| 1705 | s.target = V4L2_SEL_TGT_CROP_ACTIVE; |
| 1706 | |
| 1707 | ret = ops->vidioc_g_selection(file, fh, &s); |
| 1708 | |
| 1709 | /* copying results to old structure on success */ |
| 1710 | if (!ret) |
| 1711 | p->c = s.r; |
| 1712 | return ret; |
| 1713 | } |
| 1714 | |
| 1715 | static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, |
| 1716 | struct file *file, void *fh, void *arg) |
| 1717 | { |
| 1718 | struct v4l2_crop *p = arg; |
| 1719 | struct v4l2_selection s = { |
| 1720 | .type = p->type, |
| 1721 | .r = p->c, |
| 1722 | }; |
| 1723 | |
| 1724 | if (ops->vidioc_s_crop) |
| 1725 | return ops->vidioc_s_crop(file, fh, p); |
| 1726 | /* simulate capture crop using selection api */ |
| 1727 | |
| 1728 | /* crop means compose for output devices */ |
| 1729 | if (V4L2_TYPE_IS_OUTPUT(p->type)) |
| 1730 | s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE; |
| 1731 | else |
| 1732 | s.target = V4L2_SEL_TGT_CROP_ACTIVE; |
| 1733 | |
| 1734 | return ops->vidioc_s_selection(file, fh, &s); |
| 1735 | } |
| 1736 | |
| 1737 | static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, |
| 1738 | struct file *file, void *fh, void *arg) |
| 1739 | { |
| 1740 | struct v4l2_cropcap *p = arg; |
| 1741 | struct v4l2_selection s = { .type = p->type }; |
| 1742 | int ret; |
| 1743 | |
| 1744 | if (ops->vidioc_cropcap) |
| 1745 | return ops->vidioc_cropcap(file, fh, p); |
| 1746 | |
| 1747 | /* obtaining bounds */ |
| 1748 | if (V4L2_TYPE_IS_OUTPUT(p->type)) |
| 1749 | s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS; |
| 1750 | else |
| 1751 | s.target = V4L2_SEL_TGT_CROP_BOUNDS; |
| 1752 | |
| 1753 | ret = ops->vidioc_g_selection(file, fh, &s); |
| 1754 | if (ret) |
| 1755 | return ret; |
| 1756 | p->bounds = s.r; |
| 1757 | |
| 1758 | /* obtaining defrect */ |
| 1759 | if (V4L2_TYPE_IS_OUTPUT(p->type)) |
| 1760 | s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT; |
| 1761 | else |
| 1762 | s.target = V4L2_SEL_TGT_CROP_DEFAULT; |
| 1763 | |
| 1764 | ret = ops->vidioc_g_selection(file, fh, &s); |
| 1765 | if (ret) |
| 1766 | return ret; |
| 1767 | p->defrect = s.r; |
| 1768 | |
| 1769 | /* setting trivial pixelaspect */ |
| 1770 | p->pixelaspect.numerator = 1; |
| 1771 | p->pixelaspect.denominator = 1; |
| 1772 | return 0; |
| 1773 | } |
| 1774 | |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 1775 | static int v4l_log_status(const struct v4l2_ioctl_ops *ops, |
| 1776 | struct file *file, void *fh, void *arg) |
| 1777 | { |
| 1778 | struct video_device *vfd = video_devdata(file); |
| 1779 | int ret; |
| 1780 | |
| 1781 | if (vfd->v4l2_dev) |
| 1782 | pr_info("%s: ================= START STATUS =================\n", |
| 1783 | vfd->v4l2_dev->name); |
| 1784 | ret = ops->vidioc_log_status(file, fh); |
| 1785 | if (vfd->v4l2_dev) |
| 1786 | pr_info("%s: ================== END STATUS ==================\n", |
| 1787 | vfd->v4l2_dev->name); |
| 1788 | return ret; |
| 1789 | } |
| 1790 | |
| 1791 | static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops, |
| 1792 | struct file *file, void *fh, void *arg) |
| 1793 | { |
| 1794 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1795 | struct v4l2_dbg_register *p = arg; |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1796 | struct video_device *vfd = video_devdata(file); |
| 1797 | struct v4l2_subdev *sd; |
| 1798 | int idx = 0; |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 1799 | |
| 1800 | if (!capable(CAP_SYS_ADMIN)) |
| 1801 | return -EPERM; |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1802 | if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) { |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1803 | if (vfd->v4l2_dev == NULL) |
| 1804 | return -EINVAL; |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1805 | v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) |
| 1806 | if (p->match.addr == idx++) |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1807 | return v4l2_subdev_call(sd, core, g_register, p); |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1808 | return -EINVAL; |
| 1809 | } |
| 1810 | if (ops->vidioc_g_register) |
| 1811 | return ops->vidioc_g_register(file, fh, p); |
| 1812 | return -EINVAL; |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 1813 | #else |
| 1814 | return -ENOTTY; |
| 1815 | #endif |
| 1816 | } |
| 1817 | |
| 1818 | static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops, |
| 1819 | struct file *file, void *fh, void *arg) |
| 1820 | { |
| 1821 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1822 | const struct v4l2_dbg_register *p = arg; |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1823 | struct video_device *vfd = video_devdata(file); |
| 1824 | struct v4l2_subdev *sd; |
| 1825 | int idx = 0; |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 1826 | |
| 1827 | if (!capable(CAP_SYS_ADMIN)) |
| 1828 | return -EPERM; |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1829 | if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) { |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1830 | if (vfd->v4l2_dev == NULL) |
| 1831 | return -EINVAL; |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1832 | v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) |
| 1833 | if (p->match.addr == idx++) |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1834 | return v4l2_subdev_call(sd, core, s_register, p); |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1835 | return -EINVAL; |
| 1836 | } |
| 1837 | if (ops->vidioc_s_register) |
| 1838 | return ops->vidioc_s_register(file, fh, p); |
| 1839 | return -EINVAL; |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 1840 | #else |
| 1841 | return -ENOTTY; |
| 1842 | #endif |
| 1843 | } |
| 1844 | |
| 1845 | static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops, |
| 1846 | struct file *file, void *fh, void *arg) |
| 1847 | { |
| 1848 | struct v4l2_dbg_chip_ident *p = arg; |
| 1849 | |
| 1850 | p->ident = V4L2_IDENT_NONE; |
| 1851 | p->revision = 0; |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1852 | if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1853 | return -EINVAL; |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 1854 | return ops->vidioc_g_chip_ident(file, fh, p); |
| 1855 | } |
| 1856 | |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1857 | static int v4l_dbg_g_chip_name(const struct v4l2_ioctl_ops *ops, |
| 1858 | struct file *file, void *fh, void *arg) |
| 1859 | { |
Hans Verkuil | cd634f1 | 2013-03-27 08:04:23 -0300 | [diff] [blame] | 1860 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1861 | struct video_device *vfd = video_devdata(file); |
| 1862 | struct v4l2_dbg_chip_name *p = arg; |
| 1863 | struct v4l2_subdev *sd; |
| 1864 | int idx = 0; |
| 1865 | |
| 1866 | switch (p->match.type) { |
| 1867 | case V4L2_CHIP_MATCH_BRIDGE: |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1868 | if (ops->vidioc_s_register) |
| 1869 | p->flags |= V4L2_CHIP_FL_WRITABLE; |
| 1870 | if (ops->vidioc_g_register) |
| 1871 | p->flags |= V4L2_CHIP_FL_READABLE; |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1872 | if (vfd->v4l2_dev) |
| 1873 | strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name)); |
| 1874 | else if (vfd->parent) |
| 1875 | strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name)); |
| 1876 | else |
| 1877 | strlcpy(p->name, "bridge", sizeof(p->name)); |
Hans Verkuil | 0f0fe4b | 2013-04-06 06:06:13 -0300 | [diff] [blame^] | 1878 | if (ops->vidioc_g_chip_name) |
| 1879 | return ops->vidioc_g_chip_name(file, fh, arg); |
| 1880 | if (p->match.addr) |
| 1881 | return -EINVAL; |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1882 | return 0; |
| 1883 | |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1884 | case V4L2_CHIP_MATCH_SUBDEV: |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1885 | if (vfd->v4l2_dev == NULL) |
| 1886 | break; |
| 1887 | v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) { |
Hans Verkuil | 3eef251 | 2013-04-03 04:08:19 -0300 | [diff] [blame] | 1888 | if (p->match.addr != idx++) |
| 1889 | continue; |
| 1890 | if (sd->ops->core && sd->ops->core->s_register) |
| 1891 | p->flags |= V4L2_CHIP_FL_WRITABLE; |
| 1892 | if (sd->ops->core && sd->ops->core->g_register) |
| 1893 | p->flags |= V4L2_CHIP_FL_READABLE; |
| 1894 | strlcpy(p->name, sd->name, sizeof(p->name)); |
| 1895 | return 0; |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1896 | } |
| 1897 | break; |
| 1898 | } |
| 1899 | return -EINVAL; |
Hans Verkuil | cd634f1 | 2013-03-27 08:04:23 -0300 | [diff] [blame] | 1900 | #else |
| 1901 | return -ENOTTY; |
| 1902 | #endif |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 1903 | } |
| 1904 | |
Hans Verkuil | 458aa4a | 2012-06-09 12:55:52 -0300 | [diff] [blame] | 1905 | static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, |
| 1906 | struct file *file, void *fh, void *arg) |
| 1907 | { |
| 1908 | return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK); |
| 1909 | } |
| 1910 | |
| 1911 | static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops, |
| 1912 | struct file *file, void *fh, void *arg) |
| 1913 | { |
| 1914 | return ops->vidioc_subscribe_event(fh, arg); |
| 1915 | } |
| 1916 | |
| 1917 | static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops, |
| 1918 | struct file *file, void *fh, void *arg) |
| 1919 | { |
| 1920 | return ops->vidioc_unsubscribe_event(fh, arg); |
| 1921 | } |
| 1922 | |
| 1923 | static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops, |
| 1924 | struct file *file, void *fh, void *arg) |
| 1925 | { |
| 1926 | struct v4l2_sliced_vbi_cap *p = arg; |
Hans Verkuil | 4b20259 | 2012-09-14 07:03:35 -0300 | [diff] [blame] | 1927 | int ret = check_fmt(file, p->type); |
| 1928 | |
| 1929 | if (ret) |
| 1930 | return ret; |
Hans Verkuil | 458aa4a | 2012-06-09 12:55:52 -0300 | [diff] [blame] | 1931 | |
| 1932 | /* Clear up to type, everything after type is zeroed already */ |
| 1933 | memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type)); |
| 1934 | |
| 1935 | return ops->vidioc_g_sliced_vbi_cap(file, fh, p); |
| 1936 | } |
| 1937 | |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1938 | static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops, |
| 1939 | struct file *file, void *fh, void *arg) |
| 1940 | { |
| 1941 | struct video_device *vfd = video_devdata(file); |
| 1942 | struct v4l2_frequency_band *p = arg; |
| 1943 | enum v4l2_tuner_type type; |
| 1944 | int err; |
| 1945 | |
| 1946 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
| 1947 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
| 1948 | |
| 1949 | if (type != p->type) |
| 1950 | return -EINVAL; |
| 1951 | if (ops->vidioc_enum_freq_bands) |
| 1952 | return ops->vidioc_enum_freq_bands(file, fh, p); |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1953 | if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) { |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1954 | struct v4l2_tuner t = { |
| 1955 | .index = p->tuner, |
| 1956 | .type = type, |
| 1957 | }; |
| 1958 | |
Hans Verkuil | aa4d9b5 | 2012-08-01 15:52:46 -0300 | [diff] [blame] | 1959 | if (p->index) |
| 1960 | return -EINVAL; |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1961 | err = ops->vidioc_g_tuner(file, fh, &t); |
| 1962 | if (err) |
| 1963 | return err; |
| 1964 | p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS; |
| 1965 | p->rangelow = t.rangelow; |
| 1966 | p->rangehigh = t.rangehigh; |
| 1967 | p->modulation = (type == V4L2_TUNER_RADIO) ? |
| 1968 | V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB; |
| 1969 | return 0; |
| 1970 | } |
Hans Verkuil | 73f3541 | 2013-03-10 13:12:25 -0300 | [diff] [blame] | 1971 | if (is_valid_ioctl(vfd, VIDIOC_G_MODULATOR)) { |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1972 | struct v4l2_modulator m = { |
| 1973 | .index = p->tuner, |
| 1974 | }; |
| 1975 | |
| 1976 | if (type != V4L2_TUNER_RADIO) |
| 1977 | return -EINVAL; |
Hans Verkuil | aa4d9b5 | 2012-08-01 15:52:46 -0300 | [diff] [blame] | 1978 | if (p->index) |
| 1979 | return -EINVAL; |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1980 | err = ops->vidioc_g_modulator(file, fh, &m); |
| 1981 | if (err) |
| 1982 | return err; |
| 1983 | p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS; |
| 1984 | p->rangelow = m.rangelow; |
| 1985 | p->rangehigh = m.rangehigh; |
| 1986 | p->modulation = (type == V4L2_TUNER_RADIO) ? |
| 1987 | V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB; |
| 1988 | return 0; |
| 1989 | } |
| 1990 | return -ENOTTY; |
| 1991 | } |
| 1992 | |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 1993 | struct v4l2_ioctl_info { |
| 1994 | unsigned int ioctl; |
Hans Verkuil | 27cd2ab | 2012-06-09 08:55:31 -0300 | [diff] [blame] | 1995 | u32 flags; |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 1996 | const char * const name; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 1997 | union { |
| 1998 | u32 offset; |
| 1999 | int (*func)(const struct v4l2_ioctl_ops *ops, |
| 2000 | struct file *file, void *fh, void *p); |
Hans Verkuil | 26ddcbc | 2012-07-12 12:06:24 -0300 | [diff] [blame] | 2001 | } u; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2002 | void (*debug)(const void *arg, bool write_only); |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2003 | }; |
| 2004 | |
| 2005 | /* This control needs a priority check */ |
| 2006 | #define INFO_FL_PRIO (1 << 0) |
| 2007 | /* This control can be valid if the filehandle passes a control handler. */ |
| 2008 | #define INFO_FL_CTRL (1 << 1) |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2009 | /* This is a standard ioctl, no need for special code */ |
| 2010 | #define INFO_FL_STD (1 << 2) |
| 2011 | /* This is ioctl has its own function */ |
| 2012 | #define INFO_FL_FUNC (1 << 3) |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 2013 | /* Queuing ioctl */ |
| 2014 | #define INFO_FL_QUEUE (1 << 4) |
Hans Verkuil | 27cd2ab | 2012-06-09 08:55:31 -0300 | [diff] [blame] | 2015 | /* Zero struct from after the field to the end */ |
| 2016 | #define INFO_FL_CLEAR(v4l2_struct, field) \ |
| 2017 | ((offsetof(struct v4l2_struct, field) + \ |
| 2018 | sizeof(((struct v4l2_struct *)0)->field)) << 16) |
| 2019 | #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16) |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2020 | |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2021 | #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \ |
| 2022 | [_IOC_NR(_ioctl)] = { \ |
| 2023 | .ioctl = _ioctl, \ |
| 2024 | .flags = _flags | INFO_FL_STD, \ |
| 2025 | .name = #_ioctl, \ |
Hans Verkuil | 26ddcbc | 2012-07-12 12:06:24 -0300 | [diff] [blame] | 2026 | .u.offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \ |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2027 | .debug = _debug, \ |
| 2028 | } |
| 2029 | |
| 2030 | #define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \ |
| 2031 | [_IOC_NR(_ioctl)] = { \ |
| 2032 | .ioctl = _ioctl, \ |
| 2033 | .flags = _flags | INFO_FL_FUNC, \ |
| 2034 | .name = #_ioctl, \ |
Hans Verkuil | 26ddcbc | 2012-07-12 12:06:24 -0300 | [diff] [blame] | 2035 | .u.func = _func, \ |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2036 | .debug = _debug, \ |
| 2037 | } |
| 2038 | |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2039 | static struct v4l2_ioctl_info v4l2_ioctls[] = { |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 2040 | IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0), |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 2041 | IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)), |
| 2042 | IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)), |
| 2043 | IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO), |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 2044 | IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE), |
| 2045 | IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)), |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 2046 | IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0), |
| 2047 | IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO), |
Hans Verkuil | 737c097 | 2012-09-04 10:08:01 -0300 | [diff] [blame] | 2048 | IOCTL_INFO_FNC(VIDIOC_OVERLAY, v4l_overlay, v4l_print_u32, INFO_FL_PRIO), |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 2049 | IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE), |
Tomasz Stanislawski | b799d09a | 2012-06-14 11:32:23 -0300 | [diff] [blame] | 2050 | IOCTL_INFO_STD(VIDIOC_EXPBUF, vidioc_expbuf, v4l_print_exportbuffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_exportbuffer, flags)), |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 2051 | IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE), |
| 2052 | IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), |
| 2053 | IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), |
Hans Verkuil | eb3728e | 2012-06-22 06:23:59 -0300 | [diff] [blame] | 2054 | IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)), |
| 2055 | IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO), |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 2056 | IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0), |
| 2057 | IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO), |
| 2058 | IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)), |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 2059 | IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)), |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 2060 | IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)), |
| 2061 | IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL), |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 2062 | IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)), |
| 2063 | IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO), |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 2064 | IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0), |
| 2065 | IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_audio, INFO_FL_PRIO), |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 2066 | IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)), |
| 2067 | IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)), |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 2068 | IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0), |
| 2069 | IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO), |
| 2070 | IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0), |
| 2071 | IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO), |
| 2072 | IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)), |
| 2073 | IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0), |
| 2074 | IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO), |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 2075 | IOCTL_INFO_FNC(VIDIOC_G_MODULATOR, v4l_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)), |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 2076 | IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_modulator, INFO_FL_PRIO), |
| 2077 | IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)), |
| 2078 | IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO), |
Hans Verkuil | d84f2d94 | 2012-06-09 11:57:46 -0300 | [diff] [blame] | 2079 | IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)), |
| 2080 | IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)), |
| 2081 | IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO), |
| 2082 | IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0), |
| 2083 | IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO), |
Hans Verkuil | d806f2d | 2012-06-09 10:02:49 -0300 | [diff] [blame] | 2084 | IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0), |
| 2085 | IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO), |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 2086 | IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0), |
Hans Verkuil | be6c64e | 2012-06-22 06:12:57 -0300 | [diff] [blame] | 2087 | IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0), |
Hans Verkuil | 5907612 | 2012-06-22 06:09:54 -0300 | [diff] [blame] | 2088 | IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)), |
| 2089 | IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)), |
Hans Verkuil | d0547cb | 2012-06-09 09:27:10 -0300 | [diff] [blame] | 2090 | IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0), |
| 2091 | IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO), |
Hans Verkuil | 458aa4a | 2012-06-09 12:55:52 -0300 | [diff] [blame] | 2092 | IOCTL_INFO_FNC(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)), |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 2093 | IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0), |
Hans Verkuil | efbceec | 2012-06-09 12:54:02 -0300 | [diff] [blame] | 2094 | IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL), |
| 2095 | IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL), |
Hans Verkuil | 9bc3163 | 2012-07-18 09:34:59 -0300 | [diff] [blame] | 2096 | IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL), |
Hans Verkuil | 458aa4a | 2012-06-09 12:55:52 -0300 | [diff] [blame] | 2097 | IOCTL_INFO_STD(VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)), |
| 2098 | IOCTL_INFO_STD(VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)), |
Hans Verkuil | d806f2d | 2012-06-09 10:02:49 -0300 | [diff] [blame] | 2099 | IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0), |
| 2100 | IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), |
| 2101 | IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), |
| 2102 | IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO), |
| 2103 | IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0), |
Hans Verkuil | f16f77b | 2012-06-09 10:06:25 -0300 | [diff] [blame] | 2104 | IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0), |
| 2105 | IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0), |
| 2106 | IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0), |
Hans Verkuil | 4b1e2e4 | 2012-06-22 06:17:48 -0300 | [diff] [blame] | 2107 | IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO), |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 2108 | IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO), |
| 2109 | IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0), |
Hans Verkuil | 458aa4a | 2012-06-09 12:55:52 -0300 | [diff] [blame] | 2110 | IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0), |
| 2111 | IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0), |
| 2112 | IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0), |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 2113 | IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE), |
| 2114 | IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE), |
Hans Verkuil | efc626b | 2012-06-09 10:09:07 -0300 | [diff] [blame] | 2115 | IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0), |
| 2116 | IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0), |
Hans Verkuil | a1acb8f | 2012-07-11 09:15:06 -0300 | [diff] [blame] | 2117 | IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, type)), |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 2118 | IOCTL_INFO_FNC(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0), |
Hans Verkuil | 79b0c64 | 2013-03-18 12:16:34 -0300 | [diff] [blame] | 2119 | IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_NAME, v4l_dbg_g_chip_name, v4l_print_dbg_chip_name, INFO_FL_CLEAR(v4l2_dbg_chip_name, match)), |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2120 | }; |
| 2121 | #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) |
| 2122 | |
| 2123 | bool v4l2_is_known_ioctl(unsigned int cmd) |
| 2124 | { |
| 2125 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) |
| 2126 | return false; |
| 2127 | return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd; |
| 2128 | } |
| 2129 | |
Hans Verkuil | 5a5adf6 | 2012-06-22 07:29:35 -0300 | [diff] [blame] | 2130 | struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd) |
| 2131 | { |
| 2132 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) |
| 2133 | return vdev->lock; |
| 2134 | if (test_bit(_IOC_NR(cmd), vdev->disable_locking)) |
| 2135 | return NULL; |
| 2136 | if (vdev->queue && vdev->queue->lock && |
| 2137 | (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE)) |
| 2138 | return vdev->queue->lock; |
| 2139 | return vdev->lock; |
| 2140 | } |
| 2141 | |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2142 | /* Common ioctl debug function. This function can be used by |
| 2143 | external ioctl messages as well as internal V4L ioctl */ |
Hans Verkuil | 4a08516 | 2012-06-22 06:38:06 -0300 | [diff] [blame] | 2144 | void v4l_printk_ioctl(const char *prefix, unsigned int cmd) |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2145 | { |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2146 | const char *dir, *type; |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2147 | |
Hans Verkuil | 4a08516 | 2012-06-22 06:38:06 -0300 | [diff] [blame] | 2148 | if (prefix) |
| 2149 | printk(KERN_DEBUG "%s: ", prefix); |
| 2150 | |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2151 | switch (_IOC_TYPE(cmd)) { |
| 2152 | case 'd': |
| 2153 | type = "v4l2_int"; |
| 2154 | break; |
| 2155 | case 'V': |
| 2156 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) { |
| 2157 | type = "v4l2"; |
| 2158 | break; |
| 2159 | } |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2160 | pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name); |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2161 | return; |
| 2162 | default: |
| 2163 | type = "unknown"; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2164 | break; |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | switch (_IOC_DIR(cmd)) { |
| 2168 | case _IOC_NONE: dir = "--"; break; |
| 2169 | case _IOC_READ: dir = "r-"; break; |
| 2170 | case _IOC_WRITE: dir = "-w"; break; |
| 2171 | case _IOC_READ | _IOC_WRITE: dir = "rw"; break; |
| 2172 | default: dir = "*ERR*"; break; |
| 2173 | } |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2174 | pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)", |
Hans Verkuil | 4839e6c | 2012-06-04 05:23:40 -0300 | [diff] [blame] | 2175 | type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd); |
| 2176 | } |
| 2177 | EXPORT_SYMBOL(v4l_printk_ioctl); |
| 2178 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 2179 | static long __video_do_ioctl(struct file *file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2180 | unsigned int cmd, void *arg) |
| 2181 | { |
| 2182 | struct video_device *vfd = video_devdata(file); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2183 | const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2184 | bool write_only = false; |
| 2185 | struct v4l2_ioctl_info default_info; |
| 2186 | const struct v4l2_ioctl_info *info; |
Hans Verkuil | d5fbf32 | 2008-10-18 13:39:53 -0300 | [diff] [blame] | 2187 | void *fh = file->private_data; |
Hans Verkuil | 99cd47bc | 2011-03-11 19:00:56 -0300 | [diff] [blame] | 2188 | struct v4l2_fh *vfh = NULL; |
Hans Verkuil | b1a873a | 2011-03-22 10:14:07 -0300 | [diff] [blame] | 2189 | int use_fh_prio = 0; |
Hans Verkuil | 80131fe0 | 2012-06-22 06:37:38 -0300 | [diff] [blame] | 2190 | int debug = vfd->debug; |
Mauro Carvalho Chehab | 9190d19 | 2011-07-06 14:08:08 -0300 | [diff] [blame] | 2191 | long ret = -ENOTTY; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2192 | |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 2193 | if (ops == NULL) { |
Hans Verkuil | 4a08516 | 2012-06-22 06:38:06 -0300 | [diff] [blame] | 2194 | pr_warn("%s: has no ioctl_ops.\n", |
| 2195 | video_device_node_name(vfd)); |
Mauro Carvalho Chehab | 9190d19 | 2011-07-06 14:08:08 -0300 | [diff] [blame] | 2196 | return ret; |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 2197 | } |
| 2198 | |
Hans Verkuil | 48ea0be | 2012-05-10 05:36:00 -0300 | [diff] [blame] | 2199 | if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) { |
| 2200 | vfh = file->private_data; |
| 2201 | use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags); |
Hans Verkuil | 48ea0be | 2012-05-10 05:36:00 -0300 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | if (v4l2_is_known_ioctl(cmd)) { |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2205 | info = &v4l2_ioctls[_IOC_NR(cmd)]; |
Hans Verkuil | 48ea0be | 2012-05-10 05:36:00 -0300 | [diff] [blame] | 2206 | |
| 2207 | if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) && |
| 2208 | !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler)) |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2209 | goto done; |
Hans Verkuil | 4b902fe | 2012-05-10 05:40:50 -0300 | [diff] [blame] | 2210 | |
| 2211 | if (use_fh_prio && (info->flags & INFO_FL_PRIO)) { |
| 2212 | ret = v4l2_prio_check(vfd->prio, vfh->prio); |
| 2213 | if (ret) |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2214 | goto done; |
Hans Verkuil | 4b902fe | 2012-05-10 05:40:50 -0300 | [diff] [blame] | 2215 | } |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2216 | } else { |
| 2217 | default_info.ioctl = cmd; |
| 2218 | default_info.flags = 0; |
Hans Verkuil | f18d8e0 | 2012-06-22 06:35:01 -0300 | [diff] [blame] | 2219 | default_info.debug = v4l_print_default; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2220 | info = &default_info; |
Hans Verkuil | 48ea0be | 2012-05-10 05:36:00 -0300 | [diff] [blame] | 2221 | } |
| 2222 | |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2223 | write_only = _IOC_DIR(cmd) == _IOC_WRITE; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2224 | if (info->flags & INFO_FL_STD) { |
| 2225 | typedef int (*vidioc_op)(struct file *file, void *fh, void *p); |
| 2226 | const void *p = vfd->ioctl_ops; |
Hans Verkuil | 26ddcbc | 2012-07-12 12:06:24 -0300 | [diff] [blame] | 2227 | const vidioc_op *vidioc = p + info->u.offset; |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2228 | |
| 2229 | ret = (*vidioc)(file, fh, arg); |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2230 | } else if (info->flags & INFO_FL_FUNC) { |
Hans Verkuil | 26ddcbc | 2012-07-12 12:06:24 -0300 | [diff] [blame] | 2231 | ret = info->u.func(ops, file, fh, arg); |
Hans Verkuil | f18d8e0 | 2012-06-22 06:35:01 -0300 | [diff] [blame] | 2232 | } else if (!ops->vidioc_default) { |
| 2233 | ret = -ENOTTY; |
| 2234 | } else { |
| 2235 | ret = ops->vidioc_default(file, fh, |
| 2236 | use_fh_prio ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0, |
| 2237 | cmd, arg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2238 | } |
| 2239 | |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2240 | done: |
Hans Verkuil | 80131fe0 | 2012-06-22 06:37:38 -0300 | [diff] [blame] | 2241 | if (debug) { |
Hans Verkuil | 4a08516 | 2012-06-22 06:38:06 -0300 | [diff] [blame] | 2242 | v4l_printk_ioctl(video_device_node_name(vfd), cmd); |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2243 | if (ret < 0) |
Hans Verkuil | 505d04b | 2013-03-14 07:40:45 -0300 | [diff] [blame] | 2244 | pr_cont(": error %ld", ret); |
| 2245 | if (debug == V4L2_DEBUG_IOCTL) |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2246 | pr_cont("\n"); |
Hans Verkuil | 86748f3 | 2012-06-22 06:04:16 -0300 | [diff] [blame] | 2247 | else if (_IOC_DIR(cmd) == _IOC_NONE) |
| 2248 | info->debug(arg, write_only); |
| 2249 | else { |
| 2250 | pr_cont(": "); |
| 2251 | info->debug(arg, write_only); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | return ret; |
| 2256 | } |
| 2257 | |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2258 | static int check_array_args(unsigned int cmd, void *parg, size_t *array_size, |
| 2259 | void * __user *user_ptr, void ***kernel_ptr) |
| 2260 | { |
| 2261 | int ret = 0; |
| 2262 | |
| 2263 | switch (cmd) { |
Hans Verkuil | 96b1a70 | 2012-09-19 10:14:41 -0300 | [diff] [blame] | 2264 | case VIDIOC_PREPARE_BUF: |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2265 | case VIDIOC_QUERYBUF: |
| 2266 | case VIDIOC_QBUF: |
| 2267 | case VIDIOC_DQBUF: { |
| 2268 | struct v4l2_buffer *buf = parg; |
| 2269 | |
| 2270 | if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) { |
| 2271 | if (buf->length > VIDEO_MAX_PLANES) { |
| 2272 | ret = -EINVAL; |
| 2273 | break; |
| 2274 | } |
| 2275 | *user_ptr = (void __user *)buf->m.planes; |
Hans Petter Selasky | 2ef4037 | 2011-05-23 08:13:06 -0300 | [diff] [blame] | 2276 | *kernel_ptr = (void *)&buf->m.planes; |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2277 | *array_size = sizeof(struct v4l2_plane) * buf->length; |
| 2278 | ret = 1; |
| 2279 | } |
| 2280 | break; |
| 2281 | } |
| 2282 | |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 2283 | case VIDIOC_SUBDEV_G_EDID: |
| 2284 | case VIDIOC_SUBDEV_S_EDID: { |
| 2285 | struct v4l2_subdev_edid *edid = parg; |
| 2286 | |
| 2287 | if (edid->blocks) { |
Hans Verkuil | 1b8b10c | 2012-10-02 02:47:58 -0300 | [diff] [blame] | 2288 | if (edid->blocks > 256) { |
| 2289 | ret = -EINVAL; |
| 2290 | break; |
| 2291 | } |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 2292 | *user_ptr = (void __user *)edid->edid; |
| 2293 | *kernel_ptr = (void *)&edid->edid; |
| 2294 | *array_size = edid->blocks * 128; |
| 2295 | ret = 1; |
| 2296 | } |
| 2297 | break; |
| 2298 | } |
| 2299 | |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2300 | case VIDIOC_S_EXT_CTRLS: |
| 2301 | case VIDIOC_G_EXT_CTRLS: |
| 2302 | case VIDIOC_TRY_EXT_CTRLS: { |
| 2303 | struct v4l2_ext_controls *ctrls = parg; |
| 2304 | |
| 2305 | if (ctrls->count != 0) { |
Dan Carpenter | 6c06108 | 2012-01-05 02:27:57 -0300 | [diff] [blame] | 2306 | if (ctrls->count > V4L2_CID_MAX_CTRLS) { |
| 2307 | ret = -EINVAL; |
| 2308 | break; |
| 2309 | } |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2310 | *user_ptr = (void __user *)ctrls->controls; |
Hans Petter Selasky | 2ef4037 | 2011-05-23 08:13:06 -0300 | [diff] [blame] | 2311 | *kernel_ptr = (void *)&ctrls->controls; |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2312 | *array_size = sizeof(struct v4l2_ext_control) |
| 2313 | * ctrls->count; |
| 2314 | ret = 1; |
| 2315 | } |
| 2316 | break; |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | return ret; |
| 2321 | } |
| 2322 | |
Laurent Pinchart | fc0a807 | 2010-07-12 11:09:41 -0300 | [diff] [blame] | 2323 | long |
| 2324 | video_usercopy(struct file *file, unsigned int cmd, unsigned long arg, |
| 2325 | v4l2_kioctl func) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2326 | { |
| 2327 | char sbuf[128]; |
| 2328 | void *mbuf = NULL; |
Hans Verkuil | 1d94aa3 | 2010-04-06 08:12:21 -0300 | [diff] [blame] | 2329 | void *parg = (void *)arg; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 2330 | long err = -EINVAL; |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2331 | bool has_array_args; |
| 2332 | size_t array_size = 0; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2333 | void __user *user_ptr = NULL; |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2334 | void **kernel_ptr = NULL; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2335 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2336 | /* Copy arguments into temp kernel buffer */ |
Trent Piepho | 337f9d2 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2337 | if (_IOC_DIR(cmd) != _IOC_NONE) { |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2338 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
| 2339 | parg = sbuf; |
| 2340 | } else { |
| 2341 | /* too big to allocate from stack */ |
| 2342 | mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); |
| 2343 | if (NULL == mbuf) |
| 2344 | return -ENOMEM; |
| 2345 | parg = mbuf; |
| 2346 | } |
| 2347 | |
| 2348 | err = -EFAULT; |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2349 | if (_IOC_DIR(cmd) & _IOC_WRITE) { |
Hans Verkuil | 27cd2ab | 2012-06-09 08:55:31 -0300 | [diff] [blame] | 2350 | unsigned int n = _IOC_SIZE(cmd); |
| 2351 | |
| 2352 | /* |
| 2353 | * In some cases, only a few fields are used as input, |
| 2354 | * i.e. when the app sets "index" and then the driver |
| 2355 | * fills in the rest of the structure for the thing |
| 2356 | * with that index. We only need to copy up the first |
| 2357 | * non-input field. |
| 2358 | */ |
| 2359 | if (v4l2_is_known_ioctl(cmd)) { |
| 2360 | u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags; |
| 2361 | if (flags & INFO_FL_CLEAR_MASK) |
| 2362 | n = (flags & INFO_FL_CLEAR_MASK) >> 16; |
| 2363 | } |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2364 | |
| 2365 | if (copy_from_user(parg, (void __user *)arg, n)) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2366 | goto out; |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2367 | |
| 2368 | /* zero out anything we don't copy from userspace */ |
| 2369 | if (n < _IOC_SIZE(cmd)) |
| 2370 | memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n); |
Trent Piepho | 337f9d2 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2371 | } else { |
| 2372 | /* read-only ioctl */ |
| 2373 | memset(parg, 0, _IOC_SIZE(cmd)); |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2374 | } |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2375 | } |
| 2376 | |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2377 | err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr); |
| 2378 | if (err < 0) |
| 2379 | goto out; |
| 2380 | has_array_args = err; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2381 | |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2382 | if (has_array_args) { |
| 2383 | /* |
| 2384 | * When adding new types of array args, make sure that the |
| 2385 | * parent argument to ioctl (which contains the pointer to the |
| 2386 | * array) fits into sbuf (so that mbuf will still remain |
| 2387 | * unused up to here). |
| 2388 | */ |
| 2389 | mbuf = kmalloc(array_size, GFP_KERNEL); |
| 2390 | err = -ENOMEM; |
| 2391 | if (NULL == mbuf) |
| 2392 | goto out_array_args; |
| 2393 | err = -EFAULT; |
| 2394 | if (copy_from_user(mbuf, user_ptr, array_size)) |
| 2395 | goto out_array_args; |
| 2396 | *kernel_ptr = mbuf; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | /* Handles IOCTL */ |
Laurent Pinchart | fc0a807 | 2010-07-12 11:09:41 -0300 | [diff] [blame] | 2400 | err = func(file, cmd, parg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2401 | if (err == -ENOIOCTLCMD) |
Hans Verkuil | 02bbb81 | 2012-02-08 08:09:36 -0300 | [diff] [blame] | 2402 | err = -ENOTTY; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2403 | |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2404 | if (has_array_args) { |
| 2405 | *kernel_ptr = user_ptr; |
| 2406 | if (copy_to_user(user_ptr, mbuf, array_size)) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2407 | err = -EFAULT; |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2408 | goto out_array_args; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2409 | } |
Hans Verkuil | 5d7758e | 2012-05-15 08:06:44 -0300 | [diff] [blame] | 2410 | /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid |
| 2411 | results that must be returned. */ |
| 2412 | if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2413 | goto out; |
| 2414 | |
Pawel Osciak | d14e6d7 | 2010-12-23 04:15:27 -0300 | [diff] [blame] | 2415 | out_array_args: |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2416 | /* Copy results into user buffer */ |
| 2417 | switch (_IOC_DIR(cmd)) { |
| 2418 | case _IOC_READ: |
| 2419 | case (_IOC_WRITE | _IOC_READ): |
| 2420 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) |
| 2421 | err = -EFAULT; |
| 2422 | break; |
| 2423 | } |
| 2424 | |
| 2425 | out: |
| 2426 | kfree(mbuf); |
| 2427 | return err; |
| 2428 | } |
Laurent Pinchart | fc0a807 | 2010-07-12 11:09:41 -0300 | [diff] [blame] | 2429 | EXPORT_SYMBOL(video_usercopy); |
| 2430 | |
| 2431 | long video_ioctl2(struct file *file, |
| 2432 | unsigned int cmd, unsigned long arg) |
| 2433 | { |
| 2434 | return video_usercopy(file, cmd, arg, __video_do_ioctl); |
| 2435 | } |
Mauro Carvalho Chehab | 8a522c9 | 2008-10-21 11:58:39 -0300 | [diff] [blame] | 2436 | EXPORT_SYMBOL(video_ioctl2); |