[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / media / video / cx88 / cx88-vbi.c
blob0584ff476387bbc3233bda943467a4890e59172a
1 /*
2 * $Id: cx88-vbi.c,v 1.16 2004/12/10 12:33:39 kraxel Exp $
3 */
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>
10 #include "cx88.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) {
36 /* ntsc */
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) {
42 /* pal */
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
61 (1 << 11) ));
63 /* reset counter */
64 cx_write(MO_VBI_GPCNTRL, GP_COUNT_CONTROL_RESET);
65 q->count = 1;
67 /* enable irqs */
68 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01);
69 cx_set(MO_VID_INTMSK, 0x0f0088);
71 /* enable capture */
72 cx_set(VID_CAPTURE_CONTROL,0x18);
74 /* start dma */
75 cx_set(MO_DEV_CNTRL2, (1<<5));
76 cx_set(MO_VID_DMACNTRL, 0x88);
78 return 0;
81 int cx8800_stop_vbi_dma(struct cx8800_dev *dev)
83 struct cx88_core *core = dev->core;
85 /* stop dma */
86 cx_clear(MO_VID_DMACNTRL, 0x88);
88 /* disable capture */
89 cx_clear(VID_CAPTURE_CONTROL,0x18);
91 /* disable irqs */
92 cx_clear(MO_PCI_INTMSK, 0x000001);
93 cx_clear(MO_VID_INTMSK, 0x0f0088);
94 return 0;
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))
104 return 0;
106 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
107 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
108 buf, buf->vb.i);
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);
115 return 0;
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;
124 unsigned long flags;
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 /* ------------------------------------------------------------------ */
146 static int
147 vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
149 *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
150 if (0 == *count)
151 *count = vbibufs;
152 if (*count < 2)
153 *count = 2;
154 if (*count > 32)
155 *count = 32;
156 return 0;
159 static int
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);
166 unsigned int size;
167 int rc;
169 size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
170 if (0 != buf->vb.baddr && buf->vb.bsize < size)
171 return -EINVAL;
173 if (STATE_NEEDS_INIT == buf->vb.state) {
174 buf->vb.width = VBI_LINE_LENGTH;
175 buf->vb.height = VBI_LINE_COUNT;
176 buf->vb.size = size;
177 buf->vb.field = V4L2_FIELD_SEQ_TB;
179 if (0 != (rc = videobuf_iolock(dev->pci,&buf->vb,NULL)))
180 goto fail;
181 cx88_risc_buffer(dev->pci, &buf->risc,
182 buf->vb.dma.sglist,
183 0, buf->vb.width * buf->vb.height,
184 buf->vb.width, 0,
185 buf->vb.height);
187 buf->vb.state = STATE_PREPARED;
188 return 0;
190 fail:
191 cx88_free_buffer(dev->pci,buf);
192 return rc;
195 static void
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",
215 buf, buf->vb.i);
217 } else {
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",
224 buf, buf->vb.i);
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 /* ------------------------------------------------------------------ */
245 * Local variables:
246 * c-basic-offset: 8
247 * End: