3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/moduleparam.h>
6 #include <linux/init.h>
7 #include <linux/slab.h>
11 static unsigned int vbibufs
= 4;
12 module_param(vbibufs
,int,0644);
13 MODULE_PARM_DESC(vbibufs
,"number of vbi buffers, range 2-32");
15 static unsigned int vbi_debug
= 0;
16 module_param(vbi_debug
,int,0644);
17 MODULE_PARM_DESC(vbi_debug
,"enable debug messages [vbi]");
19 #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \
20 printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)
22 /* ------------------------------------------------------------------ */
24 void cx8800_vbi_fmt(struct cx8800_dev
*dev
, struct v4l2_format
*f
)
26 memset(&f
->fmt
.vbi
,0,sizeof(f
->fmt
.vbi
));
28 f
->fmt
.vbi
.samples_per_line
= VBI_LINE_LENGTH
;
29 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
30 f
->fmt
.vbi
.offset
= 244;
31 f
->fmt
.vbi
.count
[0] = VBI_LINE_COUNT
;
32 f
->fmt
.vbi
.count
[1] = VBI_LINE_COUNT
;
34 if (dev
->core
->tvnorm
->id
& V4L2_STD_525_60
) {
36 f
->fmt
.vbi
.sampling_rate
= 28636363;
37 f
->fmt
.vbi
.start
[0] = 10 -1;
38 f
->fmt
.vbi
.start
[1] = 273 -1;
40 } else if (dev
->core
->tvnorm
->id
& V4L2_STD_625_50
) {
42 f
->fmt
.vbi
.sampling_rate
= 35468950;
43 f
->fmt
.vbi
.start
[0] = 7 -1;
44 f
->fmt
.vbi
.start
[1] = 319 -1;
48 static int cx8800_start_vbi_dma(struct cx8800_dev
*dev
,
49 struct cx88_dmaqueue
*q
,
50 struct cx88_buffer
*buf
)
52 struct cx88_core
*core
= dev
->core
;
54 /* setup fifo + format */
55 cx88_sram_channel_setup(dev
->core
, &cx88_sram_channels
[SRAM_CH24
],
56 buf
->vb
.width
, buf
->risc
.dma
);
58 cx_write(MO_VBOS_CONTROL
, ( (1 << 18) | // comb filter delay fixup
59 (1 << 15) | // enable vbi capture
63 cx_write(MO_VBI_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
67 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
| 0x01);
68 cx_set(MO_VID_INTMSK
, 0x0f0088);
71 cx_set(VID_CAPTURE_CONTROL
,0x18);
74 cx_set(MO_DEV_CNTRL2
, (1<<5));
75 cx_set(MO_VID_DMACNTRL
, 0x88);
80 int cx8800_stop_vbi_dma(struct cx8800_dev
*dev
)
82 struct cx88_core
*core
= dev
->core
;
85 cx_clear(MO_VID_DMACNTRL
, 0x88);
88 cx_clear(VID_CAPTURE_CONTROL
,0x18);
91 cx_clear(MO_PCI_INTMSK
, 0x000001);
92 cx_clear(MO_VID_INTMSK
, 0x0f0088);
96 int cx8800_restart_vbi_queue(struct cx8800_dev
*dev
,
97 struct cx88_dmaqueue
*q
)
99 struct cx88_buffer
*buf
;
100 struct list_head
*item
;
102 if (list_empty(&q
->active
))
105 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
106 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
108 cx8800_start_vbi_dma(dev
, q
, buf
);
109 list_for_each(item
,&q
->active
) {
110 buf
= list_entry(item
, struct cx88_buffer
, vb
.queue
);
111 buf
->count
= q
->count
++;
113 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
117 void cx8800_vbi_timeout(unsigned long data
)
119 struct cx8800_dev
*dev
= (struct cx8800_dev
*)data
;
120 struct cx88_core
*core
= dev
->core
;
121 struct cx88_dmaqueue
*q
= &dev
->vbiq
;
122 struct cx88_buffer
*buf
;
125 cx88_sram_channel_dump(dev
->core
, &cx88_sram_channels
[SRAM_CH24
]);
127 cx_clear(MO_VID_DMACNTRL
, 0x88);
128 cx_clear(VID_CAPTURE_CONTROL
, 0x18);
130 spin_lock_irqsave(&dev
->slock
,flags
);
131 while (!list_empty(&q
->active
)) {
132 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
133 list_del(&buf
->vb
.queue
);
134 buf
->vb
.state
= STATE_ERROR
;
135 wake_up(&buf
->vb
.done
);
136 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev
->core
->name
,
137 buf
, buf
->vb
.i
, (unsigned long)buf
->risc
.dma
);
139 cx8800_restart_vbi_queue(dev
,q
);
140 spin_unlock_irqrestore(&dev
->slock
,flags
);
143 /* ------------------------------------------------------------------ */
146 vbi_setup(struct videobuf_queue
*q
, unsigned int *count
, unsigned int *size
)
148 *size
= VBI_LINE_COUNT
* VBI_LINE_LENGTH
* 2;
159 vbi_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
160 enum v4l2_field field
)
162 struct cx8800_fh
*fh
= q
->priv_data
;
163 struct cx8800_dev
*dev
= fh
->dev
;
164 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
168 size
= VBI_LINE_COUNT
* VBI_LINE_LENGTH
* 2;
169 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< size
)
172 if (STATE_NEEDS_INIT
== buf
->vb
.state
) {
173 buf
->vb
.width
= VBI_LINE_LENGTH
;
174 buf
->vb
.height
= VBI_LINE_COUNT
;
176 buf
->vb
.field
= V4L2_FIELD_SEQ_TB
;
178 if (0 != (rc
= videobuf_iolock(dev
->pci
,&buf
->vb
,NULL
)))
180 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
182 0, buf
->vb
.width
* buf
->vb
.height
,
186 buf
->vb
.state
= STATE_PREPARED
;
190 cx88_free_buffer(dev
->pci
,buf
);
195 vbi_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
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
;
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
);
207 if (list_empty(&q
->active
)) {
208 list_add_tail(&buf
->vb
.queue
,&q
->active
);
209 cx8800_start_vbi_dma(dev
, q
, buf
);
210 buf
->vb
.state
= STATE_ACTIVE
;
211 buf
->count
= q
->count
++;
212 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
213 dprintk(2,"[%p/%d] vbi_queue - first active\n",
217 prev
= list_entry(q
->active
.prev
, struct cx88_buffer
, vb
.queue
);
218 list_add_tail(&buf
->vb
.queue
,&q
->active
);
219 buf
->vb
.state
= STATE_ACTIVE
;
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",
227 static void vbi_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
229 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
230 struct cx8800_fh
*fh
= q
->priv_data
;
232 cx88_free_buffer(fh
->dev
->pci
,buf
);
235 struct videobuf_queue_ops cx8800_vbi_qops
= {
236 .buf_setup
= vbi_setup
,
237 .buf_prepare
= vbi_prepare
,
238 .buf_queue
= vbi_queue
,
239 .buf_release
= vbi_release
,
242 /* ------------------------------------------------------------------ */