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> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/device.h> |
| 34 | #include <linux/suspend.h> |
| 35 | #include <linux/version.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> |
| 38 | #include <media/v4l2-chip-ident.h> |
| 39 | #include <media/tuner.h> |
| 40 | #include "au0828.h" |
| 41 | #include "au0828-reg.h" |
| 42 | |
| 43 | static LIST_HEAD(au0828_devlist); |
| 44 | static DEFINE_MUTEX(au0828_sysfs_lock); |
| 45 | |
| 46 | #define AU0828_VERSION_CODE KERNEL_VERSION(0, 0, 1) |
| 47 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 48 | /* ------------------------------------------------------------------ |
| 49 | Videobuf operations |
| 50 | ------------------------------------------------------------------*/ |
| 51 | |
| 52 | static unsigned int isoc_debug; |
| 53 | module_param(isoc_debug, int, 0644); |
| 54 | MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); |
| 55 | |
| 56 | #define au0828_isocdbg(fmt, arg...) \ |
| 57 | do {\ |
| 58 | if (isoc_debug) { \ |
| 59 | printk(KERN_INFO "au0828 %s :"fmt, \ |
| 60 | __func__ , ##arg); \ |
| 61 | } \ |
| 62 | } while (0) |
| 63 | |
| 64 | static inline void print_err_status(struct au0828_dev *dev, |
| 65 | int packet, int status) |
| 66 | { |
| 67 | char *errmsg = "Unknown"; |
| 68 | |
| 69 | switch (status) { |
| 70 | case -ENOENT: |
| 71 | errmsg = "unlinked synchronuously"; |
| 72 | break; |
| 73 | case -ECONNRESET: |
| 74 | errmsg = "unlinked asynchronuously"; |
| 75 | break; |
| 76 | case -ENOSR: |
| 77 | errmsg = "Buffer error (overrun)"; |
| 78 | break; |
| 79 | case -EPIPE: |
| 80 | errmsg = "Stalled (device not responding)"; |
| 81 | break; |
| 82 | case -EOVERFLOW: |
| 83 | errmsg = "Babble (bad cable?)"; |
| 84 | break; |
| 85 | case -EPROTO: |
| 86 | errmsg = "Bit-stuff error (bad cable?)"; |
| 87 | break; |
| 88 | case -EILSEQ: |
| 89 | errmsg = "CRC/Timeout (could be anything)"; |
| 90 | break; |
| 91 | case -ETIME: |
| 92 | errmsg = "Device does not respond"; |
| 93 | break; |
| 94 | } |
| 95 | if (packet < 0) { |
| 96 | au0828_isocdbg("URB status %d [%s].\n", status, errmsg); |
| 97 | } else { |
| 98 | au0828_isocdbg("URB packet %d, status %d [%s].\n", |
| 99 | packet, status, errmsg); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static int check_dev(struct au0828_dev *dev) |
| 104 | { |
| 105 | if (dev->dev_state & DEV_DISCONNECTED) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 106 | printk(KERN_INFO "v4l2 ioctl: device not present\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 107 | return -ENODEV; |
| 108 | } |
| 109 | |
| 110 | if (dev->dev_state & DEV_MISCONFIGURED) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 111 | printk(KERN_INFO "v4l2 ioctl: device is misconfigured; " |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 112 | "close and open it again\n"); |
| 113 | return -EIO; |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * IRQ callback, called by URB callback |
| 120 | */ |
| 121 | static void au0828_irq_callback(struct urb *urb) |
| 122 | { |
| 123 | struct au0828_dmaqueue *dma_q = urb->context; |
| 124 | struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); |
| 125 | int rc, i; |
| 126 | |
| 127 | switch (urb->status) { |
| 128 | case 0: /* success */ |
| 129 | case -ETIMEDOUT: /* NAK */ |
| 130 | break; |
| 131 | case -ECONNRESET: /* kill */ |
| 132 | case -ENOENT: |
| 133 | case -ESHUTDOWN: |
| 134 | au0828_isocdbg("au0828_irq_callback called: status kill\n"); |
| 135 | return; |
| 136 | default: /* unknown error */ |
| 137 | au0828_isocdbg("urb completition error %d.\n", urb->status); |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | /* Copy data from URB */ |
| 142 | spin_lock(&dev->slock); |
| 143 | rc = dev->isoc_ctl.isoc_copy(dev, urb); |
| 144 | spin_unlock(&dev->slock); |
| 145 | |
| 146 | /* Reset urb buffers */ |
| 147 | for (i = 0; i < urb->number_of_packets; i++) { |
| 148 | urb->iso_frame_desc[i].status = 0; |
| 149 | urb->iso_frame_desc[i].actual_length = 0; |
| 150 | } |
| 151 | urb->status = 0; |
| 152 | |
| 153 | urb->status = usb_submit_urb(urb, GFP_ATOMIC); |
| 154 | if (urb->status) { |
| 155 | au0828_isocdbg("urb resubmit failed (error=%i)\n", |
| 156 | urb->status); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Stop and Deallocate URBs |
| 162 | */ |
| 163 | void au0828_uninit_isoc(struct au0828_dev *dev) |
| 164 | { |
| 165 | struct urb *urb; |
| 166 | int i; |
| 167 | |
| 168 | au0828_isocdbg("au0828: called au0828_uninit_isoc\n"); |
| 169 | |
| 170 | dev->isoc_ctl.nfields = -1; |
| 171 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
| 172 | urb = dev->isoc_ctl.urb[i]; |
| 173 | if (urb) { |
| 174 | if (!irqs_disabled()) |
| 175 | usb_kill_urb(urb); |
| 176 | else |
| 177 | usb_unlink_urb(urb); |
| 178 | |
| 179 | if (dev->isoc_ctl.transfer_buffer[i]) { |
| 180 | usb_buffer_free(dev->usbdev, |
| 181 | urb->transfer_buffer_length, |
| 182 | dev->isoc_ctl.transfer_buffer[i], |
| 183 | urb->transfer_dma); |
| 184 | } |
| 185 | usb_free_urb(urb); |
| 186 | dev->isoc_ctl.urb[i] = NULL; |
| 187 | } |
| 188 | dev->isoc_ctl.transfer_buffer[i] = NULL; |
| 189 | } |
| 190 | |
| 191 | kfree(dev->isoc_ctl.urb); |
| 192 | kfree(dev->isoc_ctl.transfer_buffer); |
| 193 | |
| 194 | dev->isoc_ctl.urb = NULL; |
| 195 | dev->isoc_ctl.transfer_buffer = NULL; |
| 196 | dev->isoc_ctl.num_bufs = 0; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Allocate URBs and start IRQ |
| 201 | */ |
| 202 | int au0828_init_isoc(struct au0828_dev *dev, int max_packets, |
| 203 | int num_bufs, int max_pkt_size, |
| 204 | int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb)) |
| 205 | { |
| 206 | struct au0828_dmaqueue *dma_q = &dev->vidq; |
| 207 | int i; |
| 208 | int sb_size, pipe; |
| 209 | struct urb *urb; |
| 210 | int j, k; |
| 211 | int rc; |
| 212 | |
| 213 | au0828_isocdbg("au0828: called au0828_prepare_isoc\n"); |
| 214 | |
| 215 | /* De-allocates all pending stuff */ |
| 216 | au0828_uninit_isoc(dev); |
| 217 | |
| 218 | dev->isoc_ctl.isoc_copy = isoc_copy; |
| 219 | dev->isoc_ctl.num_bufs = num_bufs; |
| 220 | |
| 221 | dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); |
| 222 | if (!dev->isoc_ctl.urb) { |
| 223 | au0828_isocdbg("cannot alloc memory for usb buffers\n"); |
| 224 | return -ENOMEM; |
| 225 | } |
| 226 | |
| 227 | dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs, |
| 228 | GFP_KERNEL); |
| 229 | if (!dev->isoc_ctl.transfer_buffer) { |
| 230 | au0828_isocdbg("cannot allocate memory for usb transfer\n"); |
| 231 | kfree(dev->isoc_ctl.urb); |
| 232 | return -ENOMEM; |
| 233 | } |
| 234 | |
| 235 | dev->isoc_ctl.max_pkt_size = max_pkt_size; |
| 236 | dev->isoc_ctl.buf = NULL; |
| 237 | |
| 238 | sb_size = max_packets * dev->isoc_ctl.max_pkt_size; |
| 239 | |
| 240 | /* allocate urbs and transfer buffers */ |
| 241 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
| 242 | urb = usb_alloc_urb(max_packets, GFP_KERNEL); |
| 243 | if (!urb) { |
| 244 | au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i); |
| 245 | au0828_uninit_isoc(dev); |
| 246 | return -ENOMEM; |
| 247 | } |
| 248 | dev->isoc_ctl.urb[i] = urb; |
| 249 | |
| 250 | dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->usbdev, |
| 251 | sb_size, GFP_KERNEL, &urb->transfer_dma); |
| 252 | if (!dev->isoc_ctl.transfer_buffer[i]) { |
| 253 | printk("unable to allocate %i bytes for transfer" |
| 254 | " buffer %i%s\n", |
| 255 | sb_size, i, |
| 256 | in_interrupt() ? " while in int" : ""); |
| 257 | au0828_uninit_isoc(dev); |
| 258 | return -ENOMEM; |
| 259 | } |
| 260 | memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); |
| 261 | |
| 262 | pipe = usb_rcvisocpipe(dev->usbdev, |
| 263 | dev->isoc_in_endpointaddr), |
| 264 | |
| 265 | usb_fill_int_urb(urb, dev->usbdev, pipe, |
| 266 | dev->isoc_ctl.transfer_buffer[i], sb_size, |
| 267 | au0828_irq_callback, dma_q, 1); |
| 268 | |
| 269 | urb->number_of_packets = max_packets; |
| 270 | urb->transfer_flags = URB_ISO_ASAP; |
| 271 | |
| 272 | k = 0; |
| 273 | for (j = 0; j < max_packets; j++) { |
| 274 | urb->iso_frame_desc[j].offset = k; |
| 275 | urb->iso_frame_desc[j].length = |
| 276 | dev->isoc_ctl.max_pkt_size; |
| 277 | k += dev->isoc_ctl.max_pkt_size; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | init_waitqueue_head(&dma_q->wq); |
| 282 | |
| 283 | /* submit urbs and enables IRQ */ |
| 284 | for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { |
| 285 | rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC); |
| 286 | if (rc) { |
| 287 | au0828_isocdbg("submit of urb %i failed (error=%i)\n", |
| 288 | i, rc); |
| 289 | au0828_uninit_isoc(dev); |
| 290 | return rc; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Announces that a buffer were filled and request the next |
| 299 | */ |
| 300 | static inline void buffer_filled(struct au0828_dev *dev, |
| 301 | struct au0828_dmaqueue *dma_q, |
| 302 | struct au0828_buffer *buf) |
| 303 | { |
| 304 | /* Advice that buffer was filled */ |
| 305 | au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); |
| 306 | |
| 307 | buf->vb.state = VIDEOBUF_DONE; |
| 308 | buf->vb.field_count++; |
| 309 | do_gettimeofday(&buf->vb.ts); |
| 310 | |
| 311 | dev->isoc_ctl.buf = NULL; |
| 312 | |
| 313 | list_del(&buf->vb.queue); |
| 314 | wake_up(&buf->vb.done); |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * Identify the buffer header type and properly handles |
| 319 | */ |
| 320 | static void au0828_copy_video(struct au0828_dev *dev, |
| 321 | struct au0828_dmaqueue *dma_q, |
| 322 | struct au0828_buffer *buf, |
| 323 | unsigned char *p, |
| 324 | unsigned char *outp, unsigned long len) |
| 325 | { |
| 326 | void *fieldstart, *startwrite, *startread; |
| 327 | int linesdone, currlinedone, offset, lencopy, remain; |
| 328 | int bytesperline = dev->width << 1; /* Assumes 16-bit depth @@@@ */ |
| 329 | |
| 330 | if (dma_q->pos + len > buf->vb.size) |
| 331 | len = buf->vb.size - dma_q->pos; |
| 332 | |
| 333 | startread = p; |
| 334 | remain = len; |
| 335 | |
| 336 | /* Interlaces frame */ |
| 337 | if (buf->top_field) |
| 338 | fieldstart = outp; |
| 339 | else |
| 340 | fieldstart = outp + bytesperline; |
| 341 | |
| 342 | linesdone = dma_q->pos / bytesperline; |
| 343 | currlinedone = dma_q->pos % bytesperline; |
| 344 | offset = linesdone * bytesperline * 2 + currlinedone; |
| 345 | startwrite = fieldstart + offset; |
| 346 | lencopy = bytesperline - currlinedone; |
| 347 | lencopy = lencopy > remain ? remain : lencopy; |
| 348 | |
| 349 | if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { |
| 350 | au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n", |
| 351 | ((char *)startwrite + lencopy) - |
| 352 | ((char *)outp + buf->vb.size)); |
| 353 | remain = (char *)outp + buf->vb.size - (char *)startwrite; |
| 354 | lencopy = remain; |
| 355 | } |
| 356 | if (lencopy <= 0) |
| 357 | return; |
| 358 | memcpy(startwrite, startread, lencopy); |
| 359 | |
| 360 | remain -= lencopy; |
| 361 | |
| 362 | while (remain > 0) { |
| 363 | startwrite += lencopy + bytesperline; |
| 364 | startread += lencopy; |
| 365 | if (bytesperline > remain) |
| 366 | lencopy = remain; |
| 367 | else |
| 368 | lencopy = bytesperline; |
| 369 | |
| 370 | if ((char *)startwrite + lencopy > (char *)outp + |
| 371 | buf->vb.size) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 372 | au0828_isocdbg("Overflow %zi bytes past buf end (2)\n", |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 373 | ((char *)startwrite + lencopy) - |
| 374 | ((char *)outp + buf->vb.size)); |
| 375 | lencopy = remain = (char *)outp + buf->vb.size - |
| 376 | (char *)startwrite; |
| 377 | } |
| 378 | if (lencopy <= 0) |
| 379 | break; |
| 380 | |
| 381 | memcpy(startwrite, startread, lencopy); |
| 382 | |
| 383 | remain -= lencopy; |
| 384 | } |
| 385 | |
| 386 | if (offset > 1440) { |
| 387 | /* We have enough data to check for greenscreen */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 388 | if (outp[0] < 0x60 && outp[1440] < 0x60) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 389 | dev->greenscreen_detected = 1; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | dma_q->pos += len; |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * video-buf generic routine to get the next available buffer |
| 397 | */ |
| 398 | static inline void get_next_buf(struct au0828_dmaqueue *dma_q, |
| 399 | struct au0828_buffer **buf) |
| 400 | { |
| 401 | struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); |
| 402 | |
| 403 | if (list_empty(&dma_q->active)) { |
| 404 | au0828_isocdbg("No active queue to serve\n"); |
| 405 | dev->isoc_ctl.buf = NULL; |
| 406 | *buf = NULL; |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | /* Get the next buffer */ |
| 411 | *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue); |
| 412 | dev->isoc_ctl.buf = *buf; |
| 413 | |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | /* |
| 418 | * Controls the isoc copy of each urb packet |
| 419 | */ |
| 420 | static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb) |
| 421 | { |
| 422 | struct au0828_buffer *buf; |
| 423 | struct au0828_dmaqueue *dma_q = urb->context; |
| 424 | unsigned char *outp = NULL; |
| 425 | int i, len = 0, rc = 1; |
| 426 | unsigned char *p; |
| 427 | unsigned char fbyte; |
| 428 | |
| 429 | if (!dev) |
| 430 | return 0; |
| 431 | |
| 432 | if ((dev->dev_state & DEV_DISCONNECTED) || |
| 433 | (dev->dev_state & DEV_MISCONFIGURED)) |
| 434 | return 0; |
| 435 | |
| 436 | if (urb->status < 0) { |
| 437 | print_err_status(dev, -1, urb->status); |
| 438 | if (urb->status == -ENOENT) |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | buf = dev->isoc_ctl.buf; |
| 443 | if (buf != NULL) |
| 444 | outp = videobuf_to_vmalloc(&buf->vb); |
| 445 | |
| 446 | for (i = 0; i < urb->number_of_packets; i++) { |
| 447 | int status = urb->iso_frame_desc[i].status; |
| 448 | |
| 449 | if (status < 0) { |
| 450 | print_err_status(dev, i, status); |
| 451 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 452 | continue; |
| 453 | } |
| 454 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 455 | if (urb->iso_frame_desc[i].actual_length <= 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 456 | continue; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 457 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 458 | if (urb->iso_frame_desc[i].actual_length > |
| 459 | dev->max_pkt_size) { |
| 460 | au0828_isocdbg("packet bigger than packet size"); |
| 461 | continue; |
| 462 | } |
| 463 | |
| 464 | p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
| 465 | fbyte = p[0]; |
| 466 | len = urb->iso_frame_desc[i].actual_length - 4; |
| 467 | p += 4; |
| 468 | |
| 469 | if (fbyte & 0x80) { |
| 470 | len -= 4; |
| 471 | p += 4; |
| 472 | au0828_isocdbg("Video frame %s\n", |
| 473 | (fbyte & 0x40) ? "odd" : "even"); |
| 474 | if (!(fbyte & 0x40)) { |
| 475 | if (buf != NULL) |
| 476 | buffer_filled(dev, dma_q, buf); |
| 477 | get_next_buf(dma_q, &buf); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 478 | if (buf == NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 479 | outp = NULL; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 480 | else |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 481 | outp = videobuf_to_vmalloc(&buf->vb); |
| 482 | } |
| 483 | |
| 484 | if (buf != NULL) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 485 | if (fbyte & 0x40) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 486 | buf->top_field = 1; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 487 | else |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 488 | buf->top_field = 0; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | dma_q->pos = 0; |
| 492 | } |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 493 | if (buf != NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 494 | au0828_copy_video(dev, dma_q, buf, p, outp, len); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 495 | } |
| 496 | return rc; |
| 497 | } |
| 498 | |
| 499 | static int |
| 500 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, |
| 501 | unsigned int *size) |
| 502 | { |
| 503 | struct au0828_fh *fh = vq->priv_data; |
| 504 | *size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; |
| 505 | |
| 506 | if (0 == *count) |
| 507 | *count = AU0828_DEF_BUF; |
| 508 | |
| 509 | if (*count < AU0828_MIN_BUF) |
| 510 | *count = AU0828_MIN_BUF; |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | /* This is called *without* dev->slock held; please keep it that way */ |
| 515 | static void free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf) |
| 516 | { |
| 517 | struct au0828_fh *fh = vq->priv_data; |
| 518 | struct au0828_dev *dev = fh->dev; |
| 519 | unsigned long flags = 0; |
| 520 | if (in_interrupt()) |
| 521 | BUG(); |
| 522 | |
| 523 | /* We used to wait for the buffer to finish here, but this didn't work |
| 524 | because, as we were keeping the state as VIDEOBUF_QUEUED, |
| 525 | videobuf_queue_cancel marked it as finished for us. |
| 526 | (Also, it could wedge forever if the hardware was misconfigured.) |
| 527 | |
| 528 | This should be safe; by the time we get here, the buffer isn't |
| 529 | queued anymore. If we ever start marking the buffers as |
| 530 | VIDEOBUF_ACTIVE, it won't be, though. |
| 531 | */ |
| 532 | spin_lock_irqsave(&dev->slock, flags); |
| 533 | if (dev->isoc_ctl.buf == buf) |
| 534 | dev->isoc_ctl.buf = NULL; |
| 535 | spin_unlock_irqrestore(&dev->slock, flags); |
| 536 | |
| 537 | videobuf_vmalloc_free(&buf->vb); |
| 538 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 539 | } |
| 540 | |
| 541 | static int |
| 542 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
| 543 | enum v4l2_field field) |
| 544 | { |
| 545 | struct au0828_fh *fh = vq->priv_data; |
| 546 | struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb); |
| 547 | struct au0828_dev *dev = fh->dev; |
| 548 | int rc = 0, urb_init = 0; |
| 549 | |
| 550 | buf->vb.size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; |
| 551 | |
| 552 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | buf->vb.width = dev->width; |
| 556 | buf->vb.height = dev->height; |
| 557 | buf->vb.field = field; |
| 558 | |
| 559 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
| 560 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 561 | if (rc < 0) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 562 | printk(KERN_INFO "videobuf_iolock failed\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 563 | goto fail; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (!dev->isoc_ctl.num_bufs) |
| 568 | urb_init = 1; |
| 569 | |
| 570 | if (urb_init) { |
| 571 | rc = au0828_init_isoc(dev, AU0828_ISO_PACKETS_PER_URB, |
| 572 | AU0828_MAX_ISO_BUFS, dev->max_pkt_size, |
| 573 | au0828_isoc_copy); |
| 574 | if (rc < 0) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 575 | printk(KERN_INFO "au0828_init_isoc failed\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 576 | goto fail; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | buf->vb.state = VIDEOBUF_PREPARED; |
| 581 | return 0; |
| 582 | |
| 583 | fail: |
| 584 | free_buffer(vq, buf); |
| 585 | return rc; |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 590 | { |
| 591 | struct au0828_buffer *buf = container_of(vb, |
| 592 | struct au0828_buffer, |
| 593 | vb); |
| 594 | struct au0828_fh *fh = vq->priv_data; |
| 595 | struct au0828_dev *dev = fh->dev; |
| 596 | struct au0828_dmaqueue *vidq = &dev->vidq; |
| 597 | |
| 598 | buf->vb.state = VIDEOBUF_QUEUED; |
| 599 | list_add_tail(&buf->vb.queue, &vidq->active); |
| 600 | } |
| 601 | |
| 602 | static void buffer_release(struct videobuf_queue *vq, |
| 603 | struct videobuf_buffer *vb) |
| 604 | { |
| 605 | struct au0828_buffer *buf = container_of(vb, |
| 606 | struct au0828_buffer, |
| 607 | vb); |
| 608 | |
| 609 | free_buffer(vq, buf); |
| 610 | } |
| 611 | |
| 612 | static struct videobuf_queue_ops au0828_video_qops = { |
| 613 | .buf_setup = buffer_setup, |
| 614 | .buf_prepare = buffer_prepare, |
| 615 | .buf_queue = buffer_queue, |
| 616 | .buf_release = buffer_release, |
| 617 | }; |
| 618 | |
| 619 | /* ------------------------------------------------------------------ |
| 620 | V4L2 interface |
| 621 | ------------------------------------------------------------------*/ |
| 622 | |
| 623 | static int au0828_i2s_init(struct au0828_dev *dev) |
| 624 | { |
| 625 | /* Enable i2s mode */ |
| 626 | au0828_writereg(dev, AU0828_AUDIOCTRL_50C, 0x01); |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | * Auvitek au0828 analog stream enable |
| 632 | * Please set interface0 to AS5 before enable the stream |
| 633 | */ |
| 634 | int au0828_analog_stream_enable(struct au0828_dev *d) |
| 635 | { |
| 636 | dprintk(1, "au0828_analog_stream_enable called\n"); |
| 637 | au0828_writereg(d, AU0828_SENSORCTRL_VBI_103, 0x00); |
| 638 | au0828_writereg(d, 0x106, 0x00); |
| 639 | /* set x position */ |
| 640 | au0828_writereg(d, 0x110, 0x00); |
| 641 | au0828_writereg(d, 0x111, 0x00); |
| 642 | au0828_writereg(d, 0x114, 0xa0); |
| 643 | au0828_writereg(d, 0x115, 0x05); |
| 644 | /* set y position */ |
| 645 | au0828_writereg(d, 0x112, 0x02); |
| 646 | au0828_writereg(d, 0x113, 0x00); |
| 647 | au0828_writereg(d, 0x116, 0xf2); |
| 648 | au0828_writereg(d, 0x117, 0x00); |
| 649 | au0828_writereg(d, AU0828_SENSORCTRL_100, 0xb3); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | int au0828_analog_stream_disable(struct au0828_dev *d) |
| 655 | { |
| 656 | dprintk(1, "au0828_analog_stream_disable called\n"); |
| 657 | au0828_writereg(d, AU0828_SENSORCTRL_100, 0x0); |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | void au0828_analog_stream_reset(struct au0828_dev *dev) |
| 662 | { |
| 663 | dprintk(1, "au0828_analog_stream_reset called\n"); |
| 664 | au0828_writereg(dev, AU0828_SENSORCTRL_100, 0x0); |
| 665 | mdelay(30); |
| 666 | au0828_writereg(dev, AU0828_SENSORCTRL_100, 0xb3); |
| 667 | } |
| 668 | |
| 669 | /* |
| 670 | * Some operations needs to stop current streaming |
| 671 | */ |
| 672 | static int au0828_stream_interrupt(struct au0828_dev *dev) |
| 673 | { |
| 674 | int ret = 0; |
| 675 | |
| 676 | dev->stream_state = STREAM_INTERRUPT; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 677 | if (dev->dev_state == DEV_DISCONNECTED) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 678 | return -ENODEV; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 679 | else if (ret) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 680 | dev->dev_state = DEV_MISCONFIGURED; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 681 | dprintk(1, "%s device is misconfigured!\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 682 | return ret; |
| 683 | } |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | /* |
| 688 | * au0828_release_resources |
| 689 | * unregister v4l2 devices |
| 690 | */ |
| 691 | void au0828_analog_unregister(struct au0828_dev *dev) |
| 692 | { |
| 693 | dprintk(1, "au0828_release_resources called\n"); |
| 694 | mutex_lock(&au0828_sysfs_lock); |
| 695 | |
Devin Heitmueller | 2eaf396 | 2009-03-11 03:01:02 -0300 | [diff] [blame] | 696 | if (dev->vdev) { |
| 697 | list_del(&dev->au0828list); |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 698 | video_unregister_device(dev->vdev); |
Devin Heitmueller | 2eaf396 | 2009-03-11 03:01:02 -0300 | [diff] [blame] | 699 | } |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 700 | if (dev->vbi_dev) |
| 701 | video_unregister_device(dev->vbi_dev); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 702 | |
| 703 | mutex_unlock(&au0828_sysfs_lock); |
| 704 | } |
| 705 | |
| 706 | |
| 707 | /* Usage lock check functions */ |
| 708 | static int res_get(struct au0828_fh *fh) |
| 709 | { |
| 710 | struct au0828_dev *dev = fh->dev; |
| 711 | int rc = 0; |
| 712 | |
| 713 | /* This instance already has stream_on */ |
| 714 | if (fh->stream_on) |
| 715 | return rc; |
| 716 | |
| 717 | if (dev->stream_on) |
| 718 | return -EBUSY; |
| 719 | |
| 720 | dev->stream_on = 1; |
| 721 | fh->stream_on = 1; |
| 722 | return rc; |
| 723 | } |
| 724 | |
| 725 | static int res_check(struct au0828_fh *fh) |
| 726 | { |
| 727 | return fh->stream_on; |
| 728 | } |
| 729 | |
| 730 | static void res_free(struct au0828_fh *fh) |
| 731 | { |
| 732 | struct au0828_dev *dev = fh->dev; |
| 733 | |
| 734 | fh->stream_on = 0; |
| 735 | dev->stream_on = 0; |
| 736 | } |
| 737 | |
| 738 | static int au0828_v4l2_open(struct file *filp) |
| 739 | { |
| 740 | int minor = video_devdata(filp)->minor; |
| 741 | int ret = 0; |
| 742 | struct au0828_dev *h, *dev = NULL; |
| 743 | struct au0828_fh *fh; |
| 744 | int type = 0; |
| 745 | struct list_head *list; |
| 746 | |
| 747 | list_for_each(list, &au0828_devlist) { |
| 748 | h = list_entry(list, struct au0828_dev, au0828list); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 749 | if (h->vdev->minor == minor) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 750 | dev = h; |
| 751 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 752 | } |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 753 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 754 | if (h->vbi_dev->minor == minor) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 755 | dev = h; |
| 756 | type = V4L2_BUF_TYPE_VBI_CAPTURE; |
| 757 | } |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 758 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 759 | } |
| 760 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 761 | if (NULL == dev) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 762 | return -ENODEV; |
| 763 | |
| 764 | fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 765 | if (NULL == fh) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 766 | dprintk(1, "Failed allocate au0828_fh struct!\n"); |
| 767 | return -ENOMEM; |
| 768 | } |
| 769 | |
| 770 | fh->type = type; |
| 771 | fh->dev = dev; |
| 772 | filp->private_data = fh; |
| 773 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 774 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 775 | /* set au0828 interface0 to AS5 here again */ |
| 776 | ret = usb_set_interface(dev->usbdev, 0, 5); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 777 | if (ret < 0) { |
| 778 | printk(KERN_INFO "Au0828 can't set alternate to 5!\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 779 | return -EBUSY; |
| 780 | } |
| 781 | dev->width = NTSC_STD_W; |
| 782 | dev->height = NTSC_STD_H; |
| 783 | dev->frame_size = dev->width * dev->height * 2; |
| 784 | dev->field_size = dev->width * dev->height; |
| 785 | dev->bytesperline = dev->width * 2; |
| 786 | |
| 787 | au0828_analog_stream_enable(dev); |
| 788 | au0828_analog_stream_reset(dev); |
| 789 | |
| 790 | /* If we were doing ac97 instead of i2s, it would go here...*/ |
| 791 | au0828_i2s_init(dev); |
| 792 | |
| 793 | dev->stream_state = STREAM_OFF; |
| 794 | dev->dev_state |= DEV_INITIALIZED; |
| 795 | } |
| 796 | |
| 797 | dev->users++; |
| 798 | |
| 799 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops, |
| 800 | NULL, &dev->slock, fh->type, |
| 801 | V4L2_FIELD_INTERLACED, |
| 802 | sizeof(struct au0828_buffer), fh); |
| 803 | |
| 804 | return ret; |
| 805 | } |
| 806 | |
| 807 | static int au0828_v4l2_close(struct file *filp) |
| 808 | { |
| 809 | int ret; |
| 810 | struct au0828_fh *fh = filp->private_data; |
| 811 | struct au0828_dev *dev = fh->dev; |
| 812 | |
| 813 | mutex_lock(&dev->lock); |
| 814 | if (res_check(fh)) |
| 815 | res_free(fh); |
| 816 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 817 | if (dev->users == 1) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 818 | videobuf_stop(&fh->vb_vidq); |
| 819 | videobuf_mmap_free(&fh->vb_vidq); |
| 820 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 821 | if (dev->dev_state & DEV_DISCONNECTED) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 822 | au0828_analog_unregister(dev); |
| 823 | mutex_unlock(&dev->lock); |
| 824 | kfree(dev); |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | au0828_analog_stream_disable(dev); |
| 829 | |
| 830 | au0828_uninit_isoc(dev); |
| 831 | |
| 832 | /* When close the device, set the usb intf0 into alt0 to free |
| 833 | USB bandwidth */ |
| 834 | ret = usb_set_interface(dev->usbdev, 0, 0); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 835 | if (ret < 0) |
| 836 | printk(KERN_INFO "Au0828 can't set alternate to 0!\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | kfree(fh); |
| 840 | dev->users--; |
| 841 | wake_up_interruptible_nr(&dev->open, 1); |
| 842 | mutex_unlock(&dev->lock); |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf, |
| 847 | size_t count, loff_t *pos) |
| 848 | { |
| 849 | struct au0828_fh *fh = filp->private_data; |
| 850 | struct au0828_dev *dev = fh->dev; |
| 851 | int rc; |
| 852 | |
| 853 | rc = check_dev(dev); |
| 854 | if (rc < 0) |
| 855 | return rc; |
| 856 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 857 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 858 | mutex_lock(&dev->lock); |
| 859 | rc = res_get(fh); |
| 860 | mutex_unlock(&dev->lock); |
| 861 | |
| 862 | if (unlikely(rc < 0)) |
| 863 | return rc; |
| 864 | |
| 865 | return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, |
| 866 | filp->f_flags & O_NONBLOCK); |
| 867 | } |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait) |
| 872 | { |
| 873 | struct au0828_fh *fh = filp->private_data; |
| 874 | struct au0828_dev *dev = fh->dev; |
| 875 | int rc; |
| 876 | |
| 877 | rc = check_dev(dev); |
| 878 | if (rc < 0) |
| 879 | return rc; |
| 880 | |
| 881 | mutex_lock(&dev->lock); |
| 882 | rc = res_get(fh); |
| 883 | mutex_unlock(&dev->lock); |
| 884 | |
| 885 | if (unlikely(rc < 0)) |
| 886 | return POLLERR; |
| 887 | |
| 888 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) |
| 889 | return POLLERR; |
| 890 | |
| 891 | return videobuf_poll_stream(filp, &fh->vb_vidq, wait); |
| 892 | } |
| 893 | |
| 894 | static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) |
| 895 | { |
| 896 | struct au0828_fh *fh = filp->private_data; |
| 897 | struct au0828_dev *dev = fh->dev; |
| 898 | int rc; |
| 899 | |
| 900 | rc = check_dev(dev); |
| 901 | if (rc < 0) |
| 902 | return rc; |
| 903 | |
| 904 | mutex_lock(&dev->lock); |
| 905 | rc = res_get(fh); |
| 906 | mutex_unlock(&dev->lock); |
| 907 | |
| 908 | if (unlikely(rc < 0)) |
| 909 | return rc; |
| 910 | |
| 911 | rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
| 912 | |
| 913 | dprintk(2, "vma start=0x%08lx, size=%ld, ret=%d\n", |
| 914 | (unsigned long)vma->vm_start, |
| 915 | (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, |
| 916 | rc); |
| 917 | |
| 918 | return rc; |
| 919 | } |
| 920 | |
| 921 | static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd, |
| 922 | struct v4l2_format *format) |
| 923 | { |
| 924 | int ret; |
| 925 | int width = format->fmt.pix.width; |
| 926 | int height = format->fmt.pix.height; |
| 927 | unsigned int maxwidth, maxheight; |
| 928 | |
| 929 | maxwidth = 720; |
| 930 | maxheight = 480; |
| 931 | |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 932 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 933 | if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 934 | dprintk(1, "VBI format set: to be supported!\n"); |
| 935 | return 0; |
| 936 | } |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 937 | if (format->type == V4L2_BUF_TYPE_VBI_CAPTURE) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 938 | return 0; |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 939 | #endif |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 940 | if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 941 | return -EINVAL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 942 | |
| 943 | /* If they are demanding a format other than the one we support, |
| 944 | bail out (tvtime asks for UYVY and then retries with YUYV) */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 945 | if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 946 | return -EINVAL; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 947 | |
| 948 | /* format->fmt.pix.width only support 720 and height 480 */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 949 | if (width != 720) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 950 | width = 720; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 951 | if (height != 480) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 952 | height = 480; |
| 953 | |
| 954 | format->fmt.pix.width = width; |
| 955 | format->fmt.pix.height = height; |
| 956 | format->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; |
| 957 | format->fmt.pix.bytesperline = width * 2; |
| 958 | format->fmt.pix.sizeimage = width * height * 2; |
| 959 | format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 960 | format->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 961 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 962 | if (cmd == VIDIOC_TRY_FMT) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 963 | return 0; |
| 964 | |
| 965 | /* maybe set new image format, driver current only support 720*480 */ |
| 966 | dev->width = width; |
| 967 | dev->height = height; |
| 968 | dev->frame_size = width * height * 2; |
| 969 | dev->field_size = width * height; |
| 970 | dev->bytesperline = width * 2; |
| 971 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 972 | if (dev->stream_state == STREAM_ON) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 973 | dprintk(1, "VIDIOC_SET_FMT: interrupting stream!\n"); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 974 | ret = au0828_stream_interrupt(dev); |
| 975 | if (ret != 0) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 976 | dprintk(1, "error interrupting video stream!\n"); |
| 977 | return ret; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | /* set au0828 interface0 to AS5 here again */ |
| 982 | ret = usb_set_interface(dev->usbdev, 0, 5); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 983 | if (ret < 0) { |
| 984 | printk(KERN_INFO "Au0828 can't set alt setting to 5!\n"); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 985 | return -EBUSY; |
| 986 | } |
| 987 | |
| 988 | au0828_analog_stream_enable(dev); |
| 989 | |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | |
| 994 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 995 | struct v4l2_queryctrl *qc) |
| 996 | { |
| 997 | struct au0828_fh *fh = priv; |
| 998 | struct au0828_dev *dev = fh->dev; |
| 999 | au0828_call_i2c_clients(dev, VIDIOC_QUERYCTRL, qc); |
| 1000 | if (qc->type) |
| 1001 | return 0; |
| 1002 | else |
| 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | |
| 1006 | static int vidioc_querycap(struct file *file, void *priv, |
| 1007 | struct v4l2_capability *cap) |
| 1008 | { |
| 1009 | struct au0828_fh *fh = priv; |
| 1010 | struct au0828_dev *dev = fh->dev; |
| 1011 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1012 | strlcpy(cap->driver, "au0828", sizeof(cap->driver)); |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1013 | strlcpy(cap->card, dev->board.name, sizeof(cap->card)); |
Devin Heitmueller | b14667f | 2009-03-11 03:01:04 -0300 | [diff] [blame] | 1014 | strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info)); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1015 | |
| 1016 | cap->version = AU0828_VERSION_CODE; |
| 1017 | |
| 1018 | /*set the device capabilities */ |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1019 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 1020 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1021 | V4L2_CAP_VBI_CAPTURE | |
| 1022 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1023 | V4L2_CAP_AUDIO | |
| 1024 | V4L2_CAP_READWRITE | |
| 1025 | V4L2_CAP_STREAMING | |
| 1026 | V4L2_CAP_TUNER; |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 1031 | struct v4l2_fmtdesc *f) |
| 1032 | { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1033 | if (f->index) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1034 | return -EINVAL; |
| 1035 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1036 | f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1037 | strcpy(f->description, "Packed YUV2"); |
| 1038 | |
| 1039 | f->flags = 0; |
| 1040 | f->pixelformat = V4L2_PIX_FMT_UYVY; |
| 1041 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 1046 | struct v4l2_format *f) |
| 1047 | { |
| 1048 | struct au0828_fh *fh = priv; |
| 1049 | struct au0828_dev *dev = fh->dev; |
| 1050 | |
| 1051 | f->fmt.pix.width = dev->width; |
| 1052 | f->fmt.pix.height = dev->height; |
| 1053 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; |
| 1054 | f->fmt.pix.bytesperline = dev->bytesperline; |
| 1055 | f->fmt.pix.sizeimage = dev->frame_size; |
| 1056 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */ |
| 1057 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 1062 | struct v4l2_format *f) |
| 1063 | { |
| 1064 | struct au0828_fh *fh = priv; |
| 1065 | struct au0828_dev *dev = fh->dev; |
| 1066 | |
| 1067 | return au0828_set_format(dev, VIDIOC_TRY_FMT, f); |
| 1068 | } |
| 1069 | |
| 1070 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
| 1071 | struct v4l2_format *f) |
| 1072 | { |
| 1073 | struct au0828_fh *fh = priv; |
| 1074 | struct au0828_dev *dev = fh->dev; |
| 1075 | int rc; |
| 1076 | |
| 1077 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1078 | printk(KERN_INFO "%s queue busy\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1079 | rc = -EBUSY; |
| 1080 | goto out; |
| 1081 | } |
| 1082 | |
| 1083 | if (dev->stream_on && !fh->stream_on) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1084 | printk(KERN_INFO "%s device in use by another fh\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1085 | rc = -EBUSY; |
| 1086 | goto out; |
| 1087 | } |
| 1088 | |
| 1089 | return au0828_set_format(dev, VIDIOC_S_FMT, f); |
| 1090 | out: |
| 1091 | return rc; |
| 1092 | } |
| 1093 | |
| 1094 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) |
| 1095 | { |
| 1096 | struct au0828_fh *fh = priv; |
| 1097 | struct au0828_dev *dev = fh->dev; |
| 1098 | |
| 1099 | /* FIXME: when we support something other than NTSC, we are going to |
| 1100 | have to make the au0828 bridge adjust the size of its capture |
| 1101 | buffer, which is currently hardcoded at 720x480 */ |
| 1102 | |
| 1103 | au0828_call_i2c_clients(dev, VIDIOC_S_STD, norm); |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static int vidioc_enum_input(struct file *file, void *priv, |
| 1108 | struct v4l2_input *input) |
| 1109 | { |
| 1110 | struct au0828_fh *fh = priv; |
| 1111 | struct au0828_dev *dev = fh->dev; |
| 1112 | unsigned int tmp; |
| 1113 | |
| 1114 | static const char *inames[] = { |
Devin Heitmueller | 3d62287 | 2009-03-15 17:48:26 -0300 | [diff] [blame] | 1115 | [AU0828_VMUX_UNDEFINED] = "Undefined", |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1116 | [AU0828_VMUX_COMPOSITE] = "Composite", |
| 1117 | [AU0828_VMUX_SVIDEO] = "S-Video", |
| 1118 | [AU0828_VMUX_CABLE] = "Cable TV", |
| 1119 | [AU0828_VMUX_TELEVISION] = "Television", |
| 1120 | [AU0828_VMUX_DVB] = "DVB", |
| 1121 | [AU0828_VMUX_DEBUG] = "tv debug" |
| 1122 | }; |
| 1123 | |
| 1124 | tmp = input->index; |
| 1125 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1126 | if (tmp > AU0828_MAX_INPUT) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1127 | return -EINVAL; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1128 | if (AUVI_INPUT(tmp).type == 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1129 | return -EINVAL; |
| 1130 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1131 | input->index = tmp; |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1132 | strcpy(input->name, inames[AUVI_INPUT(tmp).type]); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1133 | if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) || |
| 1134 | (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1135 | input->type |= V4L2_INPUT_TYPE_TUNER; |
| 1136 | else |
| 1137 | input->type |= V4L2_INPUT_TYPE_CAMERA; |
| 1138 | |
| 1139 | input->std = dev->vdev->tvnorms; |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1145 | { |
| 1146 | struct au0828_fh *fh = priv; |
| 1147 | struct au0828_dev *dev = fh->dev; |
| 1148 | *i = dev->ctrl_input; |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
| 1152 | static int vidioc_s_input(struct file *file, void *priv, unsigned int index) |
| 1153 | { |
| 1154 | struct au0828_fh *fh = priv; |
| 1155 | struct au0828_dev *dev = fh->dev; |
| 1156 | int i; |
| 1157 | struct v4l2_routing route; |
| 1158 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1159 | dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1160 | index); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1161 | if (index >= AU0828_MAX_INPUT) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1162 | return -EINVAL; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1163 | if (AUVI_INPUT(index).type == 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1164 | return -EINVAL; |
| 1165 | dev->ctrl_input = index; |
| 1166 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1167 | switch (AUVI_INPUT(index).type) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1168 | case AU0828_VMUX_SVIDEO: |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1169 | dev->input_type = AU0828_VMUX_SVIDEO; |
| 1170 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1171 | case AU0828_VMUX_COMPOSITE: |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1172 | dev->input_type = AU0828_VMUX_COMPOSITE; |
| 1173 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1174 | case AU0828_VMUX_TELEVISION: |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1175 | dev->input_type = AU0828_VMUX_TELEVISION; |
| 1176 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1177 | default: |
Devin Heitmueller | a1094c4 | 2009-03-15 17:43:13 -0300 | [diff] [blame] | 1178 | dprintk(1, "VIDIOC_S_INPUT unknown input type set [%d]\n", |
| 1179 | AUVI_INPUT(index).type); |
| 1180 | break; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1181 | } |
| 1182 | |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1183 | route.input = AUVI_INPUT(index).vmux; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1184 | route.output = 0; |
| 1185 | au0828_call_i2c_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); |
| 1186 | |
| 1187 | for (i = 0; i < AU0828_MAX_INPUT; i++) { |
| 1188 | int enable = 0; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1189 | if (AUVI_INPUT(i).audio_setup == NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1190 | continue; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1191 | |
| 1192 | if (i == index) |
| 1193 | enable = 1; |
| 1194 | else |
| 1195 | enable = 0; |
| 1196 | if (enable) { |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1197 | (AUVI_INPUT(i).audio_setup)(dev, enable); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1198 | } else { |
| 1199 | /* Make sure we leave it turned on if some |
| 1200 | other input is routed to this callback */ |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1201 | if ((AUVI_INPUT(i).audio_setup) != |
| 1202 | ((AUVI_INPUT(index).audio_setup))) { |
| 1203 | (AUVI_INPUT(i).audio_setup)(dev, enable); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1208 | route.input = AUVI_INPUT(index).amux; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1209 | au0828_call_i2c_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, |
| 1210 | &route); |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1215 | { |
| 1216 | struct au0828_fh *fh = priv; |
| 1217 | struct au0828_dev *dev = fh->dev; |
| 1218 | unsigned int index = a->index; |
| 1219 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1220 | if (a->index > 1) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1221 | return -EINVAL; |
| 1222 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1223 | index = dev->ctrl_ainput; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1224 | if (index == 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1225 | strcpy(a->name, "Television"); |
| 1226 | else |
| 1227 | strcpy(a->name, "Line in"); |
| 1228 | |
| 1229 | a->capability = V4L2_AUDCAP_STEREO; |
| 1230 | a->index = index; |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) |
| 1235 | { |
| 1236 | struct au0828_fh *fh = priv; |
| 1237 | struct au0828_dev *dev = fh->dev; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1238 | if (a->index != dev->ctrl_ainput) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1239 | return -EINVAL; |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1244 | struct v4l2_control *ctrl) |
| 1245 | { |
| 1246 | struct au0828_fh *fh = priv; |
| 1247 | struct au0828_dev *dev = fh->dev; |
| 1248 | |
| 1249 | au0828_call_i2c_clients(dev, VIDIOC_G_CTRL, ctrl); |
| 1250 | return 0; |
| 1251 | |
| 1252 | } |
| 1253 | |
| 1254 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1255 | struct v4l2_control *ctrl) |
| 1256 | { |
| 1257 | struct au0828_fh *fh = priv; |
| 1258 | struct au0828_dev *dev = fh->dev; |
| 1259 | au0828_call_i2c_clients(dev, VIDIOC_S_CTRL, ctrl); |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) |
| 1264 | { |
| 1265 | struct au0828_fh *fh = priv; |
| 1266 | struct au0828_dev *dev = fh->dev; |
| 1267 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1268 | if (t->index != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1269 | return -EINVAL; |
| 1270 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1271 | strcpy(t->name, "Auvitek tuner"); |
| 1272 | |
| 1273 | au0828_call_i2c_clients(dev, VIDIOC_G_TUNER, t); |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 1278 | struct v4l2_tuner *t) |
| 1279 | { |
| 1280 | struct au0828_fh *fh = priv; |
| 1281 | struct au0828_dev *dev = fh->dev; |
| 1282 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1283 | if (t->index != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1284 | return -EINVAL; |
| 1285 | |
| 1286 | t->type = V4L2_TUNER_ANALOG_TV; |
| 1287 | au0828_call_i2c_clients(dev, VIDIOC_S_TUNER, t); |
| 1288 | dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal, |
| 1289 | t->afc); |
| 1290 | return 0; |
| 1291 | |
| 1292 | } |
| 1293 | |
| 1294 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 1295 | struct v4l2_frequency *freq) |
| 1296 | { |
| 1297 | struct au0828_fh *fh = priv; |
| 1298 | struct au0828_dev *dev = fh->dev; |
Devin Heitmueller | c888923 | 2009-03-15 17:38:47 -0300 | [diff] [blame] | 1299 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1300 | freq->type = V4L2_TUNER_ANALOG_TV; |
| 1301 | freq->frequency = dev->ctrl_freq; |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 1306 | struct v4l2_frequency *freq) |
| 1307 | { |
| 1308 | struct au0828_fh *fh = priv; |
| 1309 | struct au0828_dev *dev = fh->dev; |
| 1310 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1311 | if (freq->tuner != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1312 | return -EINVAL; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1313 | if (freq->type != V4L2_TUNER_ANALOG_TV) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1314 | return -EINVAL; |
| 1315 | |
| 1316 | dev->ctrl_freq = freq->frequency; |
| 1317 | |
| 1318 | au0828_call_i2c_clients(dev, VIDIOC_S_FREQUENCY, freq); |
| 1319 | |
| 1320 | au0828_analog_stream_reset(dev); |
| 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static int vidioc_g_chip_ident(struct file *file, void *priv, |
| 1326 | struct v4l2_dbg_chip_ident *chip) |
| 1327 | { |
| 1328 | struct au0828_fh *fh = priv; |
| 1329 | struct au0828_dev *dev = fh->dev; |
| 1330 | chip->ident = V4L2_IDENT_NONE; |
| 1331 | chip->revision = 0; |
| 1332 | |
Devin Heitmueller | d9109be | 2009-03-11 03:00:58 -0300 | [diff] [blame] | 1333 | if (v4l2_chip_match_host(&chip->match)) { |
| 1334 | chip->ident = V4L2_IDENT_AU0828; |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1338 | au0828_call_i2c_clients(dev, VIDIOC_DBG_G_CHIP_IDENT, chip); |
Devin Heitmueller | d9109be | 2009-03-11 03:00:58 -0300 | [diff] [blame] | 1339 | if (chip->ident == V4L2_IDENT_NONE) |
| 1340 | return -EINVAL; |
| 1341 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1342 | return 0; |
| 1343 | } |
| 1344 | |
| 1345 | static int vidioc_cropcap(struct file *file, void *priv, |
| 1346 | struct v4l2_cropcap *cc) |
| 1347 | { |
| 1348 | struct au0828_fh *fh = priv; |
| 1349 | struct au0828_dev *dev = fh->dev; |
| 1350 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1351 | if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1352 | return -EINVAL; |
| 1353 | |
| 1354 | cc->bounds.left = 0; |
| 1355 | cc->bounds.top = 0; |
| 1356 | cc->bounds.width = dev->width; |
| 1357 | cc->bounds.height = dev->height; |
| 1358 | |
| 1359 | cc->defrect = cc->bounds; |
| 1360 | |
| 1361 | cc->pixelaspect.numerator = 54; |
| 1362 | cc->pixelaspect.denominator = 59; |
| 1363 | |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
| 1367 | static int vidioc_streamon(struct file *file, void *priv, |
| 1368 | enum v4l2_buf_type type) |
| 1369 | { |
| 1370 | struct au0828_fh *fh = priv; |
| 1371 | struct au0828_dev *dev = fh->dev; |
| 1372 | int b = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1373 | int rc; |
| 1374 | |
| 1375 | rc = check_dev(dev); |
| 1376 | if (rc < 0) |
| 1377 | return rc; |
| 1378 | |
| 1379 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 1380 | au0828_analog_stream_enable(dev); |
| 1381 | au0828_call_i2c_clients(dev, VIDIOC_STREAMON, &b); |
| 1382 | } |
| 1383 | |
| 1384 | mutex_lock(&dev->lock); |
| 1385 | rc = res_get(fh); |
| 1386 | |
| 1387 | if (likely(rc >= 0)) |
| 1388 | rc = videobuf_streamon(&fh->vb_vidq); |
| 1389 | mutex_unlock(&dev->lock); |
| 1390 | |
| 1391 | return rc; |
| 1392 | } |
| 1393 | |
| 1394 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1395 | enum v4l2_buf_type type) |
| 1396 | { |
| 1397 | struct au0828_fh *fh = priv; |
| 1398 | struct au0828_dev *dev = fh->dev; |
| 1399 | int b = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1400 | int i; |
| 1401 | int ret; |
| 1402 | int rc; |
| 1403 | |
| 1404 | rc = check_dev(dev); |
| 1405 | if (rc < 0) |
| 1406 | return rc; |
| 1407 | |
| 1408 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1409 | return -EINVAL; |
| 1410 | if (type != fh->type) |
| 1411 | return -EINVAL; |
| 1412 | |
| 1413 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 1414 | au0828_call_i2c_clients(dev, VIDIOC_STREAMOFF, &b); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1415 | ret = au0828_stream_interrupt(dev); |
| 1416 | if (ret != 0) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1417 | return ret; |
| 1418 | } |
| 1419 | |
| 1420 | for (i = 0; i < AU0828_MAX_INPUT; i++) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1421 | if (AUVI_INPUT(i).audio_setup == NULL) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1422 | continue; |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 1423 | (AUVI_INPUT(i).audio_setup)(dev, 0); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | mutex_lock(&dev->lock); |
| 1427 | videobuf_streamoff(&fh->vb_vidq); |
| 1428 | res_free(fh); |
| 1429 | mutex_unlock(&dev->lock); |
| 1430 | |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | static int vidioc_g_register(struct file *file, void *priv, |
| 1435 | struct v4l2_dbg_register *reg) |
| 1436 | { |
| 1437 | struct au0828_fh *fh = priv; |
| 1438 | struct au0828_dev *dev = fh->dev; |
| 1439 | |
| 1440 | switch (reg->match.type) { |
| 1441 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
| 1442 | au0828_call_i2c_clients(dev, VIDIOC_DBG_G_REGISTER, reg); |
| 1443 | return 0; |
| 1444 | default: |
| 1445 | return -EINVAL; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | static int vidioc_s_register(struct file *file, void *priv, |
| 1450 | struct v4l2_dbg_register *reg) |
| 1451 | { |
| 1452 | struct au0828_fh *fh = priv; |
| 1453 | struct au0828_dev *dev = fh->dev; |
| 1454 | |
| 1455 | switch (reg->match.type) { |
| 1456 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
| 1457 | au0828_call_i2c_clients(dev, VIDIOC_DBG_S_REGISTER, reg); |
| 1458 | return 0; |
| 1459 | default: |
| 1460 | return -EINVAL; |
| 1461 | } |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
| 1465 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1466 | struct v4l2_requestbuffers *rb) |
| 1467 | { |
| 1468 | struct au0828_fh *fh = priv; |
| 1469 | struct au0828_dev *dev = fh->dev; |
| 1470 | int rc; |
| 1471 | |
| 1472 | rc = check_dev(dev); |
| 1473 | if (rc < 0) |
| 1474 | return rc; |
| 1475 | |
| 1476 | return videobuf_reqbufs(&fh->vb_vidq, rb); |
| 1477 | } |
| 1478 | |
| 1479 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1480 | struct v4l2_buffer *b) |
| 1481 | { |
| 1482 | struct au0828_fh *fh = priv; |
| 1483 | struct au0828_dev *dev = fh->dev; |
| 1484 | int rc; |
| 1485 | |
| 1486 | rc = check_dev(dev); |
| 1487 | if (rc < 0) |
| 1488 | return rc; |
| 1489 | |
| 1490 | return videobuf_querybuf(&fh->vb_vidq, b); |
| 1491 | } |
| 1492 | |
| 1493 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1494 | { |
| 1495 | struct au0828_fh *fh = priv; |
| 1496 | struct au0828_dev *dev = fh->dev; |
| 1497 | int rc; |
| 1498 | |
| 1499 | rc = check_dev(dev); |
| 1500 | if (rc < 0) |
| 1501 | return rc; |
| 1502 | |
| 1503 | return videobuf_qbuf(&fh->vb_vidq, b); |
| 1504 | } |
| 1505 | |
| 1506 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) |
| 1507 | { |
| 1508 | struct au0828_fh *fh = priv; |
| 1509 | struct au0828_dev *dev = fh->dev; |
| 1510 | int rc; |
| 1511 | |
| 1512 | rc = check_dev(dev); |
| 1513 | if (rc < 0) |
| 1514 | return rc; |
| 1515 | |
| 1516 | /* Workaround for a bug in the au0828 hardware design that sometimes |
| 1517 | results in the colorspace being inverted */ |
| 1518 | if (dev->greenscreen_detected == 1) { |
| 1519 | dprintk(1, "Detected green frame. Resetting stream...\n"); |
| 1520 | au0828_analog_stream_reset(dev); |
| 1521 | dev->greenscreen_detected = 0; |
| 1522 | } |
| 1523 | |
| 1524 | return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); |
| 1525 | } |
| 1526 | |
| 1527 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1528 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
| 1529 | { |
| 1530 | struct au0828_fh *fh = priv; |
| 1531 | |
| 1532 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
| 1533 | } |
| 1534 | #endif |
| 1535 | |
| 1536 | static struct v4l2_file_operations au0828_v4l_fops = { |
| 1537 | .owner = THIS_MODULE, |
| 1538 | .open = au0828_v4l2_open, |
| 1539 | .release = au0828_v4l2_close, |
| 1540 | .read = au0828_v4l2_read, |
| 1541 | .poll = au0828_v4l2_poll, |
| 1542 | .mmap = au0828_v4l2_mmap, |
| 1543 | .ioctl = video_ioctl2, |
| 1544 | }; |
| 1545 | |
| 1546 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
| 1547 | .vidioc_querycap = vidioc_querycap, |
| 1548 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1549 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1550 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1551 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 1552 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1553 | .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, |
| 1554 | .vidioc_try_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, |
| 1555 | .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, |
| 1556 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1557 | .vidioc_g_audio = vidioc_g_audio, |
| 1558 | .vidioc_s_audio = vidioc_s_audio, |
| 1559 | .vidioc_cropcap = vidioc_cropcap, |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 1560 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1561 | .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, |
| 1562 | .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
| 1563 | .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, |
| 1564 | #endif |
| 1565 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1566 | .vidioc_querybuf = vidioc_querybuf, |
| 1567 | .vidioc_qbuf = vidioc_qbuf, |
| 1568 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1569 | .vidioc_s_std = vidioc_s_std, |
| 1570 | .vidioc_enum_input = vidioc_enum_input, |
| 1571 | .vidioc_g_input = vidioc_g_input, |
| 1572 | .vidioc_s_input = vidioc_s_input, |
| 1573 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1574 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1575 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1576 | .vidioc_streamon = vidioc_streamon, |
| 1577 | .vidioc_streamoff = vidioc_streamoff, |
| 1578 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1579 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1580 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1581 | .vidioc_s_frequency = vidioc_s_frequency, |
| 1582 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1583 | .vidioc_g_register = vidioc_g_register, |
| 1584 | .vidioc_s_register = vidioc_s_register, |
| 1585 | .vidioc_g_chip_ident = vidioc_g_chip_ident, |
| 1586 | #endif |
| 1587 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1588 | .vidiocgmbuf = vidiocgmbuf, |
| 1589 | #endif |
| 1590 | }; |
| 1591 | |
| 1592 | static const struct video_device au0828_video_template = { |
| 1593 | .fops = &au0828_v4l_fops, |
| 1594 | .release = video_device_release, |
| 1595 | .ioctl_ops = &video_ioctl_ops, |
| 1596 | .minor = -1, |
Devin Heitmueller | 0ef21071 | 2009-03-11 03:00:53 -0300 | [diff] [blame] | 1597 | .tvnorms = V4L2_STD_NTSC_M, |
| 1598 | .current_norm = V4L2_STD_NTSC_M, |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1599 | }; |
| 1600 | |
| 1601 | /**************************************************************************/ |
| 1602 | |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1603 | int au0828_analog_register(struct au0828_dev *dev, |
| 1604 | struct usb_interface *interface) |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1605 | { |
| 1606 | int retval = -ENOMEM; |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1607 | struct usb_host_interface *iface_desc; |
| 1608 | struct usb_endpoint_descriptor *endpoint; |
| 1609 | int i; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1610 | |
| 1611 | dprintk(1, "au0828_analog_register called!\n"); |
| 1612 | |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1613 | /* set au0828 usb interface0 to as5 */ |
| 1614 | retval = usb_set_interface(dev->usbdev, |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1615 | interface->cur_altsetting->desc.bInterfaceNumber, 5); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1616 | if (retval != 0) { |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1617 | printk(KERN_INFO "Failure setting usb interface0 to as5\n"); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1618 | return retval; |
| 1619 | } |
| 1620 | |
| 1621 | /* Figure out which endpoint has the isoc interface */ |
| 1622 | iface_desc = interface->cur_altsetting; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1623 | for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1624 | endpoint = &iface_desc->endpoint[i].desc; |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1625 | if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
| 1626 | == USB_DIR_IN) && |
| 1627 | ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 1628 | == USB_ENDPOINT_XFER_ISOC)) { |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1629 | |
| 1630 | /* we find our isoc in endpoint */ |
| 1631 | u16 tmp = le16_to_cpu(endpoint->wMaxPacketSize); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1632 | dev->max_pkt_size = (tmp & 0x07ff) * |
| 1633 | (((tmp & 0x1800) >> 11) + 1); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1634 | dev->isoc_in_endpointaddr = endpoint->bEndpointAddress; |
| 1635 | } |
| 1636 | } |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1637 | if (!(dev->isoc_in_endpointaddr)) { |
| 1638 | printk(KERN_INFO "Could not locate isoc endpoint\n"); |
Devin Heitmueller | fc4ce6c | 2009-03-11 03:01:00 -0300 | [diff] [blame] | 1639 | kfree(dev); |
| 1640 | return -ENODEV; |
| 1641 | } |
| 1642 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1643 | init_waitqueue_head(&dev->open); |
| 1644 | spin_lock_init(&dev->slock); |
| 1645 | mutex_init(&dev->lock); |
| 1646 | |
| 1647 | INIT_LIST_HEAD(&dev->vidq.active); |
| 1648 | INIT_LIST_HEAD(&dev->vidq.queued); |
| 1649 | |
| 1650 | dev->width = NTSC_STD_W; |
| 1651 | dev->height = NTSC_STD_H; |
| 1652 | dev->field_size = dev->width * dev->height; |
| 1653 | dev->frame_size = dev->field_size << 1; |
| 1654 | dev->bytesperline = dev->width << 1; |
| 1655 | dev->ctrl_ainput = 0; |
| 1656 | |
| 1657 | /* allocate and fill v4l2 video struct */ |
| 1658 | dev->vdev = video_device_alloc(); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1659 | if (NULL == dev->vdev) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1660 | dprintk(1, "Can't allocate video_device.\n"); |
| 1661 | return -ENOMEM; |
| 1662 | } |
| 1663 | |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 1664 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1665 | dev->vbi_dev = video_device_alloc(); |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1666 | if (NULL == dev->vbi_dev) { |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1667 | dprintk(1, "Can't allocate vbi_device.\n"); |
| 1668 | kfree(dev->vdev); |
| 1669 | return -ENOMEM; |
| 1670 | } |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1671 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1672 | |
| 1673 | /* Fill the video capture device struct */ |
| 1674 | *dev->vdev = au0828_video_template; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1675 | dev->vdev->parent = &dev->usbdev->dev; |
| 1676 | strcpy(dev->vdev->name, "au0828a video"); |
| 1677 | |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 1678 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1679 | /* Setup the VBI device */ |
| 1680 | *dev->vbi_dev = au0828_video_template; |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1681 | dev->vbi_dev->parent = &dev->usbdev->dev; |
| 1682 | strcpy(dev->vbi_dev->name, "au0828a vbi"); |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1683 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1684 | |
| 1685 | list_add_tail(&dev->au0828list, &au0828_devlist); |
| 1686 | |
| 1687 | /* Register the v4l2 device */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1688 | retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1); |
| 1689 | if (retval != 0) { |
| 1690 | dprintk(1, "unable to register video device (error = %d).\n", |
| 1691 | retval); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1692 | list_del(&dev->au0828list); |
| 1693 | video_device_release(dev->vdev); |
| 1694 | return -ENODEV; |
| 1695 | } |
| 1696 | |
Devin Heitmueller | dd27ade | 2009-03-15 18:52:10 -0300 | [diff] [blame^] | 1697 | #ifdef VBI_IS_WORKING |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1698 | /* Register the vbi device */ |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1699 | retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1); |
| 1700 | if (retval != 0) { |
| 1701 | dprintk(1, "unable to register vbi device (error = %d).\n", |
| 1702 | retval); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1703 | list_del(&dev->au0828list); |
| 1704 | video_device_release(dev->vbi_dev); |
| 1705 | video_device_release(dev->vdev); |
| 1706 | return -ENODEV; |
| 1707 | } |
Devin Heitmueller | 5a5a4e1 | 2009-03-11 03:00:55 -0300 | [diff] [blame] | 1708 | #endif |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1709 | |
Devin Heitmueller | 62899a2 | 2009-03-15 18:48:52 -0300 | [diff] [blame] | 1710 | dprintk(1, "%s completed!\n", __func__); |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 1711 | |
| 1712 | return 0; |
| 1713 | } |
| 1714 | |