Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Video for Linux Two |
| 4 | * Backward Compatibility Layer |
| 5 | * |
| 6 | * Support subroutines for providing V4L2 drivers with backward |
| 7 | * compatibility with applications using the old API. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | * |
Mauro Carvalho Chehab | 43db48d | 2007-01-09 11:20:59 -0300 | [diff] [blame] | 14 | * Author: Bill Dirks <bill@thedirks.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * et al. |
| 16 | * |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/mm.h> |
| 26 | #include <linux/fs.h> |
| 27 | #include <linux/file.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/videodev.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 32 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 33 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include <asm/uaccess.h> |
| 36 | #include <asm/system.h> |
| 37 | #include <asm/pgtable.h> |
| 38 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 39 | static unsigned int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | module_param(debug, int, 0644); |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 41 | MODULE_PARM_DESC(debug, "enable debug messages"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | MODULE_AUTHOR("Bill Dirks"); |
| 43 | MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers."); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 46 | #define dprintk(fmt, arg...) \ |
| 47 | do { \ |
| 48 | if (debug) \ |
| 49 | printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\ |
| 50 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * I O C T L T R A N S L A T I O N |
| 54 | * |
| 55 | * From here on down is the code for translating the numerous |
| 56 | * ioctl commands from the old API to the new API. |
| 57 | */ |
| 58 | |
| 59 | static int |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 60 | get_v4l_control(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | int cid, |
| 62 | v4l2_kioctl drv) |
| 63 | { |
| 64 | struct v4l2_queryctrl qctrl2; |
| 65 | struct v4l2_control ctrl2; |
| 66 | int err; |
| 67 | |
| 68 | qctrl2.id = cid; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 69 | err = drv(file, VIDIOC_QUERYCTRL, &qctrl2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (err < 0) |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 71 | dprintk("VIDIOC_QUERYCTRL: %d\n", err); |
| 72 | if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | ctrl2.id = qctrl2.id; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 74 | err = drv(file, VIDIOC_G_CTRL, &ctrl2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (err < 0) { |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 76 | dprintk("VIDIOC_G_CTRL: %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return 0; |
| 78 | } |
Julia Lawall | 75b697f | 2009-08-01 16:48:41 -0300 | [diff] [blame] | 79 | return DIV_ROUND_CLOSEST((ctrl2.value-qctrl2.minimum) * 65535, |
| 80 | qctrl2.maximum - qctrl2.minimum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static int |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 86 | set_v4l_control(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | int cid, |
| 88 | int value, |
| 89 | v4l2_kioctl drv) |
| 90 | { |
| 91 | struct v4l2_queryctrl qctrl2; |
| 92 | struct v4l2_control ctrl2; |
| 93 | int err; |
| 94 | |
| 95 | qctrl2.id = cid; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 96 | err = drv(file, VIDIOC_QUERYCTRL, &qctrl2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (err < 0) |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 98 | dprintk("VIDIOC_QUERYCTRL: %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (err == 0 && |
| 100 | !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) && |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 101 | !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (value < 0) |
| 103 | value = 0; |
| 104 | if (value > 65535) |
| 105 | value = 65535; |
| 106 | if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN) |
| 107 | value = 65535; |
| 108 | ctrl2.id = qctrl2.id; |
| 109 | ctrl2.value = |
| 110 | (value * (qctrl2.maximum - qctrl2.minimum) |
| 111 | + 32767) |
| 112 | / 65535; |
| 113 | ctrl2.value += qctrl2.minimum; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 114 | err = drv(file, VIDIOC_S_CTRL, &ctrl2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (err < 0) |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 116 | dprintk("VIDIOC_S_CTRL: %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* ----------------------------------------------------------------- */ |
| 122 | |
Tobias Klauser | c81010b | 2008-04-21 22:30:21 +0000 | [diff] [blame] | 123 | static const unsigned int palette2pixelformat[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY, |
| 125 | [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555, |
| 126 | [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565, |
| 127 | [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24, |
| 128 | [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32, |
| 129 | /* yuv packed pixel */ |
| 130 | [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV, |
| 131 | [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV, |
| 132 | [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY, |
| 133 | /* yuv planar */ |
| 134 | [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410, |
| 135 | [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420, |
| 136 | [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420, |
| 137 | [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P, |
| 138 | [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P, |
| 139 | }; |
| 140 | |
Ralf Baechle | e8c4431 | 2007-10-18 03:07:07 -0700 | [diff] [blame] | 141 | static unsigned int __pure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | palette_to_pixelformat(unsigned int palette) |
| 143 | { |
| 144 | if (palette < ARRAY_SIZE(palette2pixelformat)) |
| 145 | return palette2pixelformat[palette]; |
| 146 | else |
| 147 | return 0; |
| 148 | } |
| 149 | |
Trent Piepho | 5f12491 | 2007-04-27 22:56:28 -0300 | [diff] [blame] | 150 | static unsigned int __attribute_const__ |
| 151 | pixelformat_to_palette(unsigned int pixelformat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | int palette = 0; |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 154 | switch (pixelformat) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | case V4L2_PIX_FMT_GREY: |
| 156 | palette = VIDEO_PALETTE_GREY; |
| 157 | break; |
| 158 | case V4L2_PIX_FMT_RGB555: |
| 159 | palette = VIDEO_PALETTE_RGB555; |
| 160 | break; |
| 161 | case V4L2_PIX_FMT_RGB565: |
| 162 | palette = VIDEO_PALETTE_RGB565; |
| 163 | break; |
| 164 | case V4L2_PIX_FMT_BGR24: |
| 165 | palette = VIDEO_PALETTE_RGB24; |
| 166 | break; |
| 167 | case V4L2_PIX_FMT_BGR32: |
| 168 | palette = VIDEO_PALETTE_RGB32; |
| 169 | break; |
| 170 | /* yuv packed pixel */ |
| 171 | case V4L2_PIX_FMT_YUYV: |
| 172 | palette = VIDEO_PALETTE_YUYV; |
| 173 | break; |
| 174 | case V4L2_PIX_FMT_UYVY: |
| 175 | palette = VIDEO_PALETTE_UYVY; |
| 176 | break; |
| 177 | /* yuv planar */ |
| 178 | case V4L2_PIX_FMT_YUV410: |
| 179 | palette = VIDEO_PALETTE_YUV420; |
| 180 | break; |
| 181 | case V4L2_PIX_FMT_YUV420: |
| 182 | palette = VIDEO_PALETTE_YUV420; |
| 183 | break; |
| 184 | case V4L2_PIX_FMT_YUV411P: |
| 185 | palette = VIDEO_PALETTE_YUV411P; |
| 186 | break; |
| 187 | case V4L2_PIX_FMT_YUV422P: |
| 188 | palette = VIDEO_PALETTE_YUV422P; |
| 189 | break; |
| 190 | } |
| 191 | return palette; |
| 192 | } |
| 193 | |
| 194 | /* ----------------------------------------------------------------- */ |
| 195 | |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 196 | static int poll_one(struct file *file, struct poll_wqueues *pwq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | int retval = 1; |
| 199 | poll_table *table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 201 | poll_initwait(pwq); |
| 202 | table = &pwq->pt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | for (;;) { |
| 204 | int mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | mask = file->f_op->poll(file, table); |
| 206 | if (mask & POLLIN) |
| 207 | break; |
| 208 | table = NULL; |
| 209 | if (signal_pending(current)) { |
| 210 | retval = -ERESTARTSYS; |
| 211 | break; |
| 212 | } |
Tejun Heo | 5f820f6 | 2009-01-06 14:40:59 -0800 | [diff] [blame] | 213 | poll_schedule(pwq, TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 215 | poll_freewait(pwq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return retval; |
| 217 | } |
| 218 | |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 219 | static int count_inputs( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 220 | struct file *file, |
| 221 | v4l2_kioctl drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | struct v4l2_input input2; |
| 224 | int i; |
| 225 | |
| 226 | for (i = 0;; i++) { |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 227 | memset(&input2, 0, sizeof(input2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | input2.index = i; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 229 | if (0 != drv(file, VIDIOC_ENUMINPUT, &input2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | return i; |
| 233 | } |
| 234 | |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 235 | static int check_size( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 236 | struct file *file, |
| 237 | v4l2_kioctl drv, |
| 238 | int *maxw, |
| 239 | int *maxh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
| 241 | struct v4l2_fmtdesc desc2; |
| 242 | struct v4l2_format fmt2; |
| 243 | |
Marcin Slusarz | 8b3b90a | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 244 | memset(&desc2, 0, sizeof(desc2)); |
| 245 | memset(&fmt2, 0, sizeof(fmt2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 248 | if (0 != drv(file, VIDIOC_ENUM_FMT, &desc2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | goto done; |
| 250 | |
| 251 | fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 252 | fmt2.fmt.pix.width = 10000; |
| 253 | fmt2.fmt.pix.height = 10000; |
| 254 | fmt2.fmt.pix.pixelformat = desc2.pixelformat; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 255 | if (0 != drv(file, VIDIOC_TRY_FMT, &fmt2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | goto done; |
| 257 | |
| 258 | *maxw = fmt2.fmt.pix.width; |
| 259 | *maxh = fmt2.fmt.pix.height; |
| 260 | |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 261 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | /* ----------------------------------------------------------------- */ |
| 266 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 267 | static noinline long v4l1_compat_get_capabilities( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 268 | struct video_capability *cap, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 269 | struct file *file, |
| 270 | v4l2_kioctl drv) |
| 271 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 272 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 273 | struct v4l2_framebuffer fbuf; |
| 274 | struct v4l2_capability *cap2; |
| 275 | |
| 276 | cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL); |
| 277 | if (!cap2) { |
| 278 | err = -ENOMEM; |
| 279 | return err; |
| 280 | } |
| 281 | memset(cap, 0, sizeof(*cap)); |
| 282 | memset(&fbuf, 0, sizeof(fbuf)); |
| 283 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 284 | err = drv(file, VIDIOC_QUERYCAP, cap2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 285 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 286 | dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 287 | goto done; |
| 288 | } |
| 289 | if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) { |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 290 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 291 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 292 | dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 293 | memset(&fbuf, 0, sizeof(fbuf)); |
| 294 | } |
| 295 | err = 0; |
| 296 | } |
| 297 | |
| 298 | memcpy(cap->name, cap2->card, |
| 299 | min(sizeof(cap->name), sizeof(cap2->card))); |
| 300 | cap->name[sizeof(cap->name) - 1] = 0; |
| 301 | if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE) |
| 302 | cap->type |= VID_TYPE_CAPTURE; |
| 303 | if (cap2->capabilities & V4L2_CAP_TUNER) |
| 304 | cap->type |= VID_TYPE_TUNER; |
| 305 | if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE) |
| 306 | cap->type |= VID_TYPE_TELETEXT; |
| 307 | if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) |
| 308 | cap->type |= VID_TYPE_OVERLAY; |
| 309 | if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING) |
| 310 | cap->type |= VID_TYPE_CLIPPING; |
| 311 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 312 | cap->channels = count_inputs(file, drv); |
| 313 | check_size(file, drv, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 314 | &cap->maxwidth, &cap->maxheight); |
| 315 | cap->audios = 0; /* FIXME */ |
| 316 | cap->minwidth = 48; /* FIXME */ |
| 317 | cap->minheight = 32; /* FIXME */ |
| 318 | |
| 319 | done: |
| 320 | kfree(cap2); |
| 321 | return err; |
| 322 | } |
| 323 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 324 | static noinline long v4l1_compat_get_frame_buffer( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 325 | struct video_buffer *buffer, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 326 | struct file *file, |
| 327 | v4l2_kioctl drv) |
| 328 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 329 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 330 | struct v4l2_framebuffer fbuf; |
| 331 | |
| 332 | memset(buffer, 0, sizeof(*buffer)); |
| 333 | memset(&fbuf, 0, sizeof(fbuf)); |
| 334 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 335 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 336 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 337 | dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 338 | goto done; |
| 339 | } |
| 340 | buffer->base = fbuf.base; |
| 341 | buffer->height = fbuf.fmt.height; |
| 342 | buffer->width = fbuf.fmt.width; |
| 343 | |
| 344 | switch (fbuf.fmt.pixelformat) { |
| 345 | case V4L2_PIX_FMT_RGB332: |
| 346 | buffer->depth = 8; |
| 347 | break; |
| 348 | case V4L2_PIX_FMT_RGB555: |
| 349 | buffer->depth = 15; |
| 350 | break; |
| 351 | case V4L2_PIX_FMT_RGB565: |
| 352 | buffer->depth = 16; |
| 353 | break; |
| 354 | case V4L2_PIX_FMT_BGR24: |
| 355 | buffer->depth = 24; |
| 356 | break; |
| 357 | case V4L2_PIX_FMT_BGR32: |
| 358 | buffer->depth = 32; |
| 359 | break; |
| 360 | default: |
| 361 | buffer->depth = 0; |
| 362 | } |
| 363 | if (fbuf.fmt.bytesperline) { |
| 364 | buffer->bytesperline = fbuf.fmt.bytesperline; |
| 365 | if (!buffer->depth && buffer->width) |
| 366 | buffer->depth = ((fbuf.fmt.bytesperline<<3) |
| 367 | + (buffer->width-1)) |
| 368 | / buffer->width; |
| 369 | } else { |
| 370 | buffer->bytesperline = |
| 371 | (buffer->width * buffer->depth + 7) & 7; |
| 372 | buffer->bytesperline >>= 3; |
| 373 | } |
| 374 | done: |
| 375 | return err; |
| 376 | } |
| 377 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 378 | static noinline long v4l1_compat_set_frame_buffer( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 379 | struct video_buffer *buffer, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 380 | struct file *file, |
| 381 | v4l2_kioctl drv) |
| 382 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 383 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 384 | struct v4l2_framebuffer fbuf; |
| 385 | |
| 386 | memset(&fbuf, 0, sizeof(fbuf)); |
| 387 | fbuf.base = buffer->base; |
| 388 | fbuf.fmt.height = buffer->height; |
| 389 | fbuf.fmt.width = buffer->width; |
| 390 | switch (buffer->depth) { |
| 391 | case 8: |
| 392 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332; |
| 393 | break; |
| 394 | case 15: |
| 395 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555; |
| 396 | break; |
| 397 | case 16: |
| 398 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565; |
| 399 | break; |
| 400 | case 24: |
| 401 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24; |
| 402 | break; |
| 403 | case 32: |
| 404 | fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32; |
| 405 | break; |
| 406 | } |
| 407 | fbuf.fmt.bytesperline = buffer->bytesperline; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 408 | err = drv(file, VIDIOC_S_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 409 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 410 | dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 411 | return err; |
| 412 | } |
| 413 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 414 | static noinline long v4l1_compat_get_win_cap_dimensions( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 415 | struct video_window *win, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 416 | struct file *file, |
| 417 | v4l2_kioctl drv) |
| 418 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 419 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 420 | struct v4l2_format *fmt; |
| 421 | |
| 422 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 423 | if (!fmt) { |
| 424 | err = -ENOMEM; |
| 425 | return err; |
| 426 | } |
| 427 | memset(win, 0, sizeof(*win)); |
| 428 | |
| 429 | fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 430 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 431 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 432 | dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 433 | if (err == 0) { |
| 434 | win->x = fmt->fmt.win.w.left; |
| 435 | win->y = fmt->fmt.win.w.top; |
| 436 | win->width = fmt->fmt.win.w.width; |
| 437 | win->height = fmt->fmt.win.w.height; |
| 438 | win->chromakey = fmt->fmt.win.chromakey; |
| 439 | win->clips = NULL; |
| 440 | win->clipcount = 0; |
| 441 | goto done; |
| 442 | } |
| 443 | |
| 444 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 445 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 446 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 447 | dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 448 | goto done; |
| 449 | } |
| 450 | win->x = 0; |
| 451 | win->y = 0; |
| 452 | win->width = fmt->fmt.pix.width; |
| 453 | win->height = fmt->fmt.pix.height; |
| 454 | win->chromakey = 0; |
| 455 | win->clips = NULL; |
| 456 | win->clipcount = 0; |
| 457 | done: |
| 458 | kfree(fmt); |
| 459 | return err; |
| 460 | } |
| 461 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 462 | static noinline long v4l1_compat_set_win_cap_dimensions( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 463 | struct video_window *win, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 464 | struct file *file, |
| 465 | v4l2_kioctl drv) |
| 466 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 467 | long err, err1, err2; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 468 | struct v4l2_format *fmt; |
| 469 | |
| 470 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 471 | if (!fmt) { |
| 472 | err = -ENOMEM; |
| 473 | return err; |
| 474 | } |
| 475 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 476 | drv(file, VIDIOC_STREAMOFF, &fmt->type); |
| 477 | err1 = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 478 | if (err1 < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 479 | dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %ld\n", err1); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 480 | if (err1 == 0) { |
| 481 | fmt->fmt.pix.width = win->width; |
| 482 | fmt->fmt.pix.height = win->height; |
| 483 | fmt->fmt.pix.field = V4L2_FIELD_ANY; |
| 484 | fmt->fmt.pix.bytesperline = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 485 | err = drv(file, VIDIOC_S_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 486 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 487 | dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %ld\n", |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 488 | err); |
| 489 | win->width = fmt->fmt.pix.width; |
| 490 | win->height = fmt->fmt.pix.height; |
| 491 | } |
| 492 | |
| 493 | memset(fmt, 0, sizeof(*fmt)); |
| 494 | fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY; |
| 495 | fmt->fmt.win.w.left = win->x; |
| 496 | fmt->fmt.win.w.top = win->y; |
| 497 | fmt->fmt.win.w.width = win->width; |
| 498 | fmt->fmt.win.w.height = win->height; |
| 499 | fmt->fmt.win.chromakey = win->chromakey; |
| 500 | fmt->fmt.win.clips = (void __user *)win->clips; |
| 501 | fmt->fmt.win.clipcount = win->clipcount; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 502 | err2 = drv(file, VIDIOC_S_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 503 | if (err2 < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 504 | dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %ld\n", err2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 505 | |
| 506 | if (err1 != 0 && err2 != 0) |
| 507 | err = err1; |
| 508 | else |
| 509 | err = 0; |
| 510 | kfree(fmt); |
| 511 | return err; |
| 512 | } |
| 513 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 514 | static noinline long v4l1_compat_turn_preview_on_off( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 515 | int *on, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 516 | struct file *file, |
| 517 | v4l2_kioctl drv) |
| 518 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 519 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 520 | enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 521 | |
| 522 | if (0 == *on) { |
| 523 | /* dirty hack time. But v4l1 has no STREAMOFF |
| 524 | * equivalent in the API, and this one at |
| 525 | * least comes close ... */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 526 | drv(file, VIDIOC_STREAMOFF, &captype); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 527 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 528 | err = drv(file, VIDIOC_OVERLAY, on); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 529 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 530 | dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 531 | return err; |
| 532 | } |
| 533 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 534 | static noinline long v4l1_compat_get_input_info( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 535 | struct video_channel *chan, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 536 | struct file *file, |
| 537 | v4l2_kioctl drv) |
| 538 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 539 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 540 | struct v4l2_input input2; |
| 541 | v4l2_std_id sid; |
| 542 | |
| 543 | memset(&input2, 0, sizeof(input2)); |
| 544 | input2.index = chan->channel; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 545 | err = drv(file, VIDIOC_ENUMINPUT, &input2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 546 | if (err < 0) { |
| 547 | dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: " |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 548 | "channel=%d err=%ld\n", chan->channel, err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 549 | goto done; |
| 550 | } |
| 551 | chan->channel = input2.index; |
| 552 | memcpy(chan->name, input2.name, |
| 553 | min(sizeof(chan->name), sizeof(input2.name))); |
| 554 | chan->name[sizeof(chan->name) - 1] = 0; |
| 555 | chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0; |
| 556 | chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0; |
| 557 | switch (input2.type) { |
| 558 | case V4L2_INPUT_TYPE_TUNER: |
| 559 | chan->type = VIDEO_TYPE_TV; |
| 560 | break; |
| 561 | default: |
| 562 | case V4L2_INPUT_TYPE_CAMERA: |
| 563 | chan->type = VIDEO_TYPE_CAMERA; |
| 564 | break; |
| 565 | } |
| 566 | chan->norm = 0; |
Hans Verkuil | 707ca1e | 2009-09-15 08:08:20 -0300 | [diff] [blame] | 567 | /* Note: G_STD might not be present for radio receivers, |
| 568 | * so we should ignore any errors. */ |
| 569 | if (drv(file, VIDIOC_G_STD, &sid) == 0) { |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 570 | if (sid & V4L2_STD_PAL) |
| 571 | chan->norm = VIDEO_MODE_PAL; |
| 572 | if (sid & V4L2_STD_NTSC) |
| 573 | chan->norm = VIDEO_MODE_NTSC; |
| 574 | if (sid & V4L2_STD_SECAM) |
| 575 | chan->norm = VIDEO_MODE_SECAM; |
Russell King | 9fc4d21 | 2009-03-29 08:12:27 -0300 | [diff] [blame] | 576 | if (sid == V4L2_STD_ALL) |
| 577 | chan->norm = VIDEO_MODE_AUTO; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 578 | } |
| 579 | done: |
| 580 | return err; |
| 581 | } |
| 582 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 583 | static noinline long v4l1_compat_set_input( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 584 | struct video_channel *chan, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 585 | struct file *file, |
| 586 | v4l2_kioctl drv) |
| 587 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 588 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 589 | v4l2_std_id sid = 0; |
| 590 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 591 | err = drv(file, VIDIOC_S_INPUT, &chan->channel); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 592 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 593 | dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 594 | switch (chan->norm) { |
| 595 | case VIDEO_MODE_PAL: |
| 596 | sid = V4L2_STD_PAL; |
| 597 | break; |
| 598 | case VIDEO_MODE_NTSC: |
| 599 | sid = V4L2_STD_NTSC; |
| 600 | break; |
| 601 | case VIDEO_MODE_SECAM: |
| 602 | sid = V4L2_STD_SECAM; |
| 603 | break; |
Russell King | 9fc4d21 | 2009-03-29 08:12:27 -0300 | [diff] [blame] | 604 | case VIDEO_MODE_AUTO: |
| 605 | sid = V4L2_STD_ALL; |
| 606 | break; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 607 | } |
| 608 | if (0 != sid) { |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 609 | err = drv(file, VIDIOC_S_STD, &sid); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 610 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 611 | dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 612 | } |
| 613 | return err; |
| 614 | } |
| 615 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 616 | static noinline long v4l1_compat_get_picture( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 617 | struct video_picture *pict, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 618 | struct file *file, |
| 619 | v4l2_kioctl drv) |
| 620 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 621 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 622 | struct v4l2_format *fmt; |
| 623 | |
| 624 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 625 | if (!fmt) { |
| 626 | err = -ENOMEM; |
| 627 | return err; |
| 628 | } |
| 629 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 630 | pict->brightness = get_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 631 | V4L2_CID_BRIGHTNESS, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 632 | pict->hue = get_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 633 | V4L2_CID_HUE, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 634 | pict->contrast = get_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 635 | V4L2_CID_CONTRAST, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 636 | pict->colour = get_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 637 | V4L2_CID_SATURATION, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 638 | pict->whiteness = get_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 639 | V4L2_CID_WHITENESS, drv); |
| 640 | |
| 641 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 642 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 643 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 644 | dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 645 | goto done; |
| 646 | } |
| 647 | |
| 648 | pict->depth = ((fmt->fmt.pix.bytesperline << 3) |
| 649 | + (fmt->fmt.pix.width - 1)) |
| 650 | / fmt->fmt.pix.width; |
| 651 | pict->palette = pixelformat_to_palette( |
| 652 | fmt->fmt.pix.pixelformat); |
| 653 | done: |
| 654 | kfree(fmt); |
| 655 | return err; |
| 656 | } |
| 657 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 658 | static noinline long v4l1_compat_set_picture( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 659 | struct video_picture *pict, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 660 | struct file *file, |
| 661 | v4l2_kioctl drv) |
| 662 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 663 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 664 | struct v4l2_framebuffer fbuf; |
| 665 | int mem_err = 0, ovl_err = 0; |
| 666 | struct v4l2_format *fmt; |
| 667 | |
| 668 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 669 | if (!fmt) { |
| 670 | err = -ENOMEM; |
| 671 | return err; |
| 672 | } |
| 673 | memset(&fbuf, 0, sizeof(fbuf)); |
| 674 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 675 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 676 | V4L2_CID_BRIGHTNESS, pict->brightness, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 677 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 678 | V4L2_CID_HUE, pict->hue, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 679 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 680 | V4L2_CID_CONTRAST, pict->contrast, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 681 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 682 | V4L2_CID_SATURATION, pict->colour, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 683 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 684 | V4L2_CID_WHITENESS, pict->whiteness, drv); |
| 685 | /* |
| 686 | * V4L1 uses this ioctl to set both memory capture and overlay |
| 687 | * pixel format, while V4L2 has two different ioctls for this. |
| 688 | * Some cards may not support one or the other, and may support |
| 689 | * different pixel formats for memory vs overlay. |
| 690 | */ |
| 691 | |
| 692 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 693 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 694 | /* If VIDIOC_G_FMT failed, then the driver likely doesn't |
| 695 | support memory capture. Trying to set the memory capture |
| 696 | parameters would be pointless. */ |
| 697 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 698 | dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 699 | mem_err = -1000; /* didn't even try */ |
| 700 | } else if (fmt->fmt.pix.pixelformat != |
| 701 | palette_to_pixelformat(pict->palette)) { |
| 702 | fmt->fmt.pix.pixelformat = palette_to_pixelformat( |
| 703 | pict->palette); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 704 | mem_err = drv(file, VIDIOC_S_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 705 | if (mem_err < 0) |
| 706 | dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n", |
| 707 | mem_err); |
| 708 | } |
| 709 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 710 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 711 | /* If VIDIOC_G_FBUF failed, then the driver likely doesn't |
| 712 | support overlay. Trying to set the overlay parameters |
| 713 | would be quite pointless. */ |
| 714 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 715 | dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 716 | ovl_err = -1000; /* didn't even try */ |
| 717 | } else if (fbuf.fmt.pixelformat != |
| 718 | palette_to_pixelformat(pict->palette)) { |
| 719 | fbuf.fmt.pixelformat = palette_to_pixelformat( |
| 720 | pict->palette); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 721 | ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 722 | if (ovl_err < 0) |
| 723 | dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n", |
| 724 | ovl_err); |
| 725 | } |
| 726 | if (ovl_err < 0 && mem_err < 0) { |
| 727 | /* ioctl failed, couldn't set either parameter */ |
| 728 | if (mem_err != -1000) |
| 729 | err = mem_err; |
| 730 | else if (ovl_err == -EPERM) |
| 731 | err = 0; |
| 732 | else |
| 733 | err = ovl_err; |
| 734 | } else |
| 735 | err = 0; |
| 736 | kfree(fmt); |
| 737 | return err; |
| 738 | } |
| 739 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 740 | static noinline long v4l1_compat_get_tuner( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 741 | struct video_tuner *tun, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 742 | struct file *file, |
| 743 | v4l2_kioctl drv) |
| 744 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 745 | long err; |
| 746 | int i; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 747 | struct v4l2_tuner tun2; |
| 748 | struct v4l2_standard std2; |
| 749 | v4l2_std_id sid; |
| 750 | |
| 751 | memset(&tun2, 0, sizeof(tun2)); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 752 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 753 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 754 | dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 755 | goto done; |
| 756 | } |
| 757 | memcpy(tun->name, tun2.name, |
| 758 | min(sizeof(tun->name), sizeof(tun2.name))); |
| 759 | tun->name[sizeof(tun->name) - 1] = 0; |
| 760 | tun->rangelow = tun2.rangelow; |
| 761 | tun->rangehigh = tun2.rangehigh; |
| 762 | tun->flags = 0; |
| 763 | tun->mode = VIDEO_MODE_AUTO; |
| 764 | |
| 765 | for (i = 0; i < 64; i++) { |
| 766 | memset(&std2, 0, sizeof(std2)); |
| 767 | std2.index = i; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 768 | if (0 != drv(file, VIDIOC_ENUMSTD, &std2)) |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 769 | break; |
| 770 | if (std2.id & V4L2_STD_PAL) |
| 771 | tun->flags |= VIDEO_TUNER_PAL; |
| 772 | if (std2.id & V4L2_STD_NTSC) |
| 773 | tun->flags |= VIDEO_TUNER_NTSC; |
| 774 | if (std2.id & V4L2_STD_SECAM) |
| 775 | tun->flags |= VIDEO_TUNER_SECAM; |
| 776 | } |
| 777 | |
Hans Verkuil | 707ca1e | 2009-09-15 08:08:20 -0300 | [diff] [blame] | 778 | /* Note: G_STD might not be present for radio receivers, |
| 779 | * so we should ignore any errors. */ |
| 780 | if (drv(file, VIDIOC_G_STD, &sid) == 0) { |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 781 | if (sid & V4L2_STD_PAL) |
| 782 | tun->mode = VIDEO_MODE_PAL; |
| 783 | if (sid & V4L2_STD_NTSC) |
| 784 | tun->mode = VIDEO_MODE_NTSC; |
| 785 | if (sid & V4L2_STD_SECAM) |
| 786 | tun->mode = VIDEO_MODE_SECAM; |
| 787 | } |
| 788 | |
| 789 | if (tun2.capability & V4L2_TUNER_CAP_LOW) |
| 790 | tun->flags |= VIDEO_TUNER_LOW; |
| 791 | if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO) |
| 792 | tun->flags |= VIDEO_TUNER_STEREO_ON; |
| 793 | tun->signal = tun2.signal; |
| 794 | done: |
| 795 | return err; |
| 796 | } |
| 797 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 798 | static noinline long v4l1_compat_select_tuner( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 799 | struct video_tuner *tun, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 800 | struct file *file, |
| 801 | v4l2_kioctl drv) |
| 802 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 803 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 804 | struct v4l2_tuner t;/*84 bytes on x86_64*/ |
| 805 | memset(&t, 0, sizeof(t)); |
| 806 | |
| 807 | t.index = tun->tuner; |
| 808 | |
Russell King | 9fc4d21 | 2009-03-29 08:12:27 -0300 | [diff] [blame] | 809 | err = drv(file, VIDIOC_S_TUNER, &t); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 810 | if (err < 0) |
Russell King | 9fc4d21 | 2009-03-29 08:12:27 -0300 | [diff] [blame] | 811 | dprintk("VIDIOCSTUNER / VIDIOC_S_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 812 | return err; |
| 813 | } |
| 814 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 815 | static noinline long v4l1_compat_get_frequency( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 816 | unsigned long *freq, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 817 | struct file *file, |
| 818 | v4l2_kioctl drv) |
| 819 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 820 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 821 | struct v4l2_frequency freq2; |
| 822 | memset(&freq2, 0, sizeof(freq2)); |
| 823 | |
| 824 | freq2.tuner = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 825 | err = drv(file, VIDIOC_G_FREQUENCY, &freq2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 826 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 827 | dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 828 | if (0 == err) |
| 829 | *freq = freq2.frequency; |
| 830 | return err; |
| 831 | } |
| 832 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 833 | static noinline long v4l1_compat_set_frequency( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 834 | unsigned long *freq, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 835 | struct file *file, |
| 836 | v4l2_kioctl drv) |
| 837 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 838 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 839 | struct v4l2_frequency freq2; |
| 840 | memset(&freq2, 0, sizeof(freq2)); |
| 841 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 842 | drv(file, VIDIOC_G_FREQUENCY, &freq2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 843 | freq2.frequency = *freq; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 844 | err = drv(file, VIDIOC_S_FREQUENCY, &freq2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 845 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 846 | dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 847 | return err; |
| 848 | } |
| 849 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 850 | static noinline long v4l1_compat_get_audio( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 851 | struct video_audio *aud, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 852 | struct file *file, |
| 853 | v4l2_kioctl drv) |
| 854 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 855 | long err; |
| 856 | int i; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 857 | struct v4l2_queryctrl qctrl2; |
| 858 | struct v4l2_audio aud2; |
| 859 | struct v4l2_tuner tun2; |
| 860 | memset(&aud2, 0, sizeof(aud2)); |
| 861 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 862 | err = drv(file, VIDIOC_G_AUDIO, &aud2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 863 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 864 | dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 865 | goto done; |
| 866 | } |
| 867 | memcpy(aud->name, aud2.name, |
| 868 | min(sizeof(aud->name), sizeof(aud2.name))); |
| 869 | aud->name[sizeof(aud->name) - 1] = 0; |
| 870 | aud->audio = aud2.index; |
| 871 | aud->flags = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 872 | i = get_v4l_control(file, V4L2_CID_AUDIO_VOLUME, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 873 | if (i >= 0) { |
| 874 | aud->volume = i; |
| 875 | aud->flags |= VIDEO_AUDIO_VOLUME; |
| 876 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 877 | i = get_v4l_control(file, V4L2_CID_AUDIO_BASS, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 878 | if (i >= 0) { |
| 879 | aud->bass = i; |
| 880 | aud->flags |= VIDEO_AUDIO_BASS; |
| 881 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 882 | i = get_v4l_control(file, V4L2_CID_AUDIO_TREBLE, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 883 | if (i >= 0) { |
| 884 | aud->treble = i; |
| 885 | aud->flags |= VIDEO_AUDIO_TREBLE; |
| 886 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 887 | i = get_v4l_control(file, V4L2_CID_AUDIO_BALANCE, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 888 | if (i >= 0) { |
| 889 | aud->balance = i; |
| 890 | aud->flags |= VIDEO_AUDIO_BALANCE; |
| 891 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 892 | i = get_v4l_control(file, V4L2_CID_AUDIO_MUTE, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 893 | if (i >= 0) { |
| 894 | if (i) |
| 895 | aud->flags |= VIDEO_AUDIO_MUTE; |
| 896 | aud->flags |= VIDEO_AUDIO_MUTABLE; |
| 897 | } |
| 898 | aud->step = 1; |
| 899 | qctrl2.id = V4L2_CID_AUDIO_VOLUME; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 900 | if (drv(file, VIDIOC_QUERYCTRL, &qctrl2) == 0 && |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 901 | !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) |
| 902 | aud->step = qctrl2.step; |
| 903 | aud->mode = 0; |
| 904 | |
| 905 | memset(&tun2, 0, sizeof(tun2)); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 906 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 907 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 908 | dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 909 | err = 0; |
| 910 | goto done; |
| 911 | } |
| 912 | |
| 913 | if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2) |
| 914 | aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; |
| 915 | else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO) |
| 916 | aud->mode = VIDEO_SOUND_STEREO; |
| 917 | else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO) |
| 918 | aud->mode = VIDEO_SOUND_MONO; |
| 919 | done: |
| 920 | return err; |
| 921 | } |
| 922 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 923 | static noinline long v4l1_compat_set_audio( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 924 | struct video_audio *aud, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 925 | struct file *file, |
| 926 | v4l2_kioctl drv) |
| 927 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 928 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 929 | struct v4l2_audio aud2; |
| 930 | struct v4l2_tuner tun2; |
| 931 | |
| 932 | memset(&aud2, 0, sizeof(aud2)); |
| 933 | memset(&tun2, 0, sizeof(tun2)); |
| 934 | |
| 935 | aud2.index = aud->audio; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 936 | err = drv(file, VIDIOC_S_AUDIO, &aud2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 937 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 938 | dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 939 | goto done; |
| 940 | } |
| 941 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 942 | set_v4l_control(file, V4L2_CID_AUDIO_VOLUME, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 943 | aud->volume, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 944 | set_v4l_control(file, V4L2_CID_AUDIO_BASS, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 945 | aud->bass, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 946 | set_v4l_control(file, V4L2_CID_AUDIO_TREBLE, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 947 | aud->treble, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 948 | set_v4l_control(file, V4L2_CID_AUDIO_BALANCE, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 949 | aud->balance, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 950 | set_v4l_control(file, V4L2_CID_AUDIO_MUTE, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 951 | !!(aud->flags & VIDEO_AUDIO_MUTE), drv); |
| 952 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 953 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 954 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 955 | dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 956 | if (err == 0) { |
| 957 | switch (aud->mode) { |
| 958 | default: |
| 959 | case VIDEO_SOUND_MONO: |
| 960 | case VIDEO_SOUND_LANG1: |
| 961 | tun2.audmode = V4L2_TUNER_MODE_MONO; |
| 962 | break; |
| 963 | case VIDEO_SOUND_STEREO: |
| 964 | tun2.audmode = V4L2_TUNER_MODE_STEREO; |
| 965 | break; |
| 966 | case VIDEO_SOUND_LANG2: |
| 967 | tun2.audmode = V4L2_TUNER_MODE_LANG2; |
| 968 | break; |
| 969 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 970 | err = drv(file, VIDIOC_S_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 971 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 972 | dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 973 | } |
| 974 | err = 0; |
| 975 | done: |
| 976 | return err; |
| 977 | } |
| 978 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 979 | static noinline long v4l1_compat_capture_frame( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 980 | struct video_mmap *mm, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 981 | struct file *file, |
| 982 | v4l2_kioctl drv) |
| 983 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 984 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 985 | enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 986 | struct v4l2_buffer buf; |
| 987 | struct v4l2_format *fmt; |
| 988 | |
| 989 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 990 | if (!fmt) { |
| 991 | err = -ENOMEM; |
| 992 | return err; |
| 993 | } |
| 994 | memset(&buf, 0, sizeof(buf)); |
| 995 | |
| 996 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 997 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 998 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 999 | dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1000 | goto done; |
| 1001 | } |
| 1002 | if (mm->width != fmt->fmt.pix.width || |
| 1003 | mm->height != fmt->fmt.pix.height || |
| 1004 | palette_to_pixelformat(mm->format) != |
| 1005 | fmt->fmt.pix.pixelformat) { |
| 1006 | /* New capture format... */ |
| 1007 | fmt->fmt.pix.width = mm->width; |
| 1008 | fmt->fmt.pix.height = mm->height; |
| 1009 | fmt->fmt.pix.pixelformat = |
| 1010 | palette_to_pixelformat(mm->format); |
| 1011 | fmt->fmt.pix.field = V4L2_FIELD_ANY; |
| 1012 | fmt->fmt.pix.bytesperline = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1013 | err = drv(file, VIDIOC_S_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1014 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1015 | dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1016 | goto done; |
| 1017 | } |
| 1018 | } |
| 1019 | buf.index = mm->frame; |
| 1020 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1021 | err = drv(file, VIDIOC_QUERYBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1022 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1023 | dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1024 | goto done; |
| 1025 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1026 | err = drv(file, VIDIOC_QBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1027 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1028 | dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1029 | goto done; |
| 1030 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1031 | err = drv(file, VIDIOC_STREAMON, &captype); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1032 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1033 | dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1034 | done: |
| 1035 | kfree(fmt); |
| 1036 | return err; |
| 1037 | } |
| 1038 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1039 | static noinline long v4l1_compat_sync( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1040 | int *i, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1041 | struct file *file, |
| 1042 | v4l2_kioctl drv) |
| 1043 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1044 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1045 | enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1046 | struct v4l2_buffer buf; |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1047 | struct poll_wqueues *pwq; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1048 | |
| 1049 | memset(&buf, 0, sizeof(buf)); |
| 1050 | buf.index = *i; |
| 1051 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1052 | err = drv(file, VIDIOC_QUERYBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1053 | if (err < 0) { |
| 1054 | /* No such buffer */ |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1055 | dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1056 | goto done; |
| 1057 | } |
| 1058 | if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) { |
| 1059 | /* Buffer is not mapped */ |
| 1060 | err = -EINVAL; |
| 1061 | goto done; |
| 1062 | } |
| 1063 | |
| 1064 | /* make sure capture actually runs so we don't block forever */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1065 | err = drv(file, VIDIOC_STREAMON, &captype); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1066 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1067 | dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1068 | goto done; |
| 1069 | } |
| 1070 | |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1071 | pwq = kmalloc(sizeof(*pwq), GFP_KERNEL); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1072 | /* Loop as long as the buffer is queued, but not done */ |
| 1073 | while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE)) |
| 1074 | == V4L2_BUF_FLAG_QUEUED) { |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1075 | err = poll_one(file, pwq); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1076 | if (err < 0 || /* error or sleep was interrupted */ |
| 1077 | err == 0) /* timeout? Shouldn't occur. */ |
| 1078 | break; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1079 | err = drv(file, VIDIOC_QUERYBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1080 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1081 | dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1082 | } |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1083 | kfree(pwq); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1084 | if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */ |
| 1085 | goto done; |
| 1086 | do { |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1087 | err = drv(file, VIDIOC_DQBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1088 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1089 | dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1090 | } while (err == 0 && buf.index != *i); |
| 1091 | done: |
| 1092 | return err; |
| 1093 | } |
| 1094 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1095 | static noinline long v4l1_compat_get_vbi_format( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1096 | struct vbi_format *fmt, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1097 | struct file *file, |
| 1098 | v4l2_kioctl drv) |
| 1099 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1100 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1101 | struct v4l2_format *fmt2; |
| 1102 | |
| 1103 | fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); |
| 1104 | if (!fmt2) { |
| 1105 | err = -ENOMEM; |
| 1106 | return err; |
| 1107 | } |
| 1108 | fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 1109 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1110 | err = drv(file, VIDIOC_G_FMT, fmt2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1111 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1112 | dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1113 | goto done; |
| 1114 | } |
| 1115 | if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) { |
| 1116 | err = -EINVAL; |
| 1117 | goto done; |
| 1118 | } |
| 1119 | memset(fmt, 0, sizeof(*fmt)); |
| 1120 | fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line; |
| 1121 | fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate; |
| 1122 | fmt->sample_format = VIDEO_PALETTE_RAW; |
| 1123 | fmt->start[0] = fmt2->fmt.vbi.start[0]; |
| 1124 | fmt->count[0] = fmt2->fmt.vbi.count[0]; |
| 1125 | fmt->start[1] = fmt2->fmt.vbi.start[1]; |
| 1126 | fmt->count[1] = fmt2->fmt.vbi.count[1]; |
| 1127 | fmt->flags = fmt2->fmt.vbi.flags & 0x03; |
| 1128 | done: |
| 1129 | kfree(fmt2); |
| 1130 | return err; |
| 1131 | } |
| 1132 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1133 | static noinline long v4l1_compat_set_vbi_format( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1134 | struct vbi_format *fmt, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1135 | struct file *file, |
| 1136 | v4l2_kioctl drv) |
| 1137 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1138 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1139 | struct v4l2_format *fmt2 = NULL; |
| 1140 | |
| 1141 | if (VIDEO_PALETTE_RAW != fmt->sample_format) { |
| 1142 | err = -EINVAL; |
| 1143 | return err; |
| 1144 | } |
| 1145 | |
| 1146 | fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); |
| 1147 | if (!fmt2) { |
| 1148 | err = -ENOMEM; |
| 1149 | return err; |
| 1150 | } |
| 1151 | fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 1152 | fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line; |
| 1153 | fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate; |
| 1154 | fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 1155 | fmt2->fmt.vbi.start[0] = fmt->start[0]; |
| 1156 | fmt2->fmt.vbi.count[0] = fmt->count[0]; |
| 1157 | fmt2->fmt.vbi.start[1] = fmt->start[1]; |
| 1158 | fmt2->fmt.vbi.count[1] = fmt->count[1]; |
| 1159 | fmt2->fmt.vbi.flags = fmt->flags; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1160 | err = drv(file, VIDIOC_TRY_FMT, fmt2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1161 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1162 | dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1163 | goto done; |
| 1164 | } |
| 1165 | |
| 1166 | if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line || |
| 1167 | fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate || |
| 1168 | fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY || |
| 1169 | fmt2->fmt.vbi.start[0] != fmt->start[0] || |
| 1170 | fmt2->fmt.vbi.count[0] != fmt->count[0] || |
| 1171 | fmt2->fmt.vbi.start[1] != fmt->start[1] || |
| 1172 | fmt2->fmt.vbi.count[1] != fmt->count[1] || |
| 1173 | fmt2->fmt.vbi.flags != fmt->flags) { |
| 1174 | err = -EINVAL; |
| 1175 | goto done; |
| 1176 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1177 | err = drv(file, VIDIOC_S_FMT, fmt2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1178 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1179 | dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1180 | done: |
| 1181 | kfree(fmt2); |
| 1182 | return err; |
| 1183 | } |
| 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | /* |
| 1186 | * This function is exported. |
| 1187 | */ |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1188 | long |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1189 | v4l_compat_translate_ioctl(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | int cmd, |
| 1191 | void *arg, |
| 1192 | v4l2_kioctl drv) |
| 1193 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1194 | long err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
| 1196 | switch (cmd) { |
| 1197 | case VIDIOCGCAP: /* capability */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1198 | err = v4l1_compat_get_capabilities(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | case VIDIOCGFBUF: /* get frame buffer */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1201 | err = v4l1_compat_get_frame_buffer(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | case VIDIOCSFBUF: /* set frame buffer */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1204 | err = v4l1_compat_set_frame_buffer(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | case VIDIOCGWIN: /* get window or capture dimensions */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1207 | err = v4l1_compat_get_win_cap_dimensions(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | case VIDIOCSWIN: /* set window and/or capture dimensions */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1210 | err = v4l1_compat_set_win_cap_dimensions(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | case VIDIOCCAPTURE: /* turn on/off preview */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1213 | err = v4l1_compat_turn_preview_on_off(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | case VIDIOCGCHAN: /* get input information */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1216 | err = v4l1_compat_get_input_info(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | case VIDIOCSCHAN: /* set input */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1219 | err = v4l1_compat_set_input(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | case VIDIOCGPICT: /* get tone controls & partial capture format */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1222 | err = v4l1_compat_get_picture(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | case VIDIOCSPICT: /* set tone controls & partial capture format */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1225 | err = v4l1_compat_set_picture(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | case VIDIOCGTUNER: /* get tuner information */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1228 | err = v4l1_compat_get_tuner(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | case VIDIOCSTUNER: /* select a tuner input */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1231 | err = v4l1_compat_select_tuner(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | case VIDIOCGFREQ: /* get frequency */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1234 | err = v4l1_compat_get_frequency(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | case VIDIOCSFREQ: /* set frequency */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1237 | err = v4l1_compat_set_frequency(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | case VIDIOCGAUDIO: /* get audio properties/controls */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1240 | err = v4l1_compat_get_audio(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | case VIDIOCSAUDIO: /* set audio controls */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1243 | err = v4l1_compat_set_audio(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | case VIDIOCMCAPTURE: /* capture a frame */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1246 | err = v4l1_compat_capture_frame(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | case VIDIOCSYNC: /* wait for a frame */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1249 | err = v4l1_compat_sync(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | case VIDIOCGVBIFMT: /* query VBI data capture format */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1252 | err = v4l1_compat_get_vbi_format(arg, file, drv); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1253 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | case VIDIOCSVBIFMT: |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1255 | err = v4l1_compat_set_vbi_format(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | default: |
| 1258 | err = -ENOIOCTLCMD; |
| 1259 | break; |
| 1260 | } |
| 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | return err; |
| 1263 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | EXPORT_SYMBOL(v4l_compat_translate_ioctl); |
| 1265 | |
| 1266 | /* |
| 1267 | * Local variables: |
| 1268 | * c-basic-offset: 8 |
| 1269 | * End: |
| 1270 | */ |