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