Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 1 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 2 | |
Mauro Carvalho Chehab | d647f0b | 2015-11-13 19:40:07 -0200 | [diff] [blame] | 3 | #include <media/drv-intf/saa7146_vv.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 4 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | /****************************************************************************/ |
| 7 | /* resource management functions, shamelessly stolen from saa7134 driver */ |
| 8 | |
| 9 | int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit) |
| 10 | { |
| 11 | struct saa7146_dev *dev = fh->dev; |
| 12 | struct saa7146_vv *vv = dev->vv_data; |
| 13 | |
| 14 | if (fh->resources & bit) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 15 | DEB_D("already allocated! want: 0x%02x, cur:0x%02x\n", |
| 16 | bit, vv->resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* have it already allocated */ |
| 18 | return 1; |
| 19 | } |
| 20 | |
| 21 | /* is it free? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | if (vv->resources & bit) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 23 | DEB_D("locked! vv->resources:0x%02x, we want:0x%02x\n", |
| 24 | vv->resources, bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* no, someone else uses it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | /* it's free, grab it */ |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 29 | fh->resources |= bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | vv->resources |= bit; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 31 | DEB_D("res: get 0x%02x, cur:0x%02x\n", bit, vv->resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits) |
| 36 | { |
| 37 | struct saa7146_dev *dev = fh->dev; |
| 38 | struct saa7146_vv *vv = dev->vv_data; |
| 39 | |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 40 | BUG_ON((fh->resources & bits) != bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 42 | fh->resources &= ~bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | vv->resources &= ~bits; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 44 | DEB_D("res: put 0x%02x, cur:0x%02x\n", bits, vv->resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
| 48 | /********************************************************************************/ |
| 49 | /* common dma functions */ |
| 50 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 51 | void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q, |
| 52 | struct saa7146_buf *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 54 | struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 55 | DEB_EE("dev:%p, buf:%p\n", dev, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 57 | BUG_ON(in_interrupt()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Hans Verkuil | 0e0809a | 2010-09-26 09:01:26 -0300 | [diff] [blame] | 59 | videobuf_waiton(q, &buf->vb, 0, 0); |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 60 | videobuf_dma_unmap(q->dev, dma); |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 61 | videobuf_dma_free(dma); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 62 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
| 66 | /********************************************************************************/ |
| 67 | /* common buffer functions */ |
| 68 | |
| 69 | int saa7146_buffer_queue(struct saa7146_dev *dev, |
| 70 | struct saa7146_dmaqueue *q, |
| 71 | struct saa7146_buf *buf) |
| 72 | { |
| 73 | assert_spin_locked(&dev->slock); |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 74 | DEB_EE("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | BUG_ON(!q); |
| 77 | |
| 78 | if (NULL == q->curr) { |
| 79 | q->curr = buf; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 80 | DEB_D("immediately activating buffer %p\n", buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | buf->activate(dev,buf,NULL); |
| 82 | } else { |
| 83 | list_add_tail(&buf->vb.queue,&q->queue); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 84 | buf->vb.state = VIDEOBUF_QUEUED; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 85 | DEB_D("adding buffer %p to queue. (active buffer present)\n", |
| 86 | buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | void saa7146_buffer_finish(struct saa7146_dev *dev, |
| 92 | struct saa7146_dmaqueue *q, |
| 93 | int state) |
| 94 | { |
| 95 | assert_spin_locked(&dev->slock); |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 96 | DEB_EE("dev:%p, dmaq:%p, state:%d\n", dev, q, state); |
| 97 | DEB_EE("q->curr:%p\n", q->curr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | BUG_ON(!q->curr); |
| 100 | |
| 101 | /* finish current buffer */ |
| 102 | if (NULL == q->curr) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 103 | DEB_D("aiii. no current buffer\n"); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 104 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | q->curr->vb.state = state; |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 108 | v4l2_get_timestamp(&q->curr->vb.ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | wake_up(&q->curr->vb.done); |
| 110 | |
| 111 | q->curr = NULL; |
| 112 | } |
| 113 | |
| 114 | void saa7146_buffer_next(struct saa7146_dev *dev, |
| 115 | struct saa7146_dmaqueue *q, int vbi) |
| 116 | { |
| 117 | struct saa7146_buf *buf,*next = NULL; |
| 118 | |
| 119 | BUG_ON(!q); |
| 120 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 121 | DEB_INT("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | assert_spin_locked(&dev->slock); |
| 124 | if (!list_empty(&q->queue)) { |
| 125 | /* activate next one from queue */ |
| 126 | buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue); |
| 127 | list_del(&buf->vb.queue); |
| 128 | if (!list_empty(&q->queue)) |
| 129 | next = list_entry(q->queue.next,struct saa7146_buf, vb.queue); |
| 130 | q->curr = buf; |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 131 | DEB_INT("next buffer: buf:%p, prev:%p, next:%p\n", |
| 132 | buf, q->queue.prev, q->queue.next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | buf->activate(dev,buf,next); |
| 134 | } else { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 135 | DEB_INT("no next buffer. stopping.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if( 0 != vbi ) { |
| 137 | /* turn off video-dma3 */ |
| 138 | saa7146_write(dev,MC1, MASK_20); |
| 139 | } else { |
| 140 | /* nothing to do -- just prevent next video-dma1 transfer |
| 141 | by lowering the protection address */ |
| 142 | |
| 143 | // fixme: fix this for vflip != 0 |
| 144 | |
| 145 | saa7146_write(dev, PROT_ADDR1, 0); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 146 | saa7146_write(dev, MC2, (MASK_02|MASK_18)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | /* write the address of the rps-program */ |
| 149 | saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle); |
| 150 | /* turn on rps */ |
| 151 | saa7146_write(dev, MC1, (MASK_12 | MASK_28)); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
| 154 | printk("vdma%d.base_even: 0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1)); |
| 155 | printk("vdma%d.base_odd: 0x%08x\n", 1,saa7146_read(dev,BASE_ODD1)); |
| 156 | printk("vdma%d.prot_addr: 0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1)); |
| 157 | printk("vdma%d.base_page: 0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1)); |
| 158 | printk("vdma%d.pitch: 0x%08x\n", 1,saa7146_read(dev,PITCH1)); |
| 159 | printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1)); |
| 160 | */ |
| 161 | } |
| 162 | del_timer(&q->timeout); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | void saa7146_buffer_timeout(unsigned long data) |
| 167 | { |
| 168 | struct saa7146_dmaqueue *q = (struct saa7146_dmaqueue*)data; |
| 169 | struct saa7146_dev *dev = q->dev; |
| 170 | unsigned long flags; |
| 171 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 172 | DEB_EE("dev:%p, dmaq:%p\n", dev, q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | spin_lock_irqsave(&dev->slock,flags); |
| 175 | if (q->curr) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 176 | DEB_D("timeout on %p\n", q->curr); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 177 | saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* we don't restart the transfer here like other drivers do. when |
| 181 | a streaming capture is disabled, the timeout function will be |
| 182 | called for the current buffer. if we activate the next buffer now, |
| 183 | we mess up our capture logic. if a timeout occurs on another buffer, |
| 184 | then something is seriously broken before, so no need to buffer the |
| 185 | next capture IMHO... */ |
| 186 | /* |
| 187 | saa7146_buffer_next(dev,q); |
| 188 | */ |
| 189 | spin_unlock_irqrestore(&dev->slock,flags); |
| 190 | } |
| 191 | |
| 192 | /********************************************************************************/ |
| 193 | /* file operations */ |
| 194 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 195 | static int fops_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 197 | struct video_device *vdev = video_devdata(file); |
| 198 | struct saa7146_dev *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | struct saa7146_fh *fh = NULL; |
| 200 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 202 | DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 204 | if (mutex_lock_interruptible(vdev->lock)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return -ERESTARTSYS; |
| 206 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 207 | DEB_D("using: %p\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* check if an extension is registered */ |
| 210 | if( NULL == dev->ext ) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 211 | DEB_S("no extension registered for this device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | result = -ENODEV; |
| 213 | goto out; |
| 214 | } |
| 215 | |
| 216 | /* allocate per open data */ |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 217 | fh = kzalloc(sizeof(*fh),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | if (NULL == fh) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 219 | DEB_S("cannot allocate memory for per open data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | result = -ENOMEM; |
| 221 | goto out; |
| 222 | } |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 223 | |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 224 | v4l2_fh_init(&fh->fh, vdev); |
| 225 | |
| 226 | file->private_data = &fh->fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | fh->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 229 | if (vdev->vfl_type == VFL_TYPE_VBI) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 230 | DEB_S("initializing vbi...\n"); |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 231 | if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) |
| 232 | result = saa7146_vbi_uops.open(dev,file); |
| 233 | if (dev->ext_vv_data->vbi_fops.open) |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 234 | dev->ext_vv_data->vbi_fops.open(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } else { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 236 | DEB_S("initializing video...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | result = saa7146_video_uops.open(dev,file); |
| 238 | } |
| 239 | |
| 240 | if (0 != result) { |
| 241 | goto out; |
| 242 | } |
| 243 | |
| 244 | if( 0 == try_module_get(dev->ext->module)) { |
| 245 | result = -EINVAL; |
| 246 | goto out; |
| 247 | } |
| 248 | |
| 249 | result = 0; |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 250 | v4l2_fh_add(&fh->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | out: |
Al Viro | 5fa1247 | 2008-03-29 03:07:38 +0000 | [diff] [blame] | 252 | if (fh && result != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | kfree(fh); |
| 254 | file->private_data = NULL; |
| 255 | } |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 256 | mutex_unlock(vdev->lock); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 257 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 260 | static int fops_release(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 262 | struct video_device *vdev = video_devdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | struct saa7146_fh *fh = file->private_data; |
| 264 | struct saa7146_dev *dev = fh->dev; |
| 265 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 266 | DEB_EE("file:%p\n", file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Cyril Roelandt | 21a7339 | 2012-12-10 23:05:28 -0300 | [diff] [blame] | 268 | mutex_lock(vdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 270 | if (vdev->vfl_type == VFL_TYPE_VBI) { |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 271 | if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) |
| 272 | saa7146_vbi_uops.release(dev,file); |
| 273 | if (dev->ext_vv_data->vbi_fops.release) |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 274 | dev->ext_vv_data->vbi_fops.release(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } else { |
| 276 | saa7146_video_uops.release(dev,file); |
| 277 | } |
| 278 | |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 279 | v4l2_fh_del(&fh->fh); |
| 280 | v4l2_fh_exit(&fh->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | module_put(dev->ext->module); |
| 282 | file->private_data = NULL; |
| 283 | kfree(fh); |
| 284 | |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 285 | mutex_unlock(vdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | static int fops_mmap(struct file *file, struct vm_area_struct * vma) |
| 291 | { |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 292 | struct video_device *vdev = video_devdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | struct saa7146_fh *fh = file->private_data; |
| 294 | struct videobuf_queue *q; |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 295 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 297 | switch (vdev->vfl_type) { |
| 298 | case VFL_TYPE_GRABBER: { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 299 | DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n", |
| 300 | file, vma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | q = &fh->video_q; |
| 302 | break; |
| 303 | } |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 304 | case VFL_TYPE_VBI: { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 305 | DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n", |
| 306 | file, vma); |
Hans Verkuil | a299e40 | 2012-05-06 13:31:27 -0300 | [diff] [blame] | 307 | if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT) |
| 308 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | q = &fh->vbi_q; |
| 310 | break; |
| 311 | } |
| 312 | default: |
| 313 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 315 | |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 316 | if (mutex_lock_interruptible(vdev->lock)) |
| 317 | return -ERESTARTSYS; |
| 318 | res = videobuf_mmap_mapper(q, vma); |
| 319 | mutex_unlock(vdev->lock); |
| 320 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 323 | static unsigned int __fops_poll(struct file *file, struct poll_table_struct *wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 325 | struct video_device *vdev = video_devdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | struct saa7146_fh *fh = file->private_data; |
| 327 | struct videobuf_buffer *buf = NULL; |
| 328 | struct videobuf_queue *q; |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 329 | unsigned int res = v4l2_ctrl_poll(file, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 331 | DEB_EE("file:%p, poll:%p\n", file, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 333 | if (vdev->vfl_type == VFL_TYPE_VBI) { |
Hans Verkuil | a299e40 | 2012-05-06 13:31:27 -0300 | [diff] [blame] | 334 | if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_SLICED_VBI_OUTPUT) |
| 335 | return res | POLLOUT | POLLWRNORM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | if( 0 == fh->vbi_q.streaming ) |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 337 | return res | videobuf_poll_stream(file, &fh->vbi_q, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | q = &fh->vbi_q; |
| 339 | } else { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 340 | DEB_D("using video queue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | q = &fh->video_q; |
| 342 | } |
| 343 | |
| 344 | if (!list_empty(&q->stream)) |
| 345 | buf = list_entry(q->stream.next, struct videobuf_buffer, stream); |
| 346 | |
| 347 | if (!buf) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 348 | DEB_D("buf == NULL!\n"); |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 349 | return res | POLLERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | poll_wait(file, &buf->done, wait); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 353 | if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 354 | DEB_D("poll succeeded!\n"); |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 355 | return res | POLLIN | POLLRDNORM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 358 | DEB_D("nothing to poll for, buf->state:%d\n", buf->state); |
Hans Verkuil | 537fa49 | 2012-05-01 12:04:52 -0300 | [diff] [blame] | 359 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 362 | static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait) |
| 363 | { |
| 364 | struct video_device *vdev = video_devdata(file); |
| 365 | unsigned int res; |
| 366 | |
| 367 | mutex_lock(vdev->lock); |
| 368 | res = __fops_poll(file, wait); |
| 369 | mutex_unlock(vdev->lock); |
| 370 | return res; |
| 371 | } |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
| 374 | { |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 375 | struct video_device *vdev = video_devdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | struct saa7146_fh *fh = file->private_data; |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 377 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 379 | switch (vdev->vfl_type) { |
| 380 | case VFL_TYPE_GRABBER: |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 381 | /* |
| 382 | DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun", |
| 383 | file, data, (unsigned long)count); |
| 384 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return saa7146_video_uops.read(file,data,count,ppos); |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 386 | case VFL_TYPE_VBI: |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 387 | /* |
| 388 | DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n", |
| 389 | file, data, (unsigned long)count); |
| 390 | */ |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 391 | if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) { |
| 392 | if (mutex_lock_interruptible(vdev->lock)) |
| 393 | return -ERESTARTSYS; |
| 394 | ret = saa7146_vbi_uops.read(file, data, count, ppos); |
| 395 | mutex_unlock(vdev->lock); |
| 396 | return ret; |
| 397 | } |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 398 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | default: |
| 400 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 404 | static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos) |
| 405 | { |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 406 | struct video_device *vdev = video_devdata(file); |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 407 | struct saa7146_fh *fh = file->private_data; |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 408 | int ret; |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 409 | |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 410 | switch (vdev->vfl_type) { |
| 411 | case VFL_TYPE_GRABBER: |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 412 | return -EINVAL; |
Hans Verkuil | 6694a56 | 2012-05-01 11:39:08 -0300 | [diff] [blame] | 413 | case VFL_TYPE_VBI: |
Hans Verkuil | 6de7d14 | 2012-06-23 07:47:14 -0300 | [diff] [blame] | 414 | if (fh->dev->ext_vv_data->vbi_fops.write) { |
| 415 | if (mutex_lock_interruptible(vdev->lock)) |
| 416 | return -ERESTARTSYS; |
| 417 | ret = fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos); |
| 418 | mutex_unlock(vdev->lock); |
| 419 | return ret; |
| 420 | } |
| 421 | return -EINVAL; |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 422 | default: |
| 423 | BUG(); |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 427 | static const struct v4l2_file_operations video_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
| 429 | .owner = THIS_MODULE, |
| 430 | .open = fops_open, |
| 431 | .release = fops_release, |
| 432 | .read = fops_read, |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 433 | .write = fops_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | .poll = fops_poll, |
| 435 | .mmap = fops_mmap, |
Hans Verkuil | 9af3971 | 2010-12-18 09:20:59 -0300 | [diff] [blame] | 436 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | }; |
| 438 | |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 439 | static void vv_callback(struct saa7146_dev *dev, unsigned long status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
| 441 | u32 isr = status; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 442 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 443 | DEB_INT("dev:%p, isr:0x%08x\n", dev, (u32)status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | if (0 != (isr & (MASK_27))) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 446 | DEB_INT("irq: RPS0 (0x%08x)\n", isr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | saa7146_video_uops.irq_done(dev,isr); |
| 448 | } |
| 449 | |
| 450 | if (0 != (isr & (MASK_28))) { |
| 451 | u32 mc2 = saa7146_read(dev, MC2); |
| 452 | if( 0 != (mc2 & MASK_15)) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 453 | DEB_INT("irq: RPS1 vbi workaround (0x%08x)\n", isr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | wake_up(&dev->vv_data->vbi_wq); |
| 455 | saa7146_write(dev,MC2, MASK_31); |
| 456 | return; |
| 457 | } |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 458 | DEB_INT("irq: RPS1 (0x%08x)\n", isr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | saa7146_vbi_uops.irq_done(dev,isr); |
| 460 | } |
| 461 | } |
| 462 | |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 463 | static const struct v4l2_ctrl_ops saa7146_ctrl_ops = { |
| 464 | .s_ctrl = saa7146_s_ctrl, |
| 465 | }; |
| 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) |
| 468 | { |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 469 | struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler; |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 470 | struct v4l2_pix_format *fmt; |
Hans Verkuil | fca3469 | 2012-05-01 11:28:20 -0300 | [diff] [blame] | 471 | struct v4l2_vbi_format *vbi; |
Hans Verkuil | 230b65f | 2009-02-07 20:42:33 -0300 | [diff] [blame] | 472 | struct saa7146_vv *vv; |
Hans Verkuil | 03b1930 | 2010-03-24 19:09:55 -0300 | [diff] [blame] | 473 | int err; |
| 474 | |
| 475 | err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev); |
| 476 | if (err) |
| 477 | return err; |
Hans Verkuil | 230b65f | 2009-02-07 20:42:33 -0300 | [diff] [blame] | 478 | |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 479 | v4l2_ctrl_handler_init(hdl, 6); |
| 480 | v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops, |
| 481 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); |
| 482 | v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops, |
| 483 | V4L2_CID_CONTRAST, 0, 127, 1, 64); |
| 484 | v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops, |
| 485 | V4L2_CID_SATURATION, 0, 127, 1, 64); |
| 486 | v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops, |
| 487 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 488 | v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops, |
| 489 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 490 | if (hdl->error) { |
| 491 | err = hdl->error; |
| 492 | v4l2_ctrl_handler_free(hdl); |
| 493 | return err; |
| 494 | } |
| 495 | dev->v4l2_dev.ctrl_handler = hdl; |
| 496 | |
Hans Verkuil | 230b65f | 2009-02-07 20:42:33 -0300 | [diff] [blame] | 497 | vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 498 | if (vv == NULL) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 499 | ERR("out of memory. aborting.\n"); |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 500 | v4l2_ctrl_handler_free(hdl); |
Hans Verkuil | 230b65f | 2009-02-07 20:42:33 -0300 | [diff] [blame] | 501 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
Hans Verkuil | ab49ae0 | 2012-05-01 12:57:57 -0300 | [diff] [blame] | 503 | ext_vv->vid_ops = saa7146_video_ioctl_ops; |
| 504 | ext_vv->vbi_ops = saa7146_vbi_ioctl_ops; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 505 | ext_vv->core_ops = &saa7146_video_ioctl_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 507 | DEB_EE("dev:%p\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | /* set default values for video parts of the saa7146 */ |
| 510 | saa7146_write(dev, BCS_CTRL, 0x80400040); |
| 511 | |
| 512 | /* enable video-port pins */ |
| 513 | saa7146_write(dev, MC1, (MASK_10 | MASK_26)); |
| 514 | |
| 515 | /* save per-device extension data (one extension can |
| 516 | handle different devices that might need different |
| 517 | configuration data) */ |
| 518 | dev->ext_vv_data = ext_vv; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 519 | |
Joe Perches | 6850aea | 2014-08-08 14:24:21 -0700 | [diff] [blame] | 520 | vv->d_clipping.cpu_addr = |
| 521 | pci_zalloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, |
| 522 | &vv->d_clipping.dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | if( NULL == vv->d_clipping.cpu_addr ) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 524 | ERR("out of memory. aborting.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | kfree(vv); |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 526 | v4l2_ctrl_handler_free(hdl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return -1; |
| 528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | saa7146_video_uops.init(dev,vv); |
Oliver Endriss | 5b0fa4f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 531 | if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) |
| 532 | saa7146_vbi_uops.init(dev,vv); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 533 | |
Hans Verkuil | c9adcb7 | 2014-07-17 15:27:39 -0300 | [diff] [blame] | 534 | vv->ov_fb.fmt.width = vv->standard->h_max_out; |
| 535 | vv->ov_fb.fmt.height = vv->standard->v_max_out; |
| 536 | vv->ov_fb.fmt.pixelformat = V4L2_PIX_FMT_RGB565; |
| 537 | vv->ov_fb.fmt.bytesperline = 2 * vv->ov_fb.fmt.width; |
| 538 | vv->ov_fb.fmt.sizeimage = vv->ov_fb.fmt.bytesperline * vv->ov_fb.fmt.height; |
| 539 | vv->ov_fb.fmt.colorspace = V4L2_COLORSPACE_SRGB; |
Hans Verkuil | fd74d6e | 2012-05-01 11:17:35 -0300 | [diff] [blame] | 540 | |
| 541 | fmt = &vv->video_fmt; |
| 542 | fmt->width = 384; |
| 543 | fmt->height = 288; |
| 544 | fmt->pixelformat = V4L2_PIX_FMT_BGR24; |
| 545 | fmt->field = V4L2_FIELD_ANY; |
| 546 | fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 547 | fmt->bytesperline = 3 * fmt->width; |
| 548 | fmt->sizeimage = fmt->bytesperline * fmt->height; |
| 549 | |
Hans Verkuil | fca3469 | 2012-05-01 11:28:20 -0300 | [diff] [blame] | 550 | vbi = &vv->vbi_fmt; |
| 551 | vbi->sampling_rate = 27000000; |
| 552 | vbi->offset = 248; /* todo */ |
| 553 | vbi->samples_per_line = 720 * 2; |
| 554 | vbi->sample_format = V4L2_PIX_FMT_GREY; |
| 555 | |
| 556 | /* fixme: this only works for PAL */ |
| 557 | vbi->start[0] = 5; |
| 558 | vbi->count[0] = 16; |
| 559 | vbi->start[1] = 312; |
| 560 | vbi->count[1] = 16; |
| 561 | |
Kees Cook | 3e31491 | 2017-10-16 19:10:12 -0400 | [diff] [blame^] | 562 | timer_setup(&vv->vbi_read_timeout, NULL, 0); |
Hans Verkuil | fca3469 | 2012-05-01 11:28:20 -0300 | [diff] [blame] | 563 | |
Hans Verkuil | 5da545a | 2012-05-01 11:06:44 -0300 | [diff] [blame] | 564 | vv->ov_fb.capability = V4L2_FBUF_CAP_LIST_CLIPPING; |
| 565 | vv->ov_fb.flags = V4L2_FBUF_FLAG_PRIMARY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | dev->vv_data = vv; |
| 567 | dev->vv_callback = &vv_callback; |
| 568 | |
| 569 | return 0; |
| 570 | } |
Adrian Bunk | 5d7dc8c | 2006-04-11 10:26:57 -0300 | [diff] [blame] | 571 | EXPORT_SYMBOL_GPL(saa7146_vv_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | int saa7146_vv_release(struct saa7146_dev* dev) |
| 574 | { |
| 575 | struct saa7146_vv *vv = dev->vv_data; |
| 576 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 577 | DEB_EE("dev:%p\n", dev); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 578 | |
Hans Verkuil | 230b65f | 2009-02-07 20:42:33 -0300 | [diff] [blame] | 579 | v4l2_device_unregister(&dev->v4l2_dev); |
Marco Schluessler | 58af004 | 2007-01-31 14:27:55 -0300 | [diff] [blame] | 580 | pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle); |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 581 | v4l2_ctrl_handler_free(&dev->ctrl_handler); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 582 | kfree(vv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | dev->vv_data = NULL; |
| 584 | dev->vv_callback = NULL; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return 0; |
| 587 | } |
Adrian Bunk | 5d7dc8c | 2006-04-11 10:26:57 -0300 | [diff] [blame] | 588 | EXPORT_SYMBOL_GPL(saa7146_vv_release); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Hans Verkuil | 3ae863e | 2015-03-09 13:33:57 -0300 | [diff] [blame] | 590 | int saa7146_register_device(struct video_device *vfd, struct saa7146_dev *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | char *name, int type) |
| 592 | { |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 593 | int err; |
Hans Verkuil | d0852ed | 2009-01-26 19:13:05 -0300 | [diff] [blame] | 594 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 596 | DEB_EE("dev:%p, name:'%s', type:%d\n", dev, name, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 598 | vfd->fops = &video_fops; |
Hans Verkuil | ab49ae0 | 2012-05-01 12:57:57 -0300 | [diff] [blame] | 599 | if (type == VFL_TYPE_GRABBER) |
| 600 | vfd->ioctl_ops = &dev->ext_vv_data->vid_ops; |
| 601 | else |
| 602 | vfd->ioctl_ops = &dev->ext_vv_data->vbi_ops; |
Hans Verkuil | 3ae863e | 2015-03-09 13:33:57 -0300 | [diff] [blame] | 603 | vfd->release = video_device_release_empty; |
Hans Verkuil | 9af3971 | 2010-12-18 09:20:59 -0300 | [diff] [blame] | 604 | vfd->lock = &dev->v4l2_lock; |
Hans Verkuil | 6e65ca9 | 2012-04-29 16:47:47 -0300 | [diff] [blame] | 605 | vfd->v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | d0852ed | 2009-01-26 19:13:05 -0300 | [diff] [blame] | 606 | vfd->tvnorms = 0; |
| 607 | for (i = 0; i < dev->ext_vv_data->num_stds; i++) |
| 608 | vfd->tvnorms |= dev->ext_vv_data->stds[i].id; |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 609 | strlcpy(vfd->name, name, sizeof(vfd->name)); |
Hans Verkuil | 601e944 | 2008-08-23 07:24:07 -0300 | [diff] [blame] | 610 | video_set_drvdata(vfd, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 612 | err = video_register_device(vfd, type, -1); |
| 613 | if (err < 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 614 | ERR("cannot register v4l2 device. skipping.\n"); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 615 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 618 | pr_info("%s: registered device %s [v4l2]\n", |
| 619 | dev->name, video_device_node_name(vfd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | return 0; |
| 621 | } |
Adrian Bunk | 5d7dc8c | 2006-04-11 10:26:57 -0300 | [diff] [blame] | 622 | EXPORT_SYMBOL_GPL(saa7146_register_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Hans Verkuil | 3ae863e | 2015-03-09 13:33:57 -0300 | [diff] [blame] | 624 | int saa7146_unregister_device(struct video_device *vfd, struct saa7146_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 626 | DEB_EE("dev:%p\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Hans Verkuil | 3ae863e | 2015-03-09 13:33:57 -0300 | [diff] [blame] | 628 | video_unregister_device(vfd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return 0; |
| 630 | } |
Adrian Bunk | 5d7dc8c | 2006-04-11 10:26:57 -0300 | [diff] [blame] | 631 | EXPORT_SYMBOL_GPL(saa7146_unregister_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | static int __init saa7146_vv_init_module(void) |
| 634 | { |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | |
| 639 | static void __exit saa7146_vv_cleanup_module(void) |
| 640 | { |
| 641 | } |
| 642 | |
| 643 | module_init(saa7146_vv_init_module); |
| 644 | module_exit(saa7146_vv_cleanup_module); |
| 645 | |
| 646 | MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); |
| 647 | MODULE_DESCRIPTION("video4linux driver for saa7146-based hardware"); |
| 648 | MODULE_LICENSE("GPL"); |