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