3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/init.h>
6 #include <linux/slab.h>
10 static unsigned int vbibufs = 4;
11 module_param(vbibufs,int,0644);
12 MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32");
14 static unsigned int vbi_debug = 0;
15 module_param(vbi_debug,int,0644);
16 MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
18 #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \
19 printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)
21 /* ------------------------------------------------------------------ */
23 int cx8800_vbi_fmt (struct file *file, void *priv,
24 struct v4l2_format *f)
26 struct cx8800_fh *fh = priv;
27 struct cx8800_dev *dev = fh->dev;
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;
35 if (dev->core->tvnorm & V4L2_STD_525_60) {
37 f->fmt.vbi.sampling_rate = 28636363;
38 f->fmt.vbi.start[0] = 10;
39 f->fmt.vbi.start[1] = 273;
41 } else if (dev->core->tvnorm & V4L2_STD_625_50) {
43 f->fmt.vbi.sampling_rate = 35468950;
44 f->fmt.vbi.start[0] = 7 -1;
45 f->fmt.vbi.start[1] = 319 -1;
50 static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
51 struct cx88_dmaqueue *q,
52 struct cx88_buffer *buf)
54 struct cx88_core *core = dev->core;
56 /* setup fifo + format */
57 cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH24],
58 buf->vb.width, buf->risc.dma);
60 cx_write(MO_VBOS_CONTROL, ( (1 << 18) | // comb filter delay fixup
61 (1 << 15) | // enable vbi capture
65 cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET);
69 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
70 cx_set(MO_VID_INTMSK, 0x0f0088);
73 cx_set(VID_CAPTURE_CONTROL,0x18);
76 cx_set(MO_DEV_CNTRL2, (1<<5));
77 cx_set(MO_VID_DMACNTRL, 0x88);
82 int cx8800_stop_vbi_dma(struct cx8800_dev *dev)
84 struct cx88_core *core = dev->core;
87 cx_clear(MO_VID_DMACNTRL, 0x88);
90 cx_clear(VID_CAPTURE_CONTROL,0x18);
93 cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
94 cx_clear(MO_VID_INTMSK, 0x0f0088);
98 int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
99 struct cx88_dmaqueue *q)
101 struct cx88_buffer *buf;
102 struct list_head *item;
104 if (list_empty(&q->active))
107 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
108 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
110 cx8800_start_vbi_dma(dev, q, buf);
111 list_for_each(item,&q->active) {
112 buf = list_entry(item, struct cx88_buffer, vb.queue);
113 buf->count = q->count++;
115 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
119 void cx8800_vbi_timeout(unsigned long data)
121 struct cx8800_dev *dev = (struct cx8800_dev*)data;
122 struct cx88_core *core = dev->core;
123 struct cx88_dmaqueue *q = &dev->vbiq;
124 struct cx88_buffer *buf;
127 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH24]);
129 cx_clear(MO_VID_DMACNTRL, 0x88);
130 cx_clear(VID_CAPTURE_CONTROL, 0x18);
132 spin_lock_irqsave(&dev->slock,flags);
133 while (!list_empty(&q->active)) {
134 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
135 list_del(&buf->vb.queue);
136 buf->vb.state = STATE_ERROR;
137 wake_up(&buf->vb.done);
138 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->core->name,
139 buf, buf->vb.i, (unsigned long)buf->risc.dma);
141 cx8800_restart_vbi_queue(dev,q);
142 spin_unlock_irqrestore(&dev->slock,flags);
145 /* ------------------------------------------------------------------ */
148 vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
150 *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
161 vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
162 enum v4l2_field field)
164 struct cx8800_fh *fh = q->priv_data;
165 struct cx8800_dev *dev = fh->dev;
166 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
170 size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
171 if (0 != buf->vb.baddr && buf->vb.bsize < size)
174 if (STATE_NEEDS_INIT == buf->vb.state) {
175 buf->vb.width = VBI_LINE_LENGTH;
176 buf->vb.height = VBI_LINE_COUNT;
178 buf->vb.field = V4L2_FIELD_SEQ_TB;
180 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
182 cx88_risc_buffer(dev->pci, &buf->risc,
184 0, buf->vb.width * buf->vb.height,
188 buf->vb.state = STATE_PREPARED;
192 cx88_free_buffer(q,buf);
197 vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
199 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
200 struct cx88_buffer *prev;
201 struct cx8800_fh *fh = vq->priv_data;
202 struct cx8800_dev *dev = fh->dev;
203 struct cx88_dmaqueue *q = &dev->vbiq;
205 /* add jump to stopper */
206 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
207 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
209 if (list_empty(&q->active)) {
210 list_add_tail(&buf->vb.queue,&q->active);
211 cx8800_start_vbi_dma(dev, q, buf);
212 buf->vb.state = STATE_ACTIVE;
213 buf->count = q->count++;
214 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
215 dprintk(2,"[%p/%d] vbi_queue - first active\n",
219 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
220 list_add_tail(&buf->vb.queue,&q->active);
221 buf->vb.state = STATE_ACTIVE;
222 buf->count = q->count++;
223 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
224 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
229 static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
231 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
233 cx88_free_buffer(q,buf);
236 struct videobuf_queue_ops cx8800_vbi_qops = {
237 .buf_setup = vbi_setup,
238 .buf_prepare = vbi_prepare,
239 .buf_queue = vbi_queue,
240 .buf_release = vbi_release,
243 /* ------------------------------------------------------------------ */