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