blob: d6d980774c21bbbe20491f9a1d4c18a2488dfb3f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Support for the mpeg transport stream transfers
4 * PCI function #2 of the cx2388x.
5 *
6 * (c) 2004 Jelle Foks <jelle@foks.8m.com>
7 * (c) 2004 Chris Pascoe <c.pascoe@itee.uq.edu.au>
8 * (c) 2004 Gerd Knorr <kraxel@bytesex.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/device.h>
29#include <linux/interrupt.h>
30#include <asm/delay.h>
31
32#include "cx88.h"
33
34/* ------------------------------------------------------------------ */
35
36MODULE_DESCRIPTION("mpeg driver for cx2388x based TV cards");
37MODULE_AUTHOR("Jelle Foks <jelle@foks.8m.com>");
38MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
39MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
40MODULE_LICENSE("GPL");
41
42static unsigned int debug = 0;
43module_param(debug,int,0644);
44MODULE_PARM_DESC(debug,"enable debug messages [mpeg]");
45
46#define dprintk(level,fmt, arg...) if (debug >= level) \
47 printk(KERN_DEBUG "%s/2: " fmt, dev->core->name , ## arg)
48
49/* ------------------------------------------------------------------ */
50
51static int cx8802_start_dma(struct cx8802_dev *dev,
52 struct cx88_dmaqueue *q,
53 struct cx88_buffer *buf)
54{
55 struct cx88_core *core = dev->core;
56
Trent Piepho76d313b2006-04-10 09:27:08 -030057 dprintk(1, "cx8802_start_dma w: %d, h: %d, f: %d\n", dev->width, dev->height, buf->vb.field);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 /* setup fifo + format */
60 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
61 dev->ts_packet_size, buf->risc.dma);
62
63 /* write TS length to chip */
64 cx_write(MO_TS_LNGTH, buf->vb.width);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /* FIXME: this needs a review.
67 * also: move to cx88-blackbird + cx88-dvb source files? */
Michael Krufky48d5e802006-09-25 14:09:10 -030068 if (cx88_boards[core->board].mpeg == (CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD) ) {
Steven Toth3a5ba522006-09-25 12:43:45 -030069 /* Report a warning until the mini driver patch is applied,
70 * else the following conditions will set the dma registers incorrectly.
71 * This will be removed in the next major patch and changes to the conditions
72 * will be made.
73 */
Michael Krufky48d5e802006-09-25 14:09:10 -030074 printk(KERN_INFO "%s() board->(CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD) is invalid\n", __FUNCTION__);
Steven Toth3a5ba522006-09-25 12:43:45 -030075 return -EINVAL;
76 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Michael Krufky48d5e802006-09-25 14:09:10 -030078 if (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* negedge driven & software reset */
Michael Krufkyf1798492005-07-07 17:58:39 -070080 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 udelay(100);
82 cx_write(MO_PINMUX_IO, 0x00);
Michael Krufky0d723c02005-07-07 17:58:42 -070083 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -070084 switch (core->board) {
85 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
86 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
87 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
Rusty Scottda215d22006-04-07 02:21:31 -030088 case CX88_BOARD_PCHDTV_HD5500:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070089 cx_write(TS_SOP_STAT, 1<<13);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -070090 break;
Steven Toth0fa14aa2006-01-09 15:25:02 -020091 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
92 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
93 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */
94 udelay(100);
95 break;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -070096 default:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070097 cx_write(TS_SOP_STAT, 0x00);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -070098 break;
Michael Krufkyf1798492005-07-07 17:58:39 -070099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
101 udelay(100);
102 }
103
Michael Krufky48d5e802006-09-25 14:09:10 -0300104 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */
108 udelay(100);
109
110 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 cx_write(TS_VALERR_CNTRL, 0x2000);
112
113 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
114 udelay(100);
115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* reset counter */
118 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET);
119 q->count = 1;
120
121 /* enable irqs */
Trent Piepho76d313b2006-04-10 09:27:08 -0300122 dprintk( 1, "setting the interrupt mask\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04);
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700124 cx_set(MO_TS_INTMSK, 0x1f0011);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 /* start dma */
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700127 cx_set(MO_DEV_CNTRL2, (1<<5));
128 cx_set(MO_TS_DMACNTRL, 0x11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
130}
131
132static int cx8802_stop_dma(struct cx8802_dev *dev)
133{
134 struct cx88_core *core = dev->core;
Trent Piepho76d313b2006-04-10 09:27:08 -0300135 dprintk( 1, "cx8802_stop_dma\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* stop dma */
138 cx_clear(MO_TS_DMACNTRL, 0x11);
139
140 /* disable irqs */
141 cx_clear(MO_PCI_INTMSK, 0x000004);
142 cx_clear(MO_TS_INTMSK, 0x1f0011);
143
144 /* Reset the controller */
145 cx_write(TS_GEN_CNTRL, 0xcd);
146 return 0;
147}
148
149static int cx8802_restart_queue(struct cx8802_dev *dev,
150 struct cx88_dmaqueue *q)
151{
152 struct cx88_buffer *buf;
153 struct list_head *item;
154
Jelle Foksf14ac0b2006-03-09 17:44:07 -0300155 dprintk( 1, "cx8802_restart_queue\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 if (list_empty(&q->active))
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700157 {
Jelle Foksf14ac0b2006-03-09 17:44:07 -0300158 struct cx88_buffer *prev;
159 prev = NULL;
160
161 dprintk(1, "cx8802_restart_queue: queue is empty\n" );
162
163 for (;;) {
164 if (list_empty(&q->queued))
165 return 0;
166 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
167 if (NULL == prev) {
168 list_del(&buf->vb.queue);
169 list_add_tail(&buf->vb.queue,&q->active);
170 cx8802_start_dma(dev, q, buf);
171 buf->vb.state = STATE_ACTIVE;
172 buf->count = q->count++;
173 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
174 dprintk(1,"[%p/%d] restart_queue - first active\n",
175 buf,buf->vb.i);
176
177 } else if (prev->vb.width == buf->vb.width &&
178 prev->vb.height == buf->vb.height &&
179 prev->fmt == buf->fmt) {
180 list_del(&buf->vb.queue);
181 list_add_tail(&buf->vb.queue,&q->active);
182 buf->vb.state = STATE_ACTIVE;
183 buf->count = q->count++;
184 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
185 dprintk(1,"[%p/%d] restart_queue - move to active\n",
186 buf,buf->vb.i);
187 } else {
188 return 0;
189 }
190 prev = buf;
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return 0;
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
196 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
197 buf, buf->vb.i);
198 cx8802_start_dma(dev, q, buf);
199 list_for_each(item,&q->active) {
200 buf = list_entry(item, struct cx88_buffer, vb.queue);
201 buf->count = q->count++;
202 }
203 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
204 return 0;
205}
206
207/* ------------------------------------------------------------------ */
208
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300209int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
210 struct cx88_buffer *buf, enum v4l2_field field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 int size = dev->ts_packet_size * dev->ts_packet_count;
213 int rc;
214
215 dprintk(1, "%s: %p\n", __FUNCTION__, buf);
216 if (0 != buf->vb.baddr && buf->vb.bsize < size)
217 return -EINVAL;
218
219 if (STATE_NEEDS_INIT == buf->vb.state) {
220 buf->vb.width = dev->ts_packet_size;
221 buf->vb.height = dev->ts_packet_count;
222 buf->vb.size = size;
Catalin Climov31629422005-11-08 21:36:17 -0800223 buf->vb.field = field /*V4L2_FIELD_TOP*/;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300225 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 goto fail;
227 cx88_risc_databuffer(dev->pci, &buf->risc,
228 buf->vb.dma.sglist,
229 buf->vb.width, buf->vb.height);
230 }
231 buf->vb.state = STATE_PREPARED;
232 return 0;
233
234 fail:
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300235 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return rc;
237}
238
239void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
240{
241 struct cx88_buffer *prev;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300242 struct cx88_dmaqueue *cx88q = &dev->mpegq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700244 dprintk( 1, "cx8802_buf_queue\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 /* add jump to stopper */
246 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300247 buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300249 if (list_empty(&cx88q->active)) {
Trent Piepho76d313b2006-04-10 09:27:08 -0300250 dprintk( 1, "queue is empty - first active\n" );
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300251 list_add_tail(&buf->vb.queue,&cx88q->active);
252 cx8802_start_dma(dev, cx88q, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 buf->vb.state = STATE_ACTIVE;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300254 buf->count = cx88q->count++;
255 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT);
Trent Piepho76d313b2006-04-10 09:27:08 -0300256 dprintk(1,"[%p/%d] %s - first active\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 buf, buf->vb.i, __FUNCTION__);
258
259 } else {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700260 dprintk( 1, "queue is not empty - append to active\n" );
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300261 prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue);
262 list_add_tail(&buf->vb.queue,&cx88q->active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 buf->vb.state = STATE_ACTIVE;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300264 buf->count = cx88q->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700266 dprintk( 1, "[%p/%d] %s - append to active\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 buf, buf->vb.i, __FUNCTION__);
268 }
269}
270
271/* ----------------------------------------------------------- */
272
273static void do_cancel_buffers(struct cx8802_dev *dev, char *reason, int restart)
274{
275 struct cx88_dmaqueue *q = &dev->mpegq;
276 struct cx88_buffer *buf;
277 unsigned long flags;
278
279 spin_lock_irqsave(&dev->slock,flags);
280 while (!list_empty(&q->active)) {
281 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
282 list_del(&buf->vb.queue);
283 buf->vb.state = STATE_ERROR;
284 wake_up(&buf->vb.done);
285 dprintk(1,"[%p/%d] %s - dma=0x%08lx\n",
286 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
287 }
288 if (restart)
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700289 {
Trent Piepho76d313b2006-04-10 09:27:08 -0300290 dprintk(1, "restarting queue\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 cx8802_restart_queue(dev,q);
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 spin_unlock_irqrestore(&dev->slock,flags);
294}
295
296void cx8802_cancel_buffers(struct cx8802_dev *dev)
297{
298 struct cx88_dmaqueue *q = &dev->mpegq;
299
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700300 dprintk( 1, "cx8802_cancel_buffers" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 del_timer_sync(&q->timeout);
302 cx8802_stop_dma(dev);
303 do_cancel_buffers(dev,"cancel",0);
304}
305
306static void cx8802_timeout(unsigned long data)
307{
308 struct cx8802_dev *dev = (struct cx8802_dev*)data;
309
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700310 dprintk(0, "%s\n",__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 if (debug)
313 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
314 cx8802_stop_dma(dev);
315 do_cancel_buffers(dev,"timeout",1);
316}
317
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700318static char *cx88_mpeg_irqs[32] = {
319 "ts_risci1", NULL, NULL, NULL,
320 "ts_risci2", NULL, NULL, NULL,
321 "ts_oflow", NULL, NULL, NULL,
322 "ts_sync", NULL, NULL, NULL,
323 "opc_err", "par_err", "rip_err", "pci_abort",
324 "ts_err?",
325};
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327static void cx8802_mpeg_irq(struct cx8802_dev *dev)
328{
329 struct cx88_core *core = dev->core;
330 u32 status, mask, count;
331
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700332 dprintk( 1, "cx8802_mpeg_irq\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 status = cx_read(MO_TS_INTSTAT);
334 mask = cx_read(MO_TS_INTMSK);
335 if (0 == (status & mask))
336 return;
337
338 cx_write(MO_TS_INTSTAT, status);
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (debug || (status & mask & ~0xff))
341 cx88_print_irqbits(core->name, "irq mpeg ",
342 cx88_mpeg_irqs, status, mask);
343
344 /* risc op code error */
345 if (status & (1 << 16)) {
346 printk(KERN_WARNING "%s: mpeg risc op code error\n",core->name);
347 cx_clear(MO_TS_DMACNTRL, 0x11);
348 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
349 }
350
351 /* risc1 y */
352 if (status & 0x01) {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700353 dprintk( 1, "wake up\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 spin_lock(&dev->slock);
355 count = cx_read(MO_TS_GPCNT);
356 cx88_wakeup(dev->core, &dev->mpegq, count);
357 spin_unlock(&dev->slock);
358 }
359
360 /* risc2 y */
361 if (status & 0x10) {
362 spin_lock(&dev->slock);
363 cx8802_restart_queue(dev,&dev->mpegq);
364 spin_unlock(&dev->slock);
365 }
366
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800367 /* other general errors */
368 if (status & 0x1f0100) {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700369 dprintk( 0, "general errors: 0x%08x\n", status & 0x1f0100 );
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800370 spin_lock(&dev->slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 cx8802_stop_dma(dev);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800372 cx8802_restart_queue(dev,&dev->mpegq);
373 spin_unlock(&dev->slock);
374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375}
376
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700377#define MAX_IRQ_LOOP 10
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379static irqreturn_t cx8802_irq(int irq, void *dev_id, struct pt_regs *regs)
380{
381 struct cx8802_dev *dev = dev_id;
382 struct cx88_core *core = dev->core;
383 u32 status;
384 int loop, handled = 0;
385
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700386 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x04);
388 if (0 == status)
389 goto out;
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700390 dprintk( 1, "cx8802_irq\n" );
391 dprintk( 1, " loop: %d/%d\n", loop, MAX_IRQ_LOOP );
392 dprintk( 1, " status: %d\n", status );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 handled = 1;
394 cx_write(MO_PCI_INTSTAT, status);
395
396 if (status & core->pci_irqmask)
397 cx88_core_irq(core,status);
398 if (status & 0x04)
399 cx8802_mpeg_irq(dev);
400 };
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700401 if (MAX_IRQ_LOOP == loop) {
402 dprintk( 0, "clearing mask\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
404 core->name);
405 cx_write(MO_PCI_INTMSK,0);
406 }
407
408 out:
409 return IRQ_RETVAL(handled);
410}
411
412/* ----------------------------------------------------------- */
413/* exported stuff */
414
415int cx8802_init_common(struct cx8802_dev *dev)
416{
417 struct cx88_core *core = dev->core;
418 int err;
419
420 /* pci init */
421 if (pci_enable_device(dev->pci))
422 return -EIO;
423 pci_set_master(dev->pci);
424 if (!pci_dma_supported(dev->pci,0xffffffff)) {
425 printk("%s/2: Oops: no 32bit PCI DMA ???\n",dev->core->name);
426 return -EIO;
427 }
428
429 pci_read_config_byte(dev->pci, PCI_CLASS_REVISION, &dev->pci_rev);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800430 pci_read_config_byte(dev->pci, PCI_LATENCY_TIMER, &dev->pci_lat);
431 printk(KERN_INFO "%s/2: found at %s, rev: %d, irq: %d, "
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -0700432 "latency: %d, mmio: 0x%llx\n", dev->core->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 pci_name(dev->pci), dev->pci_rev, dev->pci->irq,
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -0700434 dev->pci_lat,(unsigned long long)pci_resource_start(dev->pci,0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 /* initialize driver struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 spin_lock_init(&dev->slock);
438
439 /* init dma queue */
440 INIT_LIST_HEAD(&dev->mpegq.active);
441 INIT_LIST_HEAD(&dev->mpegq.queued);
442 dev->mpegq.timeout.function = cx8802_timeout;
443 dev->mpegq.timeout.data = (unsigned long)dev;
444 init_timer(&dev->mpegq.timeout);
445 cx88_risc_stopper(dev->pci,&dev->mpegq.stopper,
446 MO_TS_DMACNTRL,0x11,0x00);
447
448 /* get irq */
449 err = request_irq(dev->pci->irq, cx8802_irq,
Thomas Gleixner8076fe32006-07-01 19:29:37 -0700450 IRQF_SHARED | IRQF_DISABLED, dev->core->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 if (err < 0) {
452 printk(KERN_ERR "%s: can't get IRQ %d\n",
453 dev->core->name, dev->pci->irq);
454 return err;
455 }
456 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
457
458 /* everything worked */
459 pci_set_drvdata(dev->pci,dev);
460 return 0;
461}
462
463void cx8802_fini_common(struct cx8802_dev *dev)
464{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700465 dprintk( 2, "cx8802_fini_common\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 cx8802_stop_dma(dev);
467 pci_disable_device(dev->pci);
468
469 /* unregister stuff */
470 free_irq(dev->pci->irq, dev);
471 pci_set_drvdata(dev->pci, NULL);
472
473 /* free memory */
474 btcx_riscmem_free(dev->pci,&dev->mpegq.stopper);
475}
476
477/* ----------------------------------------------------------- */
478
479int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
480{
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800481 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 struct cx88_core *core = dev->core;
483
484 /* stop mpeg dma */
485 spin_lock(&dev->slock);
486 if (!list_empty(&dev->mpegq.active)) {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700487 dprintk( 2, "suspend\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 printk("%s: suspend mpeg\n", core->name);
489 cx8802_stop_dma(dev);
490 del_timer(&dev->mpegq.timeout);
491 }
492 spin_unlock(&dev->slock);
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 /* FIXME -- shutdown device */
495 cx88_shutdown(dev->core);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 pci_save_state(pci_dev);
498 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
499 pci_disable_device(pci_dev);
500 dev->state.disabled = 1;
501 }
502 return 0;
503}
504
505int cx8802_resume_common(struct pci_dev *pci_dev)
506{
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -0700507 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 struct cx88_core *core = dev->core;
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -0700509 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 if (dev->state.disabled) {
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -0700512 err=pci_enable_device(pci_dev);
513 if (err) {
514 printk(KERN_ERR "%s: can't enable device\n",
515 dev->core->name);
516 return err;
517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 dev->state.disabled = 0;
519 }
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -0700520 err=pci_set_power_state(pci_dev, PCI_D0);
521 if (err) {
522 printk(KERN_ERR "%s: can't enable device\n",
523 dev->core->name);
524 pci_disable_device(pci_dev);
525 dev->state.disabled = 1;
526
527 return err;
528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 pci_restore_state(pci_dev);
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* FIXME: re-initialize hardware */
532 cx88_reset(dev->core);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 /* restart video+vbi capture */
535 spin_lock(&dev->slock);
536 if (!list_empty(&dev->mpegq.active)) {
537 printk("%s: resume mpeg\n", core->name);
538 cx8802_restart_queue(dev,&dev->mpegq);
539 }
540 spin_unlock(&dev->slock);
541
542 return 0;
543}
544
545/* ----------------------------------------------------------- */
546
547EXPORT_SYMBOL(cx8802_buf_prepare);
548EXPORT_SYMBOL(cx8802_buf_queue);
549EXPORT_SYMBOL(cx8802_cancel_buffers);
550
551EXPORT_SYMBOL(cx8802_init_common);
552EXPORT_SYMBOL(cx8802_fini_common);
553
554EXPORT_SYMBOL(cx8802_suspend_common);
555EXPORT_SYMBOL(cx8802_resume_common);
556
557/* ----------------------------------------------------------- */
558/*
559 * Local variables:
560 * c-basic-offset: 8
561 * End:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700562 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 */