25 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/device.h>
31 #include <asm/delay.h>
44 static unsigned int debug;
48 #define dprintk(level,fmt, arg...) if (debug >= level) \
49 printk(KERN_DEBUG "%s/2-mpeg: " fmt, dev->core->name, ## arg)
51 #define mpeg_dbg(level,fmt, arg...) if (debug >= level) \
52 printk(KERN_DEBUG "%s/2-mpeg: " fmt, core->name, ## arg)
54 #if defined(CONFIG_MODULES) && defined(MODULE)
60 request_module(
"cx88-dvb");
62 request_module(
"cx88-blackbird");
76 #define request_modules(dev)
77 #define flush_request_modules(dev)
91 dprintk(1,
"cx8802_start_dma w: %d, h: %d, f: %d\n",
92 buf->
vb.width, buf->
vb.height, buf->
vb.field);
109 dprintk( 1,
"cx8802_start_dma doing .dvb\n");
153 dprintk( 1,
"cx8802_start_dma doing .blackbird\n");
165 printk(
"%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __func__,
175 dprintk( 1,
"setting the interrupt mask\n" );
185 static int cx8802_stop_dma(
struct cx8802_dev *dev)
188 dprintk( 1,
"cx8802_stop_dma\n" );
202 static int cx8802_restart_queue(
struct cx8802_dev *dev,
207 dprintk( 1,
"cx8802_restart_queue\n" );
208 if (list_empty(&q->
active))
213 dprintk(1,
"cx8802_restart_queue: queue is empty\n" );
216 if (list_empty(&q->
queued))
222 cx8802_start_dma(dev, q, buf);
226 dprintk(1,
"[%p/%d] restart_queue - first active\n",
229 }
else if (prev->
vb.width == buf->
vb.width &&
230 prev->
vb.height == buf->
vb.height &&
237 dprintk(1,
"[%p/%d] restart_queue - move to active\n",
248 dprintk(2,
"restart_queue [%p/%d]: restart dma\n",
250 cx8802_start_dma(dev, q, buf);
262 int size = dev->ts_packet_size * dev->ts_packet_count;
266 dprintk(1,
"%s: %p\n", __func__, buf);
267 if (0 != buf->vb.baddr && buf->vb.bsize < size)
271 buf->vb.width = dev->ts_packet_size;
272 buf->vb.height = dev->ts_packet_count;
274 buf->vb.field = field ;
280 buf->vb.width, buf->vb.height, 0);
295 dprintk( 1,
"cx8802_buf_queue\n" );
300 if (list_empty(&cx88q->
active)) {
301 dprintk( 1,
"queue is empty - first active\n" );
303 cx8802_start_dma(dev, cx88q, buf);
307 dprintk(1,
"[%p/%d] %s - first active\n",
308 buf, buf->
vb.i, __func__);
311 dprintk( 1,
"queue is not empty - append to active\n" );
317 dprintk( 1,
"[%p/%d] %s - append to active\n",
318 buf, buf->
vb.i, __func__);
331 while (!list_empty(&q->
active)) {
336 dprintk(1,
"[%p/%d] %s - dma=0x%08lx\n",
337 buf, buf->
vb.i, reason, (
unsigned long)buf->
risc.dma);
341 dprintk(1,
"restarting queue\n" );
342 cx8802_restart_queue(dev,q);
344 spin_unlock_irqrestore(&dev->
slock,flags);
351 dprintk( 1,
"cx8802_cancel_buffers" );
353 cx8802_stop_dma(dev);
354 do_cancel_buffers(dev,
"cancel",0);
357 static void cx8802_timeout(
unsigned long data)
365 cx8802_stop_dma(dev);
366 do_cancel_buffers(dev,
"timeout",1);
369 static const char * cx88_mpeg_irqs[32] = {
374 "opc_err",
"par_err",
"rip_err",
"pci_abort",
378 static void cx8802_mpeg_irq(
struct cx8802_dev *dev)
383 dprintk( 1,
"cx8802_mpeg_irq\n" );
386 if (0 == (status & mask))
391 if (
debug || (status & mask & ~0xff))
397 if (status & (1 << 16)) {
406 spin_lock(&dev->
slock);
409 spin_unlock(&dev->
slock);
414 spin_lock(&dev->
slock);
415 cx8802_restart_queue(dev,&dev->
mpegq);
416 spin_unlock(&dev->
slock);
420 if (status & 0x1f0100) {
421 dprintk( 0,
"general errors: 0x%08x\n", status & 0x1f0100 );
422 spin_lock(&dev->
slock);
423 cx8802_stop_dma(dev);
424 cx8802_restart_queue(dev,&dev->
mpegq);
425 spin_unlock(&dev->
slock);
429 #define MAX_IRQ_LOOP 10
436 int loop, handled = 0;
444 dprintk( 1,
" loop: %d/%d\n", loop, MAX_IRQ_LOOP );
445 dprintk( 1,
" status: %d\n", status );
452 cx8802_mpeg_irq(dev);
454 if (MAX_IRQ_LOOP == loop) {
455 dprintk( 0,
"clearing mask\n" );
465 static int cx8802_init_common(
struct cx8802_dev *dev)
475 printk(
"%s/2: Oops: no 32bit PCI DMA ???\n",dev->
core->name);
482 "latency: %d, mmio: 0x%llx\n", dev->
core->name,
490 INIT_LIST_HEAD(&dev->
mpegq.active);
491 INIT_LIST_HEAD(&dev->
mpegq.queued);
492 dev->
mpegq.timeout.function = cx8802_timeout;
493 dev->
mpegq.timeout.data = (
unsigned long)dev;
503 dev->
core->name, dev->
pci->irq);
509 pci_set_drvdata(dev->
pci,dev);
513 static void cx8802_fini_common(
struct cx8802_dev *dev)
515 dprintk( 2,
"cx8802_fini_common\n" );
516 cx8802_stop_dma(dev);
521 pci_set_drvdata(dev->
pci,
NULL);
531 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
535 spin_lock(&dev->
slock);
536 if (!list_empty(&dev->
mpegq.active)) {
539 cx8802_stop_dma(dev);
542 spin_unlock(&dev->
slock);
550 dev->
state.disabled = 1;
555 static int cx8802_resume_common(
struct pci_dev *pci_dev)
557 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
561 if (dev->
state.disabled) {
568 dev->
state.disabled = 0;
575 dev->
state.disabled = 1;
585 spin_lock(&dev->
slock);
586 if (!list_empty(&dev->
mpegq.active)) {
588 cx8802_restart_queue(dev,&dev->
mpegq);
590 spin_unlock(&dev->
slock);
695 "cx88/2: registering cx8802 driver, type: %s access: %s\n",
699 if ((err = cx8802_check_driver(drv)) != 0) {
708 "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n",
709 dev->
core->name, dev->
pci->subsystem_vendor,
710 dev->
pci->subsystem_device, dev->
core->board.name,
715 if (driver ==
NULL) {
722 drv->
suspend = cx8802_suspend_common;
723 drv->
resume = cx8802_resume_common;
726 memcpy(driver, drv,
sizeof(*driver));
729 err = drv->
probe(driver);
735 "%s/2: cx8802 probe failed, err = %d\n",
736 dev->
core->name, err);
754 "cx88/2: unregistering cx8802 driver, type: %s access: %s\n",
762 "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n",
763 dev->
core->name, dev->
pci->subsystem_vendor,
764 dev->
pci->subsystem_device, dev->
core->board.name,
780 "failed (%d)\n", dev->
core->name, err);
792 static int __devinit cx8802_probe(
struct pci_dev *pci_dev,
804 printk(
"%s/2: cx2388x 8802 Driver Manager\n", core->
name);
807 if (!core->
board.mpeg)
820 err = cx8802_init_common(dev);
841 static void __devexit cx8802_remove(
struct pci_dev *pci_dev)
845 dev = pci_get_drvdata(pci_dev);
853 if (!list_empty(&dev->
drvlist)) {
858 "while cx8802 sub-drivers still loaded?!\n",
867 "failed (%d)\n", dev->
core->name, err);
878 cx8802_fini_common(dev);
895 static struct pci_driver cx8802_pci_driver = {
896 .name =
"cx88-mpeg driver manager",
897 .id_table = cx8802_pci_tbl,
898 .probe = cx8802_probe,
902 static int __init cx8802_init(
void)
904 printk(
KERN_INFO "cx88/2: cx2388x MPEG-TS Driver Manager version %s loaded\n",
906 return pci_register_driver(&cx8802_pci_driver);
909 static void __exit cx8802_fini(
void)