1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/slab.h>
8 static unsigned int vbibufs = 4;
9 MODULE_PARM(vbibufs,"i");
10 MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32");
12 static unsigned int vbi_debug = 0;
13 MODULE_PARM(vbi_debug,"i");
14 MODULE_PARM_DESC(vbi_debug,"enable debug messages [video]");
16 #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \
17 printk(KERN_DEBUG "%s: " fmt, dev->name , ## arg)
19 /* ------------------------------------------------------------------ */
21 void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f)
23 memset(&f->fmt.vbi,0,sizeof(f->fmt.vbi));
25 f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
26 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
27 f->fmt.vbi.offset = 244;
28 f->fmt.vbi.count[0] = VBI_LINE_COUNT;
29 f->fmt.vbi.count[1] = VBI_LINE_COUNT;
31 if (dev->tvnorm->id & V4L2_STD_525_60) {
33 f->fmt.vbi.sampling_rate = 28636363;
34 f->fmt.vbi.start[0] = 10 -1;
35 f->fmt.vbi.start[1] = 273 -1;
37 } else if (V4L2_STD_625_50) {
39 f->fmt.vbi.sampling_rate = 35468950;
40 f->fmt.vbi.start[0] = 7 -1;
41 f->fmt.vbi.start[1] = 319 -1;
45 int cx8800_start_vbi_dma(struct cx8800_dev *dev,
46 struct cx88_dmaqueue *q,
47 struct cx88_buffer *buf)
49 /* setup fifo + format */
50 cx88_sram_channel_setup(dev, &cx88_sram_channels[SRAM_CH24],
51 buf->vb.width, buf->risc.dma);
53 cx_write(MO_VBOS_CONTROL, ( (1 << 18) | // comb filter delay fixup
54 (1 << 15) | // enable vbi capture
58 cx_write(MO_VBI_GPCNTRL,0x3);
62 cx_set(MO_PCI_INTMSK, 0x00fc01);
63 cx_set(MO_VID_INTMSK, 0x0f0088);
66 cx_set(VID_CAPTURE_CONTROL,0x18);
69 cx_set(MO_DEV_CNTRL2, (1<<5));
70 cx_set(MO_VID_DMACNTRL, 0x88);
75 int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
76 struct cx88_dmaqueue *q)
78 struct cx88_buffer *buf;
79 struct list_head *item;
81 if (list_empty(&q->active))
84 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
85 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
87 cx8800_start_vbi_dma(dev, q, buf);
88 list_for_each(item,&q->active) {
89 buf = list_entry(item, struct cx88_buffer, vb.queue);
90 buf->count = q->count++;
92 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
96 void cx8800_vbi_timeout(unsigned long data)
98 struct cx8800_dev *dev = (struct cx8800_dev*)data;
99 struct cx88_dmaqueue *q = &dev->vbiq;
100 struct cx88_buffer *buf;
103 cx88_sram_channel_dump(dev, &cx88_sram_channels[SRAM_CH24]);
105 cx_clear(MO_VID_DMACNTRL, 0x88);
106 cx_clear(VID_CAPTURE_CONTROL, 0x18);
108 spin_lock_irqsave(&dev->slock,flags);
109 while (!list_empty(&q->active)) {
110 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
111 list_del(&buf->vb.queue);
112 buf->vb.state = STATE_ERROR;
113 wake_up(&buf->vb.done);
114 printk("%s: [%p/%d] timeout - dma=0x%08lx\n", dev->name,
115 buf, buf->vb.i, (unsigned long)buf->risc.dma);
117 cx8800_restart_vbi_queue(dev,q);
118 spin_unlock_irqrestore(&dev->slock,flags);
121 /* ------------------------------------------------------------------ */
124 vbi_setup(struct file *file, unsigned int *count, unsigned int *size)
126 *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
137 vbi_prepare(struct file *file, struct videobuf_buffer *vb,
138 enum v4l2_field field)
140 struct cx8800_fh *fh = file->private_data;
141 struct cx8800_dev *dev = fh->dev;
142 struct cx88_buffer *buf = (struct cx88_buffer*)vb;
146 size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
147 if (0 != buf->vb.baddr && buf->vb.bsize < size)
150 if (STATE_NEEDS_INIT == buf->vb.state) {
151 buf->vb.width = VBI_LINE_LENGTH;
152 buf->vb.height = VBI_LINE_COUNT;
154 buf->vb.field = V4L2_FIELD_SEQ_TB;
156 if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL)))
158 cx88_risc_buffer(dev->pci, &buf->risc,
160 0, buf->vb.width * buf->vb.height,
164 buf->vb.state = STATE_PREPARED;
168 cx88_free_buffer(dev->pci,buf);
173 vbi_queue(struct file *file, struct videobuf_buffer *vb)
175 struct cx88_buffer *buf = (struct cx88_buffer*)vb;
176 struct cx88_buffer *prev;
177 struct cx8800_fh *fh = file->private_data;
178 struct cx8800_dev *dev = fh->dev;
179 struct cx88_dmaqueue *q = &dev->vbiq;
181 /* add jump to stopper */
182 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | 0x10000);
183 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
185 if (list_empty(&q->active)) {
186 list_add_tail(&buf->vb.queue,&q->active);
187 cx8800_start_vbi_dma(dev, q, buf);
188 buf->vb.state = STATE_ACTIVE;
189 buf->count = q->count++;
190 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
191 dprintk(2,"[%p/%d] vbi_queue - first active\n",
195 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
196 list_add_tail(&buf->vb.queue,&q->active);
197 buf->vb.state = STATE_ACTIVE;
198 buf->count = q->count++;
199 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
200 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
205 static void vbi_release(struct file *file, struct videobuf_buffer *vb)
207 struct cx88_buffer *buf = (struct cx88_buffer*)vb;
208 struct cx8800_fh *fh = file->private_data;
210 cx88_free_buffer(fh->dev->pci,buf);
213 struct videobuf_queue_ops cx8800_vbi_qops = {
214 .buf_setup = vbi_setup,
215 .buf_prepare = vbi_prepare,
216 .buf_queue = vbi_queue,
217 .buf_release = vbi_release,
220 /* ------------------------------------------------------------------ */