GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / media / video / cx23885 / cx23885-vbi.c
blobc0b60382ad13602ff9c2fc512cf92fe531568cc2
1 /*
2 * Driver for the Conexant CX23885 PCIe bridge
4 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/init.h>
27 #include "cx23885.h"
29 static unsigned int vbibufs = 4;
30 module_param(vbibufs, int, 0644);
31 MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32");
33 static unsigned int vbi_debug;
34 module_param(vbi_debug, int, 0644);
35 MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
37 #define dprintk(level, fmt, arg...)\
38 do { if (vbi_debug >= level)\
39 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
40 } while (0)
42 /* ------------------------------------------------------------------ */
44 int cx23885_vbi_fmt(struct file *file, void *priv,
45 struct v4l2_format *f)
47 struct cx23885_fh *fh = priv;
48 struct cx23885_dev *dev = fh->dev;
50 if (dev->tvnorm & V4L2_STD_525_60) {
51 /* ntsc */
52 f->fmt.vbi.sampling_rate = 28636363;
53 f->fmt.vbi.start[0] = 10;
54 f->fmt.vbi.start[1] = 273;
56 } else if (dev->tvnorm & V4L2_STD_625_50) {
57 /* pal */
58 f->fmt.vbi.sampling_rate = 35468950;
59 f->fmt.vbi.start[0] = 7 - 1;
60 f->fmt.vbi.start[1] = 319 - 1;
62 return 0;
65 static int cx23885_start_vbi_dma(struct cx23885_dev *dev,
66 struct cx23885_dmaqueue *q,
67 struct cx23885_buffer *buf)
69 /* setup fifo + format */
70 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH02],
71 buf->vb.width, buf->risc.dma);
73 /* reset counter */
74 q->count = 1;
76 /* enable irqs */
77 cx23885_irq_add_enable(dev, 0x01);
78 cx_set(VID_A_INT_MSK, 0x000022);
80 /* start dma */
81 cx_set(DEV_CNTRL2, (1<<5));
82 cx_set(VID_A_DMA_CTL, 0x00000022);
84 return 0;
88 static int cx23885_restart_vbi_queue(struct cx23885_dev *dev,
89 struct cx23885_dmaqueue *q)
91 struct cx23885_buffer *buf;
92 struct list_head *item;
94 if (list_empty(&q->active))
95 return 0;
97 buf = list_entry(q->active.next, struct cx23885_buffer, vb.queue);
98 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
99 buf, buf->vb.i);
100 cx23885_start_vbi_dma(dev, q, buf);
101 list_for_each(item, &q->active) {
102 buf = list_entry(item, struct cx23885_buffer, vb.queue);
103 buf->count = q->count++;
105 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
106 return 0;
109 void cx23885_vbi_timeout(unsigned long data)
111 struct cx23885_dev *dev = (struct cx23885_dev *)data;
112 struct cx23885_dmaqueue *q = &dev->vbiq;
113 struct cx23885_buffer *buf;
114 unsigned long flags;
116 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH02]);
118 cx_clear(VID_A_DMA_CTL, 0x22);
120 spin_lock_irqsave(&dev->slock, flags);
121 while (!list_empty(&q->active)) {
122 buf = list_entry(q->active.next, struct cx23885_buffer,
123 vb.queue);
124 list_del(&buf->vb.queue);
125 buf->vb.state = VIDEOBUF_ERROR;
126 wake_up(&buf->vb.done);
127 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->name,
128 buf, buf->vb.i, (unsigned long)buf->risc.dma);
130 cx23885_restart_vbi_queue(dev, q);
131 spin_unlock_irqrestore(&dev->slock, flags);
134 /* ------------------------------------------------------------------ */
135 #define VBI_LINE_LENGTH 2048
136 #define VBI_LINE_COUNT 17
138 static int
139 vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
141 *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
142 if (0 == *count)
143 *count = vbibufs;
144 if (*count < 2)
145 *count = 2;
146 if (*count > 32)
147 *count = 32;
148 return 0;
151 static int
152 vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
153 enum v4l2_field field)
155 struct cx23885_fh *fh = q->priv_data;
156 struct cx23885_dev *dev = fh->dev;
157 struct cx23885_buffer *buf = container_of(vb,
158 struct cx23885_buffer, vb);
159 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
160 unsigned int size;
161 int rc;
163 size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
164 if (0 != buf->vb.baddr && buf->vb.bsize < size)
165 return -EINVAL;
167 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
168 buf->vb.width = VBI_LINE_LENGTH;
169 buf->vb.height = VBI_LINE_COUNT;
170 buf->vb.size = size;
171 buf->vb.field = V4L2_FIELD_SEQ_TB;
173 rc = videobuf_iolock(q, &buf->vb, NULL);
174 if (0 != rc)
175 goto fail;
176 cx23885_risc_buffer(dev->pci, &buf->risc,
177 dma->sglist,
178 0, buf->vb.width * buf->vb.height,
179 buf->vb.width, 0,
180 buf->vb.height);
182 buf->vb.state = VIDEOBUF_PREPARED;
183 return 0;
185 fail:
186 cx23885_free_buffer(q, buf);
187 return rc;
190 static void
191 vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
193 struct cx23885_buffer *buf =
194 container_of(vb, struct cx23885_buffer, vb);
195 struct cx23885_buffer *prev;
196 struct cx23885_fh *fh = vq->priv_data;
197 struct cx23885_dev *dev = fh->dev;
198 struct cx23885_dmaqueue *q = &dev->vbiq;
200 /* add jump to stopper */
201 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
202 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
203 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
205 if (list_empty(&q->active)) {
206 list_add_tail(&buf->vb.queue, &q->active);
207 cx23885_start_vbi_dma(dev, q, buf);
208 buf->vb.state = VIDEOBUF_ACTIVE;
209 buf->count = q->count++;
210 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
211 dprintk(2, "[%p/%d] vbi_queue - first active\n",
212 buf, buf->vb.i);
214 } else {
215 prev = list_entry(q->active.prev, struct cx23885_buffer,
216 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 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63-32 */
222 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
223 buf, buf->vb.i);
227 static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
229 struct cx23885_buffer *buf =
230 container_of(vb, struct cx23885_buffer, vb);
232 cx23885_free_buffer(q, buf);
235 struct videobuf_queue_ops cx23885_vbi_qops = {
236 .buf_setup = vbi_setup,
237 .buf_prepare = vbi_prepare,
238 .buf_queue = vbi_queue,
239 .buf_release = vbi_release,
242 /* ------------------------------------------------------------------ */
244 * Local variables:
245 * c-basic-offset: 8
246 * End: