3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/init.h>
9 static unsigned int vbibufs
= 4;
10 module_param(vbibufs
,int,0644);
11 MODULE_PARM_DESC(vbibufs
,"number of vbi buffers, range 2-32");
13 static unsigned int vbi_debug
;
14 module_param(vbi_debug
,int,0644);
15 MODULE_PARM_DESC(vbi_debug
,"enable debug messages [vbi]");
17 #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \
18 printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)
20 /* ------------------------------------------------------------------ */
22 int cx8800_vbi_fmt (struct file
*file
, void *priv
,
23 struct v4l2_format
*f
)
25 struct cx8800_fh
*fh
= priv
;
26 struct cx8800_dev
*dev
= fh
->dev
;
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
& V4L2_STD_525_60
) {
36 f
->fmt
.vbi
.sampling_rate
= 28636363;
37 f
->fmt
.vbi
.start
[0] = 10;
38 f
->fmt
.vbi
.start
[1] = 273;
40 } else if (dev
->core
->tvnorm
& 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;
49 static int cx8800_start_vbi_dma(struct cx8800_dev
*dev
,
50 struct cx88_dmaqueue
*q
,
51 struct cx88_buffer
*buf
)
53 struct cx88_core
*core
= dev
->core
;
55 /* setup fifo + format */
56 cx88_sram_channel_setup(dev
->core
, &cx88_sram_channels
[SRAM_CH24
],
57 buf
->vb
.width
, buf
->risc
.dma
);
59 cx_write(MO_VBOS_CONTROL
, ( (1 << 18) | // comb filter delay fixup
60 (1 << 15) | // enable vbi capture
64 cx_write(MO_VBI_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
68 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
| PCI_INT_VIDINT
);
69 cx_set(MO_VID_INTMSK
, 0x0f0088);
72 cx_set(VID_CAPTURE_CONTROL
,0x18);
75 cx_set(MO_DEV_CNTRL2
, (1<<5));
76 cx_set(MO_VID_DMACNTRL
, 0x88);
81 int cx8800_stop_vbi_dma(struct cx8800_dev
*dev
)
83 struct cx88_core
*core
= dev
->core
;
86 cx_clear(MO_VID_DMACNTRL
, 0x88);
89 cx_clear(VID_CAPTURE_CONTROL
,0x18);
92 cx_clear(MO_PCI_INTMSK
, PCI_INT_VIDINT
);
93 cx_clear(MO_VID_INTMSK
, 0x0f0088);
97 int cx8800_restart_vbi_queue(struct cx8800_dev
*dev
,
98 struct cx88_dmaqueue
*q
)
100 struct cx88_buffer
*buf
;
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_entry(buf
, &q
->active
, vb
.queue
)
110 buf
->count
= q
->count
++;
111 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
115 void cx8800_vbi_timeout(unsigned long data
)
117 struct cx8800_dev
*dev
= (struct cx8800_dev
*)data
;
118 struct cx88_core
*core
= dev
->core
;
119 struct cx88_dmaqueue
*q
= &dev
->vbiq
;
120 struct cx88_buffer
*buf
;
123 cx88_sram_channel_dump(dev
->core
, &cx88_sram_channels
[SRAM_CH24
]);
125 cx_clear(MO_VID_DMACNTRL
, 0x88);
126 cx_clear(VID_CAPTURE_CONTROL
, 0x18);
128 spin_lock_irqsave(&dev
->slock
,flags
);
129 while (!list_empty(&q
->active
)) {
130 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
131 list_del(&buf
->vb
.queue
);
132 buf
->vb
.state
= VIDEOBUF_ERROR
;
133 wake_up(&buf
->vb
.done
);
134 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev
->core
->name
,
135 buf
, buf
->vb
.i
, (unsigned long)buf
->risc
.dma
);
137 cx8800_restart_vbi_queue(dev
,q
);
138 spin_unlock_irqrestore(&dev
->slock
,flags
);
141 /* ------------------------------------------------------------------ */
144 vbi_setup(struct videobuf_queue
*q
, unsigned int *count
, unsigned int *size
)
146 *size
= VBI_LINE_COUNT
* VBI_LINE_LENGTH
* 2;
157 vbi_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
158 enum v4l2_field field
)
160 struct cx8800_fh
*fh
= q
->priv_data
;
161 struct cx8800_dev
*dev
= fh
->dev
;
162 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
166 size
= VBI_LINE_COUNT
* VBI_LINE_LENGTH
* 2;
167 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< size
)
170 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
171 struct videobuf_dmabuf
*dma
=videobuf_to_dma(&buf
->vb
);
172 buf
->vb
.width
= VBI_LINE_LENGTH
;
173 buf
->vb
.height
= VBI_LINE_COUNT
;
175 buf
->vb
.field
= V4L2_FIELD_SEQ_TB
;
177 if (0 != (rc
= videobuf_iolock(q
,&buf
->vb
,NULL
)))
179 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
181 0, buf
->vb
.width
* buf
->vb
.height
,
185 buf
->vb
.state
= VIDEOBUF_PREPARED
;
189 cx88_free_buffer(q
,buf
);
194 vbi_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
196 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
197 struct cx88_buffer
*prev
;
198 struct cx8800_fh
*fh
= vq
->priv_data
;
199 struct cx8800_dev
*dev
= fh
->dev
;
200 struct cx88_dmaqueue
*q
= &dev
->vbiq
;
202 /* add jump to stopper */
203 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
204 buf
->risc
.jmp
[1] = cpu_to_le32(q
->stopper
.dma
);
206 if (list_empty(&q
->active
)) {
207 list_add_tail(&buf
->vb
.queue
,&q
->active
);
208 cx8800_start_vbi_dma(dev
, q
, buf
);
209 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
210 buf
->count
= q
->count
++;
211 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
212 dprintk(2,"[%p/%d] vbi_queue - first active\n",
216 prev
= list_entry(q
->active
.prev
, struct cx88_buffer
, vb
.queue
);
217 list_add_tail(&buf
->vb
.queue
,&q
->active
);
218 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
219 buf
->count
= q
->count
++;
220 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
221 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
226 static void vbi_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
228 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
230 cx88_free_buffer(q
,buf
);
233 const struct videobuf_queue_ops cx8800_vbi_qops
= {
234 .buf_setup
= vbi_setup
,
235 .buf_prepare
= vbi_prepare
,
236 .buf_queue
= vbi_queue
,
237 .buf_release
= vbi_release
,
240 /* ------------------------------------------------------------------ */