Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Auvitek AU0828 USB Bridge (Analog video support) |
| 3 | * |
| 4 | * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org> |
| 5 | * Copyright (C) 2005-2008 Auvitek International, Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * As published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 | * 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | /* Developer Notes: |
| 24 | * |
| 25 | * VBI support is not yet working |
| 26 | * The hardware scaler supported is unimplemented |
| 27 | * AC97 audio support is unimplemented (only i2s audio mode) |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 33 | #include <linux/init.h> |
| 34 | #include <linux/device.h> |
| 35 | #include <linux/suspend.h> |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 36 | #include <media/v4l2-common.h> |
| 37 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 38 | #include <media/v4l2-event.h> |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 39 | #include <media/tuner.h> |
| 40 | #include "au0828.h" |
| 41 | #include "au0828-reg.h" |
| 42 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 43 | static DEFINE_MUTEX(au0828_sysfs_lock); |
| 44 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 45 | /* ------------------------------------------------------------------ |
| 46 | Videobuf operations |
| 47 | ------------------------------------------------------------------*/ |
| 48 | |
| 49 | static unsigned int isoc_debug; |
| 50 | module_param(isoc_debug, int, 0644); |
| 51 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); |
| 52 | |
| 53 | #define au0828_isocdbg(fmt, arg...) \ |
| 54 | do {\ |
| 55 | if (isoc_debug) { \ |
| 56 | printk(KERN_INFO "au0828 %s :"fmt, \ |
| 57 | __func__ , ##arg); \ |
| 58 | } \ |
| 59 | } while (0) |
| 60 | |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 61 | static inline void i2c_gate_ctrl(struct au0828_dev *dev, int val) |
| 62 | { |
| 63 | if (dev->dvb.frontend && dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl) |
| 64 | dev->dvb.frontend->ops.analog_ops.i2c_gate_ctrl(dev->dvb.frontend, val); |
| 65 | } |
| 66 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 67 | static inline void print_err_status(struct au0828_dev *dev, |
| 68 | int packet, int status) |
| 69 | { |
| 70 | char *errmsg = "Unknown"; |
| 71 | |
| 72 | switch (status) { |
| 73 | case -ENOENT: |
| 74 | errmsg = "unlinked synchronuously"; |
| 75 | break; |
| 76 | case -ECONNRESET: |
| 77 | errmsg = "unlinked asynchronuously"; |
| 78 | break; |
| 79 | case -ENOSR: |
| 80 | errmsg = "Buffer error (overrun)"; |
| 81 | break; |
| 82 | case -EPIPE: |
| 83 | errmsg = "Stalled (device not responding)"; |
| 84 | break; |
| 85 | case -EOVERFLOW: |
| 86 | errmsg = "Babble (bad cable?)"; |
| 87 | break; |
| 88 | case -EPROTO: |
| 89 | errmsg = "Bit-stuff error (bad cable?)"; |
| 90 | break; |
| 91 | case -EILSEQ: |
| 92 | errmsg = "CRC/Timeout (could be anything)"; |
| 93 | break; |
| 94 | case -ETIME: |
| 95 | errmsg = "Device does not respond"; |
| 96 | break; |
| 97 | } |
| 98 | if (packet < 0) { |
| 99 | au0828_isocdbg("URB status %d [%s].\n", status, errmsg); |
| 100 | } else { |
| 101 | au0828_isocdbg("URB packet %d, status %d [%s].\n", |
| 102 | packet, status, errmsg); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static int check_dev(struct au0828_dev *dev) |
| 107 | { |
| 108 | if (dev->dev_state & DEV_DISCONNECTED) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 109 | printk(KERN_INFO "v4l2 ioctl: device not present\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 110 | return -ENODEV; |
| 111 | } |
| 112 | |
| 113 | if (dev->dev_state & DEV_MISCONFIGURED) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 114 | printk(KERN_INFO "v4l2 ioctl: device is misconfigured; " |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 115 | "close and open it again\n"); |
| 116 | return -EIO; |
| 117 | } |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * IRQ callback, called by URB callback |
| 123 | */ |
| 124 | static void au0828_irq_callback(struct urb *urb) |
| 125 | { |
| 126 | struct au0828_dmaqueue *dma_q = urb->context; |
| 127 | struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 128 | unsigned long flags = 0; |
Hans Verkuil | e92ba28 | 2012-05-14 10:17:35 -0300 | [diff] [blame] | 129 | int i; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 130 | |
| 131 | switch (urb->status) { |
| 132 | case 0: /* success */ |
| 133 | case -ETIMEDOUT: /* NAK */ |
| 134 | break; |
| 135 | case -ECONNRESET: /* kill */ |
| 136 | case -ENOENT: |
| 137 | case -ESHUTDOWN: |
| 138 | au0828_isocdbg("au0828_irq_callback called: status kill\n"); |
| 139 | return; |
| 140 | default: /* unknown error */ |
| 141 | au0828_isocdbg("urb completition error %d.\n", urb->status); |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | /* Copy data from URB */ |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 146 | spin_lock_irqsave(&dev->slock, flags); |
Hans Verkuil | e92ba28 | 2012-05-14 10:17:35 -0300 | [diff] [blame] | 147 | dev->isoc_ctl.isoc_copy(dev, urb); |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 148 | spin_unlock_irqrestore(&dev->slock, flags); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 149 | |
| 150 | /* Reset urb buffers */ |
| 151 | for (i = 0; i < urb->number_of_packets; i++) { |
| 152 | urb->iso_frame_desc[i].status = 0; |
| 153 | urb->iso_frame_desc[i].actual_length = 0; |
| 154 | } |
| 155 | urb->status = 0; |
| 156 | |
| 157 | urb->status = usb_submit_urb(urb, GFP_ATOMIC); |
| 158 | if (urb->status) { |
| 159 | au0828_isocdbg("urb resubmit failed (error=%i)\n", |
| 160 | urb->status); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Stop and Deallocate URBs |
| 166 | */ |
Mauro Carvalho Chehab | a094ca4 | 2012-10-27 14:00:30 -0300 | [diff] [blame] | 167 | static void au0828_uninit_isoc(struct au0828_dev *dev) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 168 | { |
| 169 | struct urb *urb; |
| 170 | int i; |
| 171 | |
| 172 | au0828_isocdbg("au0828: called au0828_uninit_isoc\n"); |
| 173 | |
| 174 | dev->isoc_ctl.nfields = -1; |
| 175 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
| 176 | urb = dev->isoc_ctl.urb[i]; |
| 177 | if (urb) { |
| 178 | if (!irqs_disabled()) |
| 179 | usb_kill_urb(urb); |
| 180 | else |
| 181 | usb_unlink_urb(urb); |
| 182 | |
| 183 | if (dev->isoc_ctl.transfer_buffer[i]) { |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 184 | usb_free_coherent(dev->usbdev, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 185 | urb->transfer_buffer_length, |
| 186 | dev->isoc_ctl.transfer_buffer[i], |
| 187 | urb->transfer_dma); |
| 188 | } |
| 189 | usb_free_urb(urb); |
| 190 | dev->isoc_ctl.urb[i] = NULL; |
| 191 | } |
| 192 | dev->isoc_ctl.transfer_buffer[i] = NULL; |
| 193 | } |
| 194 | |
| 195 | kfree(dev->isoc_ctl.urb); |
| 196 | kfree(dev->isoc_ctl.transfer_buffer); |
| 197 | |
| 198 | dev->isoc_ctl.urb = NULL; |
| 199 | dev->isoc_ctl.transfer_buffer = NULL; |
| 200 | dev->isoc_ctl.num_bufs = 0; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Allocate URBs and start IRQ |
| 205 | */ |
Mauro Carvalho Chehab | a094ca4 | 2012-10-27 14:00:30 -0300 | [diff] [blame] | 206 | static int au0828_init_isoc(struct au0828_dev *dev, int max_packets, |
| 207 | int num_bufs, int max_pkt_size, |
| 208 | int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb)) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 209 | { |
| 210 | struct au0828_dmaqueue *dma_q = &dev->vidq; |
| 211 | int i; |
| 212 | int sb_size, pipe; |
| 213 | struct urb *urb; |
| 214 | int j, k; |
| 215 | int rc; |
| 216 | |
| 217 | au0828_isocdbg("au0828: called au0828_prepare_isoc\n"); |
| 218 | |
| 219 | /* De-allocates all pending stuff */ |
| 220 | au0828_uninit_isoc(dev); |
| 221 | |
| 222 | dev->isoc_ctl.isoc_copy = isoc_copy; |
| 223 | dev->isoc_ctl.num_bufs = num_bufs; |
| 224 | |
| 225 | dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); |
| 226 | if (!dev->isoc_ctl.urb) { |
| 227 | au0828_isocdbg("cannot alloc memory for usb buffers\n"); |
| 228 | return -ENOMEM; |
| 229 | } |
| 230 | |
| 231 | dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs, |
| 232 | GFP_KERNEL); |
| 233 | if (!dev->isoc_ctl.transfer_buffer) { |
| 234 | au0828_isocdbg("cannot allocate memory for usb transfer\n"); |
| 235 | kfree(dev->isoc_ctl.urb); |
| 236 | return -ENOMEM; |
| 237 | } |
| 238 | |
| 239 | dev->isoc_ctl.max_pkt_size = max_pkt_size; |
| 240 | dev->isoc_ctl.buf = NULL; |
| 241 | |
| 242 | sb_size = max_packets * dev->isoc_ctl.max_pkt_size; |
| 243 | |
| 244 | /* allocate urbs and transfer buffers */ |
| 245 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
| 246 | urb = usb_alloc_urb(max_packets, GFP_KERNEL); |
| 247 | if (!urb) { |
| 248 | au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i); |
| 249 | au0828_uninit_isoc(dev); |
| 250 | return -ENOMEM; |
| 251 | } |
| 252 | dev->isoc_ctl.urb[i] = urb; |
| 253 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 254 | dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->usbdev, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 255 | sb_size, GFP_KERNEL, &urb->transfer_dma); |
| 256 | if (!dev->isoc_ctl.transfer_buffer[i]) { |
| 257 | printk("unable to allocate %i bytes for transfer" |
| 258 | " buffer %i%s\n", |
| 259 | sb_size, i, |
| 260 | in_interrupt() ? " while in int" : ""); |
| 261 | au0828_uninit_isoc(dev); |
| 262 | return -ENOMEM; |
| 263 | } |
| 264 | memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); |
| 265 | |
| 266 | pipe = usb_rcvisocpipe(dev->usbdev, |
| 267 | dev->isoc_in_endpointaddr), |
| 268 | |
| 269 | usb_fill_int_urb(urb, dev->usbdev, pipe, |
| 270 | dev->isoc_ctl.transfer_buffer[i], sb_size, |
| 271 | au0828_irq_callback, dma_q, 1); |
| 272 | |
| 273 | urb->number_of_packets = max_packets; |
Devin Heitmueller | fadadb7 | 2009-03-22 23:42:26 -0300 | [diff] [blame] | 274 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 275 | |
| 276 | k = 0; |
| 277 | for (j = 0; j < max_packets; j++) { |
| 278 | urb->iso_frame_desc[j].offset = k; |
| 279 | urb->iso_frame_desc[j].length = |
| 280 | dev->isoc_ctl.max_pkt_size; |
| 281 | k += dev->isoc_ctl.max_pkt_size; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | init_waitqueue_head(&dma_q->wq); |
| 286 | |
| 287 | /* submit urbs and enables IRQ */ |
| 288 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
| 289 | rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC); |
| 290 | if (rc) { |
| 291 | au0828_isocdbg("submit of urb %i failed (error=%i)\n", |
| 292 | i, rc); |
| 293 | au0828_uninit_isoc(dev); |
| 294 | return rc; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Announces that a buffer were filled and request the next |
| 303 | */ |
| 304 | static inline void buffer_filled(struct au0828_dev *dev, |
| 305 | struct au0828_dmaqueue *dma_q, |
| 306 | struct au0828_buffer *buf) |
| 307 | { |
| 308 | /* Advice that buffer was filled */ |
| 309 | au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 310 | |
| 311 | buf->vb.state = VIDEOBUF_DONE; |
| 312 | buf->vb.field_count++; |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 313 | v4l2_get_timestamp(&buf->vb.ts); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 314 | |
| 315 | dev->isoc_ctl.buf = NULL; |
| 316 | |
| 317 | list_del(&buf->vb.queue); |
| 318 | wake_up(&buf->vb.done); |
| 319 | } |
| 320 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 321 | static inline void vbi_buffer_filled(struct au0828_dev *dev, |
| 322 | struct au0828_dmaqueue *dma_q, |
| 323 | struct au0828_buffer *buf) |
| 324 | { |
| 325 | /* Advice that buffer was filled */ |
| 326 | au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 327 | |
| 328 | buf->vb.state = VIDEOBUF_DONE; |
| 329 | buf->vb.field_count++; |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 330 | v4l2_get_timestamp(&buf->vb.ts); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 331 | |
| 332 | dev->isoc_ctl.vbi_buf = NULL; |
| 333 | |
| 334 | list_del(&buf->vb.queue); |
| 335 | wake_up(&buf->vb.done); |
| 336 | } |
| 337 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 338 | /* |
| 339 | * Identify the buffer header type and properly handles |
| 340 | */ |
| 341 | static void au0828_copy_video(struct au0828_dev *dev, |
| 342 | struct au0828_dmaqueue *dma_q, |
| 343 | struct au0828_buffer *buf, |
| 344 | unsigned char *p, |
| 345 | unsigned char *outp, unsigned long len) |
| 346 | { |
| 347 | void *fieldstart, *startwrite, *startread; |
| 348 | int linesdone, currlinedone, offset, lencopy, remain; |
| 349 | int bytesperline = dev->width << 1; /* Assumes 16-bit depth @@@@ */ |
| 350 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 351 | if (len == 0) |
| 352 | return; |
| 353 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 354 | if (dma_q->pos + len > buf->vb.size) |
| 355 | len = buf->vb.size - dma_q->pos; |
| 356 | |
| 357 | startread = p; |
| 358 | remain = len; |
| 359 | |
| 360 | /* Interlaces frame */ |
| 361 | if (buf->top_field) |
| 362 | fieldstart = outp; |
| 363 | else |
| 364 | fieldstart = outp + bytesperline; |
| 365 | |
| 366 | linesdone = dma_q->pos / bytesperline; |
| 367 | currlinedone = dma_q->pos % bytesperline; |
| 368 | offset = linesdone * bytesperline * 2 + currlinedone; |
| 369 | startwrite = fieldstart + offset; |
| 370 | lencopy = bytesperline - currlinedone; |
| 371 | lencopy = lencopy > remain ? remain : lencopy; |
| 372 | |
| 373 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { |
| 374 | au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n", |
| 375 | ((char *)startwrite + lencopy) - |
| 376 | ((char *)outp + buf->vb.size)); |
| 377 | remain = (char *)outp + buf->vb.size - (char *)startwrite; |
| 378 | lencopy = remain; |
| 379 | } |
| 380 | if (lencopy <= 0) |
| 381 | return; |
| 382 | memcpy(startwrite, startread, lencopy); |
| 383 | |
| 384 | remain -= lencopy; |
| 385 | |
| 386 | while (remain > 0) { |
| 387 | startwrite += lencopy + bytesperline; |
| 388 | startread += lencopy; |
| 389 | if (bytesperline > remain) |
| 390 | lencopy = remain; |
| 391 | else |
| 392 | lencopy = bytesperline; |
| 393 | |
| 394 | if ((char *)startwrite + lencopy > (char *)outp + |
| 395 | buf->vb.size) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 396 | au0828_isocdbg("Overflow %zi bytes past buf end (2)\n", |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 397 | ((char *)startwrite + lencopy) - |
| 398 | ((char *)outp + buf->vb.size)); |
| 399 | lencopy = remain = (char *)outp + buf->vb.size - |
| 400 | (char *)startwrite; |
| 401 | } |
| 402 | if (lencopy <= 0) |
| 403 | break; |
| 404 | |
| 405 | memcpy(startwrite, startread, lencopy); |
| 406 | |
| 407 | remain -= lencopy; |
| 408 | } |
| 409 | |
| 410 | if (offset > 1440) { |
| 411 | /* We have enough data to check for greenscreen */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 412 | if (outp[0] < 0x60 && outp[1440] < 0x60) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 413 | dev->greenscreen_detected = 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | dma_q->pos += len; |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * video-buf generic routine to get the next available buffer |
| 421 | */ |
| 422 | static inline void get_next_buf(struct au0828_dmaqueue *dma_q, |
| 423 | struct au0828_buffer **buf) |
| 424 | { |
| 425 | struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); |
| 426 | |
| 427 | if (list_empty(&dma_q->active)) { |
| 428 | au0828_isocdbg("No active queue to serve\n"); |
| 429 | dev->isoc_ctl.buf = NULL; |
| 430 | *buf = NULL; |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | /* Get the next buffer */ |
| 435 | *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue); |
| 436 | dev->isoc_ctl.buf = *buf; |
| 437 | |
| 438 | return; |
| 439 | } |
| 440 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 441 | static void au0828_copy_vbi(struct au0828_dev *dev, |
| 442 | struct au0828_dmaqueue *dma_q, |
| 443 | struct au0828_buffer *buf, |
| 444 | unsigned char *p, |
| 445 | unsigned char *outp, unsigned long len) |
| 446 | { |
| 447 | unsigned char *startwrite, *startread; |
Dan Carpenter | b5f5933 | 2010-07-23 07:09:20 -0300 | [diff] [blame] | 448 | int bytesperline; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 449 | int i, j = 0; |
| 450 | |
| 451 | if (dev == NULL) { |
| 452 | au0828_isocdbg("dev is null\n"); |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | if (dma_q == NULL) { |
| 457 | au0828_isocdbg("dma_q is null\n"); |
| 458 | return; |
| 459 | } |
| 460 | if (buf == NULL) |
| 461 | return; |
| 462 | if (p == NULL) { |
| 463 | au0828_isocdbg("p is null\n"); |
| 464 | return; |
| 465 | } |
| 466 | if (outp == NULL) { |
| 467 | au0828_isocdbg("outp is null\n"); |
| 468 | return; |
| 469 | } |
| 470 | |
Dan Carpenter | b5f5933 | 2010-07-23 07:09:20 -0300 | [diff] [blame] | 471 | bytesperline = dev->vbi_width; |
| 472 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 473 | if (dma_q->pos + len > buf->vb.size) |
| 474 | len = buf->vb.size - dma_q->pos; |
| 475 | |
| 476 | startread = p; |
| 477 | startwrite = outp + (dma_q->pos / 2); |
| 478 | |
| 479 | /* Make sure the bottom field populates the second half of the frame */ |
| 480 | if (buf->top_field == 0) |
| 481 | startwrite += bytesperline * dev->vbi_height; |
| 482 | |
| 483 | for (i = 0; i < len; i += 2) |
| 484 | startwrite[j++] = startread[i+1]; |
| 485 | |
| 486 | dma_q->pos += len; |
| 487 | } |
| 488 | |
| 489 | |
| 490 | /* |
| 491 | * video-buf generic routine to get the next available VBI buffer |
| 492 | */ |
| 493 | static inline void vbi_get_next_buf(struct au0828_dmaqueue *dma_q, |
| 494 | struct au0828_buffer **buf) |
| 495 | { |
| 496 | struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vbiq); |
| 497 | char *outp; |
| 498 | |
| 499 | if (list_empty(&dma_q->active)) { |
| 500 | au0828_isocdbg("No active queue to serve\n"); |
| 501 | dev->isoc_ctl.vbi_buf = NULL; |
| 502 | *buf = NULL; |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | /* Get the next buffer */ |
| 507 | *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 508 | /* Cleans up buffer - Useful for testing for frame/URB loss */ |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 509 | outp = videobuf_to_vmalloc(&(*buf)->vb); |
| 510 | memset(outp, 0x00, (*buf)->vb.size); |
| 511 | |
| 512 | dev->isoc_ctl.vbi_buf = *buf; |
| 513 | |
| 514 | return; |
| 515 | } |
| 516 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 517 | /* |
| 518 | * Controls the isoc copy of each urb packet |
| 519 | */ |
| 520 | static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb) |
| 521 | { |
| 522 | struct au0828_buffer *buf; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 523 | struct au0828_buffer *vbi_buf; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 524 | struct au0828_dmaqueue *dma_q = urb->context; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 525 | struct au0828_dmaqueue *vbi_dma_q = &dev->vbiq; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 526 | unsigned char *outp = NULL; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 527 | unsigned char *vbioutp = NULL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 528 | int i, len = 0, rc = 1; |
| 529 | unsigned char *p; |
| 530 | unsigned char fbyte; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 531 | unsigned int vbi_field_size; |
| 532 | unsigned int remain, lencopy; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 533 | |
| 534 | if (!dev) |
| 535 | return 0; |
| 536 | |
| 537 | if ((dev->dev_state & DEV_DISCONNECTED) || |
| 538 | (dev->dev_state & DEV_MISCONFIGURED)) |
| 539 | return 0; |
| 540 | |
| 541 | if (urb->status < 0) { |
| 542 | print_err_status(dev, -1, urb->status); |
| 543 | if (urb->status == -ENOENT) |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | buf = dev->isoc_ctl.buf; |
| 548 | if (buf != NULL) |
| 549 | outp = videobuf_to_vmalloc(&buf->vb); |
| 550 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 551 | vbi_buf = dev->isoc_ctl.vbi_buf; |
| 552 | if (vbi_buf != NULL) |
| 553 | vbioutp = videobuf_to_vmalloc(&vbi_buf->vb); |
| 554 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 555 | for (i = 0; i < urb->number_of_packets; i++) { |
| 556 | int status = urb->iso_frame_desc[i].status; |
| 557 | |
| 558 | if (status < 0) { |
| 559 | print_err_status(dev, i, status); |
| 560 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 561 | continue; |
| 562 | } |
| 563 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 564 | if (urb->iso_frame_desc[i].actual_length <= 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 565 | continue; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 566 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 567 | if (urb->iso_frame_desc[i].actual_length > |
| 568 | dev->max_pkt_size) { |
| 569 | au0828_isocdbg("packet bigger than packet size"); |
| 570 | continue; |
| 571 | } |
| 572 | |
| 573 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
| 574 | fbyte = p[0]; |
| 575 | len = urb->iso_frame_desc[i].actual_length - 4; |
| 576 | p += 4; |
| 577 | |
| 578 | if (fbyte & 0x80) { |
| 579 | len -= 4; |
| 580 | p += 4; |
| 581 | au0828_isocdbg("Video frame %s\n", |
| 582 | (fbyte & 0x40) ? "odd" : "even"); |
Devin Heitmueller | bde3bb9 | 2010-07-05 13:05:16 -0300 | [diff] [blame] | 583 | if (fbyte & 0x40) { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 584 | /* VBI */ |
| 585 | if (vbi_buf != NULL) |
| 586 | vbi_buffer_filled(dev, |
| 587 | vbi_dma_q, |
| 588 | vbi_buf); |
| 589 | vbi_get_next_buf(vbi_dma_q, &vbi_buf); |
| 590 | if (vbi_buf == NULL) |
| 591 | vbioutp = NULL; |
| 592 | else |
| 593 | vbioutp = videobuf_to_vmalloc( |
| 594 | &vbi_buf->vb); |
| 595 | |
| 596 | /* Video */ |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 597 | if (buf != NULL) |
| 598 | buffer_filled(dev, dma_q, buf); |
| 599 | get_next_buf(dma_q, &buf); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 600 | if (buf == NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 601 | outp = NULL; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 602 | else |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 603 | outp = videobuf_to_vmalloc(&buf->vb); |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 604 | |
| 605 | /* As long as isoc traffic is arriving, keep |
| 606 | resetting the timer */ |
| 607 | if (dev->vid_timeout_running) |
| 608 | mod_timer(&dev->vid_timeout, |
| 609 | jiffies + (HZ / 10)); |
| 610 | if (dev->vbi_timeout_running) |
| 611 | mod_timer(&dev->vbi_timeout, |
| 612 | jiffies + (HZ / 10)); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | if (buf != NULL) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 616 | if (fbyte & 0x40) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 617 | buf->top_field = 1; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 618 | else |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 619 | buf->top_field = 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 620 | } |
| 621 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 622 | if (vbi_buf != NULL) { |
| 623 | if (fbyte & 0x40) |
| 624 | vbi_buf->top_field = 1; |
| 625 | else |
| 626 | vbi_buf->top_field = 0; |
| 627 | } |
| 628 | |
| 629 | dev->vbi_read = 0; |
| 630 | vbi_dma_q->pos = 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 631 | dma_q->pos = 0; |
| 632 | } |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 633 | |
| 634 | vbi_field_size = dev->vbi_width * dev->vbi_height * 2; |
| 635 | if (dev->vbi_read < vbi_field_size) { |
| 636 | remain = vbi_field_size - dev->vbi_read; |
| 637 | if (len < remain) |
| 638 | lencopy = len; |
| 639 | else |
| 640 | lencopy = remain; |
| 641 | |
| 642 | if (vbi_buf != NULL) |
| 643 | au0828_copy_vbi(dev, vbi_dma_q, vbi_buf, p, |
| 644 | vbioutp, len); |
| 645 | |
| 646 | len -= lencopy; |
| 647 | p += lencopy; |
| 648 | dev->vbi_read += lencopy; |
| 649 | } |
| 650 | |
| 651 | if (dev->vbi_read >= vbi_field_size && buf != NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 652 | au0828_copy_video(dev, dma_q, buf, p, outp, len); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 653 | } |
| 654 | return rc; |
| 655 | } |
| 656 | |
| 657 | static int |
| 658 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, |
| 659 | unsigned int *size) |
| 660 | { |
| 661 | struct au0828_fh *fh = vq->priv_data; |
| 662 | *size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; |
| 663 | |
| 664 | if (0 == *count) |
| 665 | *count = AU0828_DEF_BUF; |
| 666 | |
| 667 | if (*count < AU0828_MIN_BUF) |
| 668 | *count = AU0828_MIN_BUF; |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | /* This is called *without* dev->slock held; please keep it that way */ |
| 673 | static void free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf) |
| 674 | { |
| 675 | struct au0828_fh *fh = vq->priv_data; |
| 676 | struct au0828_dev *dev = fh->dev; |
| 677 | unsigned long flags = 0; |
| 678 | if (in_interrupt()) |
| 679 | BUG(); |
| 680 | |
| 681 | /* We used to wait for the buffer to finish here, but this didn't work |
| 682 | because, as we were keeping the state as VIDEOBUF_QUEUED, |
| 683 | videobuf_queue_cancel marked it as finished for us. |
| 684 | (Also, it could wedge forever if the hardware was misconfigured.) |
| 685 | |
| 686 | This should be safe; by the time we get here, the buffer isn't |
| 687 | queued anymore. If we ever start marking the buffers as |
| 688 | VIDEOBUF_ACTIVE, it won't be, though. |
| 689 | */ |
| 690 | spin_lock_irqsave(&dev->slock, flags); |
| 691 | if (dev->isoc_ctl.buf == buf) |
| 692 | dev->isoc_ctl.buf = NULL; |
| 693 | spin_unlock_irqrestore(&dev->slock, flags); |
| 694 | |
| 695 | videobuf_vmalloc_free(&buf->vb); |
| 696 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 697 | } |
| 698 | |
| 699 | static int |
| 700 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
| 701 | enum v4l2_field field) |
| 702 | { |
| 703 | struct au0828_fh *fh = vq->priv_data; |
| 704 | struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb); |
| 705 | struct au0828_dev *dev = fh->dev; |
| 706 | int rc = 0, urb_init = 0; |
| 707 | |
| 708 | buf->vb.size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; |
| 709 | |
| 710 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 711 | return -EINVAL; |
| 712 | |
| 713 | buf->vb.width = dev->width; |
| 714 | buf->vb.height = dev->height; |
| 715 | buf->vb.field = field; |
| 716 | |
| 717 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 718 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 719 | if (rc < 0) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 720 | printk(KERN_INFO "videobuf_iolock failed\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 721 | goto fail; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | if (!dev->isoc_ctl.num_bufs) |
| 726 | urb_init = 1; |
| 727 | |
| 728 | if (urb_init) { |
| 729 | rc = au0828_init_isoc(dev, AU0828_ISO_PACKETS_PER_URB, |
| 730 | AU0828_MAX_ISO_BUFS, dev->max_pkt_size, |
| 731 | au0828_isoc_copy); |
| 732 | if (rc < 0) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 733 | printk(KERN_INFO "au0828_init_isoc failed\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 734 | goto fail; |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | buf->vb.state = VIDEOBUF_PREPARED; |
| 739 | return 0; |
| 740 | |
| 741 | fail: |
| 742 | free_buffer(vq, buf); |
| 743 | return rc; |
| 744 | } |
| 745 | |
| 746 | static void |
| 747 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 748 | { |
| 749 | struct au0828_buffer *buf = container_of(vb, |
| 750 | struct au0828_buffer, |
| 751 | vb); |
| 752 | struct au0828_fh *fh = vq->priv_data; |
| 753 | struct au0828_dev *dev = fh->dev; |
| 754 | struct au0828_dmaqueue *vidq = &dev->vidq; |
| 755 | |
| 756 | buf->vb.state = VIDEOBUF_QUEUED; |
| 757 | list_add_tail(&buf->vb.queue, &vidq->active); |
| 758 | } |
| 759 | |
| 760 | static void buffer_release(struct videobuf_queue *vq, |
| 761 | struct videobuf_buffer *vb) |
| 762 | { |
| 763 | struct au0828_buffer *buf = container_of(vb, |
| 764 | struct au0828_buffer, |
| 765 | vb); |
| 766 | |
| 767 | free_buffer(vq, buf); |
| 768 | } |
| 769 | |
| 770 | static struct videobuf_queue_ops au0828_video_qops = { |
| 771 | .buf_setup = buffer_setup, |
| 772 | .buf_prepare = buffer_prepare, |
| 773 | .buf_queue = buffer_queue, |
| 774 | .buf_release = buffer_release, |
| 775 | }; |
| 776 | |
| 777 | /* ------------------------------------------------------------------ |
| 778 | V4L2 interface |
| 779 | ------------------------------------------------------------------*/ |
| 780 | |
| 781 | static int au0828_i2s_init(struct au0828_dev *dev) |
| 782 | { |
| 783 | /* Enable i2s mode */ |
| 784 | au0828_writereg(dev, AU0828_AUDIOCTRL_50C, 0x01); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | /* |
| 789 | * Auvitek au0828 analog stream enable |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 790 | */ |
Mauro Carvalho Chehab | a094ca4 | 2012-10-27 14:00:30 -0300 | [diff] [blame] | 791 | static int au0828_analog_stream_enable(struct au0828_dev *d) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 792 | { |
Mauro Carvalho Chehab | 64ea37b | 2014-06-08 13:54:57 -0300 | [diff] [blame] | 793 | struct usb_interface *iface; |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 794 | int ret, h, w; |
Mauro Carvalho Chehab | 64ea37b | 2014-06-08 13:54:57 -0300 | [diff] [blame] | 795 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 796 | dprintk(1, "au0828_analog_stream_enable called\n"); |
Mauro Carvalho Chehab | 64ea37b | 2014-06-08 13:54:57 -0300 | [diff] [blame] | 797 | |
| 798 | iface = usb_ifnum_to_if(d->usbdev, 0); |
| 799 | if (iface && iface->cur_altsetting->desc.bAlternateSetting != 5) { |
| 800 | dprintk(1, "Changing intf#0 to alt 5\n"); |
| 801 | /* set au0828 interface0 to AS5 here again */ |
| 802 | ret = usb_set_interface(d->usbdev, 0, 5); |
| 803 | if (ret < 0) { |
| 804 | printk(KERN_INFO "Au0828 can't set alt setting to 5!\n"); |
| 805 | return -EBUSY; |
| 806 | } |
| 807 | } |
| 808 | |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 809 | h = d->height / 2 + 2; |
| 810 | w = d->width * 2; |
Mauro Carvalho Chehab | 64ea37b | 2014-06-08 13:54:57 -0300 | [diff] [blame] | 811 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 812 | au0828_writereg(d, AU0828_SENSORCTRL_VBI_103, 0x00); |
| 813 | au0828_writereg(d, 0x106, 0x00); |
| 814 | /* set x position */ |
| 815 | au0828_writereg(d, 0x110, 0x00); |
| 816 | au0828_writereg(d, 0x111, 0x00); |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 817 | au0828_writereg(d, 0x114, w & 0xff); |
| 818 | au0828_writereg(d, 0x115, w >> 8); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 819 | /* set y position */ |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 820 | au0828_writereg(d, 0x112, 0x00); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 821 | au0828_writereg(d, 0x113, 0x00); |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 822 | au0828_writereg(d, 0x116, h & 0xff); |
| 823 | au0828_writereg(d, 0x117, h >> 8); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 824 | au0828_writereg(d, AU0828_SENSORCTRL_100, 0xb3); |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | int au0828_analog_stream_disable(struct au0828_dev *d) |
| 830 | { |
| 831 | dprintk(1, "au0828_analog_stream_disable called\n"); |
| 832 | au0828_writereg(d, AU0828_SENSORCTRL_100, 0x0); |
| 833 | return 0; |
| 834 | } |
| 835 | |
Mauro Carvalho Chehab | a094ca4 | 2012-10-27 14:00:30 -0300 | [diff] [blame] | 836 | static void au0828_analog_stream_reset(struct au0828_dev *dev) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 837 | { |
| 838 | dprintk(1, "au0828_analog_stream_reset called\n"); |
| 839 | au0828_writereg(dev, AU0828_SENSORCTRL_100, 0x0); |
| 840 | mdelay(30); |
| 841 | au0828_writereg(dev, AU0828_SENSORCTRL_100, 0xb3); |
| 842 | } |
| 843 | |
| 844 | /* |
| 845 | * Some operations needs to stop current streaming |
| 846 | */ |
| 847 | static int au0828_stream_interrupt(struct au0828_dev *dev) |
| 848 | { |
| 849 | int ret = 0; |
| 850 | |
| 851 | dev->stream_state = STREAM_INTERRUPT; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 852 | if (dev->dev_state == DEV_DISCONNECTED) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 853 | return -ENODEV; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 854 | else if (ret) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 855 | dev->dev_state = DEV_MISCONFIGURED; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 856 | dprintk(1, "%s device is misconfigured!\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 857 | return ret; |
| 858 | } |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | /* |
| 863 | * au0828_release_resources |
| 864 | * unregister v4l2 devices |
| 865 | */ |
| 866 | void au0828_analog_unregister(struct au0828_dev *dev) |
| 867 | { |
| 868 | dprintk(1, "au0828_release_resources called\n"); |
| 869 | mutex_lock(&au0828_sysfs_lock); |
| 870 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 871 | if (dev->vdev) |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 872 | video_unregister_device(dev->vdev); |
| 873 | if (dev->vbi_dev) |
| 874 | video_unregister_device(dev->vbi_dev); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 875 | |
| 876 | mutex_unlock(&au0828_sysfs_lock); |
| 877 | } |
| 878 | |
| 879 | |
| 880 | /* Usage lock check functions */ |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 881 | static int res_get(struct au0828_fh *fh, unsigned int bit) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 882 | { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 883 | struct au0828_dev *dev = fh->dev; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 884 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 885 | if (fh->resources & bit) |
| 886 | /* have it already allocated */ |
| 887 | return 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 888 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 889 | /* is it free? */ |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 890 | if (dev->resources & bit) { |
| 891 | /* no, someone else uses it */ |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | /* it's free, grab it */ |
| 895 | fh->resources |= bit; |
| 896 | dev->resources |= bit; |
| 897 | dprintk(1, "res: get %d\n", bit); |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 898 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 899 | return 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 900 | } |
| 901 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 902 | static int res_check(struct au0828_fh *fh, unsigned int bit) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 903 | { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 904 | return fh->resources & bit; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 905 | } |
| 906 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 907 | static int res_locked(struct au0828_dev *dev, unsigned int bit) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 908 | { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 909 | return dev->resources & bit; |
| 910 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 911 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 912 | static void res_free(struct au0828_fh *fh, unsigned int bits) |
| 913 | { |
| 914 | struct au0828_dev *dev = fh->dev; |
| 915 | |
| 916 | BUG_ON((fh->resources & bits) != bits); |
| 917 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 918 | fh->resources &= ~bits; |
| 919 | dev->resources &= ~bits; |
| 920 | dprintk(1, "res: put %d\n", bits); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static int get_ressource(struct au0828_fh *fh) |
| 924 | { |
| 925 | switch (fh->type) { |
| 926 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 927 | return AU0828_RESOURCE_VIDEO; |
| 928 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 929 | return AU0828_RESOURCE_VBI; |
| 930 | default: |
| 931 | BUG(); |
| 932 | return 0; |
| 933 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 934 | } |
| 935 | |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 936 | /* This function ensures that video frames continue to be delivered even if |
| 937 | the ITU-656 input isn't receiving any data (thereby preventing applications |
| 938 | such as tvtime from hanging) */ |
Mauro Carvalho Chehab | a094ca4 | 2012-10-27 14:00:30 -0300 | [diff] [blame] | 939 | static void au0828_vid_buffer_timeout(unsigned long data) |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 940 | { |
| 941 | struct au0828_dev *dev = (struct au0828_dev *) data; |
| 942 | struct au0828_dmaqueue *dma_q = &dev->vidq; |
| 943 | struct au0828_buffer *buf; |
| 944 | unsigned char *vid_data; |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 945 | unsigned long flags = 0; |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 946 | |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 947 | spin_lock_irqsave(&dev->slock, flags); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 948 | |
| 949 | buf = dev->isoc_ctl.buf; |
| 950 | if (buf != NULL) { |
| 951 | vid_data = videobuf_to_vmalloc(&buf->vb); |
| 952 | memset(vid_data, 0x00, buf->vb.size); /* Blank green frame */ |
| 953 | buffer_filled(dev, dma_q, buf); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 954 | } |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 955 | get_next_buf(dma_q, &buf); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 956 | |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 957 | if (dev->vid_timeout_running == 1) |
| 958 | mod_timer(&dev->vid_timeout, jiffies + (HZ / 10)); |
| 959 | |
| 960 | spin_unlock_irqrestore(&dev->slock, flags); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 961 | } |
| 962 | |
Mauro Carvalho Chehab | a094ca4 | 2012-10-27 14:00:30 -0300 | [diff] [blame] | 963 | static void au0828_vbi_buffer_timeout(unsigned long data) |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 964 | { |
| 965 | struct au0828_dev *dev = (struct au0828_dev *) data; |
| 966 | struct au0828_dmaqueue *dma_q = &dev->vbiq; |
| 967 | struct au0828_buffer *buf; |
| 968 | unsigned char *vbi_data; |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 969 | unsigned long flags = 0; |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 970 | |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 971 | spin_lock_irqsave(&dev->slock, flags); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 972 | |
| 973 | buf = dev->isoc_ctl.vbi_buf; |
| 974 | if (buf != NULL) { |
| 975 | vbi_data = videobuf_to_vmalloc(&buf->vb); |
| 976 | memset(vbi_data, 0x00, buf->vb.size); |
| 977 | vbi_buffer_filled(dev, dma_q, buf); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 978 | } |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 979 | vbi_get_next_buf(dma_q, &buf); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 980 | |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 981 | if (dev->vbi_timeout_running == 1) |
| 982 | mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10)); |
| 983 | spin_unlock_irqrestore(&dev->slock, flags); |
Devin Heitmueller | 6e04b7b | 2010-09-01 22:03:43 -0300 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 987 | static int au0828_v4l2_open(struct file *filp) |
| 988 | { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 989 | int ret = 0; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 990 | struct video_device *vdev = video_devdata(filp); |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 991 | struct au0828_dev *dev = video_drvdata(filp); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 992 | struct au0828_fh *fh; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 993 | int type; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 994 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 995 | switch (vdev->vfl_type) { |
| 996 | case VFL_TYPE_GRABBER: |
| 997 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 998 | break; |
| 999 | case VFL_TYPE_VBI: |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 1000 | type = V4L2_BUF_TYPE_VBI_CAPTURE; |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1001 | break; |
| 1002 | default: |
| 1003 | return -EINVAL; |
| 1004 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1005 | |
| 1006 | fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1007 | if (NULL == fh) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1008 | dprintk(1, "Failed allocate au0828_fh struct!\n"); |
| 1009 | return -ENOMEM; |
| 1010 | } |
| 1011 | |
| 1012 | fh->type = type; |
| 1013 | fh->dev = dev; |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1014 | v4l2_fh_init(&fh->fh, vdev); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1015 | filp->private_data = fh; |
| 1016 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1017 | if (mutex_lock_interruptible(&dev->lock)) { |
| 1018 | kfree(fh); |
| 1019 | return -ERESTARTSYS; |
| 1020 | } |
| 1021 | if (dev->users == 0) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1022 | au0828_analog_stream_enable(dev); |
| 1023 | au0828_analog_stream_reset(dev); |
| 1024 | |
| 1025 | /* If we were doing ac97 instead of i2s, it would go here...*/ |
| 1026 | au0828_i2s_init(dev); |
| 1027 | |
| 1028 | dev->stream_state = STREAM_OFF; |
| 1029 | dev->dev_state |= DEV_INITIALIZED; |
| 1030 | } |
| 1031 | |
| 1032 | dev->users++; |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1033 | mutex_unlock(&dev->lock); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1034 | |
| 1035 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops, |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1036 | NULL, &dev->slock, |
| 1037 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1038 | V4L2_FIELD_INTERLACED, |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 1039 | sizeof(struct au0828_buffer), fh, |
| 1040 | &dev->lock); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1041 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1042 | /* VBI Setup */ |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1043 | videobuf_queue_vmalloc_init(&fh->vb_vbiq, &au0828_vbi_qops, |
| 1044 | NULL, &dev->slock, |
| 1045 | V4L2_BUF_TYPE_VBI_CAPTURE, |
| 1046 | V4L2_FIELD_SEQ_TB, |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 1047 | sizeof(struct au0828_buffer), fh, |
| 1048 | &dev->lock); |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1049 | v4l2_fh_add(&fh->fh); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1050 | return ret; |
| 1051 | } |
| 1052 | |
| 1053 | static int au0828_v4l2_close(struct file *filp) |
| 1054 | { |
| 1055 | int ret; |
| 1056 | struct au0828_fh *fh = filp->private_data; |
| 1057 | struct au0828_dev *dev = fh->dev; |
| 1058 | |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1059 | v4l2_fh_del(&fh->fh); |
| 1060 | v4l2_fh_exit(&fh->fh); |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1061 | mutex_lock(&dev->lock); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1062 | if (res_check(fh, AU0828_RESOURCE_VIDEO)) { |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1063 | /* Cancel timeout thread in case they didn't call streamoff */ |
| 1064 | dev->vid_timeout_running = 0; |
| 1065 | del_timer_sync(&dev->vid_timeout); |
| 1066 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1067 | videobuf_stop(&fh->vb_vidq); |
| 1068 | res_free(fh, AU0828_RESOURCE_VIDEO); |
| 1069 | } |
| 1070 | |
| 1071 | if (res_check(fh, AU0828_RESOURCE_VBI)) { |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1072 | /* Cancel timeout thread in case they didn't call streamoff */ |
| 1073 | dev->vbi_timeout_running = 0; |
| 1074 | del_timer_sync(&dev->vbi_timeout); |
| 1075 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1076 | videobuf_stop(&fh->vb_vbiq); |
| 1077 | res_free(fh, AU0828_RESOURCE_VBI); |
| 1078 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1079 | |
Hans Verkuil | 823beb7 | 2013-03-11 10:16:45 -0300 | [diff] [blame] | 1080 | if (dev->users == 1 && video_is_registered(video_devdata(filp))) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1081 | au0828_analog_stream_disable(dev); |
| 1082 | |
| 1083 | au0828_uninit_isoc(dev); |
| 1084 | |
Devin Heitmueller | e4b8bc5 | 2009-05-06 20:54:00 -0300 | [diff] [blame] | 1085 | /* Save some power by putting tuner to sleep */ |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 1086 | v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0); |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1087 | dev->std_set_in_tuner_core = 0; |
Devin Heitmueller | e4b8bc5 | 2009-05-06 20:54:00 -0300 | [diff] [blame] | 1088 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1089 | /* When close the device, set the usb intf0 into alt0 to free |
| 1090 | USB bandwidth */ |
| 1091 | ret = usb_set_interface(dev->usbdev, 0, 0); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1092 | if (ret < 0) |
| 1093 | printk(KERN_INFO "Au0828 can't set alternate to 0!\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1094 | } |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1095 | mutex_unlock(&dev->lock); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1096 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1097 | videobuf_mmap_free(&fh->vb_vidq); |
| 1098 | videobuf_mmap_free(&fh->vb_vbiq); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1099 | kfree(fh); |
| 1100 | dev->users--; |
| 1101 | wake_up_interruptible_nr(&dev->open, 1); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1102 | return 0; |
| 1103 | } |
| 1104 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1105 | /* Must be called with dev->lock held */ |
| 1106 | static void au0828_init_tuner(struct au0828_dev *dev) |
| 1107 | { |
| 1108 | struct v4l2_frequency f = { |
| 1109 | .frequency = dev->ctrl_freq, |
| 1110 | .type = V4L2_TUNER_ANALOG_TV, |
| 1111 | }; |
| 1112 | |
| 1113 | if (dev->std_set_in_tuner_core) |
| 1114 | return; |
| 1115 | dev->std_set_in_tuner_core = 1; |
| 1116 | i2c_gate_ctrl(dev, 1); |
| 1117 | /* If we've never sent the standard in tuner core, do so now. |
| 1118 | We don't do this at device probe because we don't want to |
| 1119 | incur the cost of a firmware load */ |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 1120 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, dev->std); |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1121 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f); |
| 1122 | i2c_gate_ctrl(dev, 0); |
| 1123 | } |
| 1124 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1125 | static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf, |
| 1126 | size_t count, loff_t *pos) |
| 1127 | { |
| 1128 | struct au0828_fh *fh = filp->private_data; |
| 1129 | struct au0828_dev *dev = fh->dev; |
| 1130 | int rc; |
| 1131 | |
| 1132 | rc = check_dev(dev); |
| 1133 | if (rc < 0) |
| 1134 | return rc; |
| 1135 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1136 | if (mutex_lock_interruptible(&dev->lock)) |
| 1137 | return -ERESTARTSYS; |
| 1138 | au0828_init_tuner(dev); |
| 1139 | mutex_unlock(&dev->lock); |
| 1140 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1141 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1142 | if (res_locked(dev, AU0828_RESOURCE_VIDEO)) |
| 1143 | return -EBUSY; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1144 | |
| 1145 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
| 1146 | filp->f_flags & O_NONBLOCK); |
| 1147 | } |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1148 | |
| 1149 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
| 1150 | if (!res_get(fh, AU0828_RESOURCE_VBI)) |
| 1151 | return -EBUSY; |
| 1152 | |
Devin Heitmueller | bf79716 | 2010-10-09 15:09:17 -0300 | [diff] [blame] | 1153 | if (dev->vbi_timeout_running == 0) { |
| 1154 | /* Handle case where caller tries to read without |
| 1155 | calling streamon first */ |
| 1156 | dev->vbi_timeout_running = 1; |
| 1157 | mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10)); |
| 1158 | } |
| 1159 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1160 | return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0, |
| 1161 | filp->f_flags & O_NONBLOCK); |
| 1162 | } |
| 1163 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait) |
| 1168 | { |
| 1169 | struct au0828_fh *fh = filp->private_data; |
| 1170 | struct au0828_dev *dev = fh->dev; |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1171 | unsigned long req_events = poll_requested_events(wait); |
| 1172 | unsigned int res; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1173 | |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1174 | if (check_dev(dev) < 0) |
| 1175 | return POLLERR; |
| 1176 | |
| 1177 | res = v4l2_ctrl_poll(filp, wait); |
| 1178 | if (!(req_events & (POLLIN | POLLRDNORM))) |
| 1179 | return res; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1180 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1181 | if (mutex_lock_interruptible(&dev->lock)) |
| 1182 | return -ERESTARTSYS; |
| 1183 | au0828_init_tuner(dev); |
| 1184 | mutex_unlock(&dev->lock); |
| 1185 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1186 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 1187 | if (!res_get(fh, AU0828_RESOURCE_VIDEO)) |
| 1188 | return POLLERR; |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1189 | return res | videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
| 1190 | } |
| 1191 | if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1192 | if (!res_get(fh, AU0828_RESOURCE_VBI)) |
| 1193 | return POLLERR; |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1194 | return res | videobuf_poll_stream(filp, &fh->vb_vbiq, wait); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1195 | } |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1196 | return POLLERR; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) |
| 1200 | { |
| 1201 | struct au0828_fh *fh = filp->private_data; |
| 1202 | struct au0828_dev *dev = fh->dev; |
| 1203 | int rc; |
| 1204 | |
| 1205 | rc = check_dev(dev); |
| 1206 | if (rc < 0) |
| 1207 | return rc; |
| 1208 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1209 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1210 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
| 1211 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1212 | rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1213 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1214 | return rc; |
| 1215 | } |
| 1216 | |
| 1217 | static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd, |
| 1218 | struct v4l2_format *format) |
| 1219 | { |
| 1220 | int ret; |
| 1221 | int width = format->fmt.pix.width; |
| 1222 | int height = format->fmt.pix.height; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1223 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1224 | /* If they are demanding a format other than the one we support, |
| 1225 | bail out (tvtime asks for UYVY and then retries with YUYV) */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1226 | if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1227 | return -EINVAL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1228 | |
| 1229 | /* format->fmt.pix.width only support 720 and height 480 */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1230 | if (width != 720) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1231 | width = 720; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1232 | if (height != 480) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1233 | height = 480; |
| 1234 | |
| 1235 | format->fmt.pix.width = width; |
| 1236 | format->fmt.pix.height = height; |
| 1237 | format->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; |
| 1238 | format->fmt.pix.bytesperline = width * 2; |
| 1239 | format->fmt.pix.sizeimage = width * height * 2; |
| 1240 | format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 1241 | format->fmt.pix.field = V4L2_FIELD_INTERLACED; |
Hans Verkuil | 8d86e4e | 2013-03-11 17:48:34 -0300 | [diff] [blame] | 1242 | format->fmt.pix.priv = 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1243 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1244 | if (cmd == VIDIOC_TRY_FMT) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1245 | return 0; |
| 1246 | |
| 1247 | /* maybe set new image format, driver current only support 720*480 */ |
| 1248 | dev->width = width; |
| 1249 | dev->height = height; |
| 1250 | dev->frame_size = width * height * 2; |
| 1251 | dev->field_size = width * height; |
| 1252 | dev->bytesperline = width * 2; |
| 1253 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1254 | if (dev->stream_state == STREAM_ON) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1255 | dprintk(1, "VIDIOC_SET_FMT: interrupting stream!\n"); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1256 | ret = au0828_stream_interrupt(dev); |
| 1257 | if (ret != 0) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1258 | dprintk(1, "error interrupting video stream!\n"); |
| 1259 | return ret; |
| 1260 | } |
| 1261 | } |
| 1262 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1263 | au0828_analog_stream_enable(dev); |
| 1264 | |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
| 1268 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1269 | static int vidioc_querycap(struct file *file, void *priv, |
| 1270 | struct v4l2_capability *cap) |
| 1271 | { |
Hans Verkuil | 59e0548 | 2013-02-15 08:11:04 -0300 | [diff] [blame] | 1272 | struct video_device *vdev = video_devdata(file); |
| 1273 | struct au0828_fh *fh = priv; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1274 | struct au0828_dev *dev = fh->dev; |
| 1275 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1276 | strlcpy(cap->driver, "au0828", sizeof(cap->driver)); |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1277 | strlcpy(cap->card, dev->board.name, sizeof(cap->card)); |
Hans Verkuil | 59e0548 | 2013-02-15 08:11:04 -0300 | [diff] [blame] | 1278 | usb_make_path(dev->usbdev, cap->bus_info, sizeof(cap->bus_info)); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1279 | |
Hans Verkuil | 59e0548 | 2013-02-15 08:11:04 -0300 | [diff] [blame] | 1280 | /* set the device capabilities */ |
| 1281 | cap->device_caps = V4L2_CAP_AUDIO | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1282 | V4L2_CAP_READWRITE | |
| 1283 | V4L2_CAP_STREAMING | |
| 1284 | V4L2_CAP_TUNER; |
Hans Verkuil | 59e0548 | 2013-02-15 08:11:04 -0300 | [diff] [blame] | 1285 | if (vdev->vfl_type == VFL_TYPE_GRABBER) |
| 1286 | cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE; |
| 1287 | else |
| 1288 | cap->device_caps |= V4L2_CAP_VBI_CAPTURE; |
| 1289 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS | |
| 1290 | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 1295 | struct v4l2_fmtdesc *f) |
| 1296 | { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1297 | if (f->index) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1298 | return -EINVAL; |
| 1299 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1300 | f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1301 | strcpy(f->description, "Packed YUV2"); |
| 1302 | |
| 1303 | f->flags = 0; |
| 1304 | f->pixelformat = V4L2_PIX_FMT_UYVY; |
| 1305 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 1310 | struct v4l2_format *f) |
| 1311 | { |
| 1312 | struct au0828_fh *fh = priv; |
| 1313 | struct au0828_dev *dev = fh->dev; |
| 1314 | |
| 1315 | f->fmt.pix.width = dev->width; |
| 1316 | f->fmt.pix.height = dev->height; |
| 1317 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; |
| 1318 | f->fmt.pix.bytesperline = dev->bytesperline; |
| 1319 | f->fmt.pix.sizeimage = dev->frame_size; |
| 1320 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */ |
| 1321 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
Hans Verkuil | 8d86e4e | 2013-03-11 17:48:34 -0300 | [diff] [blame] | 1322 | f->fmt.pix.priv = 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 1327 | struct v4l2_format *f) |
| 1328 | { |
| 1329 | struct au0828_fh *fh = priv; |
| 1330 | struct au0828_dev *dev = fh->dev; |
| 1331 | |
| 1332 | return au0828_set_format(dev, VIDIOC_TRY_FMT, f); |
| 1333 | } |
| 1334 | |
| 1335 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
| 1336 | struct v4l2_format *f) |
| 1337 | { |
| 1338 | struct au0828_fh *fh = priv; |
| 1339 | struct au0828_dev *dev = fh->dev; |
| 1340 | int rc; |
| 1341 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1342 | rc = check_dev(dev); |
| 1343 | if (rc < 0) |
| 1344 | return rc; |
| 1345 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1346 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1347 | printk(KERN_INFO "%s queue busy\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1348 | rc = -EBUSY; |
| 1349 | goto out; |
| 1350 | } |
| 1351 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1352 | rc = au0828_set_format(dev, VIDIOC_S_FMT, f); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1353 | out: |
| 1354 | return rc; |
| 1355 | } |
| 1356 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1357 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1358 | { |
| 1359 | struct au0828_fh *fh = priv; |
| 1360 | struct au0828_dev *dev = fh->dev; |
| 1361 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1362 | dev->std = norm; |
| 1363 | |
| 1364 | au0828_init_tuner(dev); |
| 1365 | |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 1366 | i2c_gate_ctrl(dev, 1); |
Devin Heitmueller | e58071f | 2012-08-06 22:47:12 -0300 | [diff] [blame] | 1367 | |
Mauro Carvalho Chehab | f2fd7ce | 2014-06-08 13:54:56 -0300 | [diff] [blame] | 1368 | /* |
| 1369 | * FIXME: when we support something other than 60Hz standards, |
| 1370 | * we are going to have to make the au0828 bridge adjust the size |
| 1371 | * of its capture buffer, which is currently hardcoded at 720x480 |
| 1372 | */ |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1373 | |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 1374 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, norm); |
Devin Heitmueller | e58071f | 2012-08-06 22:47:12 -0300 | [diff] [blame] | 1375 | |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 1376 | i2c_gate_ctrl(dev, 0); |
Devin Heitmueller | e58071f | 2012-08-06 22:47:12 -0300 | [diff] [blame] | 1377 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1378 | return 0; |
| 1379 | } |
| 1380 | |
Hans Verkuil | 33b6b89 | 2013-02-15 09:22:37 -0300 | [diff] [blame] | 1381 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm) |
| 1382 | { |
| 1383 | struct au0828_fh *fh = priv; |
| 1384 | struct au0828_dev *dev = fh->dev; |
| 1385 | |
| 1386 | *norm = dev->std; |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1390 | static int vidioc_enum_input(struct file *file, void *priv, |
| 1391 | struct v4l2_input *input) |
| 1392 | { |
| 1393 | struct au0828_fh *fh = priv; |
| 1394 | struct au0828_dev *dev = fh->dev; |
| 1395 | unsigned int tmp; |
| 1396 | |
| 1397 | static const char *inames[] = { |
Devin Heitmueller | 3d62287 | 2009-03-15 17:48:26 -0300 | [diff] [blame] | 1398 | [AU0828_VMUX_UNDEFINED] = "Undefined", |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1399 | [AU0828_VMUX_COMPOSITE] = "Composite", |
| 1400 | [AU0828_VMUX_SVIDEO] = "S-Video", |
| 1401 | [AU0828_VMUX_CABLE] = "Cable TV", |
| 1402 | [AU0828_VMUX_TELEVISION] = "Television", |
| 1403 | [AU0828_VMUX_DVB] = "DVB", |
| 1404 | [AU0828_VMUX_DEBUG] = "tv debug" |
| 1405 | }; |
| 1406 | |
| 1407 | tmp = input->index; |
| 1408 | |
Dan Carpenter | f5e20c3 | 2010-03-28 08:21:18 -0300 | [diff] [blame] | 1409 | if (tmp >= AU0828_MAX_INPUT) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1410 | return -EINVAL; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1411 | if (AUVI_INPUT(tmp).type == 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1412 | return -EINVAL; |
| 1413 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1414 | input->index = tmp; |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1415 | strcpy(input->name, inames[AUVI_INPUT(tmp).type]); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1416 | if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) || |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1417 | (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1418 | input->type |= V4L2_INPUT_TYPE_TUNER; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1419 | input->audioset = 1; |
| 1420 | } else { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1421 | input->type |= V4L2_INPUT_TYPE_CAMERA; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1422 | input->audioset = 2; |
| 1423 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1424 | |
| 1425 | input->std = dev->vdev->tvnorms; |
| 1426 | |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
| 1430 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1431 | { |
| 1432 | struct au0828_fh *fh = priv; |
| 1433 | struct au0828_dev *dev = fh->dev; |
| 1434 | *i = dev->ctrl_input; |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
Hans Verkuil | 56230d1 | 2013-03-11 16:18:31 -0300 | [diff] [blame] | 1438 | static void au0828_s_input(struct au0828_dev *dev, int index) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1439 | { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1440 | int i; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1441 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1442 | switch (AUVI_INPUT(index).type) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1443 | case AU0828_VMUX_SVIDEO: |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1444 | dev->input_type = AU0828_VMUX_SVIDEO; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1445 | dev->ctrl_ainput = 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1446 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1447 | case AU0828_VMUX_COMPOSITE: |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1448 | dev->input_type = AU0828_VMUX_COMPOSITE; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1449 | dev->ctrl_ainput = 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1450 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1451 | case AU0828_VMUX_TELEVISION: |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1452 | dev->input_type = AU0828_VMUX_TELEVISION; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1453 | dev->ctrl_ainput = 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1454 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1455 | default: |
Hans Verkuil | 56230d1 | 2013-03-11 16:18:31 -0300 | [diff] [blame] | 1456 | dprintk(1, "unknown input type set [%d]\n", |
Devin Heitmueller | a1094c4 | 2009-03-15 17:43:13 -0300 | [diff] [blame] | 1457 | AUVI_INPUT(index).type); |
| 1458 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1459 | } |
| 1460 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1461 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, |
| 1462 | AUVI_INPUT(index).vmux, 0, 0); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1463 | |
| 1464 | for (i = 0; i < AU0828_MAX_INPUT; i++) { |
| 1465 | int enable = 0; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1466 | if (AUVI_INPUT(i).audio_setup == NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1467 | continue; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1468 | |
| 1469 | if (i == index) |
| 1470 | enable = 1; |
| 1471 | else |
| 1472 | enable = 0; |
| 1473 | if (enable) { |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1474 | (AUVI_INPUT(i).audio_setup)(dev, enable); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1475 | } else { |
| 1476 | /* Make sure we leave it turned on if some |
| 1477 | other input is routed to this callback */ |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1478 | if ((AUVI_INPUT(i).audio_setup) != |
| 1479 | ((AUVI_INPUT(index).audio_setup))) { |
| 1480 | (AUVI_INPUT(i).audio_setup)(dev, enable); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1485 | v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, |
| 1486 | AUVI_INPUT(index).amux, 0, 0); |
Hans Verkuil | 56230d1 | 2013-03-11 16:18:31 -0300 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static int vidioc_s_input(struct file *file, void *priv, unsigned int index) |
| 1490 | { |
| 1491 | struct au0828_fh *fh = priv; |
| 1492 | struct au0828_dev *dev = fh->dev; |
| 1493 | |
| 1494 | dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__, |
| 1495 | index); |
| 1496 | if (index >= AU0828_MAX_INPUT) |
| 1497 | return -EINVAL; |
| 1498 | if (AUVI_INPUT(index).type == 0) |
| 1499 | return -EINVAL; |
| 1500 | dev->ctrl_input = index; |
| 1501 | au0828_s_input(dev, index); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1502 | return 0; |
| 1503 | } |
| 1504 | |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1505 | static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1506 | { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1507 | if (a->index > 1) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1508 | return -EINVAL; |
| 1509 | |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1510 | if (a->index == 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1511 | strcpy(a->name, "Television"); |
| 1512 | else |
| 1513 | strcpy(a->name, "Line in"); |
| 1514 | |
| 1515 | a->capability = V4L2_AUDCAP_STEREO; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1520 | { |
| 1521 | struct au0828_fh *fh = priv; |
| 1522 | struct au0828_dev *dev = fh->dev; |
| 1523 | |
| 1524 | a->index = dev->ctrl_ainput; |
| 1525 | if (a->index == 0) |
| 1526 | strcpy(a->name, "Television"); |
| 1527 | else |
| 1528 | strcpy(a->name, "Line in"); |
| 1529 | |
| 1530 | a->capability = V4L2_AUDCAP_STEREO; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1531 | return 0; |
| 1532 | } |
| 1533 | |
Hans Verkuil | 0e8025b9 | 2012-09-04 11:59:31 -0300 | [diff] [blame] | 1534 | static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1535 | { |
| 1536 | struct au0828_fh *fh = priv; |
| 1537 | struct au0828_dev *dev = fh->dev; |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1538 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1539 | if (a->index != dev->ctrl_ainput) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1540 | return -EINVAL; |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1544 | static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
| 1545 | { |
| 1546 | struct au0828_fh *fh = priv; |
| 1547 | struct au0828_dev *dev = fh->dev; |
| 1548 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1549 | if (t->index != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1550 | return -EINVAL; |
| 1551 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1552 | strcpy(t->name, "Auvitek tuner"); |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1553 | |
| 1554 | au0828_init_tuner(dev); |
| 1555 | i2c_gate_ctrl(dev, 1); |
Devin Heitmueller | 2689d3d | 2009-03-15 20:01:53 -0300 | [diff] [blame] | 1556 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1557 | i2c_gate_ctrl(dev, 0); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | static int vidioc_s_tuner(struct file *file, void *priv, |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 1562 | const struct v4l2_tuner *t) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1563 | { |
| 1564 | struct au0828_fh *fh = priv; |
| 1565 | struct au0828_dev *dev = fh->dev; |
| 1566 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1567 | if (t->index != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1568 | return -EINVAL; |
| 1569 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1570 | au0828_init_tuner(dev); |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 1571 | i2c_gate_ctrl(dev, 1); |
Devin Heitmueller | 2689d3d | 2009-03-15 20:01:53 -0300 | [diff] [blame] | 1572 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 1573 | i2c_gate_ctrl(dev, 0); |
Devin Heitmueller | e58071f | 2012-08-06 22:47:12 -0300 | [diff] [blame] | 1574 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1575 | dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal, |
| 1576 | t->afc); |
Devin Heitmueller | e58071f | 2012-08-06 22:47:12 -0300 | [diff] [blame] | 1577 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1578 | return 0; |
| 1579 | |
| 1580 | } |
| 1581 | |
| 1582 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 1583 | struct v4l2_frequency *freq) |
| 1584 | { |
| 1585 | struct au0828_fh *fh = priv; |
| 1586 | struct au0828_dev *dev = fh->dev; |
Devin Heitmueller | c888923 | 2009-03-15 17:38:47 -0300 | [diff] [blame] | 1587 | |
Hans Verkuil | e1cf658 | 2013-03-22 13:32:20 -0300 | [diff] [blame] | 1588 | if (freq->tuner != 0) |
| 1589 | return -EINVAL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1590 | freq->frequency = dev->ctrl_freq; |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | static int vidioc_s_frequency(struct file *file, void *priv, |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 1595 | const struct v4l2_frequency *freq) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1596 | { |
| 1597 | struct au0828_fh *fh = priv; |
| 1598 | struct au0828_dev *dev = fh->dev; |
Hans Verkuil | e1cf658 | 2013-03-22 13:32:20 -0300 | [diff] [blame] | 1599 | struct v4l2_frequency new_freq = *freq; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1600 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1601 | if (freq->tuner != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1602 | return -EINVAL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1603 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1604 | au0828_init_tuner(dev); |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 1605 | i2c_gate_ctrl(dev, 1); |
Devin Heitmueller | 4a03daf | 2012-08-06 22:47:02 -0300 | [diff] [blame] | 1606 | |
Devin Heitmueller | 2689d3d | 2009-03-15 20:01:53 -0300 | [diff] [blame] | 1607 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, freq); |
Hans Verkuil | e1cf658 | 2013-03-22 13:32:20 -0300 | [diff] [blame] | 1608 | /* Get the actual set (and possibly clamped) frequency */ |
| 1609 | v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, &new_freq); |
| 1610 | dev->ctrl_freq = new_freq.frequency; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1611 | |
Hans Verkuil | fa09cb9 | 2013-03-11 16:10:33 -0300 | [diff] [blame] | 1612 | i2c_gate_ctrl(dev, 0); |
Devin Heitmueller | 4a03daf | 2012-08-06 22:47:02 -0300 | [diff] [blame] | 1613 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1614 | au0828_analog_stream_reset(dev); |
| 1615 | |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1619 | |
| 1620 | /* RAW VBI ioctls */ |
| 1621 | |
| 1622 | static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, |
| 1623 | struct v4l2_format *format) |
| 1624 | { |
| 1625 | struct au0828_fh *fh = priv; |
| 1626 | struct au0828_dev *dev = fh->dev; |
| 1627 | |
| 1628 | format->fmt.vbi.samples_per_line = dev->vbi_width; |
| 1629 | format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 1630 | format->fmt.vbi.offset = 0; |
| 1631 | format->fmt.vbi.flags = 0; |
| 1632 | format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; |
| 1633 | |
| 1634 | format->fmt.vbi.count[0] = dev->vbi_height; |
| 1635 | format->fmt.vbi.count[1] = dev->vbi_height; |
| 1636 | format->fmt.vbi.start[0] = 21; |
| 1637 | format->fmt.vbi.start[1] = 284; |
Hans Verkuil | 8d86e4e | 2013-03-11 17:48:34 -0300 | [diff] [blame] | 1638 | memset(format->fmt.vbi.reserved, 0, sizeof(format->fmt.vbi.reserved)); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1639 | |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1643 | static int vidioc_cropcap(struct file *file, void *priv, |
| 1644 | struct v4l2_cropcap *cc) |
| 1645 | { |
| 1646 | struct au0828_fh *fh = priv; |
| 1647 | struct au0828_dev *dev = fh->dev; |
| 1648 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1649 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1650 | return -EINVAL; |
| 1651 | |
| 1652 | cc->bounds.left = 0; |
| 1653 | cc->bounds.top = 0; |
| 1654 | cc->bounds.width = dev->width; |
| 1655 | cc->bounds.height = dev->height; |
| 1656 | |
| 1657 | cc->defrect = cc->bounds; |
| 1658 | |
| 1659 | cc->pixelaspect.numerator = 54; |
| 1660 | cc->pixelaspect.denominator = 59; |
| 1661 | |
| 1662 | return 0; |
| 1663 | } |
| 1664 | |
| 1665 | static int vidioc_streamon(struct file *file, void *priv, |
| 1666 | enum v4l2_buf_type type) |
| 1667 | { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1668 | struct au0828_fh *fh = priv; |
| 1669 | struct au0828_dev *dev = fh->dev; |
| 1670 | int rc = -EINVAL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1671 | |
| 1672 | rc = check_dev(dev); |
| 1673 | if (rc < 0) |
| 1674 | return rc; |
| 1675 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1676 | if (unlikely(type != fh->type)) |
| 1677 | return -EINVAL; |
| 1678 | |
| 1679 | dprintk(1, "vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n", |
| 1680 | fh, type, fh->resources, dev->resources); |
| 1681 | |
| 1682 | if (unlikely(!res_get(fh, get_ressource(fh)))) |
| 1683 | return -EBUSY; |
| 1684 | |
Hans Verkuil | ea86968f | 2013-03-11 16:22:13 -0300 | [diff] [blame] | 1685 | au0828_init_tuner(dev); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1686 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 1687 | au0828_analog_stream_enable(dev); |
Devin Heitmueller | 2689d3d | 2009-03-15 20:01:53 -0300 | [diff] [blame] | 1688 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1689 | } |
| 1690 | |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1691 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1692 | rc = videobuf_streamon(&fh->vb_vidq); |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1693 | dev->vid_timeout_running = 1; |
| 1694 | mod_timer(&dev->vid_timeout, jiffies + (HZ / 10)); |
| 1695 | } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1696 | rc = videobuf_streamon(&fh->vb_vbiq); |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1697 | dev->vbi_timeout_running = 1; |
| 1698 | mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10)); |
| 1699 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1700 | |
| 1701 | return rc; |
| 1702 | } |
| 1703 | |
| 1704 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1705 | enum v4l2_buf_type type) |
| 1706 | { |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1707 | struct au0828_fh *fh = priv; |
| 1708 | struct au0828_dev *dev = fh->dev; |
| 1709 | int rc; |
| 1710 | int i; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1711 | |
| 1712 | rc = check_dev(dev); |
| 1713 | if (rc < 0) |
| 1714 | return rc; |
| 1715 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1716 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 1717 | fh->type != V4L2_BUF_TYPE_VBI_CAPTURE) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1718 | return -EINVAL; |
| 1719 | if (type != fh->type) |
| 1720 | return -EINVAL; |
| 1721 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1722 | dprintk(1, "vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n", |
| 1723 | fh, type, fh->resources, dev->resources); |
| 1724 | |
| 1725 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1726 | dev->vid_timeout_running = 0; |
| 1727 | del_timer_sync(&dev->vid_timeout); |
| 1728 | |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 1729 | au0828_analog_stream_disable(dev); |
Devin Heitmueller | 2689d3d | 2009-03-15 20:01:53 -0300 | [diff] [blame] | 1730 | v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1731 | rc = au0828_stream_interrupt(dev); |
| 1732 | if (rc != 0) |
| 1733 | return rc; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1734 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1735 | for (i = 0; i < AU0828_MAX_INPUT; i++) { |
| 1736 | if (AUVI_INPUT(i).audio_setup == NULL) |
| 1737 | continue; |
| 1738 | (AUVI_INPUT(i).audio_setup)(dev, 0); |
| 1739 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1740 | |
Devin Heitmueller | a595c1c | 2012-08-06 22:47:03 -0300 | [diff] [blame] | 1741 | if (res_check(fh, AU0828_RESOURCE_VIDEO)) { |
| 1742 | videobuf_streamoff(&fh->vb_vidq); |
| 1743 | res_free(fh, AU0828_RESOURCE_VIDEO); |
| 1744 | } |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1745 | } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1746 | dev->vbi_timeout_running = 0; |
| 1747 | del_timer_sync(&dev->vbi_timeout); |
| 1748 | |
Devin Heitmueller | a595c1c | 2012-08-06 22:47:03 -0300 | [diff] [blame] | 1749 | if (res_check(fh, AU0828_RESOURCE_VBI)) { |
| 1750 | videobuf_streamoff(&fh->vb_vbiq); |
| 1751 | res_free(fh, AU0828_RESOURCE_VBI); |
| 1752 | } |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1753 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1754 | |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
Mauro Carvalho Chehab | 80c6e35 | 2009-03-19 19:26:23 -0300 | [diff] [blame] | 1758 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1759 | static int vidioc_g_register(struct file *file, void *priv, |
| 1760 | struct v4l2_dbg_register *reg) |
| 1761 | { |
| 1762 | struct au0828_fh *fh = priv; |
| 1763 | struct au0828_dev *dev = fh->dev; |
| 1764 | |
Devin Heitmueller | 364d2db | 2012-08-06 22:46:54 -0300 | [diff] [blame] | 1765 | reg->val = au0828_read(dev, reg->reg); |
Hans Verkuil | ead5bc4 | 2013-05-29 07:00:03 -0300 | [diff] [blame] | 1766 | reg->size = 1; |
Devin Heitmueller | 364d2db | 2012-08-06 22:46:54 -0300 | [diff] [blame] | 1767 | return 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | static int vidioc_s_register(struct file *file, void *priv, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1771 | const struct v4l2_dbg_register *reg) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1772 | { |
| 1773 | struct au0828_fh *fh = priv; |
| 1774 | struct au0828_dev *dev = fh->dev; |
| 1775 | |
Devin Heitmueller | 364d2db | 2012-08-06 22:46:54 -0300 | [diff] [blame] | 1776 | return au0828_writereg(dev, reg->reg, reg->val); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1777 | } |
Mauro Carvalho Chehab | 80c6e35 | 2009-03-19 19:26:23 -0300 | [diff] [blame] | 1778 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1779 | |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1780 | static int vidioc_log_status(struct file *file, void *fh) |
| 1781 | { |
| 1782 | struct video_device *vdev = video_devdata(file); |
| 1783 | |
| 1784 | v4l2_ctrl_log_status(file, fh); |
| 1785 | v4l2_device_call_all(vdev->v4l2_dev, 0, core, log_status); |
| 1786 | return 0; |
| 1787 | } |
| 1788 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1789 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1790 | struct v4l2_requestbuffers *rb) |
| 1791 | { |
| 1792 | struct au0828_fh *fh = priv; |
| 1793 | struct au0828_dev *dev = fh->dev; |
| 1794 | int rc; |
| 1795 | |
| 1796 | rc = check_dev(dev); |
| 1797 | if (rc < 0) |
| 1798 | return rc; |
| 1799 | |
Devin Heitmueller | 54ebb8b | 2011-01-23 19:12:27 -0300 | [diff] [blame] | 1800 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1801 | rc = videobuf_reqbufs(&fh->vb_vidq, rb); |
| 1802 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1803 | rc = videobuf_reqbufs(&fh->vb_vbiq, rb); |
| 1804 | |
| 1805 | return rc; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1809 | struct v4l2_buffer *b) |
| 1810 | { |
| 1811 | struct au0828_fh *fh = priv; |
| 1812 | struct au0828_dev *dev = fh->dev; |
| 1813 | int rc; |
| 1814 | |
| 1815 | rc = check_dev(dev); |
| 1816 | if (rc < 0) |
| 1817 | return rc; |
| 1818 | |
Devin Heitmueller | 54ebb8b | 2011-01-23 19:12:27 -0300 | [diff] [blame] | 1819 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1820 | rc = videobuf_querybuf(&fh->vb_vidq, b); |
| 1821 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1822 | rc = videobuf_querybuf(&fh->vb_vbiq, b); |
| 1823 | |
| 1824 | return rc; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1828 | { |
| 1829 | struct au0828_fh *fh = priv; |
| 1830 | struct au0828_dev *dev = fh->dev; |
| 1831 | int rc; |
| 1832 | |
| 1833 | rc = check_dev(dev); |
| 1834 | if (rc < 0) |
| 1835 | return rc; |
| 1836 | |
Devin Heitmueller | 54ebb8b | 2011-01-23 19:12:27 -0300 | [diff] [blame] | 1837 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1838 | rc = videobuf_qbuf(&fh->vb_vidq, b); |
| 1839 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1840 | rc = videobuf_qbuf(&fh->vb_vbiq, b); |
| 1841 | |
| 1842 | return rc; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1846 | { |
| 1847 | struct au0828_fh *fh = priv; |
| 1848 | struct au0828_dev *dev = fh->dev; |
| 1849 | int rc; |
| 1850 | |
| 1851 | rc = check_dev(dev); |
| 1852 | if (rc < 0) |
| 1853 | return rc; |
| 1854 | |
| 1855 | /* Workaround for a bug in the au0828 hardware design that sometimes |
| 1856 | results in the colorspace being inverted */ |
| 1857 | if (dev->greenscreen_detected == 1) { |
| 1858 | dprintk(1, "Detected green frame. Resetting stream...\n"); |
| 1859 | au0828_analog_stream_reset(dev); |
| 1860 | dev->greenscreen_detected = 0; |
| 1861 | } |
| 1862 | |
Devin Heitmueller | 54ebb8b | 2011-01-23 19:12:27 -0300 | [diff] [blame] | 1863 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1864 | rc = videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); |
| 1865 | else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
| 1866 | rc = videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags & O_NONBLOCK); |
| 1867 | |
| 1868 | return rc; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1869 | } |
| 1870 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1871 | static struct v4l2_file_operations au0828_v4l_fops = { |
| 1872 | .owner = THIS_MODULE, |
| 1873 | .open = au0828_v4l2_open, |
| 1874 | .release = au0828_v4l2_close, |
| 1875 | .read = au0828_v4l2_read, |
| 1876 | .poll = au0828_v4l2_poll, |
| 1877 | .mmap = au0828_v4l2_mmap, |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 1878 | .unlocked_ioctl = video_ioctl2, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1879 | }; |
| 1880 | |
| 1881 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
| 1882 | .vidioc_querycap = vidioc_querycap, |
| 1883 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1884 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1885 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1886 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1887 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
Hans Verkuil | 8d86e4e | 2013-03-11 17:48:34 -0300 | [diff] [blame] | 1888 | .vidioc_try_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1889 | .vidioc_s_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
Hans Verkuil | a2cf96f | 2013-02-15 08:41:24 -0300 | [diff] [blame] | 1890 | .vidioc_enumaudio = vidioc_enumaudio, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1891 | .vidioc_g_audio = vidioc_g_audio, |
| 1892 | .vidioc_s_audio = vidioc_s_audio, |
| 1893 | .vidioc_cropcap = vidioc_cropcap, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1894 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1895 | .vidioc_querybuf = vidioc_querybuf, |
| 1896 | .vidioc_qbuf = vidioc_qbuf, |
| 1897 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1898 | .vidioc_s_std = vidioc_s_std, |
Hans Verkuil | 33b6b89 | 2013-02-15 09:22:37 -0300 | [diff] [blame] | 1899 | .vidioc_g_std = vidioc_g_std, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1900 | .vidioc_enum_input = vidioc_enum_input, |
| 1901 | .vidioc_g_input = vidioc_g_input, |
| 1902 | .vidioc_s_input = vidioc_s_input, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1903 | .vidioc_streamon = vidioc_streamon, |
| 1904 | .vidioc_streamoff = vidioc_streamoff, |
| 1905 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1906 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1907 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1908 | .vidioc_s_frequency = vidioc_s_frequency, |
| 1909 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1910 | .vidioc_g_register = vidioc_g_register, |
| 1911 | .vidioc_s_register = vidioc_s_register, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1912 | #endif |
Hans Verkuil | 83b0942 | 2013-02-15 09:14:00 -0300 | [diff] [blame] | 1913 | .vidioc_log_status = vidioc_log_status, |
| 1914 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1915 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1916 | }; |
| 1917 | |
| 1918 | static const struct video_device au0828_video_template = { |
| 1919 | .fops = &au0828_v4l_fops, |
| 1920 | .release = video_device_release, |
| 1921 | .ioctl_ops = &video_ioctl_ops, |
Mauro Carvalho Chehab | f2fd7ce | 2014-06-08 13:54:56 -0300 | [diff] [blame] | 1922 | .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_M, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1923 | }; |
| 1924 | |
| 1925 | /**************************************************************************/ |
| 1926 | |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1927 | int au0828_analog_register(struct au0828_dev *dev, |
| 1928 | struct usb_interface *interface) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1929 | { |
| 1930 | int retval = -ENOMEM; |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1931 | struct usb_host_interface *iface_desc; |
| 1932 | struct usb_endpoint_descriptor *endpoint; |
Julia Lawall | d63b21b | 2012-04-22 07:54:42 -0300 | [diff] [blame] | 1933 | int i, ret; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1934 | |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 1935 | dprintk(1, "au0828_analog_register called for intf#%d!\n", |
| 1936 | interface->cur_altsetting->desc.bInterfaceNumber); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1937 | |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1938 | /* set au0828 usb interface0 to as5 */ |
| 1939 | retval = usb_set_interface(dev->usbdev, |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1940 | interface->cur_altsetting->desc.bInterfaceNumber, 5); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1941 | if (retval != 0) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1942 | printk(KERN_INFO "Failure setting usb interface0 to as5\n"); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1943 | return retval; |
| 1944 | } |
| 1945 | |
| 1946 | /* Figure out which endpoint has the isoc interface */ |
| 1947 | iface_desc = interface->cur_altsetting; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1948 | for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1949 | endpoint = &iface_desc->endpoint[i].desc; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1950 | if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
| 1951 | == USB_DIR_IN) && |
| 1952 | ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 1953 | == USB_ENDPOINT_XFER_ISOC)) { |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1954 | |
| 1955 | /* we find our isoc in endpoint */ |
| 1956 | u16 tmp = le16_to_cpu(endpoint->wMaxPacketSize); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1957 | dev->max_pkt_size = (tmp & 0x07ff) * |
| 1958 | (((tmp & 0x1800) >> 11) + 1); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1959 | dev->isoc_in_endpointaddr = endpoint->bEndpointAddress; |
Mauro Carvalho Chehab | 1fe3a8f | 2014-06-08 13:54:58 -0300 | [diff] [blame] | 1960 | dprintk(1, |
| 1961 | "Found isoc endpoint 0x%02x, max size = %d\n", |
| 1962 | dev->isoc_in_endpointaddr, dev->max_pkt_size); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1963 | } |
| 1964 | } |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1965 | if (!(dev->isoc_in_endpointaddr)) { |
| 1966 | printk(KERN_INFO "Could not locate isoc endpoint\n"); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1967 | kfree(dev); |
| 1968 | return -ENODEV; |
| 1969 | } |
| 1970 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1971 | init_waitqueue_head(&dev->open); |
| 1972 | spin_lock_init(&dev->slock); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1973 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1974 | /* init video dma queues */ |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1975 | INIT_LIST_HEAD(&dev->vidq.active); |
| 1976 | INIT_LIST_HEAD(&dev->vidq.queued); |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 1977 | INIT_LIST_HEAD(&dev->vbiq.active); |
| 1978 | INIT_LIST_HEAD(&dev->vbiq.queued); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1979 | |
Devin Heitmueller | 78ca500 | 2010-10-09 14:43:53 -0300 | [diff] [blame] | 1980 | dev->vid_timeout.function = au0828_vid_buffer_timeout; |
| 1981 | dev->vid_timeout.data = (unsigned long) dev; |
| 1982 | init_timer(&dev->vid_timeout); |
| 1983 | |
| 1984 | dev->vbi_timeout.function = au0828_vbi_buffer_timeout; |
| 1985 | dev->vbi_timeout.data = (unsigned long) dev; |
| 1986 | init_timer(&dev->vbi_timeout); |
| 1987 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1988 | dev->width = NTSC_STD_W; |
| 1989 | dev->height = NTSC_STD_H; |
| 1990 | dev->field_size = dev->width * dev->height; |
| 1991 | dev->frame_size = dev->field_size << 1; |
| 1992 | dev->bytesperline = dev->width << 1; |
Hans Verkuil | de8d2bb | 2013-03-11 16:12:17 -0300 | [diff] [blame] | 1993 | dev->vbi_width = 720; |
| 1994 | dev->vbi_height = 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1995 | dev->ctrl_ainput = 0; |
Hans Verkuil | e1cf658 | 2013-03-22 13:32:20 -0300 | [diff] [blame] | 1996 | dev->ctrl_freq = 960; |
Hans Verkuil | 33b6b89 | 2013-02-15 09:22:37 -0300 | [diff] [blame] | 1997 | dev->std = V4L2_STD_NTSC_M; |
Hans Verkuil | 56230d1 | 2013-03-11 16:18:31 -0300 | [diff] [blame] | 1998 | au0828_s_input(dev, 0); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1999 | |
| 2000 | /* allocate and fill v4l2 video struct */ |
| 2001 | dev->vdev = video_device_alloc(); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 2002 | if (NULL == dev->vdev) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2003 | dprintk(1, "Can't allocate video_device.\n"); |
| 2004 | return -ENOMEM; |
| 2005 | } |
| 2006 | |
Devin Heitmueller | 7f8eacd | 2010-05-29 17:18:45 -0300 | [diff] [blame] | 2007 | /* allocate the VBI struct */ |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2008 | dev->vbi_dev = video_device_alloc(); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 2009 | if (NULL == dev->vbi_dev) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2010 | dprintk(1, "Can't allocate vbi_device.\n"); |
Julia Lawall | d63b21b | 2012-04-22 07:54:42 -0300 | [diff] [blame] | 2011 | ret = -ENOMEM; |
| 2012 | goto err_vdev; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /* Fill the video capture device struct */ |
| 2016 | *dev->vdev = au0828_video_template; |
Hans Verkuil | e8c26f4 | 2013-02-15 08:55:41 -0300 | [diff] [blame] | 2017 | dev->vdev->v4l2_dev = &dev->v4l2_dev; |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 2018 | dev->vdev->lock = &dev->lock; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2019 | strcpy(dev->vdev->name, "au0828a video"); |
| 2020 | |
| 2021 | /* Setup the VBI device */ |
| 2022 | *dev->vbi_dev = au0828_video_template; |
Hans Verkuil | e8c26f4 | 2013-02-15 08:55:41 -0300 | [diff] [blame] | 2023 | dev->vbi_dev->v4l2_dev = &dev->v4l2_dev; |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 2024 | dev->vbi_dev->lock = &dev->lock; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2025 | strcpy(dev->vbi_dev->name, "au0828a vbi"); |
| 2026 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2027 | /* Register the v4l2 device */ |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2028 | video_set_drvdata(dev->vdev, dev); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 2029 | retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1); |
| 2030 | if (retval != 0) { |
| 2031 | dprintk(1, "unable to register video device (error = %d).\n", |
| 2032 | retval); |
Julia Lawall | d63b21b | 2012-04-22 07:54:42 -0300 | [diff] [blame] | 2033 | ret = -ENODEV; |
| 2034 | goto err_vbi_dev; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | /* Register the vbi device */ |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 2038 | video_set_drvdata(dev->vbi_dev, dev); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 2039 | retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1); |
| 2040 | if (retval != 0) { |
| 2041 | dprintk(1, "unable to register vbi device (error = %d).\n", |
| 2042 | retval); |
Julia Lawall | d63b21b | 2012-04-22 07:54:42 -0300 | [diff] [blame] | 2043 | ret = -ENODEV; |
| 2044 | goto err_vbi_dev; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2045 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2046 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 2047 | dprintk(1, "%s completed!\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2048 | |
| 2049 | return 0; |
Julia Lawall | d63b21b | 2012-04-22 07:54:42 -0300 | [diff] [blame] | 2050 | |
| 2051 | err_vbi_dev: |
| 2052 | video_device_release(dev->vbi_dev); |
| 2053 | err_vdev: |
| 2054 | video_device_release(dev->vdev); |
| 2055 | return ret; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 2056 | } |
| 2057 | |