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> |
| 19 | |
| 20 | #define __OLD_VIDIOC_ /* To allow fixing old calls */ |
Mauro Carvalho Chehab | 7e0a16f | 2009-03-10 05:31:34 -0300 | [diff] [blame] | 21 | #include <linux/videodev.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 22 | #include <linux/videodev2.h> |
| 23 | |
| 24 | #ifdef CONFIG_VIDEO_V4L1 |
| 25 | #include <linux/videodev.h> |
| 26 | #endif |
| 27 | #include <media/v4l2-common.h> |
| 28 | #include <media/v4l2-ioctl.h> |
Sakari Ailus | d3d7c96 | 2010-03-27 11:02:10 -0300 | [diff] [blame^] | 29 | #include <media/v4l2-fh.h> |
| 30 | #include <media/v4l2-event.h> |
Hans Verkuil | 80b36e0 | 2009-02-07 11:00:02 -0300 | [diff] [blame] | 31 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 32 | |
| 33 | #define dbgarg(cmd, fmt, arg...) \ |
| 34 | do { \ |
| 35 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \ |
| 36 | printk(KERN_DEBUG "%s: ", vfd->name); \ |
| 37 | v4l_printk_ioctl(cmd); \ |
| 38 | printk(" " fmt, ## arg); \ |
| 39 | } \ |
| 40 | } while (0) |
| 41 | |
| 42 | #define dbgarg2(fmt, arg...) \ |
| 43 | do { \ |
| 44 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \ |
| 45 | printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\ |
| 46 | } while (0) |
| 47 | |
Mauro Carvalho Chehab | d33fbcb | 2009-07-02 17:07:32 -0300 | [diff] [blame] | 48 | #define dbgarg3(fmt, arg...) \ |
| 49 | do { \ |
| 50 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \ |
| 51 | printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\ |
| 52 | } while (0) |
| 53 | |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 54 | /* Zero out the end of the struct pointed to by p. Everthing after, but |
| 55 | * not including, the specified field is cleared. */ |
| 56 | #define CLEAR_AFTER_FIELD(p, field) \ |
| 57 | memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \ |
| 58 | 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field)) |
| 59 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 60 | struct std_descr { |
| 61 | v4l2_std_id std; |
| 62 | const char *descr; |
| 63 | }; |
| 64 | |
| 65 | static const struct std_descr standards[] = { |
| 66 | { V4L2_STD_NTSC, "NTSC" }, |
| 67 | { V4L2_STD_NTSC_M, "NTSC-M" }, |
| 68 | { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" }, |
| 69 | { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" }, |
| 70 | { V4L2_STD_NTSC_443, "NTSC-443" }, |
| 71 | { V4L2_STD_PAL, "PAL" }, |
| 72 | { V4L2_STD_PAL_BG, "PAL-BG" }, |
| 73 | { V4L2_STD_PAL_B, "PAL-B" }, |
| 74 | { V4L2_STD_PAL_B1, "PAL-B1" }, |
| 75 | { V4L2_STD_PAL_G, "PAL-G" }, |
| 76 | { V4L2_STD_PAL_H, "PAL-H" }, |
| 77 | { V4L2_STD_PAL_I, "PAL-I" }, |
| 78 | { V4L2_STD_PAL_DK, "PAL-DK" }, |
| 79 | { V4L2_STD_PAL_D, "PAL-D" }, |
| 80 | { V4L2_STD_PAL_D1, "PAL-D1" }, |
| 81 | { V4L2_STD_PAL_K, "PAL-K" }, |
| 82 | { V4L2_STD_PAL_M, "PAL-M" }, |
| 83 | { V4L2_STD_PAL_N, "PAL-N" }, |
| 84 | { V4L2_STD_PAL_Nc, "PAL-Nc" }, |
| 85 | { V4L2_STD_PAL_60, "PAL-60" }, |
| 86 | { V4L2_STD_SECAM, "SECAM" }, |
| 87 | { V4L2_STD_SECAM_B, "SECAM-B" }, |
| 88 | { V4L2_STD_SECAM_G, "SECAM-G" }, |
| 89 | { V4L2_STD_SECAM_H, "SECAM-H" }, |
| 90 | { V4L2_STD_SECAM_DK, "SECAM-DK" }, |
| 91 | { V4L2_STD_SECAM_D, "SECAM-D" }, |
| 92 | { V4L2_STD_SECAM_K, "SECAM-K" }, |
| 93 | { V4L2_STD_SECAM_K1, "SECAM-K1" }, |
| 94 | { V4L2_STD_SECAM_L, "SECAM-L" }, |
| 95 | { V4L2_STD_SECAM_LC, "SECAM-Lc" }, |
| 96 | { 0, "Unknown" } |
| 97 | }; |
| 98 | |
| 99 | /* video4linux standard ID conversion to standard name |
| 100 | */ |
| 101 | const char *v4l2_norm_to_name(v4l2_std_id id) |
| 102 | { |
| 103 | u32 myid = id; |
| 104 | int i; |
| 105 | |
| 106 | /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle |
| 107 | 64 bit comparations. So, on that architecture, with some gcc |
| 108 | variants, compilation fails. Currently, the max value is 30bit wide. |
| 109 | */ |
| 110 | BUG_ON(myid != id); |
| 111 | |
| 112 | for (i = 0; standards[i].std; i++) |
| 113 | if (myid == standards[i].std) |
| 114 | break; |
| 115 | return standards[i].descr; |
| 116 | } |
| 117 | EXPORT_SYMBOL(v4l2_norm_to_name); |
| 118 | |
Trent Piepho | 51f0b8d5 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 119 | /* Returns frame period for the given standard */ |
| 120 | void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod) |
| 121 | { |
| 122 | if (id & V4L2_STD_525_60) { |
| 123 | frameperiod->numerator = 1001; |
| 124 | frameperiod->denominator = 30000; |
| 125 | } else { |
| 126 | frameperiod->numerator = 1; |
| 127 | frameperiod->denominator = 25; |
| 128 | } |
| 129 | } |
| 130 | EXPORT_SYMBOL(v4l2_video_std_frame_period); |
| 131 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 132 | /* Fill in the fields of a v4l2_standard structure according to the |
| 133 | 'id' and 'transmission' parameters. Returns negative on error. */ |
| 134 | int v4l2_video_std_construct(struct v4l2_standard *vs, |
| 135 | int id, const char *name) |
| 136 | { |
Trent Piepho | 51f0b8d5 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 137 | vs->id = id; |
| 138 | v4l2_video_std_frame_period(id, &vs->frameperiod); |
| 139 | vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 140 | strlcpy(vs->name, name, sizeof(vs->name)); |
| 141 | return 0; |
| 142 | } |
| 143 | EXPORT_SYMBOL(v4l2_video_std_construct); |
| 144 | |
| 145 | /* ----------------------------------------------------------------- */ |
| 146 | /* some arrays for pretty-printing debug messages of enum types */ |
| 147 | |
| 148 | const char *v4l2_field_names[] = { |
| 149 | [V4L2_FIELD_ANY] = "any", |
| 150 | [V4L2_FIELD_NONE] = "none", |
| 151 | [V4L2_FIELD_TOP] = "top", |
| 152 | [V4L2_FIELD_BOTTOM] = "bottom", |
| 153 | [V4L2_FIELD_INTERLACED] = "interlaced", |
| 154 | [V4L2_FIELD_SEQ_TB] = "seq-tb", |
| 155 | [V4L2_FIELD_SEQ_BT] = "seq-bt", |
| 156 | [V4L2_FIELD_ALTERNATE] = "alternate", |
| 157 | [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb", |
| 158 | [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt", |
| 159 | }; |
| 160 | EXPORT_SYMBOL(v4l2_field_names); |
| 161 | |
| 162 | const char *v4l2_type_names[] = { |
| 163 | [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap", |
| 164 | [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay", |
| 165 | [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out", |
| 166 | [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", |
| 167 | [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", |
| 168 | [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap", |
| 169 | [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out", |
| 170 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay", |
| 171 | }; |
| 172 | EXPORT_SYMBOL(v4l2_type_names); |
| 173 | |
| 174 | static const char *v4l2_memory_names[] = { |
| 175 | [V4L2_MEMORY_MMAP] = "mmap", |
| 176 | [V4L2_MEMORY_USERPTR] = "userptr", |
| 177 | [V4L2_MEMORY_OVERLAY] = "overlay", |
| 178 | }; |
| 179 | |
| 180 | #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \ |
| 181 | arr[a] : "unknown") |
| 182 | |
| 183 | /* ------------------------------------------------------------------ */ |
| 184 | /* debug help functions */ |
| 185 | |
| 186 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 187 | static const char *v4l1_ioctls[] = { |
| 188 | [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP", |
| 189 | [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN", |
| 190 | [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN", |
| 191 | [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER", |
| 192 | [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER", |
| 193 | [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT", |
| 194 | [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT", |
| 195 | [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE", |
| 196 | [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN", |
| 197 | [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN", |
| 198 | [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF", |
| 199 | [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF", |
| 200 | [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY", |
| 201 | [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ", |
| 202 | [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ", |
| 203 | [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO", |
| 204 | [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO", |
| 205 | [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC", |
| 206 | [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE", |
| 207 | [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF", |
| 208 | [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT", |
| 209 | [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE", |
| 210 | [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE", |
| 211 | [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE", |
| 212 | [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE", |
| 213 | [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO", |
| 214 | [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE", |
| 215 | [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT", |
| 216 | [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT" |
| 217 | }; |
| 218 | #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls) |
| 219 | #endif |
| 220 | |
| 221 | static const char *v4l2_ioctls[] = { |
| 222 | [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP", |
| 223 | [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED", |
| 224 | [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT", |
| 225 | [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT", |
| 226 | [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT", |
| 227 | [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS", |
| 228 | [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF", |
| 229 | [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF", |
| 230 | [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF", |
| 231 | [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY", |
| 232 | [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF", |
| 233 | [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF", |
| 234 | [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON", |
| 235 | [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF", |
| 236 | [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM", |
| 237 | [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM", |
| 238 | [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD", |
| 239 | [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD", |
| 240 | [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD", |
| 241 | [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT", |
| 242 | [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL", |
| 243 | [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL", |
| 244 | [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER", |
| 245 | [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER", |
| 246 | [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO", |
| 247 | [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO", |
| 248 | [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL", |
| 249 | [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU", |
| 250 | [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT", |
| 251 | [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT", |
| 252 | [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT", |
| 253 | [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT", |
| 254 | [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT", |
| 255 | [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT", |
| 256 | [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT", |
| 257 | [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR", |
| 258 | [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR", |
| 259 | [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY", |
| 260 | [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY", |
| 261 | [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP", |
| 262 | [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP", |
| 263 | [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP", |
| 264 | [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP", |
| 265 | [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP", |
| 266 | [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD", |
| 267 | [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT", |
| 268 | [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO", |
| 269 | [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT", |
| 270 | [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY", |
| 271 | [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY", |
| 272 | [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP", |
| 273 | [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS", |
| 274 | [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS", |
| 275 | [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS", |
| 276 | [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS", |
| 277 | #if 1 |
| 278 | [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES", |
| 279 | [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS", |
| 280 | [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX", |
| 281 | [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD", |
| 282 | [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD", |
| 283 | |
| 284 | [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER", |
| 285 | [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER", |
| 286 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 287 | [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT", |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 288 | [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK", |
| 289 | #endif |
Muralidharan Karicheri | b6456c0 | 2009-11-19 12:00:31 -0300 | [diff] [blame] | 290 | [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS", |
| 291 | [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET", |
| 292 | [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET", |
| 293 | [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET", |
| 294 | [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS", |
| 295 | [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS", |
Sakari Ailus | fda1021 | 2010-02-24 19:19:05 -0300 | [diff] [blame] | 296 | [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT", |
| 297 | [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT", |
| 298 | [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT", |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 299 | }; |
| 300 | #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) |
| 301 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 302 | /* Common ioctl debug function. This function can be used by |
| 303 | external ioctl messages as well as internal V4L ioctl */ |
| 304 | void v4l_printk_ioctl(unsigned int cmd) |
| 305 | { |
| 306 | char *dir, *type; |
| 307 | |
| 308 | switch (_IOC_TYPE(cmd)) { |
| 309 | case 'd': |
Hans Verkuil | 78a3b4d | 2009-04-01 03:41:09 -0300 | [diff] [blame] | 310 | type = "v4l2_int"; |
| 311 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 312 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 313 | case 'v': |
| 314 | if (_IOC_NR(cmd) >= V4L1_IOCTLS) { |
| 315 | type = "v4l1"; |
| 316 | break; |
| 317 | } |
| 318 | printk("%s", v4l1_ioctls[_IOC_NR(cmd)]); |
| 319 | return; |
| 320 | #endif |
| 321 | case 'V': |
| 322 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) { |
| 323 | type = "v4l2"; |
| 324 | break; |
| 325 | } |
| 326 | printk("%s", v4l2_ioctls[_IOC_NR(cmd)]); |
| 327 | return; |
| 328 | default: |
| 329 | type = "unknown"; |
| 330 | } |
| 331 | |
| 332 | switch (_IOC_DIR(cmd)) { |
| 333 | case _IOC_NONE: dir = "--"; break; |
| 334 | case _IOC_READ: dir = "r-"; break; |
| 335 | case _IOC_WRITE: dir = "-w"; break; |
| 336 | case _IOC_READ | _IOC_WRITE: dir = "rw"; break; |
| 337 | default: dir = "*ERR*"; break; |
| 338 | } |
| 339 | printk("%s ioctl '%c', dir=%s, #%d (0x%08x)", |
| 340 | type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd); |
| 341 | } |
| 342 | EXPORT_SYMBOL(v4l_printk_ioctl); |
| 343 | |
| 344 | /* |
| 345 | * helper function -- handles userspace copying for ioctl arguments |
| 346 | */ |
| 347 | |
| 348 | #ifdef __OLD_VIDIOC_ |
| 349 | static unsigned int |
| 350 | video_fix_command(unsigned int cmd) |
| 351 | { |
| 352 | switch (cmd) { |
| 353 | case VIDIOC_OVERLAY_OLD: |
| 354 | cmd = VIDIOC_OVERLAY; |
| 355 | break; |
| 356 | case VIDIOC_S_PARM_OLD: |
| 357 | cmd = VIDIOC_S_PARM; |
| 358 | break; |
| 359 | case VIDIOC_S_CTRL_OLD: |
| 360 | cmd = VIDIOC_S_CTRL; |
| 361 | break; |
| 362 | case VIDIOC_G_AUDIO_OLD: |
| 363 | cmd = VIDIOC_G_AUDIO; |
| 364 | break; |
| 365 | case VIDIOC_G_AUDOUT_OLD: |
| 366 | cmd = VIDIOC_G_AUDOUT; |
| 367 | break; |
| 368 | case VIDIOC_CROPCAP_OLD: |
| 369 | cmd = VIDIOC_CROPCAP; |
| 370 | break; |
| 371 | } |
| 372 | return cmd; |
| 373 | } |
| 374 | #endif |
| 375 | |
| 376 | /* |
| 377 | * Obsolete usercopy function - Should be removed soon |
| 378 | */ |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 379 | long |
Hans Verkuil | f473bf7 | 2008-11-01 08:25:11 -0300 | [diff] [blame] | 380 | video_usercopy(struct file *file, unsigned int cmd, unsigned long arg, |
| 381 | v4l2_kioctl func) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 382 | { |
| 383 | char sbuf[128]; |
| 384 | void *mbuf = NULL; |
| 385 | void *parg = NULL; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 386 | long err = -EINVAL; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 387 | int is_ext_ctrl; |
| 388 | size_t ctrls_size = 0; |
| 389 | void __user *user_ptr = NULL; |
| 390 | |
| 391 | #ifdef __OLD_VIDIOC_ |
| 392 | cmd = video_fix_command(cmd); |
| 393 | #endif |
| 394 | is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS || |
| 395 | cmd == VIDIOC_TRY_EXT_CTRLS); |
| 396 | |
| 397 | /* Copy arguments into temp kernel buffer */ |
| 398 | switch (_IOC_DIR(cmd)) { |
| 399 | case _IOC_NONE: |
| 400 | parg = NULL; |
| 401 | break; |
| 402 | case _IOC_READ: |
| 403 | case _IOC_WRITE: |
| 404 | case (_IOC_WRITE | _IOC_READ): |
| 405 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
| 406 | parg = sbuf; |
| 407 | } else { |
| 408 | /* too big to allocate from stack */ |
| 409 | mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); |
| 410 | if (NULL == mbuf) |
| 411 | return -ENOMEM; |
| 412 | parg = mbuf; |
| 413 | } |
| 414 | |
| 415 | err = -EFAULT; |
| 416 | if (_IOC_DIR(cmd) & _IOC_WRITE) |
| 417 | if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd))) |
| 418 | goto out; |
| 419 | break; |
| 420 | } |
| 421 | if (is_ext_ctrl) { |
| 422 | struct v4l2_ext_controls *p = parg; |
| 423 | |
| 424 | /* In case of an error, tell the caller that it wasn't |
| 425 | a specific control that caused it. */ |
| 426 | p->error_idx = p->count; |
| 427 | user_ptr = (void __user *)p->controls; |
| 428 | if (p->count) { |
| 429 | ctrls_size = sizeof(struct v4l2_ext_control) * p->count; |
| 430 | /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */ |
| 431 | mbuf = kmalloc(ctrls_size, GFP_KERNEL); |
| 432 | err = -ENOMEM; |
| 433 | if (NULL == mbuf) |
| 434 | goto out_ext_ctrl; |
| 435 | err = -EFAULT; |
| 436 | if (copy_from_user(mbuf, user_ptr, ctrls_size)) |
| 437 | goto out_ext_ctrl; |
| 438 | p->controls = mbuf; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /* call driver */ |
Hans Verkuil | f473bf7 | 2008-11-01 08:25:11 -0300 | [diff] [blame] | 443 | err = func(file, cmd, parg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 444 | if (err == -ENOIOCTLCMD) |
| 445 | err = -EINVAL; |
| 446 | if (is_ext_ctrl) { |
| 447 | struct v4l2_ext_controls *p = parg; |
| 448 | |
| 449 | p->controls = (void *)user_ptr; |
| 450 | if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size)) |
| 451 | err = -EFAULT; |
| 452 | goto out_ext_ctrl; |
| 453 | } |
| 454 | if (err < 0) |
| 455 | goto out; |
| 456 | |
| 457 | out_ext_ctrl: |
| 458 | /* Copy results into user buffer */ |
| 459 | switch (_IOC_DIR(cmd)) { |
| 460 | case _IOC_READ: |
| 461 | case (_IOC_WRITE | _IOC_READ): |
| 462 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) |
| 463 | err = -EFAULT; |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | out: |
| 468 | kfree(mbuf); |
| 469 | return err; |
| 470 | } |
| 471 | EXPORT_SYMBOL(video_usercopy); |
| 472 | |
| 473 | static void dbgbuf(unsigned int cmd, struct video_device *vfd, |
| 474 | struct v4l2_buffer *p) |
| 475 | { |
| 476 | struct v4l2_timecode *tc = &p->timecode; |
| 477 | |
| 478 | dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, " |
| 479 | "bytesused=%d, flags=0x%08d, " |
| 480 | "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n", |
| 481 | p->timestamp.tv_sec / 3600, |
| 482 | (int)(p->timestamp.tv_sec / 60) % 60, |
| 483 | (int)(p->timestamp.tv_sec % 60), |
Alexander Beregalov | b045979 | 2008-09-03 16:47:38 -0300 | [diff] [blame] | 484 | (long)p->timestamp.tv_usec, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 485 | p->index, |
| 486 | prt_names(p->type, v4l2_type_names), |
| 487 | p->bytesused, p->flags, |
| 488 | p->field, p->sequence, |
| 489 | prt_names(p->memory, v4l2_memory_names), |
| 490 | p->m.userptr, p->length); |
| 491 | dbgarg2("timecode=%02d:%02d:%02d type=%d, " |
| 492 | "flags=0x%08d, frames=%d, userbits=0x%08x\n", |
| 493 | tc->hours, tc->minutes, tc->seconds, |
| 494 | tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits); |
| 495 | } |
| 496 | |
| 497 | static inline void dbgrect(struct video_device *vfd, char *s, |
| 498 | struct v4l2_rect *r) |
| 499 | { |
| 500 | dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top, |
| 501 | r->width, r->height); |
| 502 | }; |
| 503 | |
| 504 | static inline void v4l_print_pix_fmt(struct video_device *vfd, |
| 505 | struct v4l2_pix_format *fmt) |
| 506 | { |
| 507 | dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, " |
| 508 | "bytesperline=%d sizeimage=%d, colorspace=%d\n", |
| 509 | fmt->width, fmt->height, |
| 510 | (fmt->pixelformat & 0xff), |
| 511 | (fmt->pixelformat >> 8) & 0xff, |
| 512 | (fmt->pixelformat >> 16) & 0xff, |
| 513 | (fmt->pixelformat >> 24) & 0xff, |
| 514 | prt_names(fmt->field, v4l2_field_names), |
| 515 | fmt->bytesperline, fmt->sizeimage, fmt->colorspace); |
| 516 | }; |
| 517 | |
| 518 | static inline void v4l_print_ext_ctrls(unsigned int cmd, |
| 519 | struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals) |
| 520 | { |
| 521 | __u32 i; |
| 522 | |
| 523 | if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) |
| 524 | return; |
| 525 | dbgarg(cmd, ""); |
| 526 | printk(KERN_CONT "class=0x%x", c->ctrl_class); |
| 527 | for (i = 0; i < c->count; i++) { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 528 | if (show_vals && !c->controls[i].size) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 529 | printk(KERN_CONT " id/val=0x%x/0x%x", |
| 530 | c->controls[i].id, c->controls[i].value); |
| 531 | else |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 532 | printk(KERN_CONT " id=0x%x,size=%u", |
| 533 | c->controls[i].id, c->controls[i].size); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 534 | } |
| 535 | printk(KERN_CONT "\n"); |
| 536 | }; |
| 537 | |
| 538 | static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) |
| 539 | { |
| 540 | __u32 i; |
| 541 | |
| 542 | /* zero the reserved fields */ |
| 543 | c->reserved[0] = c->reserved[1] = 0; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 544 | for (i = 0; i < c->count; i++) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 545 | c->controls[i].reserved2[0] = 0; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 546 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 547 | /* V4L2_CID_PRIVATE_BASE cannot be used as control class |
| 548 | when using extended controls. |
| 549 | Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL |
| 550 | is it allowed for backwards compatibility. |
| 551 | */ |
| 552 | if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE) |
| 553 | return 0; |
| 554 | /* Check that all controls are from the same control class. */ |
| 555 | for (i = 0; i < c->count; i++) { |
| 556 | if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) { |
| 557 | c->error_idx = i; |
| 558 | return 0; |
| 559 | } |
| 560 | } |
| 561 | return 1; |
| 562 | } |
| 563 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 564 | static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 565 | { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 566 | if (ops == NULL) |
| 567 | return -EINVAL; |
| 568 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 569 | switch (type) { |
| 570 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 571 | if (ops->vidioc_g_fmt_vid_cap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 572 | return 0; |
| 573 | break; |
| 574 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 575 | if (ops->vidioc_g_fmt_vid_overlay) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 576 | return 0; |
| 577 | break; |
| 578 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 579 | if (ops->vidioc_g_fmt_vid_out) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 580 | return 0; |
| 581 | break; |
| 582 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 583 | if (ops->vidioc_g_fmt_vid_out_overlay) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 584 | return 0; |
| 585 | break; |
| 586 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 587 | if (ops->vidioc_g_fmt_vbi_cap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 588 | return 0; |
| 589 | break; |
| 590 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 591 | if (ops->vidioc_g_fmt_vbi_out) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 592 | return 0; |
| 593 | break; |
| 594 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 595 | if (ops->vidioc_g_fmt_sliced_vbi_cap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 596 | return 0; |
| 597 | break; |
| 598 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 599 | if (ops->vidioc_g_fmt_sliced_vbi_out) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 600 | return 0; |
| 601 | break; |
| 602 | case V4L2_BUF_TYPE_PRIVATE: |
Trent Piepho | 1175d61 | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 603 | if (ops->vidioc_g_fmt_type_private) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 604 | return 0; |
| 605 | break; |
| 606 | } |
| 607 | return -EINVAL; |
| 608 | } |
| 609 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 610 | static long __video_do_ioctl(struct file *file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 611 | unsigned int cmd, void *arg) |
| 612 | { |
| 613 | struct video_device *vfd = video_devdata(file); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 614 | const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; |
Hans Verkuil | d5fbf32 | 2008-10-18 13:39:53 -0300 | [diff] [blame] | 615 | void *fh = file->private_data; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 616 | long ret = -EINVAL; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 617 | |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 618 | if (ops == NULL) { |
| 619 | printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n", |
| 620 | vfd->name); |
| 621 | return -EINVAL; |
| 622 | } |
| 623 | |
| 624 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 625 | /******************************************************** |
| 626 | All other V4L1 calls are handled by v4l1_compat module. |
| 627 | Those calls will be translated into V4L2 calls, and |
| 628 | __video_do_ioctl will be called again, with one or more |
| 629 | V4L2 ioctls. |
| 630 | ********************************************************/ |
| 631 | if (_IOC_TYPE(cmd) == 'v' && cmd != VIDIOCGMBUF && |
| 632 | _IOC_NR(cmd) < BASE_VIDIOCPRIVATE) { |
| 633 | return v4l_compat_translate_ioctl(file, cmd, arg, |
| 634 | __video_do_ioctl); |
| 635 | } |
| 636 | #endif |
| 637 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 638 | if ((vfd->debug & V4L2_DEBUG_IOCTL) && |
| 639 | !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) { |
| 640 | v4l_print_ioctl(vfd->name, cmd); |
| 641 | printk(KERN_CONT "\n"); |
| 642 | } |
| 643 | |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 644 | switch (cmd) { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 645 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 646 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 647 | /*********************************************************** |
| 648 | Handles calls to the obsoleted V4L1 API |
| 649 | Due to the nature of VIDIOCGMBUF, each driver that supports |
| 650 | V4L1 should implement its own handler for this ioctl. |
| 651 | ***********************************************************/ |
| 652 | |
| 653 | /* --- streaming capture ------------------------------------- */ |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 654 | case VIDIOCGMBUF: |
| 655 | { |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 656 | struct video_mbuf *p = arg; |
| 657 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 658 | if (!ops->vidiocgmbuf) |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 659 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 660 | ret = ops->vidiocgmbuf(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 661 | if (!ret) |
| 662 | dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n", |
| 663 | p->size, p->frames, |
| 664 | (unsigned long)p->offsets); |
Hans Verkuil | 6a71788 | 2010-04-06 15:56:08 -0300 | [diff] [blame] | 665 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 666 | } |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 667 | #endif |
| 668 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 669 | /* --- capabilities ------------------------------------------ */ |
| 670 | case VIDIOC_QUERYCAP: |
| 671 | { |
| 672 | struct v4l2_capability *cap = (struct v4l2_capability *)arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 673 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 674 | if (!ops->vidioc_querycap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 675 | break; |
| 676 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 677 | ret = ops->vidioc_querycap(file, fh, cap); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 678 | if (!ret) |
| 679 | dbgarg(cmd, "driver=%s, card=%s, bus=%s, " |
| 680 | "version=0x%08x, " |
| 681 | "capabilities=0x%08x\n", |
| 682 | cap->driver, cap->card, cap->bus_info, |
| 683 | cap->version, |
| 684 | cap->capabilities); |
| 685 | break; |
| 686 | } |
| 687 | |
| 688 | /* --- priority ------------------------------------------ */ |
| 689 | case VIDIOC_G_PRIORITY: |
| 690 | { |
| 691 | enum v4l2_priority *p = arg; |
| 692 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 693 | if (!ops->vidioc_g_priority) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 694 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 695 | ret = ops->vidioc_g_priority(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 696 | if (!ret) |
| 697 | dbgarg(cmd, "priority is %d\n", *p); |
| 698 | break; |
| 699 | } |
| 700 | case VIDIOC_S_PRIORITY: |
| 701 | { |
| 702 | enum v4l2_priority *p = arg; |
| 703 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 704 | if (!ops->vidioc_s_priority) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 705 | break; |
| 706 | dbgarg(cmd, "setting priority to %d\n", *p); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 707 | ret = ops->vidioc_s_priority(file, fh, *p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 708 | break; |
| 709 | } |
| 710 | |
| 711 | /* --- capture ioctls ---------------------------------------- */ |
| 712 | case VIDIOC_ENUM_FMT: |
| 713 | { |
| 714 | struct v4l2_fmtdesc *f = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 715 | |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 716 | switch (f->type) { |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 717 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 718 | if (ops->vidioc_enum_fmt_vid_cap) |
| 719 | ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 720 | break; |
| 721 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 722 | if (ops->vidioc_enum_fmt_vid_overlay) |
| 723 | ret = ops->vidioc_enum_fmt_vid_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 724 | fh, f); |
| 725 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 726 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 727 | if (ops->vidioc_enum_fmt_vid_out) |
| 728 | ret = ops->vidioc_enum_fmt_vid_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 729 | break; |
| 730 | case V4L2_BUF_TYPE_PRIVATE: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 731 | if (ops->vidioc_enum_fmt_type_private) |
| 732 | ret = ops->vidioc_enum_fmt_type_private(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 733 | fh, f); |
| 734 | break; |
| 735 | default: |
| 736 | break; |
| 737 | } |
| 738 | if (!ret) |
| 739 | dbgarg(cmd, "index=%d, type=%d, flags=%d, " |
| 740 | "pixelformat=%c%c%c%c, description='%s'\n", |
| 741 | f->index, f->type, f->flags, |
| 742 | (f->pixelformat & 0xff), |
| 743 | (f->pixelformat >> 8) & 0xff, |
| 744 | (f->pixelformat >> 16) & 0xff, |
| 745 | (f->pixelformat >> 24) & 0xff, |
| 746 | f->description); |
| 747 | break; |
| 748 | } |
| 749 | case VIDIOC_G_FMT: |
| 750 | { |
| 751 | struct v4l2_format *f = (struct v4l2_format *)arg; |
| 752 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 753 | /* FIXME: Should be one dump per type */ |
| 754 | dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names)); |
| 755 | |
| 756 | switch (f->type) { |
| 757 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 758 | if (ops->vidioc_g_fmt_vid_cap) |
| 759 | ret = ops->vidioc_g_fmt_vid_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 760 | if (!ret) |
| 761 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
| 762 | break; |
| 763 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 764 | if (ops->vidioc_g_fmt_vid_overlay) |
| 765 | ret = ops->vidioc_g_fmt_vid_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 766 | fh, f); |
| 767 | break; |
| 768 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 769 | if (ops->vidioc_g_fmt_vid_out) |
| 770 | ret = ops->vidioc_g_fmt_vid_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 771 | if (!ret) |
| 772 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
| 773 | break; |
| 774 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 775 | if (ops->vidioc_g_fmt_vid_out_overlay) |
| 776 | ret = ops->vidioc_g_fmt_vid_out_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 777 | fh, f); |
| 778 | break; |
| 779 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 780 | if (ops->vidioc_g_fmt_vbi_cap) |
| 781 | ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 782 | break; |
| 783 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 784 | if (ops->vidioc_g_fmt_vbi_out) |
| 785 | ret = ops->vidioc_g_fmt_vbi_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 786 | break; |
| 787 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 788 | if (ops->vidioc_g_fmt_sliced_vbi_cap) |
| 789 | ret = ops->vidioc_g_fmt_sliced_vbi_cap(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 790 | fh, f); |
| 791 | break; |
| 792 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 793 | if (ops->vidioc_g_fmt_sliced_vbi_out) |
| 794 | ret = ops->vidioc_g_fmt_sliced_vbi_out(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 795 | fh, f); |
| 796 | break; |
| 797 | case V4L2_BUF_TYPE_PRIVATE: |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 798 | if (ops->vidioc_g_fmt_type_private) |
| 799 | ret = ops->vidioc_g_fmt_type_private(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 800 | fh, f); |
| 801 | break; |
| 802 | } |
| 803 | |
| 804 | break; |
| 805 | } |
| 806 | case VIDIOC_S_FMT: |
| 807 | { |
| 808 | struct v4l2_format *f = (struct v4l2_format *)arg; |
| 809 | |
| 810 | /* FIXME: Should be one dump per type */ |
| 811 | dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names)); |
| 812 | |
| 813 | switch (f->type) { |
| 814 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 815 | CLEAR_AFTER_FIELD(f, fmt.pix); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 816 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 817 | if (ops->vidioc_s_fmt_vid_cap) |
| 818 | ret = ops->vidioc_s_fmt_vid_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 819 | break; |
| 820 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 821 | CLEAR_AFTER_FIELD(f, fmt.win); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 822 | if (ops->vidioc_s_fmt_vid_overlay) |
| 823 | ret = ops->vidioc_s_fmt_vid_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 824 | fh, f); |
| 825 | break; |
| 826 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 827 | CLEAR_AFTER_FIELD(f, fmt.pix); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 828 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 829 | if (ops->vidioc_s_fmt_vid_out) |
| 830 | ret = ops->vidioc_s_fmt_vid_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 831 | break; |
| 832 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 833 | CLEAR_AFTER_FIELD(f, fmt.win); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 834 | if (ops->vidioc_s_fmt_vid_out_overlay) |
| 835 | ret = ops->vidioc_s_fmt_vid_out_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 836 | fh, f); |
| 837 | break; |
| 838 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 839 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 840 | if (ops->vidioc_s_fmt_vbi_cap) |
| 841 | ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 842 | break; |
| 843 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 844 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 845 | if (ops->vidioc_s_fmt_vbi_out) |
| 846 | ret = ops->vidioc_s_fmt_vbi_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 847 | break; |
| 848 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 849 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 850 | if (ops->vidioc_s_fmt_sliced_vbi_cap) |
| 851 | ret = ops->vidioc_s_fmt_sliced_vbi_cap(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 852 | fh, f); |
| 853 | break; |
| 854 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 855 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 856 | if (ops->vidioc_s_fmt_sliced_vbi_out) |
| 857 | ret = ops->vidioc_s_fmt_sliced_vbi_out(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 858 | fh, f); |
| 859 | break; |
| 860 | case V4L2_BUF_TYPE_PRIVATE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 861 | /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */ |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 862 | if (ops->vidioc_s_fmt_type_private) |
| 863 | ret = ops->vidioc_s_fmt_type_private(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 864 | fh, f); |
| 865 | break; |
| 866 | } |
| 867 | break; |
| 868 | } |
| 869 | case VIDIOC_TRY_FMT: |
| 870 | { |
| 871 | struct v4l2_format *f = (struct v4l2_format *)arg; |
| 872 | |
| 873 | /* FIXME: Should be one dump per type */ |
| 874 | dbgarg(cmd, "type=%s\n", prt_names(f->type, |
| 875 | v4l2_type_names)); |
| 876 | switch (f->type) { |
| 877 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 878 | CLEAR_AFTER_FIELD(f, fmt.pix); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 879 | if (ops->vidioc_try_fmt_vid_cap) |
| 880 | ret = ops->vidioc_try_fmt_vid_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 881 | if (!ret) |
| 882 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
| 883 | break; |
| 884 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 885 | CLEAR_AFTER_FIELD(f, fmt.win); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 886 | if (ops->vidioc_try_fmt_vid_overlay) |
| 887 | ret = ops->vidioc_try_fmt_vid_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 888 | fh, f); |
| 889 | break; |
| 890 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 891 | CLEAR_AFTER_FIELD(f, fmt.pix); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 892 | if (ops->vidioc_try_fmt_vid_out) |
| 893 | ret = ops->vidioc_try_fmt_vid_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 894 | if (!ret) |
| 895 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
| 896 | break; |
| 897 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 898 | CLEAR_AFTER_FIELD(f, fmt.win); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 899 | if (ops->vidioc_try_fmt_vid_out_overlay) |
| 900 | ret = ops->vidioc_try_fmt_vid_out_overlay(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 901 | fh, f); |
| 902 | break; |
| 903 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 904 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 905 | if (ops->vidioc_try_fmt_vbi_cap) |
| 906 | ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 907 | break; |
| 908 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 909 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 910 | if (ops->vidioc_try_fmt_vbi_out) |
| 911 | ret = ops->vidioc_try_fmt_vbi_out(file, fh, f); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 912 | break; |
| 913 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 914 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 915 | if (ops->vidioc_try_fmt_sliced_vbi_cap) |
| 916 | ret = ops->vidioc_try_fmt_sliced_vbi_cap(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 917 | fh, f); |
| 918 | break; |
| 919 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 920 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 921 | if (ops->vidioc_try_fmt_sliced_vbi_out) |
| 922 | ret = ops->vidioc_try_fmt_sliced_vbi_out(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 923 | fh, f); |
| 924 | break; |
| 925 | case V4L2_BUF_TYPE_PRIVATE: |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 926 | /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */ |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 927 | if (ops->vidioc_try_fmt_type_private) |
| 928 | ret = ops->vidioc_try_fmt_type_private(file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 929 | fh, f); |
| 930 | break; |
| 931 | } |
| 932 | |
| 933 | break; |
| 934 | } |
| 935 | /* FIXME: Those buf reqs could be handled here, |
| 936 | with some changes on videobuf to allow its header to be included at |
| 937 | videodev2.h or being merged at videodev2. |
| 938 | */ |
| 939 | case VIDIOC_REQBUFS: |
| 940 | { |
| 941 | struct v4l2_requestbuffers *p = arg; |
| 942 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 943 | if (!ops->vidioc_reqbufs) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 944 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 945 | ret = check_fmt(ops, p->type); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 946 | if (ret) |
| 947 | break; |
| 948 | |
Trent Piepho | 7ecc0cf | 2009-04-30 21:03:34 -0300 | [diff] [blame] | 949 | if (p->type < V4L2_BUF_TYPE_PRIVATE) |
| 950 | CLEAR_AFTER_FIELD(p, memory); |
| 951 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 952 | ret = ops->vidioc_reqbufs(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 953 | dbgarg(cmd, "count=%d, type=%s, memory=%s\n", |
| 954 | p->count, |
| 955 | prt_names(p->type, v4l2_type_names), |
| 956 | prt_names(p->memory, v4l2_memory_names)); |
| 957 | break; |
| 958 | } |
| 959 | case VIDIOC_QUERYBUF: |
| 960 | { |
| 961 | struct v4l2_buffer *p = arg; |
| 962 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 963 | if (!ops->vidioc_querybuf) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 964 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 965 | ret = check_fmt(ops, p->type); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 966 | if (ret) |
| 967 | break; |
| 968 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 969 | ret = ops->vidioc_querybuf(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 970 | if (!ret) |
| 971 | dbgbuf(cmd, vfd, p); |
| 972 | break; |
| 973 | } |
| 974 | case VIDIOC_QBUF: |
| 975 | { |
| 976 | struct v4l2_buffer *p = arg; |
| 977 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 978 | if (!ops->vidioc_qbuf) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 979 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 980 | ret = check_fmt(ops, p->type); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 981 | if (ret) |
| 982 | break; |
| 983 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 984 | ret = ops->vidioc_qbuf(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 985 | if (!ret) |
| 986 | dbgbuf(cmd, vfd, p); |
| 987 | break; |
| 988 | } |
| 989 | case VIDIOC_DQBUF: |
| 990 | { |
| 991 | struct v4l2_buffer *p = arg; |
| 992 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 993 | if (!ops->vidioc_dqbuf) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 994 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 995 | ret = check_fmt(ops, p->type); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 996 | if (ret) |
| 997 | break; |
| 998 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 999 | ret = ops->vidioc_dqbuf(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1000 | if (!ret) |
| 1001 | dbgbuf(cmd, vfd, p); |
| 1002 | break; |
| 1003 | } |
| 1004 | case VIDIOC_OVERLAY: |
| 1005 | { |
| 1006 | int *i = arg; |
| 1007 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1008 | if (!ops->vidioc_overlay) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1009 | break; |
| 1010 | dbgarg(cmd, "value=%d\n", *i); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1011 | ret = ops->vidioc_overlay(file, fh, *i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| 1014 | case VIDIOC_G_FBUF: |
| 1015 | { |
| 1016 | struct v4l2_framebuffer *p = arg; |
| 1017 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1018 | if (!ops->vidioc_g_fbuf) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1019 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1020 | ret = ops->vidioc_g_fbuf(file, fh, arg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1021 | if (!ret) { |
| 1022 | dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n", |
| 1023 | p->capability, p->flags, |
| 1024 | (unsigned long)p->base); |
| 1025 | v4l_print_pix_fmt(vfd, &p->fmt); |
| 1026 | } |
| 1027 | break; |
| 1028 | } |
| 1029 | case VIDIOC_S_FBUF: |
| 1030 | { |
| 1031 | struct v4l2_framebuffer *p = arg; |
| 1032 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1033 | if (!ops->vidioc_s_fbuf) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1034 | break; |
| 1035 | dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n", |
| 1036 | p->capability, p->flags, (unsigned long)p->base); |
| 1037 | v4l_print_pix_fmt(vfd, &p->fmt); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1038 | ret = ops->vidioc_s_fbuf(file, fh, arg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1039 | break; |
| 1040 | } |
| 1041 | case VIDIOC_STREAMON: |
| 1042 | { |
| 1043 | enum v4l2_buf_type i = *(int *)arg; |
| 1044 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1045 | if (!ops->vidioc_streamon) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1046 | break; |
| 1047 | dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names)); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1048 | ret = ops->vidioc_streamon(file, fh, i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1049 | break; |
| 1050 | } |
| 1051 | case VIDIOC_STREAMOFF: |
| 1052 | { |
| 1053 | enum v4l2_buf_type i = *(int *)arg; |
| 1054 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1055 | if (!ops->vidioc_streamoff) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1056 | break; |
| 1057 | dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names)); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1058 | ret = ops->vidioc_streamoff(file, fh, i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1059 | break; |
| 1060 | } |
| 1061 | /* ---------- tv norms ---------- */ |
| 1062 | case VIDIOC_ENUMSTD: |
| 1063 | { |
| 1064 | struct v4l2_standard *p = arg; |
| 1065 | v4l2_std_id id = vfd->tvnorms, curr_id = 0; |
| 1066 | unsigned int index = p->index, i, j = 0; |
| 1067 | const char *descr = ""; |
| 1068 | |
| 1069 | /* Return norm array in a canonical way */ |
| 1070 | for (i = 0; i <= index && id; i++) { |
| 1071 | /* last std value in the standards array is 0, so this |
| 1072 | while always ends there since (id & 0) == 0. */ |
| 1073 | while ((id & standards[j].std) != standards[j].std) |
| 1074 | j++; |
| 1075 | curr_id = standards[j].std; |
| 1076 | descr = standards[j].descr; |
| 1077 | j++; |
| 1078 | if (curr_id == 0) |
| 1079 | break; |
| 1080 | if (curr_id != V4L2_STD_PAL && |
| 1081 | curr_id != V4L2_STD_SECAM && |
| 1082 | curr_id != V4L2_STD_NTSC) |
| 1083 | id &= ~curr_id; |
| 1084 | } |
| 1085 | if (i <= index) |
Hans Verkuil | 3f5e182 | 2010-04-06 08:14:11 -0300 | [diff] [blame] | 1086 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1087 | |
| 1088 | v4l2_video_std_construct(p, curr_id, descr); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1089 | |
| 1090 | dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, " |
| 1091 | "framelines=%d\n", p->index, |
| 1092 | (unsigned long long)p->id, p->name, |
| 1093 | p->frameperiod.numerator, |
| 1094 | p->frameperiod.denominator, |
| 1095 | p->framelines); |
| 1096 | |
| 1097 | ret = 0; |
| 1098 | break; |
| 1099 | } |
| 1100 | case VIDIOC_G_STD: |
| 1101 | { |
| 1102 | v4l2_std_id *id = arg; |
| 1103 | |
| 1104 | ret = 0; |
| 1105 | /* Calls the specific handler */ |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1106 | if (ops->vidioc_g_std) |
| 1107 | ret = ops->vidioc_g_std(file, fh, id); |
Hans Verkuil | 9bedc7f | 2009-08-07 07:28:16 -0300 | [diff] [blame] | 1108 | else if (vfd->current_norm) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1109 | *id = vfd->current_norm; |
Hans Verkuil | 9bedc7f | 2009-08-07 07:28:16 -0300 | [diff] [blame] | 1110 | else |
| 1111 | ret = -EINVAL; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1112 | |
| 1113 | if (!ret) |
| 1114 | dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id); |
| 1115 | break; |
| 1116 | } |
| 1117 | case VIDIOC_S_STD: |
| 1118 | { |
| 1119 | v4l2_std_id *id = arg, norm; |
| 1120 | |
| 1121 | dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id); |
| 1122 | |
| 1123 | norm = (*id) & vfd->tvnorms; |
| 1124 | if (vfd->tvnorms && !norm) /* Check if std is supported */ |
| 1125 | break; |
| 1126 | |
| 1127 | /* Calls the specific handler */ |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1128 | if (ops->vidioc_s_std) |
| 1129 | ret = ops->vidioc_s_std(file, fh, &norm); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1130 | else |
| 1131 | ret = -EINVAL; |
| 1132 | |
| 1133 | /* Updates standard information */ |
| 1134 | if (ret >= 0) |
| 1135 | vfd->current_norm = norm; |
| 1136 | break; |
| 1137 | } |
| 1138 | case VIDIOC_QUERYSTD: |
| 1139 | { |
| 1140 | v4l2_std_id *p = arg; |
| 1141 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1142 | if (!ops->vidioc_querystd) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1143 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1144 | ret = ops->vidioc_querystd(file, fh, arg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1145 | if (!ret) |
| 1146 | dbgarg(cmd, "detected std=%08Lx\n", |
| 1147 | (unsigned long long)*p); |
| 1148 | break; |
| 1149 | } |
| 1150 | /* ------ input switching ---------- */ |
| 1151 | /* FIXME: Inputs can be handled inside videodev2 */ |
| 1152 | case VIDIOC_ENUMINPUT: |
| 1153 | { |
| 1154 | struct v4l2_input *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1155 | |
Muralidharan Karicheri | b6456c0 | 2009-11-19 12:00:31 -0300 | [diff] [blame] | 1156 | /* |
| 1157 | * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS & |
| 1158 | * CAP_STD here based on ioctl handler provided by the |
| 1159 | * driver. If the driver doesn't support these |
| 1160 | * for a specific input, it must override these flags. |
| 1161 | */ |
| 1162 | if (ops->vidioc_s_std) |
| 1163 | p->capabilities |= V4L2_IN_CAP_STD; |
| 1164 | if (ops->vidioc_s_dv_preset) |
| 1165 | p->capabilities |= V4L2_IN_CAP_PRESETS; |
| 1166 | if (ops->vidioc_s_dv_timings) |
| 1167 | p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS; |
| 1168 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1169 | if (!ops->vidioc_enum_input) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1170 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1171 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1172 | ret = ops->vidioc_enum_input(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1173 | if (!ret) |
| 1174 | dbgarg(cmd, "index=%d, name=%s, type=%d, " |
| 1175 | "audioset=%d, " |
| 1176 | "tuner=%d, std=%08Lx, status=%d\n", |
| 1177 | p->index, p->name, p->type, p->audioset, |
| 1178 | p->tuner, |
| 1179 | (unsigned long long)p->std, |
| 1180 | p->status); |
| 1181 | break; |
| 1182 | } |
| 1183 | case VIDIOC_G_INPUT: |
| 1184 | { |
| 1185 | unsigned int *i = arg; |
| 1186 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1187 | if (!ops->vidioc_g_input) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1188 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1189 | ret = ops->vidioc_g_input(file, fh, i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1190 | if (!ret) |
| 1191 | dbgarg(cmd, "value=%d\n", *i); |
| 1192 | break; |
| 1193 | } |
| 1194 | case VIDIOC_S_INPUT: |
| 1195 | { |
| 1196 | unsigned int *i = arg; |
| 1197 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1198 | if (!ops->vidioc_s_input) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1199 | break; |
| 1200 | dbgarg(cmd, "value=%d\n", *i); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1201 | ret = ops->vidioc_s_input(file, fh, *i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1202 | break; |
| 1203 | } |
| 1204 | |
| 1205 | /* ------ output switching ---------- */ |
| 1206 | case VIDIOC_ENUMOUTPUT: |
| 1207 | { |
| 1208 | struct v4l2_output *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1209 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1210 | if (!ops->vidioc_enum_output) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1211 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1212 | |
Muralidharan Karicheri | b6456c0 | 2009-11-19 12:00:31 -0300 | [diff] [blame] | 1213 | /* |
| 1214 | * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS & |
| 1215 | * CAP_STD here based on ioctl handler provided by the |
| 1216 | * driver. If the driver doesn't support these |
| 1217 | * for a specific output, it must override these flags. |
| 1218 | */ |
| 1219 | if (ops->vidioc_s_std) |
| 1220 | p->capabilities |= V4L2_OUT_CAP_STD; |
| 1221 | if (ops->vidioc_s_dv_preset) |
| 1222 | p->capabilities |= V4L2_OUT_CAP_PRESETS; |
| 1223 | if (ops->vidioc_s_dv_timings) |
| 1224 | p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS; |
| 1225 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1226 | ret = ops->vidioc_enum_output(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1227 | if (!ret) |
| 1228 | dbgarg(cmd, "index=%d, name=%s, type=%d, " |
| 1229 | "audioset=0x%x, " |
| 1230 | "modulator=%d, std=0x%08Lx\n", |
| 1231 | p->index, p->name, p->type, p->audioset, |
| 1232 | p->modulator, (unsigned long long)p->std); |
| 1233 | break; |
| 1234 | } |
| 1235 | case VIDIOC_G_OUTPUT: |
| 1236 | { |
| 1237 | unsigned int *i = arg; |
| 1238 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1239 | if (!ops->vidioc_g_output) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1240 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1241 | ret = ops->vidioc_g_output(file, fh, i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1242 | if (!ret) |
| 1243 | dbgarg(cmd, "value=%d\n", *i); |
| 1244 | break; |
| 1245 | } |
| 1246 | case VIDIOC_S_OUTPUT: |
| 1247 | { |
| 1248 | unsigned int *i = arg; |
| 1249 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1250 | if (!ops->vidioc_s_output) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1251 | break; |
| 1252 | dbgarg(cmd, "value=%d\n", *i); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1253 | ret = ops->vidioc_s_output(file, fh, *i); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | /* --- controls ---------------------------------------------- */ |
| 1258 | case VIDIOC_QUERYCTRL: |
| 1259 | { |
| 1260 | struct v4l2_queryctrl *p = arg; |
| 1261 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1262 | if (!ops->vidioc_queryctrl) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1263 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1264 | ret = ops->vidioc_queryctrl(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1265 | if (!ret) |
| 1266 | dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, " |
| 1267 | "step=%d, default=%d, flags=0x%08x\n", |
| 1268 | p->id, p->type, p->name, |
| 1269 | p->minimum, p->maximum, |
| 1270 | p->step, p->default_value, p->flags); |
| 1271 | else |
| 1272 | dbgarg(cmd, "id=0x%x\n", p->id); |
| 1273 | break; |
| 1274 | } |
| 1275 | case VIDIOC_G_CTRL: |
| 1276 | { |
| 1277 | struct v4l2_control *p = arg; |
| 1278 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1279 | if (ops->vidioc_g_ctrl) |
| 1280 | ret = ops->vidioc_g_ctrl(file, fh, p); |
| 1281 | else if (ops->vidioc_g_ext_ctrls) { |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1282 | struct v4l2_ext_controls ctrls; |
| 1283 | struct v4l2_ext_control ctrl; |
| 1284 | |
| 1285 | ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id); |
| 1286 | ctrls.count = 1; |
| 1287 | ctrls.controls = &ctrl; |
| 1288 | ctrl.id = p->id; |
| 1289 | ctrl.value = p->value; |
| 1290 | if (check_ext_ctrls(&ctrls, 1)) { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1291 | ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1292 | if (ret == 0) |
| 1293 | p->value = ctrl.value; |
| 1294 | } |
| 1295 | } else |
| 1296 | break; |
| 1297 | if (!ret) |
| 1298 | dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value); |
| 1299 | else |
| 1300 | dbgarg(cmd, "id=0x%x\n", p->id); |
| 1301 | break; |
| 1302 | } |
| 1303 | case VIDIOC_S_CTRL: |
| 1304 | { |
| 1305 | struct v4l2_control *p = arg; |
| 1306 | struct v4l2_ext_controls ctrls; |
| 1307 | struct v4l2_ext_control ctrl; |
| 1308 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1309 | if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1310 | break; |
| 1311 | |
| 1312 | dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value); |
| 1313 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1314 | if (ops->vidioc_s_ctrl) { |
| 1315 | ret = ops->vidioc_s_ctrl(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1316 | break; |
| 1317 | } |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1318 | if (!ops->vidioc_s_ext_ctrls) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1319 | break; |
| 1320 | |
| 1321 | ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id); |
| 1322 | ctrls.count = 1; |
| 1323 | ctrls.controls = &ctrl; |
| 1324 | ctrl.id = p->id; |
| 1325 | ctrl.value = p->value; |
| 1326 | if (check_ext_ctrls(&ctrls, 1)) |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1327 | ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1328 | break; |
| 1329 | } |
| 1330 | case VIDIOC_G_EXT_CTRLS: |
| 1331 | { |
| 1332 | struct v4l2_ext_controls *p = arg; |
| 1333 | |
| 1334 | p->error_idx = p->count; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1335 | if (!ops->vidioc_g_ext_ctrls) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1336 | break; |
| 1337 | if (check_ext_ctrls(p, 0)) |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1338 | ret = ops->vidioc_g_ext_ctrls(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1339 | v4l_print_ext_ctrls(cmd, vfd, p, !ret); |
| 1340 | break; |
| 1341 | } |
| 1342 | case VIDIOC_S_EXT_CTRLS: |
| 1343 | { |
| 1344 | struct v4l2_ext_controls *p = arg; |
| 1345 | |
| 1346 | p->error_idx = p->count; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1347 | if (!ops->vidioc_s_ext_ctrls) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1348 | break; |
| 1349 | v4l_print_ext_ctrls(cmd, vfd, p, 1); |
| 1350 | if (check_ext_ctrls(p, 0)) |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1351 | ret = ops->vidioc_s_ext_ctrls(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1352 | break; |
| 1353 | } |
| 1354 | case VIDIOC_TRY_EXT_CTRLS: |
| 1355 | { |
| 1356 | struct v4l2_ext_controls *p = arg; |
| 1357 | |
| 1358 | p->error_idx = p->count; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1359 | if (!ops->vidioc_try_ext_ctrls) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1360 | break; |
| 1361 | v4l_print_ext_ctrls(cmd, vfd, p, 1); |
| 1362 | if (check_ext_ctrls(p, 0)) |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1363 | ret = ops->vidioc_try_ext_ctrls(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1364 | break; |
| 1365 | } |
| 1366 | case VIDIOC_QUERYMENU: |
| 1367 | { |
| 1368 | struct v4l2_querymenu *p = arg; |
| 1369 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1370 | if (!ops->vidioc_querymenu) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1371 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1372 | ret = ops->vidioc_querymenu(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1373 | if (!ret) |
| 1374 | dbgarg(cmd, "id=0x%x, index=%d, name=%s\n", |
| 1375 | p->id, p->index, p->name); |
| 1376 | else |
| 1377 | dbgarg(cmd, "id=0x%x, index=%d\n", |
| 1378 | p->id, p->index); |
| 1379 | break; |
| 1380 | } |
| 1381 | /* --- audio ---------------------------------------------- */ |
| 1382 | case VIDIOC_ENUMAUDIO: |
| 1383 | { |
| 1384 | struct v4l2_audio *p = arg; |
| 1385 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1386 | if (!ops->vidioc_enumaudio) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1387 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1388 | ret = ops->vidioc_enumaudio(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1389 | if (!ret) |
| 1390 | dbgarg(cmd, "index=%d, name=%s, capability=0x%x, " |
| 1391 | "mode=0x%x\n", p->index, p->name, |
| 1392 | p->capability, p->mode); |
| 1393 | else |
| 1394 | dbgarg(cmd, "index=%d\n", p->index); |
| 1395 | break; |
| 1396 | } |
| 1397 | case VIDIOC_G_AUDIO: |
| 1398 | { |
| 1399 | struct v4l2_audio *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1400 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1401 | if (!ops->vidioc_g_audio) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1402 | break; |
| 1403 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1404 | ret = ops->vidioc_g_audio(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1405 | if (!ret) |
| 1406 | dbgarg(cmd, "index=%d, name=%s, capability=0x%x, " |
| 1407 | "mode=0x%x\n", p->index, |
| 1408 | p->name, p->capability, p->mode); |
| 1409 | else |
| 1410 | dbgarg(cmd, "index=%d\n", p->index); |
| 1411 | break; |
| 1412 | } |
| 1413 | case VIDIOC_S_AUDIO: |
| 1414 | { |
| 1415 | struct v4l2_audio *p = arg; |
| 1416 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1417 | if (!ops->vidioc_s_audio) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1418 | break; |
| 1419 | dbgarg(cmd, "index=%d, name=%s, capability=0x%x, " |
| 1420 | "mode=0x%x\n", p->index, p->name, |
| 1421 | p->capability, p->mode); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1422 | ret = ops->vidioc_s_audio(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | case VIDIOC_ENUMAUDOUT: |
| 1426 | { |
| 1427 | struct v4l2_audioout *p = arg; |
| 1428 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1429 | if (!ops->vidioc_enumaudout) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1430 | break; |
| 1431 | dbgarg(cmd, "Enum for index=%d\n", p->index); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1432 | ret = ops->vidioc_enumaudout(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1433 | if (!ret) |
| 1434 | dbgarg2("index=%d, name=%s, capability=%d, " |
| 1435 | "mode=%d\n", p->index, p->name, |
| 1436 | p->capability, p->mode); |
| 1437 | break; |
| 1438 | } |
| 1439 | case VIDIOC_G_AUDOUT: |
| 1440 | { |
| 1441 | struct v4l2_audioout *p = arg; |
| 1442 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1443 | if (!ops->vidioc_g_audout) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1444 | break; |
Trent Piepho | 337f9d2 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 1445 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1446 | ret = ops->vidioc_g_audout(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1447 | if (!ret) |
| 1448 | dbgarg2("index=%d, name=%s, capability=%d, " |
| 1449 | "mode=%d\n", p->index, p->name, |
| 1450 | p->capability, p->mode); |
| 1451 | break; |
| 1452 | } |
| 1453 | case VIDIOC_S_AUDOUT: |
| 1454 | { |
| 1455 | struct v4l2_audioout *p = arg; |
| 1456 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1457 | if (!ops->vidioc_s_audout) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1458 | break; |
| 1459 | dbgarg(cmd, "index=%d, name=%s, capability=%d, " |
| 1460 | "mode=%d\n", p->index, p->name, |
| 1461 | p->capability, p->mode); |
| 1462 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1463 | ret = ops->vidioc_s_audout(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1464 | break; |
| 1465 | } |
| 1466 | case VIDIOC_G_MODULATOR: |
| 1467 | { |
| 1468 | struct v4l2_modulator *p = arg; |
| 1469 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1470 | if (!ops->vidioc_g_modulator) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1471 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1472 | ret = ops->vidioc_g_modulator(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1473 | if (!ret) |
| 1474 | dbgarg(cmd, "index=%d, name=%s, " |
| 1475 | "capability=%d, rangelow=%d," |
| 1476 | " rangehigh=%d, txsubchans=%d\n", |
| 1477 | p->index, p->name, p->capability, |
| 1478 | p->rangelow, p->rangehigh, |
| 1479 | p->txsubchans); |
| 1480 | break; |
| 1481 | } |
| 1482 | case VIDIOC_S_MODULATOR: |
| 1483 | { |
| 1484 | struct v4l2_modulator *p = arg; |
| 1485 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1486 | if (!ops->vidioc_s_modulator) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1487 | break; |
| 1488 | dbgarg(cmd, "index=%d, name=%s, capability=%d, " |
| 1489 | "rangelow=%d, rangehigh=%d, txsubchans=%d\n", |
| 1490 | p->index, p->name, p->capability, p->rangelow, |
| 1491 | p->rangehigh, p->txsubchans); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1492 | ret = ops->vidioc_s_modulator(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | case VIDIOC_G_CROP: |
| 1496 | { |
| 1497 | struct v4l2_crop *p = arg; |
| 1498 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1499 | if (!ops->vidioc_g_crop) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1500 | break; |
Mauro Carvalho Chehab | a56a18c | 2008-11-11 21:15:03 -0300 | [diff] [blame] | 1501 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1502 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1503 | ret = ops->vidioc_g_crop(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1504 | if (!ret) |
| 1505 | dbgrect(vfd, "", &p->c); |
| 1506 | break; |
| 1507 | } |
| 1508 | case VIDIOC_S_CROP: |
| 1509 | { |
| 1510 | struct v4l2_crop *p = arg; |
| 1511 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1512 | if (!ops->vidioc_s_crop) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1513 | break; |
| 1514 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
| 1515 | dbgrect(vfd, "", &p->c); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1516 | ret = ops->vidioc_s_crop(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1517 | break; |
| 1518 | } |
| 1519 | case VIDIOC_CROPCAP: |
| 1520 | { |
| 1521 | struct v4l2_cropcap *p = arg; |
| 1522 | |
| 1523 | /*FIXME: Should also show v4l2_fract pixelaspect */ |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1524 | if (!ops->vidioc_cropcap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1525 | break; |
Mauro Carvalho Chehab | a56a18c | 2008-11-11 21:15:03 -0300 | [diff] [blame] | 1526 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1527 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1528 | ret = ops->vidioc_cropcap(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1529 | if (!ret) { |
| 1530 | dbgrect(vfd, "bounds ", &p->bounds); |
| 1531 | dbgrect(vfd, "defrect ", &p->defrect); |
| 1532 | } |
| 1533 | break; |
| 1534 | } |
| 1535 | case VIDIOC_G_JPEGCOMP: |
| 1536 | { |
| 1537 | struct v4l2_jpegcompression *p = arg; |
| 1538 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1539 | if (!ops->vidioc_g_jpegcomp) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1540 | break; |
Mauro Carvalho Chehab | a56a18c | 2008-11-11 21:15:03 -0300 | [diff] [blame] | 1541 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1542 | ret = ops->vidioc_g_jpegcomp(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1543 | if (!ret) |
| 1544 | dbgarg(cmd, "quality=%d, APPn=%d, " |
| 1545 | "APP_len=%d, COM_len=%d, " |
| 1546 | "jpeg_markers=%d\n", |
| 1547 | p->quality, p->APPn, p->APP_len, |
| 1548 | p->COM_len, p->jpeg_markers); |
| 1549 | break; |
| 1550 | } |
| 1551 | case VIDIOC_S_JPEGCOMP: |
| 1552 | { |
| 1553 | struct v4l2_jpegcompression *p = arg; |
| 1554 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1555 | if (!ops->vidioc_g_jpegcomp) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1556 | break; |
| 1557 | dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, " |
| 1558 | "COM_len=%d, jpeg_markers=%d\n", |
| 1559 | p->quality, p->APPn, p->APP_len, |
| 1560 | p->COM_len, p->jpeg_markers); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1561 | ret = ops->vidioc_s_jpegcomp(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1562 | break; |
| 1563 | } |
| 1564 | case VIDIOC_G_ENC_INDEX: |
| 1565 | { |
| 1566 | struct v4l2_enc_idx *p = arg; |
| 1567 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1568 | if (!ops->vidioc_g_enc_index) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1569 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1570 | ret = ops->vidioc_g_enc_index(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1571 | if (!ret) |
| 1572 | dbgarg(cmd, "entries=%d, entries_cap=%d\n", |
| 1573 | p->entries, p->entries_cap); |
| 1574 | break; |
| 1575 | } |
| 1576 | case VIDIOC_ENCODER_CMD: |
| 1577 | { |
| 1578 | struct v4l2_encoder_cmd *p = arg; |
| 1579 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1580 | if (!ops->vidioc_encoder_cmd) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1581 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1582 | ret = ops->vidioc_encoder_cmd(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1583 | if (!ret) |
| 1584 | dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); |
| 1585 | break; |
| 1586 | } |
| 1587 | case VIDIOC_TRY_ENCODER_CMD: |
| 1588 | { |
| 1589 | struct v4l2_encoder_cmd *p = arg; |
| 1590 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1591 | if (!ops->vidioc_try_encoder_cmd) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1592 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1593 | ret = ops->vidioc_try_encoder_cmd(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1594 | if (!ret) |
| 1595 | dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); |
| 1596 | break; |
| 1597 | } |
| 1598 | case VIDIOC_G_PARM: |
| 1599 | { |
| 1600 | struct v4l2_streamparm *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1601 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1602 | if (ops->vidioc_g_parm) { |
Trent Piepho | 34796bc | 2009-03-28 22:25:35 -0300 | [diff] [blame] | 1603 | ret = check_fmt(ops, p->type); |
| 1604 | if (ret) |
| 1605 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1606 | ret = ops->vidioc_g_parm(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1607 | } else { |
Hans Verkuil | 9bedc7f | 2009-08-07 07:28:16 -0300 | [diff] [blame] | 1608 | v4l2_std_id std = vfd->current_norm; |
| 1609 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1610 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Hans Verkuil | 3f5e182 | 2010-04-06 08:14:11 -0300 | [diff] [blame] | 1611 | break; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1612 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1613 | ret = 0; |
Hans Verkuil | 9bedc7f | 2009-08-07 07:28:16 -0300 | [diff] [blame] | 1614 | if (ops->vidioc_g_std) |
| 1615 | ret = ops->vidioc_g_std(file, fh, &std); |
| 1616 | else if (std == 0) |
| 1617 | ret = -EINVAL; |
| 1618 | if (ret == 0) |
| 1619 | v4l2_video_std_frame_period(std, |
| 1620 | &p->parm.capture.timeperframe); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | dbgarg(cmd, "type=%d\n", p->type); |
| 1624 | break; |
| 1625 | } |
| 1626 | case VIDIOC_S_PARM: |
| 1627 | { |
| 1628 | struct v4l2_streamparm *p = arg; |
| 1629 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1630 | if (!ops->vidioc_s_parm) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1631 | break; |
Trent Piepho | 34796bc | 2009-03-28 22:25:35 -0300 | [diff] [blame] | 1632 | ret = check_fmt(ops, p->type); |
| 1633 | if (ret) |
| 1634 | break; |
| 1635 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1636 | dbgarg(cmd, "type=%d\n", p->type); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1637 | ret = ops->vidioc_s_parm(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1638 | break; |
| 1639 | } |
| 1640 | case VIDIOC_G_TUNER: |
| 1641 | { |
| 1642 | struct v4l2_tuner *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1643 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1644 | if (!ops->vidioc_g_tuner) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1645 | break; |
| 1646 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1647 | ret = ops->vidioc_g_tuner(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1648 | if (!ret) |
| 1649 | dbgarg(cmd, "index=%d, name=%s, type=%d, " |
| 1650 | "capability=0x%x, rangelow=%d, " |
| 1651 | "rangehigh=%d, signal=%d, afc=%d, " |
| 1652 | "rxsubchans=0x%x, audmode=%d\n", |
| 1653 | p->index, p->name, p->type, |
| 1654 | p->capability, p->rangelow, |
| 1655 | p->rangehigh, p->signal, p->afc, |
| 1656 | p->rxsubchans, p->audmode); |
| 1657 | break; |
| 1658 | } |
| 1659 | case VIDIOC_S_TUNER: |
| 1660 | { |
| 1661 | struct v4l2_tuner *p = arg; |
| 1662 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1663 | if (!ops->vidioc_s_tuner) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1664 | break; |
| 1665 | dbgarg(cmd, "index=%d, name=%s, type=%d, " |
| 1666 | "capability=0x%x, rangelow=%d, " |
| 1667 | "rangehigh=%d, signal=%d, afc=%d, " |
| 1668 | "rxsubchans=0x%x, audmode=%d\n", |
| 1669 | p->index, p->name, p->type, |
| 1670 | p->capability, p->rangelow, |
| 1671 | p->rangehigh, p->signal, p->afc, |
| 1672 | p->rxsubchans, p->audmode); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1673 | ret = ops->vidioc_s_tuner(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1674 | break; |
| 1675 | } |
| 1676 | case VIDIOC_G_FREQUENCY: |
| 1677 | { |
| 1678 | struct v4l2_frequency *p = arg; |
| 1679 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1680 | if (!ops->vidioc_g_frequency) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1681 | break; |
| 1682 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1683 | ret = ops->vidioc_g_frequency(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1684 | if (!ret) |
| 1685 | dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n", |
| 1686 | p->tuner, p->type, p->frequency); |
| 1687 | break; |
| 1688 | } |
| 1689 | case VIDIOC_S_FREQUENCY: |
| 1690 | { |
| 1691 | struct v4l2_frequency *p = arg; |
| 1692 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1693 | if (!ops->vidioc_s_frequency) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1694 | break; |
| 1695 | dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n", |
| 1696 | p->tuner, p->type, p->frequency); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1697 | ret = ops->vidioc_s_frequency(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1698 | break; |
| 1699 | } |
| 1700 | case VIDIOC_G_SLICED_VBI_CAP: |
| 1701 | { |
| 1702 | struct v4l2_sliced_vbi_cap *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1703 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1704 | if (!ops->vidioc_g_sliced_vbi_cap) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1705 | break; |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 1706 | |
| 1707 | /* Clear up to type, everything after type is zerod already */ |
| 1708 | memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type)); |
| 1709 | |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1710 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1711 | ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1712 | if (!ret) |
| 1713 | dbgarg2("service_set=%d\n", p->service_set); |
| 1714 | break; |
| 1715 | } |
| 1716 | case VIDIOC_LOG_STATUS: |
| 1717 | { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1718 | if (!ops->vidioc_log_status) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1719 | break; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1720 | ret = ops->vidioc_log_status(file, fh); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1721 | break; |
| 1722 | } |
| 1723 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1724 | case VIDIOC_DBG_G_REGISTER: |
| 1725 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1726 | struct v4l2_dbg_register *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1727 | |
| 1728 | if (!capable(CAP_SYS_ADMIN)) |
| 1729 | ret = -EPERM; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1730 | else if (ops->vidioc_g_register) |
| 1731 | ret = ops->vidioc_g_register(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | case VIDIOC_DBG_S_REGISTER: |
| 1735 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1736 | struct v4l2_dbg_register *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1737 | |
| 1738 | if (!capable(CAP_SYS_ADMIN)) |
| 1739 | ret = -EPERM; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1740 | else if (ops->vidioc_s_register) |
| 1741 | ret = ops->vidioc_s_register(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1742 | break; |
| 1743 | } |
| 1744 | #endif |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1745 | case VIDIOC_DBG_G_CHIP_IDENT: |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1746 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1747 | struct v4l2_dbg_chip_ident *p = arg; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1748 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1749 | if (!ops->vidioc_g_chip_ident) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1750 | break; |
Hans Verkuil | 80b36e0 | 2009-02-07 11:00:02 -0300 | [diff] [blame] | 1751 | p->ident = V4L2_IDENT_NONE; |
| 1752 | p->revision = 0; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1753 | ret = ops->vidioc_g_chip_ident(file, fh, p); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1754 | if (!ret) |
| 1755 | dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision); |
| 1756 | break; |
| 1757 | } |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1758 | case VIDIOC_S_HW_FREQ_SEEK: |
| 1759 | { |
| 1760 | struct v4l2_hw_freq_seek *p = arg; |
| 1761 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1762 | if (!ops->vidioc_s_hw_freq_seek) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 1763 | break; |
| 1764 | dbgarg(cmd, |
| 1765 | "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n", |
| 1766 | p->tuner, p->type, p->seek_upward, p->wrap_around); |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1767 | ret = ops->vidioc_s_hw_freq_seek(file, fh, p); |
| 1768 | break; |
| 1769 | } |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1770 | case VIDIOC_ENUM_FRAMESIZES: |
| 1771 | { |
| 1772 | struct v4l2_frmsizeenum *p = arg; |
| 1773 | |
| 1774 | if (!ops->vidioc_enum_framesizes) |
| 1775 | break; |
| 1776 | |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1777 | ret = ops->vidioc_enum_framesizes(file, fh, p); |
| 1778 | dbgarg(cmd, |
Mauro Carvalho Chehab | d1afe42 | 2009-06-21 22:37:12 -0300 | [diff] [blame] | 1779 | "index=%d, pixelformat=%c%c%c%c, type=%d ", |
| 1780 | p->index, |
| 1781 | (p->pixel_format & 0xff), |
| 1782 | (p->pixel_format >> 8) & 0xff, |
| 1783 | (p->pixel_format >> 16) & 0xff, |
| 1784 | (p->pixel_format >> 24) & 0xff, |
| 1785 | p->type); |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1786 | switch (p->type) { |
| 1787 | case V4L2_FRMSIZE_TYPE_DISCRETE: |
Mauro Carvalho Chehab | d33fbcb | 2009-07-02 17:07:32 -0300 | [diff] [blame] | 1788 | dbgarg3("width = %d, height=%d\n", |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1789 | p->discrete.width, p->discrete.height); |
| 1790 | break; |
| 1791 | case V4L2_FRMSIZE_TYPE_STEPWISE: |
Mauro Carvalho Chehab | d33fbcb | 2009-07-02 17:07:32 -0300 | [diff] [blame] | 1792 | dbgarg3("min %dx%d, max %dx%d, step %dx%d\n", |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1793 | p->stepwise.min_width, p->stepwise.min_height, |
| 1794 | p->stepwise.step_width, p->stepwise.step_height, |
| 1795 | p->stepwise.max_width, p->stepwise.max_height); |
| 1796 | break; |
| 1797 | case V4L2_FRMSIZE_TYPE_CONTINUOUS: |
Mauro Carvalho Chehab | d33fbcb | 2009-07-02 17:07:32 -0300 | [diff] [blame] | 1798 | dbgarg3("continuous\n"); |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1799 | break; |
| 1800 | default: |
Mauro Carvalho Chehab | d33fbcb | 2009-07-02 17:07:32 -0300 | [diff] [blame] | 1801 | dbgarg3("- Unknown type!\n"); |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | break; |
| 1805 | } |
| 1806 | case VIDIOC_ENUM_FRAMEINTERVALS: |
| 1807 | { |
| 1808 | struct v4l2_frmivalenum *p = arg; |
| 1809 | |
| 1810 | if (!ops->vidioc_enum_frameintervals) |
| 1811 | break; |
| 1812 | |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1813 | ret = ops->vidioc_enum_frameintervals(file, fh, p); |
| 1814 | dbgarg(cmd, |
| 1815 | "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ", |
| 1816 | p->index, p->pixel_format, |
| 1817 | p->width, p->height, p->type); |
| 1818 | switch (p->type) { |
| 1819 | case V4L2_FRMIVAL_TYPE_DISCRETE: |
| 1820 | dbgarg2("fps=%d/%d\n", |
| 1821 | p->discrete.numerator, |
| 1822 | p->discrete.denominator); |
| 1823 | break; |
| 1824 | case V4L2_FRMIVAL_TYPE_STEPWISE: |
Mauro Carvalho Chehab | 1958578 | 2008-11-12 01:03:02 -0300 | [diff] [blame] | 1825 | dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n", |
| 1826 | p->stepwise.min.numerator, |
| 1827 | p->stepwise.min.denominator, |
| 1828 | p->stepwise.max.numerator, |
| 1829 | p->stepwise.max.denominator, |
| 1830 | p->stepwise.step.numerator, |
| 1831 | p->stepwise.step.denominator); |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1832 | break; |
| 1833 | case V4L2_FRMIVAL_TYPE_CONTINUOUS: |
| 1834 | dbgarg2("continuous\n"); |
| 1835 | break; |
| 1836 | default: |
| 1837 | dbgarg2("- Unknown type!\n"); |
| 1838 | } |
| 1839 | break; |
| 1840 | } |
Muralidharan Karicheri | b6456c0 | 2009-11-19 12:00:31 -0300 | [diff] [blame] | 1841 | case VIDIOC_ENUM_DV_PRESETS: |
| 1842 | { |
| 1843 | struct v4l2_dv_enum_preset *p = arg; |
| 1844 | |
| 1845 | if (!ops->vidioc_enum_dv_presets) |
| 1846 | break; |
| 1847 | |
| 1848 | ret = ops->vidioc_enum_dv_presets(file, fh, p); |
| 1849 | if (!ret) |
| 1850 | dbgarg(cmd, |
| 1851 | "index=%d, preset=%d, name=%s, width=%d," |
| 1852 | " height=%d ", |
| 1853 | p->index, p->preset, p->name, p->width, |
| 1854 | p->height); |
| 1855 | break; |
| 1856 | } |
| 1857 | case VIDIOC_S_DV_PRESET: |
| 1858 | { |
| 1859 | struct v4l2_dv_preset *p = arg; |
| 1860 | |
| 1861 | if (!ops->vidioc_s_dv_preset) |
| 1862 | break; |
| 1863 | |
| 1864 | dbgarg(cmd, "preset=%d\n", p->preset); |
| 1865 | ret = ops->vidioc_s_dv_preset(file, fh, p); |
| 1866 | break; |
| 1867 | } |
| 1868 | case VIDIOC_G_DV_PRESET: |
| 1869 | { |
| 1870 | struct v4l2_dv_preset *p = arg; |
| 1871 | |
| 1872 | if (!ops->vidioc_g_dv_preset) |
| 1873 | break; |
| 1874 | |
| 1875 | ret = ops->vidioc_g_dv_preset(file, fh, p); |
| 1876 | if (!ret) |
| 1877 | dbgarg(cmd, "preset=%d\n", p->preset); |
| 1878 | break; |
| 1879 | } |
| 1880 | case VIDIOC_QUERY_DV_PRESET: |
| 1881 | { |
| 1882 | struct v4l2_dv_preset *p = arg; |
| 1883 | |
| 1884 | if (!ops->vidioc_query_dv_preset) |
| 1885 | break; |
| 1886 | |
| 1887 | ret = ops->vidioc_query_dv_preset(file, fh, p); |
| 1888 | if (!ret) |
| 1889 | dbgarg(cmd, "preset=%d\n", p->preset); |
| 1890 | break; |
| 1891 | } |
| 1892 | case VIDIOC_S_DV_TIMINGS: |
| 1893 | { |
| 1894 | struct v4l2_dv_timings *p = arg; |
| 1895 | |
| 1896 | if (!ops->vidioc_s_dv_timings) |
| 1897 | break; |
| 1898 | |
| 1899 | switch (p->type) { |
| 1900 | case V4L2_DV_BT_656_1120: |
| 1901 | dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld," |
| 1902 | " width=%d, height=%d, polarities=%x," |
| 1903 | " hfrontporch=%d, hsync=%d, hbackporch=%d," |
| 1904 | " vfrontporch=%d, vsync=%d, vbackporch=%d," |
| 1905 | " il_vfrontporch=%d, il_vsync=%d," |
| 1906 | " il_vbackporch=%d\n", |
| 1907 | p->bt.interlaced, p->bt.pixelclock, |
| 1908 | p->bt.width, p->bt.height, p->bt.polarities, |
| 1909 | p->bt.hfrontporch, p->bt.hsync, |
| 1910 | p->bt.hbackporch, p->bt.vfrontporch, |
| 1911 | p->bt.vsync, p->bt.vbackporch, |
| 1912 | p->bt.il_vfrontporch, p->bt.il_vsync, |
| 1913 | p->bt.il_vbackporch); |
| 1914 | ret = ops->vidioc_s_dv_timings(file, fh, p); |
| 1915 | break; |
| 1916 | default: |
| 1917 | dbgarg2("Unknown type %d!\n", p->type); |
| 1918 | break; |
| 1919 | } |
| 1920 | break; |
| 1921 | } |
| 1922 | case VIDIOC_G_DV_TIMINGS: |
| 1923 | { |
| 1924 | struct v4l2_dv_timings *p = arg; |
| 1925 | |
| 1926 | if (!ops->vidioc_g_dv_timings) |
| 1927 | break; |
| 1928 | |
| 1929 | ret = ops->vidioc_g_dv_timings(file, fh, p); |
| 1930 | if (!ret) { |
| 1931 | switch (p->type) { |
| 1932 | case V4L2_DV_BT_656_1120: |
| 1933 | dbgarg2("bt-656/1120:interlaced=%d," |
| 1934 | " pixelclock=%lld," |
| 1935 | " width=%d, height=%d, polarities=%x," |
| 1936 | " hfrontporch=%d, hsync=%d," |
| 1937 | " hbackporch=%d, vfrontporch=%d," |
| 1938 | " vsync=%d, vbackporch=%d," |
| 1939 | " il_vfrontporch=%d, il_vsync=%d," |
| 1940 | " il_vbackporch=%d\n", |
| 1941 | p->bt.interlaced, p->bt.pixelclock, |
| 1942 | p->bt.width, p->bt.height, |
| 1943 | p->bt.polarities, p->bt.hfrontporch, |
| 1944 | p->bt.hsync, p->bt.hbackporch, |
| 1945 | p->bt.vfrontporch, p->bt.vsync, |
| 1946 | p->bt.vbackporch, p->bt.il_vfrontporch, |
| 1947 | p->bt.il_vsync, p->bt.il_vbackporch); |
| 1948 | break; |
| 1949 | default: |
| 1950 | dbgarg2("Unknown type %d!\n", p->type); |
| 1951 | break; |
| 1952 | } |
| 1953 | } |
| 1954 | break; |
| 1955 | } |
Sakari Ailus | d3d7c96 | 2010-03-27 11:02:10 -0300 | [diff] [blame^] | 1956 | case VIDIOC_DQEVENT: |
| 1957 | { |
| 1958 | struct v4l2_event *ev = arg; |
Mauro Carvalho Chehab | 74d83fa | 2008-11-11 21:13:47 -0300 | [diff] [blame] | 1959 | |
Sakari Ailus | d3d7c96 | 2010-03-27 11:02:10 -0300 | [diff] [blame^] | 1960 | if (!ops->vidioc_subscribe_event) |
| 1961 | break; |
| 1962 | |
| 1963 | ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK); |
| 1964 | if (ret < 0) { |
| 1965 | dbgarg(cmd, "no pending events?"); |
| 1966 | break; |
| 1967 | } |
| 1968 | dbgarg(cmd, |
| 1969 | "pending=%d, type=0x%8.8x, sequence=%d, " |
| 1970 | "timestamp=%lu.%9.9lu ", |
| 1971 | ev->pending, ev->type, ev->sequence, |
| 1972 | ev->timestamp.tv_sec, ev->timestamp.tv_nsec); |
| 1973 | break; |
| 1974 | } |
| 1975 | case VIDIOC_SUBSCRIBE_EVENT: |
| 1976 | { |
| 1977 | struct v4l2_event_subscription *sub = arg; |
| 1978 | |
| 1979 | if (!ops->vidioc_subscribe_event) |
| 1980 | break; |
| 1981 | |
| 1982 | ret = ops->vidioc_subscribe_event(fh, sub); |
| 1983 | if (ret < 0) { |
| 1984 | dbgarg(cmd, "failed, ret=%ld", ret); |
| 1985 | break; |
| 1986 | } |
| 1987 | dbgarg(cmd, "type=0x%8.8x", sub->type); |
| 1988 | break; |
| 1989 | } |
| 1990 | case VIDIOC_UNSUBSCRIBE_EVENT: |
| 1991 | { |
| 1992 | struct v4l2_event_subscription *sub = arg; |
| 1993 | |
| 1994 | if (!ops->vidioc_unsubscribe_event) |
| 1995 | break; |
| 1996 | |
| 1997 | ret = ops->vidioc_unsubscribe_event(fh, sub); |
| 1998 | if (ret < 0) { |
| 1999 | dbgarg(cmd, "failed, ret=%ld", ret); |
| 2000 | break; |
| 2001 | } |
| 2002 | dbgarg(cmd, "type=0x%8.8x", sub->type); |
| 2003 | break; |
| 2004 | } |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2005 | default: |
| 2006 | { |
| 2007 | if (!ops->vidioc_default) |
| 2008 | break; |
| 2009 | ret = ops->vidioc_default(file, fh, cmd, arg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2010 | break; |
| 2011 | } |
| 2012 | } /* switch */ |
| 2013 | |
| 2014 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { |
| 2015 | if (ret < 0) { |
| 2016 | v4l_print_ioctl(vfd->name, cmd); |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 2017 | printk(KERN_CONT " error %ld\n", ret); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | return ret; |
| 2022 | } |
| 2023 | |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2024 | /* In some cases, only a few fields are used as input, i.e. when the app sets |
| 2025 | * "index" and then the driver fills in the rest of the structure for the thing |
| 2026 | * with that index. We only need to copy up the first non-input field. */ |
| 2027 | static unsigned long cmd_input_size(unsigned int cmd) |
| 2028 | { |
| 2029 | /* Size of structure up to and including 'field' */ |
Hans Verkuil | 9f1a693 | 2009-03-08 10:35:23 -0300 | [diff] [blame] | 2030 | #define CMDINSIZE(cmd, type, field) \ |
| 2031 | case VIDIOC_##cmd: \ |
| 2032 | return offsetof(struct v4l2_##type, field) + \ |
| 2033 | sizeof(((struct v4l2_##type *)0)->field); |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2034 | |
Hans Verkuil | 9f1a693 | 2009-03-08 10:35:23 -0300 | [diff] [blame] | 2035 | switch (cmd) { |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2036 | CMDINSIZE(ENUM_FMT, fmtdesc, type); |
| 2037 | CMDINSIZE(G_FMT, format, type); |
| 2038 | CMDINSIZE(QUERYBUF, buffer, type); |
| 2039 | CMDINSIZE(G_PARM, streamparm, type); |
| 2040 | CMDINSIZE(ENUMSTD, standard, index); |
| 2041 | CMDINSIZE(ENUMINPUT, input, index); |
| 2042 | CMDINSIZE(G_CTRL, control, id); |
| 2043 | CMDINSIZE(G_TUNER, tuner, index); |
| 2044 | CMDINSIZE(QUERYCTRL, queryctrl, id); |
| 2045 | CMDINSIZE(QUERYMENU, querymenu, index); |
| 2046 | CMDINSIZE(ENUMOUTPUT, output, index); |
| 2047 | CMDINSIZE(G_MODULATOR, modulator, index); |
| 2048 | CMDINSIZE(G_FREQUENCY, frequency, tuner); |
| 2049 | CMDINSIZE(CROPCAP, cropcap, type); |
| 2050 | CMDINSIZE(G_CROP, crop, type); |
| 2051 | CMDINSIZE(ENUMAUDIO, audio, index); |
| 2052 | CMDINSIZE(ENUMAUDOUT, audioout, index); |
| 2053 | CMDINSIZE(ENCODER_CMD, encoder_cmd, flags); |
| 2054 | CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags); |
| 2055 | CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type); |
| 2056 | CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format); |
| 2057 | CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height); |
| 2058 | default: |
| 2059 | return _IOC_SIZE(cmd); |
| 2060 | } |
| 2061 | } |
| 2062 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 2063 | long video_ioctl2(struct file *file, |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2064 | unsigned int cmd, unsigned long arg) |
| 2065 | { |
| 2066 | char sbuf[128]; |
| 2067 | void *mbuf = NULL; |
Hans Verkuil | 1d94aa3 | 2010-04-06 08:12:21 -0300 | [diff] [blame] | 2068 | void *parg = (void *)arg; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 2069 | long err = -EINVAL; |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2070 | int is_ext_ctrl; |
| 2071 | size_t ctrls_size = 0; |
| 2072 | void __user *user_ptr = NULL; |
| 2073 | |
| 2074 | #ifdef __OLD_VIDIOC_ |
| 2075 | cmd = video_fix_command(cmd); |
| 2076 | #endif |
| 2077 | is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS || |
| 2078 | cmd == VIDIOC_TRY_EXT_CTRLS); |
| 2079 | |
| 2080 | /* Copy arguments into temp kernel buffer */ |
Trent Piepho | 337f9d2 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2081 | if (_IOC_DIR(cmd) != _IOC_NONE) { |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2082 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
| 2083 | parg = sbuf; |
| 2084 | } else { |
| 2085 | /* too big to allocate from stack */ |
| 2086 | mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); |
| 2087 | if (NULL == mbuf) |
| 2088 | return -ENOMEM; |
| 2089 | parg = mbuf; |
| 2090 | } |
| 2091 | |
| 2092 | err = -EFAULT; |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2093 | if (_IOC_DIR(cmd) & _IOC_WRITE) { |
| 2094 | unsigned long n = cmd_input_size(cmd); |
| 2095 | |
| 2096 | if (copy_from_user(parg, (void __user *)arg, n)) |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2097 | goto out; |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2098 | |
| 2099 | /* zero out anything we don't copy from userspace */ |
| 2100 | if (n < _IOC_SIZE(cmd)) |
| 2101 | memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n); |
Trent Piepho | 337f9d2 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2102 | } else { |
| 2103 | /* read-only ioctl */ |
| 2104 | memset(parg, 0, _IOC_SIZE(cmd)); |
Trent Piepho | 19c96e4 | 2009-03-04 01:21:02 -0300 | [diff] [blame] | 2105 | } |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | if (is_ext_ctrl) { |
| 2109 | struct v4l2_ext_controls *p = parg; |
| 2110 | |
| 2111 | /* In case of an error, tell the caller that it wasn't |
| 2112 | a specific control that caused it. */ |
| 2113 | p->error_idx = p->count; |
| 2114 | user_ptr = (void __user *)p->controls; |
| 2115 | if (p->count) { |
| 2116 | ctrls_size = sizeof(struct v4l2_ext_control) * p->count; |
| 2117 | /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */ |
| 2118 | mbuf = kmalloc(ctrls_size, GFP_KERNEL); |
| 2119 | err = -ENOMEM; |
| 2120 | if (NULL == mbuf) |
| 2121 | goto out_ext_ctrl; |
| 2122 | err = -EFAULT; |
| 2123 | if (copy_from_user(mbuf, user_ptr, ctrls_size)) |
| 2124 | goto out_ext_ctrl; |
| 2125 | p->controls = mbuf; |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | /* Handles IOCTL */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 2130 | err = __video_do_ioctl(file, cmd, parg); |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 2131 | if (err == -ENOIOCTLCMD) |
| 2132 | err = -EINVAL; |
| 2133 | if (is_ext_ctrl) { |
| 2134 | struct v4l2_ext_controls *p = parg; |
| 2135 | |
| 2136 | p->controls = (void *)user_ptr; |
| 2137 | if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size)) |
| 2138 | err = -EFAULT; |
| 2139 | goto out_ext_ctrl; |
| 2140 | } |
| 2141 | if (err < 0) |
| 2142 | goto out; |
| 2143 | |
| 2144 | out_ext_ctrl: |
| 2145 | /* Copy results into user buffer */ |
| 2146 | switch (_IOC_DIR(cmd)) { |
| 2147 | case _IOC_READ: |
| 2148 | case (_IOC_WRITE | _IOC_READ): |
| 2149 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) |
| 2150 | err = -EFAULT; |
| 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | out: |
| 2155 | kfree(mbuf); |
| 2156 | return err; |
| 2157 | } |
Mauro Carvalho Chehab | 8a522c9 | 2008-10-21 11:58:39 -0300 | [diff] [blame] | 2158 | EXPORT_SYMBOL(video_ioctl2); |