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