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 | |
Dr. David Alan Gilbert | 910f5f0 | 2010-10-24 13:33:09 -0300 | [diff] [blame] | 648 | if (fmt->fmt.pix.width) |
| 649 | { |
| 650 | pict->depth = ((fmt->fmt.pix.bytesperline << 3) |
| 651 | + (fmt->fmt.pix.width - 1)) |
| 652 | / fmt->fmt.pix.width; |
| 653 | } else { |
| 654 | err = -EINVAL; |
| 655 | goto done; |
| 656 | } |
| 657 | |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 658 | pict->palette = pixelformat_to_palette( |
| 659 | fmt->fmt.pix.pixelformat); |
| 660 | done: |
| 661 | kfree(fmt); |
| 662 | return err; |
| 663 | } |
| 664 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 665 | static noinline long v4l1_compat_set_picture( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 666 | struct video_picture *pict, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 667 | struct file *file, |
| 668 | v4l2_kioctl drv) |
| 669 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 670 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 671 | struct v4l2_framebuffer fbuf; |
| 672 | int mem_err = 0, ovl_err = 0; |
| 673 | struct v4l2_format *fmt; |
| 674 | |
| 675 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 676 | if (!fmt) { |
| 677 | err = -ENOMEM; |
| 678 | return err; |
| 679 | } |
| 680 | memset(&fbuf, 0, sizeof(fbuf)); |
| 681 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 682 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 683 | V4L2_CID_BRIGHTNESS, pict->brightness, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 684 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 685 | V4L2_CID_HUE, pict->hue, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 686 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 687 | V4L2_CID_CONTRAST, pict->contrast, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 688 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 689 | V4L2_CID_SATURATION, pict->colour, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 690 | set_v4l_control(file, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 691 | V4L2_CID_WHITENESS, pict->whiteness, drv); |
| 692 | /* |
| 693 | * V4L1 uses this ioctl to set both memory capture and overlay |
| 694 | * pixel format, while V4L2 has two different ioctls for this. |
| 695 | * Some cards may not support one or the other, and may support |
| 696 | * different pixel formats for memory vs overlay. |
| 697 | */ |
| 698 | |
| 699 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 700 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 701 | /* If VIDIOC_G_FMT failed, then the driver likely doesn't |
| 702 | support memory capture. Trying to set the memory capture |
| 703 | parameters would be pointless. */ |
| 704 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 705 | dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 706 | mem_err = -1000; /* didn't even try */ |
| 707 | } else if (fmt->fmt.pix.pixelformat != |
| 708 | palette_to_pixelformat(pict->palette)) { |
| 709 | fmt->fmt.pix.pixelformat = palette_to_pixelformat( |
| 710 | pict->palette); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 711 | mem_err = drv(file, VIDIOC_S_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 712 | if (mem_err < 0) |
| 713 | dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n", |
| 714 | mem_err); |
| 715 | } |
| 716 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 717 | err = drv(file, VIDIOC_G_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 718 | /* If VIDIOC_G_FBUF failed, then the driver likely doesn't |
| 719 | support overlay. Trying to set the overlay parameters |
| 720 | would be quite pointless. */ |
| 721 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 722 | dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 723 | ovl_err = -1000; /* didn't even try */ |
| 724 | } else if (fbuf.fmt.pixelformat != |
| 725 | palette_to_pixelformat(pict->palette)) { |
| 726 | fbuf.fmt.pixelformat = palette_to_pixelformat( |
| 727 | pict->palette); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 728 | ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 729 | if (ovl_err < 0) |
| 730 | dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n", |
| 731 | ovl_err); |
| 732 | } |
| 733 | if (ovl_err < 0 && mem_err < 0) { |
| 734 | /* ioctl failed, couldn't set either parameter */ |
| 735 | if (mem_err != -1000) |
| 736 | err = mem_err; |
| 737 | else if (ovl_err == -EPERM) |
| 738 | err = 0; |
| 739 | else |
| 740 | err = ovl_err; |
| 741 | } else |
| 742 | err = 0; |
| 743 | kfree(fmt); |
| 744 | return err; |
| 745 | } |
| 746 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 747 | static noinline long v4l1_compat_get_tuner( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 748 | struct video_tuner *tun, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 749 | struct file *file, |
| 750 | v4l2_kioctl drv) |
| 751 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 752 | long err; |
| 753 | int i; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 754 | struct v4l2_tuner tun2; |
| 755 | struct v4l2_standard std2; |
| 756 | v4l2_std_id sid; |
| 757 | |
| 758 | memset(&tun2, 0, sizeof(tun2)); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 759 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 760 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 761 | dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 762 | goto done; |
| 763 | } |
| 764 | memcpy(tun->name, tun2.name, |
| 765 | min(sizeof(tun->name), sizeof(tun2.name))); |
| 766 | tun->name[sizeof(tun->name) - 1] = 0; |
| 767 | tun->rangelow = tun2.rangelow; |
| 768 | tun->rangehigh = tun2.rangehigh; |
| 769 | tun->flags = 0; |
| 770 | tun->mode = VIDEO_MODE_AUTO; |
| 771 | |
| 772 | for (i = 0; i < 64; i++) { |
| 773 | memset(&std2, 0, sizeof(std2)); |
| 774 | std2.index = i; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 775 | if (0 != drv(file, VIDIOC_ENUMSTD, &std2)) |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 776 | break; |
| 777 | if (std2.id & V4L2_STD_PAL) |
| 778 | tun->flags |= VIDEO_TUNER_PAL; |
| 779 | if (std2.id & V4L2_STD_NTSC) |
| 780 | tun->flags |= VIDEO_TUNER_NTSC; |
| 781 | if (std2.id & V4L2_STD_SECAM) |
| 782 | tun->flags |= VIDEO_TUNER_SECAM; |
| 783 | } |
| 784 | |
Hans Verkuil | 707ca1e | 2009-09-15 08:08:20 -0300 | [diff] [blame] | 785 | /* Note: G_STD might not be present for radio receivers, |
| 786 | * so we should ignore any errors. */ |
| 787 | if (drv(file, VIDIOC_G_STD, &sid) == 0) { |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 788 | if (sid & V4L2_STD_PAL) |
| 789 | tun->mode = VIDEO_MODE_PAL; |
| 790 | if (sid & V4L2_STD_NTSC) |
| 791 | tun->mode = VIDEO_MODE_NTSC; |
| 792 | if (sid & V4L2_STD_SECAM) |
| 793 | tun->mode = VIDEO_MODE_SECAM; |
| 794 | } |
| 795 | |
| 796 | if (tun2.capability & V4L2_TUNER_CAP_LOW) |
| 797 | tun->flags |= VIDEO_TUNER_LOW; |
| 798 | if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO) |
| 799 | tun->flags |= VIDEO_TUNER_STEREO_ON; |
| 800 | tun->signal = tun2.signal; |
| 801 | done: |
| 802 | return err; |
| 803 | } |
| 804 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 805 | static noinline long v4l1_compat_select_tuner( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 806 | struct video_tuner *tun, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 807 | struct file *file, |
| 808 | v4l2_kioctl drv) |
| 809 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 810 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 811 | struct v4l2_tuner t;/*84 bytes on x86_64*/ |
| 812 | memset(&t, 0, sizeof(t)); |
| 813 | |
| 814 | t.index = tun->tuner; |
| 815 | |
Russell King | 9fc4d21 | 2009-03-29 08:12:27 -0300 | [diff] [blame] | 816 | err = drv(file, VIDIOC_S_TUNER, &t); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 817 | if (err < 0) |
Russell King | 9fc4d21 | 2009-03-29 08:12:27 -0300 | [diff] [blame] | 818 | dprintk("VIDIOCSTUNER / VIDIOC_S_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 819 | return err; |
| 820 | } |
| 821 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 822 | static noinline long v4l1_compat_get_frequency( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 823 | unsigned long *freq, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 824 | struct file *file, |
| 825 | v4l2_kioctl drv) |
| 826 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 827 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 828 | struct v4l2_frequency freq2; |
| 829 | memset(&freq2, 0, sizeof(freq2)); |
| 830 | |
| 831 | freq2.tuner = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 832 | err = drv(file, VIDIOC_G_FREQUENCY, &freq2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 833 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 834 | dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 835 | if (0 == err) |
| 836 | *freq = freq2.frequency; |
| 837 | return err; |
| 838 | } |
| 839 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 840 | static noinline long v4l1_compat_set_frequency( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 841 | unsigned long *freq, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 842 | struct file *file, |
| 843 | v4l2_kioctl drv) |
| 844 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 845 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 846 | struct v4l2_frequency freq2; |
| 847 | memset(&freq2, 0, sizeof(freq2)); |
| 848 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 849 | drv(file, VIDIOC_G_FREQUENCY, &freq2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 850 | freq2.frequency = *freq; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 851 | err = drv(file, VIDIOC_S_FREQUENCY, &freq2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 852 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 853 | dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 854 | return err; |
| 855 | } |
| 856 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 857 | static noinline long v4l1_compat_get_audio( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 858 | struct video_audio *aud, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 859 | struct file *file, |
| 860 | v4l2_kioctl drv) |
| 861 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 862 | long err; |
| 863 | int i; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 864 | struct v4l2_queryctrl qctrl2; |
| 865 | struct v4l2_audio aud2; |
| 866 | struct v4l2_tuner tun2; |
| 867 | memset(&aud2, 0, sizeof(aud2)); |
| 868 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 869 | err = drv(file, VIDIOC_G_AUDIO, &aud2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 870 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 871 | dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 872 | goto done; |
| 873 | } |
| 874 | memcpy(aud->name, aud2.name, |
| 875 | min(sizeof(aud->name), sizeof(aud2.name))); |
| 876 | aud->name[sizeof(aud->name) - 1] = 0; |
| 877 | aud->audio = aud2.index; |
| 878 | aud->flags = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 879 | i = get_v4l_control(file, V4L2_CID_AUDIO_VOLUME, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 880 | if (i >= 0) { |
| 881 | aud->volume = i; |
| 882 | aud->flags |= VIDEO_AUDIO_VOLUME; |
| 883 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 884 | i = get_v4l_control(file, V4L2_CID_AUDIO_BASS, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 885 | if (i >= 0) { |
| 886 | aud->bass = i; |
| 887 | aud->flags |= VIDEO_AUDIO_BASS; |
| 888 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 889 | i = get_v4l_control(file, V4L2_CID_AUDIO_TREBLE, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 890 | if (i >= 0) { |
| 891 | aud->treble = i; |
| 892 | aud->flags |= VIDEO_AUDIO_TREBLE; |
| 893 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 894 | i = get_v4l_control(file, V4L2_CID_AUDIO_BALANCE, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 895 | if (i >= 0) { |
| 896 | aud->balance = i; |
| 897 | aud->flags |= VIDEO_AUDIO_BALANCE; |
| 898 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 899 | i = get_v4l_control(file, V4L2_CID_AUDIO_MUTE, drv); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 900 | if (i >= 0) { |
| 901 | if (i) |
| 902 | aud->flags |= VIDEO_AUDIO_MUTE; |
| 903 | aud->flags |= VIDEO_AUDIO_MUTABLE; |
| 904 | } |
| 905 | aud->step = 1; |
| 906 | qctrl2.id = V4L2_CID_AUDIO_VOLUME; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 907 | if (drv(file, VIDIOC_QUERYCTRL, &qctrl2) == 0 && |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 908 | !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) |
| 909 | aud->step = qctrl2.step; |
| 910 | aud->mode = 0; |
| 911 | |
| 912 | memset(&tun2, 0, sizeof(tun2)); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 913 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 914 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 915 | dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 916 | err = 0; |
| 917 | goto done; |
| 918 | } |
| 919 | |
| 920 | if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2) |
| 921 | aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; |
| 922 | else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO) |
| 923 | aud->mode = VIDEO_SOUND_STEREO; |
| 924 | else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO) |
| 925 | aud->mode = VIDEO_SOUND_MONO; |
| 926 | done: |
| 927 | return err; |
| 928 | } |
| 929 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 930 | static noinline long v4l1_compat_set_audio( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 931 | struct video_audio *aud, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 932 | struct file *file, |
| 933 | v4l2_kioctl drv) |
| 934 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 935 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 936 | struct v4l2_audio aud2; |
| 937 | struct v4l2_tuner tun2; |
| 938 | |
| 939 | memset(&aud2, 0, sizeof(aud2)); |
| 940 | memset(&tun2, 0, sizeof(tun2)); |
| 941 | |
| 942 | aud2.index = aud->audio; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 943 | err = drv(file, VIDIOC_S_AUDIO, &aud2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 944 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 945 | dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 946 | goto done; |
| 947 | } |
| 948 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 949 | set_v4l_control(file, V4L2_CID_AUDIO_VOLUME, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 950 | aud->volume, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 951 | set_v4l_control(file, V4L2_CID_AUDIO_BASS, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 952 | aud->bass, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 953 | set_v4l_control(file, V4L2_CID_AUDIO_TREBLE, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 954 | aud->treble, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 955 | set_v4l_control(file, V4L2_CID_AUDIO_BALANCE, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 956 | aud->balance, drv); |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 957 | set_v4l_control(file, V4L2_CID_AUDIO_MUTE, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 958 | !!(aud->flags & VIDEO_AUDIO_MUTE), drv); |
| 959 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 960 | err = drv(file, VIDIOC_G_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 961 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 962 | dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 963 | if (err == 0) { |
| 964 | switch (aud->mode) { |
| 965 | default: |
| 966 | case VIDEO_SOUND_MONO: |
| 967 | case VIDEO_SOUND_LANG1: |
| 968 | tun2.audmode = V4L2_TUNER_MODE_MONO; |
| 969 | break; |
| 970 | case VIDEO_SOUND_STEREO: |
| 971 | tun2.audmode = V4L2_TUNER_MODE_STEREO; |
| 972 | break; |
| 973 | case VIDEO_SOUND_LANG2: |
| 974 | tun2.audmode = V4L2_TUNER_MODE_LANG2; |
| 975 | break; |
| 976 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 977 | err = drv(file, VIDIOC_S_TUNER, &tun2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 978 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 979 | dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 980 | } |
| 981 | err = 0; |
| 982 | done: |
| 983 | return err; |
| 984 | } |
| 985 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 986 | static noinline long v4l1_compat_capture_frame( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 987 | struct video_mmap *mm, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 988 | struct file *file, |
| 989 | v4l2_kioctl drv) |
| 990 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 991 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 992 | enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 993 | struct v4l2_buffer buf; |
| 994 | struct v4l2_format *fmt; |
| 995 | |
| 996 | fmt = kzalloc(sizeof(*fmt), GFP_KERNEL); |
| 997 | if (!fmt) { |
| 998 | err = -ENOMEM; |
| 999 | return err; |
| 1000 | } |
| 1001 | memset(&buf, 0, sizeof(buf)); |
| 1002 | |
| 1003 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1004 | err = drv(file, VIDIOC_G_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1005 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1006 | dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1007 | goto done; |
| 1008 | } |
| 1009 | if (mm->width != fmt->fmt.pix.width || |
| 1010 | mm->height != fmt->fmt.pix.height || |
| 1011 | palette_to_pixelformat(mm->format) != |
| 1012 | fmt->fmt.pix.pixelformat) { |
| 1013 | /* New capture format... */ |
| 1014 | fmt->fmt.pix.width = mm->width; |
| 1015 | fmt->fmt.pix.height = mm->height; |
| 1016 | fmt->fmt.pix.pixelformat = |
| 1017 | palette_to_pixelformat(mm->format); |
| 1018 | fmt->fmt.pix.field = V4L2_FIELD_ANY; |
| 1019 | fmt->fmt.pix.bytesperline = 0; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1020 | err = drv(file, VIDIOC_S_FMT, fmt); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1021 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1022 | dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1023 | goto done; |
| 1024 | } |
| 1025 | } |
| 1026 | buf.index = mm->frame; |
| 1027 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1028 | err = drv(file, VIDIOC_QUERYBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1029 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1030 | dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1031 | goto done; |
| 1032 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1033 | err = drv(file, VIDIOC_QBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1034 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1035 | dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1036 | goto done; |
| 1037 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1038 | err = drv(file, VIDIOC_STREAMON, &captype); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1039 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1040 | dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1041 | done: |
| 1042 | kfree(fmt); |
| 1043 | return err; |
| 1044 | } |
| 1045 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1046 | static noinline long v4l1_compat_sync( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1047 | int *i, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1048 | struct file *file, |
| 1049 | v4l2_kioctl drv) |
| 1050 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1051 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1052 | enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1053 | struct v4l2_buffer buf; |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1054 | struct poll_wqueues *pwq; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1055 | |
| 1056 | memset(&buf, 0, sizeof(buf)); |
| 1057 | buf.index = *i; |
| 1058 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1059 | err = drv(file, VIDIOC_QUERYBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1060 | if (err < 0) { |
| 1061 | /* No such buffer */ |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1062 | dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1063 | goto done; |
| 1064 | } |
| 1065 | if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) { |
| 1066 | /* Buffer is not mapped */ |
| 1067 | err = -EINVAL; |
| 1068 | goto done; |
| 1069 | } |
| 1070 | |
| 1071 | /* make sure capture actually runs so we don't block forever */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1072 | err = drv(file, VIDIOC_STREAMON, &captype); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1073 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1074 | dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1075 | goto done; |
| 1076 | } |
| 1077 | |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1078 | pwq = kmalloc(sizeof(*pwq), GFP_KERNEL); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1079 | /* Loop as long as the buffer is queued, but not done */ |
| 1080 | while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE)) |
| 1081 | == V4L2_BUF_FLAG_QUEUED) { |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1082 | err = poll_one(file, pwq); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1083 | if (err < 0 || /* error or sleep was interrupted */ |
| 1084 | err == 0) /* timeout? Shouldn't occur. */ |
| 1085 | break; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1086 | err = drv(file, VIDIOC_QUERYBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1087 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1088 | dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1089 | } |
Marcin Slusarz | 76e41e4 | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1090 | kfree(pwq); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1091 | if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */ |
| 1092 | goto done; |
| 1093 | do { |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1094 | err = drv(file, VIDIOC_DQBUF, &buf); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1095 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1096 | dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1097 | } while (err == 0 && buf.index != *i); |
| 1098 | done: |
| 1099 | return err; |
| 1100 | } |
| 1101 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1102 | static noinline long v4l1_compat_get_vbi_format( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1103 | struct vbi_format *fmt, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1104 | struct file *file, |
| 1105 | v4l2_kioctl drv) |
| 1106 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1107 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1108 | struct v4l2_format *fmt2; |
| 1109 | |
| 1110 | fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); |
| 1111 | if (!fmt2) { |
| 1112 | err = -ENOMEM; |
| 1113 | return err; |
| 1114 | } |
| 1115 | fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 1116 | |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1117 | err = drv(file, VIDIOC_G_FMT, fmt2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1118 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1119 | dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1120 | goto done; |
| 1121 | } |
| 1122 | if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) { |
| 1123 | err = -EINVAL; |
| 1124 | goto done; |
| 1125 | } |
| 1126 | memset(fmt, 0, sizeof(*fmt)); |
| 1127 | fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line; |
| 1128 | fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate; |
| 1129 | fmt->sample_format = VIDEO_PALETTE_RAW; |
| 1130 | fmt->start[0] = fmt2->fmt.vbi.start[0]; |
| 1131 | fmt->count[0] = fmt2->fmt.vbi.count[0]; |
| 1132 | fmt->start[1] = fmt2->fmt.vbi.start[1]; |
| 1133 | fmt->count[1] = fmt2->fmt.vbi.count[1]; |
| 1134 | fmt->flags = fmt2->fmt.vbi.flags & 0x03; |
| 1135 | done: |
| 1136 | kfree(fmt2); |
| 1137 | return err; |
| 1138 | } |
| 1139 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1140 | static noinline long v4l1_compat_set_vbi_format( |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1141 | struct vbi_format *fmt, |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1142 | struct file *file, |
| 1143 | v4l2_kioctl drv) |
| 1144 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1145 | long err; |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1146 | struct v4l2_format *fmt2 = NULL; |
| 1147 | |
| 1148 | if (VIDEO_PALETTE_RAW != fmt->sample_format) { |
| 1149 | err = -EINVAL; |
| 1150 | return err; |
| 1151 | } |
| 1152 | |
| 1153 | fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); |
| 1154 | if (!fmt2) { |
| 1155 | err = -ENOMEM; |
| 1156 | return err; |
| 1157 | } |
| 1158 | fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 1159 | fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line; |
| 1160 | fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate; |
| 1161 | fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 1162 | fmt2->fmt.vbi.start[0] = fmt->start[0]; |
| 1163 | fmt2->fmt.vbi.count[0] = fmt->count[0]; |
| 1164 | fmt2->fmt.vbi.start[1] = fmt->start[1]; |
| 1165 | fmt2->fmt.vbi.count[1] = fmt->count[1]; |
| 1166 | fmt2->fmt.vbi.flags = fmt->flags; |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1167 | err = drv(file, VIDIOC_TRY_FMT, fmt2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1168 | if (err < 0) { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1169 | dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1170 | goto done; |
| 1171 | } |
| 1172 | |
| 1173 | if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line || |
| 1174 | fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate || |
| 1175 | fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY || |
| 1176 | fmt2->fmt.vbi.start[0] != fmt->start[0] || |
| 1177 | fmt2->fmt.vbi.count[0] != fmt->count[0] || |
| 1178 | fmt2->fmt.vbi.start[1] != fmt->start[1] || |
| 1179 | fmt2->fmt.vbi.count[1] != fmt->count[1] || |
| 1180 | fmt2->fmt.vbi.flags != fmt->flags) { |
| 1181 | err = -EINVAL; |
| 1182 | goto done; |
| 1183 | } |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1184 | err = drv(file, VIDIOC_S_FMT, fmt2); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1185 | if (err < 0) |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1186 | dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %ld\n", err); |
Marcin Slusarz | b524f7b | 2008-04-22 14:45:57 -0300 | [diff] [blame] | 1187 | done: |
| 1188 | kfree(fmt2); |
| 1189 | return err; |
| 1190 | } |
| 1191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | /* |
| 1193 | * This function is exported. |
| 1194 | */ |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1195 | long |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1196 | v4l_compat_translate_ioctl(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | int cmd, |
| 1198 | void *arg, |
| 1199 | v4l2_kioctl drv) |
| 1200 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1201 | long err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
| 1203 | switch (cmd) { |
| 1204 | case VIDIOCGCAP: /* capability */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1205 | err = v4l1_compat_get_capabilities(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | case VIDIOCGFBUF: /* get frame buffer */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1208 | err = v4l1_compat_get_frame_buffer(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | case VIDIOCSFBUF: /* set frame buffer */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1211 | err = v4l1_compat_set_frame_buffer(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | case VIDIOCGWIN: /* get window or capture dimensions */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1214 | err = v4l1_compat_get_win_cap_dimensions(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | case VIDIOCSWIN: /* set window and/or capture dimensions */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1217 | err = v4l1_compat_set_win_cap_dimensions(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | case VIDIOCCAPTURE: /* turn on/off preview */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1220 | err = v4l1_compat_turn_preview_on_off(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | case VIDIOCGCHAN: /* get input information */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1223 | err = v4l1_compat_get_input_info(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | case VIDIOCSCHAN: /* set input */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1226 | err = v4l1_compat_set_input(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | case VIDIOCGPICT: /* get tone controls & partial capture format */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1229 | err = v4l1_compat_get_picture(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | case VIDIOCSPICT: /* set tone controls & partial capture format */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1232 | err = v4l1_compat_set_picture(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | case VIDIOCGTUNER: /* get tuner information */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1235 | err = v4l1_compat_get_tuner(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | case VIDIOCSTUNER: /* select a tuner input */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1238 | err = v4l1_compat_select_tuner(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | case VIDIOCGFREQ: /* get frequency */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1241 | err = v4l1_compat_get_frequency(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | case VIDIOCSFREQ: /* set frequency */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1244 | err = v4l1_compat_set_frequency(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | case VIDIOCGAUDIO: /* get audio properties/controls */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1247 | err = v4l1_compat_get_audio(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | case VIDIOCSAUDIO: /* set audio controls */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1250 | err = v4l1_compat_set_audio(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | case VIDIOCMCAPTURE: /* capture a frame */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1253 | err = v4l1_compat_capture_frame(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | case VIDIOCSYNC: /* wait for a frame */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1256 | err = v4l1_compat_sync(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | case VIDIOCGVBIFMT: /* query VBI data capture format */ |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1259 | err = v4l1_compat_get_vbi_format(arg, file, drv); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1260 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | case VIDIOCSVBIFMT: |
Mauro Carvalho Chehab | b1f8840 | 2008-10-21 11:27:20 -0300 | [diff] [blame] | 1262 | err = v4l1_compat_set_vbi_format(arg, file, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | default: |
| 1265 | err = -ENOIOCTLCMD; |
| 1266 | break; |
| 1267 | } |
| 1268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | return err; |
| 1270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | EXPORT_SYMBOL(v4l_compat_translate_ioctl); |
| 1272 | |
| 1273 | /* |
| 1274 | * Local variables: |
| 1275 | * c-basic-offset: 8 |
| 1276 | * End: |
| 1277 | */ |