Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | */ |
| 3 | #include <linux/kernel.h> |
| 4 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/init.h> |
| 6 | #include <linux/slab.h> |
| 7 | |
| 8 | #include "cx88.h" |
| 9 | |
| 10 | static unsigned int vbibufs = 4; |
| 11 | module_param(vbibufs,int,0644); |
| 12 | MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32"); |
| 13 | |
| 14 | static unsigned int vbi_debug = 0; |
| 15 | module_param(vbi_debug,int,0644); |
| 16 | MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]"); |
| 17 | |
| 18 | #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \ |
| 19 | printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg) |
| 20 | |
| 21 | /* ------------------------------------------------------------------ */ |
| 22 | |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 23 | int cx8800_vbi_fmt (struct file *file, void *priv, |
| 24 | struct v4l2_format *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 26 | struct cx8800_fh *fh = priv; |
| 27 | struct cx8800_dev *dev = fh->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; |
| 30 | f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; |
| 31 | f->fmt.vbi.offset = 244; |
| 32 | f->fmt.vbi.count[0] = VBI_LINE_COUNT; |
| 33 | f->fmt.vbi.count[1] = VBI_LINE_COUNT; |
| 34 | |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 35 | if (dev->core->tvnorm & V4L2_STD_525_60) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* ntsc */ |
| 37 | f->fmt.vbi.sampling_rate = 28636363; |
Michael Schimek | 419ac5d | 2006-05-22 10:32:11 -0300 | [diff] [blame] | 38 | f->fmt.vbi.start[0] = 10; |
| 39 | f->fmt.vbi.start[1] = 273; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | 63ab1bd | 2007-01-20 13:58:33 -0300 | [diff] [blame] | 41 | } else if (dev->core->tvnorm & V4L2_STD_625_50) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* pal */ |
| 43 | f->fmt.vbi.sampling_rate = 35468950; |
| 44 | f->fmt.vbi.start[0] = 7 -1; |
| 45 | f->fmt.vbi.start[1] = 319 -1; |
| 46 | } |
Mauro Carvalho Chehab | 8d87cb9 | 2007-01-20 13:58:17 -0300 | [diff] [blame] | 47 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 50 | static int cx8800_start_vbi_dma(struct cx8800_dev *dev, |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 51 | struct cx88_dmaqueue *q, |
| 52 | struct cx88_buffer *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | struct cx88_core *core = dev->core; |
| 55 | |
| 56 | /* setup fifo + format */ |
| 57 | cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH24], |
| 58 | buf->vb.width, buf->risc.dma); |
| 59 | |
| 60 | cx_write(MO_VBOS_CONTROL, ( (1 << 18) | // comb filter delay fixup |
| 61 | (1 << 15) | // enable vbi capture |
| 62 | (1 << 11) )); |
| 63 | |
| 64 | /* reset counter */ |
| 65 | cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET); |
| 66 | q->count = 1; |
| 67 | |
| 68 | /* enable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 69 | cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | cx_set(MO_VID_INTMSK, 0x0f0088); |
| 71 | |
| 72 | /* enable capture */ |
| 73 | cx_set(VID_CAPTURE_CONTROL,0x18); |
| 74 | |
| 75 | /* start dma */ |
| 76 | cx_set(MO_DEV_CNTRL2, (1<<5)); |
| 77 | cx_set(MO_VID_DMACNTRL, 0x88); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | int cx8800_stop_vbi_dma(struct cx8800_dev *dev) |
| 83 | { |
| 84 | struct cx88_core *core = dev->core; |
| 85 | |
| 86 | /* stop dma */ |
| 87 | cx_clear(MO_VID_DMACNTRL, 0x88); |
| 88 | |
| 89 | /* disable capture */ |
| 90 | cx_clear(VID_CAPTURE_CONTROL,0x18); |
| 91 | |
| 92 | /* disable irqs */ |
Trent Piepho | 8ddac9e | 2007-08-18 06:57:55 -0300 | [diff] [blame] | 93 | cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | cx_clear(MO_VID_INTMSK, 0x0f0088); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | int cx8800_restart_vbi_queue(struct cx8800_dev *dev, |
| 99 | struct cx88_dmaqueue *q) |
| 100 | { |
| 101 | struct cx88_buffer *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | if (list_empty(&q->active)) |
| 104 | return 0; |
| 105 | |
| 106 | buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); |
| 107 | dprintk(2,"restart_queue [%p/%d]: restart dma\n", |
| 108 | buf, buf->vb.i); |
| 109 | cx8800_start_vbi_dma(dev, q, buf); |
Trent Piepho | 8bb629e2 | 2007-10-10 05:37:40 -0300 | [diff] [blame] | 110 | list_for_each_entry(buf, &q->active, vb.queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | buf->count = q->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | void cx8800_vbi_timeout(unsigned long data) |
| 117 | { |
| 118 | struct cx8800_dev *dev = (struct cx8800_dev*)data; |
| 119 | struct cx88_core *core = dev->core; |
| 120 | struct cx88_dmaqueue *q = &dev->vbiq; |
| 121 | struct cx88_buffer *buf; |
| 122 | unsigned long flags; |
| 123 | |
| 124 | cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH24]); |
| 125 | |
| 126 | cx_clear(MO_VID_DMACNTRL, 0x88); |
| 127 | cx_clear(VID_CAPTURE_CONTROL, 0x18); |
| 128 | |
| 129 | spin_lock_irqsave(&dev->slock,flags); |
| 130 | while (!list_empty(&q->active)) { |
| 131 | buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); |
| 132 | list_del(&buf->vb.queue); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 133 | buf->vb.state = VIDEOBUF_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | wake_up(&buf->vb.done); |
| 135 | printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->core->name, |
| 136 | buf, buf->vb.i, (unsigned long)buf->risc.dma); |
| 137 | } |
| 138 | cx8800_restart_vbi_queue(dev,q); |
| 139 | spin_unlock_irqrestore(&dev->slock,flags); |
| 140 | } |
| 141 | |
| 142 | /* ------------------------------------------------------------------ */ |
| 143 | |
| 144 | static int |
| 145 | vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) |
| 146 | { |
| 147 | *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2; |
| 148 | if (0 == *count) |
| 149 | *count = vbibufs; |
| 150 | if (*count < 2) |
| 151 | *count = 2; |
| 152 | if (*count > 32) |
| 153 | *count = 32; |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static int |
| 158 | vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, |
| 159 | enum v4l2_field field) |
| 160 | { |
| 161 | struct cx8800_fh *fh = q->priv_data; |
| 162 | struct cx8800_dev *dev = fh->dev; |
| 163 | struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); |
| 164 | unsigned int size; |
| 165 | int rc; |
| 166 | |
| 167 | size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2; |
| 168 | if (0 != buf->vb.baddr && buf->vb.bsize < size) |
| 169 | return -EINVAL; |
| 170 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 171 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 172 | struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | buf->vb.width = VBI_LINE_LENGTH; |
| 174 | buf->vb.height = VBI_LINE_COUNT; |
| 175 | buf->vb.size = size; |
| 176 | buf->vb.field = V4L2_FIELD_SEQ_TB; |
| 177 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 178 | if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | goto fail; |
| 180 | cx88_risc_buffer(dev->pci, &buf->risc, |
Mauro Carvalho Chehab | c1accaa | 2007-08-23 16:37:49 -0300 | [diff] [blame] | 181 | dma->sglist, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | 0, buf->vb.width * buf->vb.height, |
| 183 | buf->vb.width, 0, |
| 184 | buf->vb.height); |
| 185 | } |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 186 | buf->vb.state = VIDEOBUF_PREPARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | return 0; |
| 188 | |
| 189 | fail: |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 190 | cx88_free_buffer(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | return rc; |
| 192 | } |
| 193 | |
| 194 | static void |
| 195 | vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 196 | { |
| 197 | struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); |
| 198 | struct cx88_buffer *prev; |
| 199 | struct cx8800_fh *fh = vq->priv_data; |
| 200 | struct cx8800_dev *dev = fh->dev; |
| 201 | struct cx88_dmaqueue *q = &dev->vbiq; |
| 202 | |
| 203 | /* add jump to stopper */ |
| 204 | buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); |
| 205 | buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); |
| 206 | |
| 207 | if (list_empty(&q->active)) { |
| 208 | list_add_tail(&buf->vb.queue,&q->active); |
| 209 | cx8800_start_vbi_dma(dev, q, buf); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 210 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | buf->count = q->count++; |
| 212 | mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); |
| 213 | dprintk(2,"[%p/%d] vbi_queue - first active\n", |
| 214 | buf, buf->vb.i); |
| 215 | |
| 216 | } else { |
| 217 | prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); |
| 218 | list_add_tail(&buf->vb.queue,&q->active); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 219 | buf->vb.state = VIDEOBUF_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | buf->count = q->count++; |
| 221 | prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); |
| 222 | dprintk(2,"[%p/%d] buffer_queue - append to active\n", |
| 223 | buf, buf->vb.i); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb) |
| 228 | { |
| 229 | struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 231 | cx88_free_buffer(q,buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | struct videobuf_queue_ops cx8800_vbi_qops = { |
| 235 | .buf_setup = vbi_setup, |
| 236 | .buf_prepare = vbi_prepare, |
| 237 | .buf_queue = vbi_queue, |
| 238 | .buf_release = vbi_release, |
| 239 | }; |
| 240 | |
| 241 | /* ------------------------------------------------------------------ */ |
| 242 | /* |
| 243 | * Local variables: |
| 244 | * c-basic-offset: 8 |
| 245 | * End: |
| 246 | */ |