2 * $Id: cx88-vbi.c,v 1.16 2004/12/10 12:33:39 kraxel Exp $
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/moduleparam.h>
7 #include <linux/init.h>
8 #include <linux/slab.h>
12 static unsigned int vbibufs
= 4;
13 module_param(vbibufs
,int,0644);
14 MODULE_PARM_DESC(vbibufs
,"number of vbi buffers, range 2-32");
16 static unsigned int vbi_debug
= 0;
17 module_param(vbi_debug
,int,0644);
18 MODULE_PARM_DESC(vbi_debug
,"enable debug messages [vbi]");
20 #define dprintk(level,fmt, arg...) if (vbi_debug >= level) \
21 printk(KERN_DEBUG "%s: " fmt, dev->core->name , ## arg)
23 /* ------------------------------------------------------------------ */
25 void cx8800_vbi_fmt(struct cx8800_dev
*dev
, struct v4l2_format
*f
)
27 memset(&f
->fmt
.vbi
,0,sizeof(f
->fmt
.vbi
));
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
->id
& V4L2_STD_525_60
) {
37 f
->fmt
.vbi
.sampling_rate
= 28636363;
38 f
->fmt
.vbi
.start
[0] = 10 -1;
39 f
->fmt
.vbi
.start
[1] = 273 -1;
41 } else if (dev
->core
->tvnorm
->id
& 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;
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
| 0x01);
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
, 0x000001);
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
;
101 struct list_head
*item
;
103 if (list_empty(&q
->active
))
106 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
107 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
109 cx8800_start_vbi_dma(dev
, q
, buf
);
110 list_for_each(item
,&q
->active
) {
111 buf
= list_entry(item
, struct cx88_buffer
, vb
.queue
);
112 buf
->count
= q
->count
++;
114 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
118 void cx8800_vbi_timeout(unsigned long data
)
120 struct cx8800_dev
*dev
= (struct cx8800_dev
*)data
;
121 struct cx88_core
*core
= dev
->core
;
122 struct cx88_dmaqueue
*q
= &dev
->vbiq
;
123 struct cx88_buffer
*buf
;
126 cx88_sram_channel_dump(dev
->core
, &cx88_sram_channels
[SRAM_CH24
]);
128 cx_clear(MO_VID_DMACNTRL
, 0x88);
129 cx_clear(VID_CAPTURE_CONTROL
, 0x18);
131 spin_lock_irqsave(&dev
->slock
,flags
);
132 while (!list_empty(&q
->active
)) {
133 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
134 list_del(&buf
->vb
.queue
);
135 buf
->vb
.state
= STATE_ERROR
;
136 wake_up(&buf
->vb
.done
);
137 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev
->core
->name
,
138 buf
, buf
->vb
.i
, (unsigned long)buf
->risc
.dma
);
140 cx8800_restart_vbi_queue(dev
,q
);
141 spin_unlock_irqrestore(&dev
->slock
,flags
);
144 /* ------------------------------------------------------------------ */
147 vbi_setup(struct videobuf_queue
*q
, unsigned int *count
, unsigned int *size
)
149 *size
= VBI_LINE_COUNT
* VBI_LINE_LENGTH
* 2;
160 vbi_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
161 enum v4l2_field field
)
163 struct cx8800_fh
*fh
= q
->priv_data
;
164 struct cx8800_dev
*dev
= fh
->dev
;
165 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
169 size
= VBI_LINE_COUNT
* VBI_LINE_LENGTH
* 2;
170 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< size
)
173 if (STATE_NEEDS_INIT
== buf
->vb
.state
) {
174 buf
->vb
.width
= VBI_LINE_LENGTH
;
175 buf
->vb
.height
= VBI_LINE_COUNT
;
177 buf
->vb
.field
= V4L2_FIELD_SEQ_TB
;
179 if (0 != (rc
= videobuf_iolock(dev
->pci
,&buf
->vb
,NULL
)))
181 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
183 0, buf
->vb
.width
* buf
->vb
.height
,
187 buf
->vb
.state
= STATE_PREPARED
;
191 cx88_free_buffer(dev
->pci
,buf
);
196 vbi_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
198 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
199 struct cx88_buffer
*prev
;
200 struct cx8800_fh
*fh
= vq
->priv_data
;
201 struct cx8800_dev
*dev
= fh
->dev
;
202 struct cx88_dmaqueue
*q
= &dev
->vbiq
;
204 /* add jump to stopper */
205 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
206 buf
->risc
.jmp
[1] = cpu_to_le32(q
->stopper
.dma
);
208 if (list_empty(&q
->active
)) {
209 list_add_tail(&buf
->vb
.queue
,&q
->active
);
210 cx8800_start_vbi_dma(dev
, q
, buf
);
211 buf
->vb
.state
= STATE_ACTIVE
;
212 buf
->count
= q
->count
++;
213 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
214 dprintk(2,"[%p/%d] vbi_queue - first active\n",
218 prev
= list_entry(q
->active
.prev
, struct cx88_buffer
, vb
.queue
);
219 list_add_tail(&buf
->vb
.queue
,&q
->active
);
220 buf
->vb
.state
= STATE_ACTIVE
;
221 buf
->count
= q
->count
++;
222 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
223 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
228 static void vbi_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
230 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
231 struct cx8800_fh
*fh
= q
->priv_data
;
233 cx88_free_buffer(fh
->dev
->pci
,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 /* ------------------------------------------------------------------ */