3 * Support for the mpeg transport stream transfers
4 * PCI function #2 of the cx2388x.
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>
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.
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.
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.
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>
34 /* ------------------------------------------------------------------ */
36 MODULE_DESCRIPTION("mpeg driver for cx2388x based TV cards");
37 MODULE_AUTHOR("Jelle Foks <jelle@foks.8m.com>");
38 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
39 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
40 MODULE_LICENSE("GPL");
42 static unsigned int debug = 0;
43 module_param(debug,int,0644);
44 MODULE_PARM_DESC(debug,"enable debug messages [mpeg]");
46 #define dprintk(level,fmt, arg...) if (debug >= level) \
47 printk(KERN_DEBUG "%s/2-mpeg: " fmt, dev->core->name, ## arg)
49 #define mpeg_dbg(level,fmt, arg...) if (debug >= level) \
50 printk(KERN_DEBUG "%s/2-mpeg: " fmt, core->name, ## arg)
52 #if defined(CONFIG_MODULES) && defined(MODULE)
53 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
54 static void request_module_async(void *ptr)
56 struct cx8802_dev *dev=(struct cx8802_dev*)ptr;
58 static void request_module_async(struct work_struct *work)
60 struct cx8802_dev *dev=container_of(work, struct cx8802_dev, request_module_wk);
63 if (cx88_boards[dev->core->board].mpeg & CX88_MPEG_DVB)
64 request_module("cx88-dvb");
65 if (cx88_boards[dev->core->board].mpeg & CX88_MPEG_BLACKBIRD)
66 request_module("cx88-blackbird");
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
70 #define request_modules(dev)
72 static void request_modules(struct cx8802_dev *dev)
74 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
75 INIT_WORK(&dev->request_module_wk, request_module_async, (void*)dev);
77 INIT_WORK(&dev->request_module_wk, request_module_async);
79 schedule_work(&dev->request_module_wk);
83 #define request_modules(dev)
84 #endif /* CONFIG_MODULES */
86 static LIST_HEAD(cx8802_devlist);
87 /* ------------------------------------------------------------------ */
89 static int cx8802_start_dma(struct cx8802_dev *dev,
90 struct cx88_dmaqueue *q,
91 struct cx88_buffer *buf)
93 struct cx88_core *core = dev->core;
95 dprintk(1, "cx8802_start_dma w: %d, h: %d, f: %d\n", dev->width, dev->height, buf->vb.field);
97 /* setup fifo + format */
98 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
99 dev->ts_packet_size, buf->risc.dma);
101 /* write TS length to chip */
102 cx_write(MO_TS_LNGTH, buf->vb.width);
104 /* FIXME: this needs a review.
105 * also: move to cx88-blackbird + cx88-dvb source files? */
107 dprintk( 1, "core->active_type_id = 0x%08x\n", core->active_type_id);
109 if ( (core->active_type_id == CX88_MPEG_DVB) &&
110 (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) ) {
112 dprintk( 1, "cx8802_start_dma doing .dvb\n");
113 /* negedge driven & software reset */
114 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
116 cx_write(MO_PINMUX_IO, 0x00);
117 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
118 switch (core->board) {
119 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
120 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
121 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
122 case CX88_BOARD_PCHDTV_HD5500:
123 cx_write(TS_SOP_STAT, 1<<13);
125 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
126 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
127 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */
130 case CX88_BOARD_HAUPPAUGE_HVR1300:
133 cx_write(TS_SOP_STAT, 0x00);
136 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
138 } else if ( (core->active_type_id == CX88_MPEG_BLACKBIRD) &&
139 (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) ) {
140 dprintk( 1, "cx8802_start_dma doing .blackbird\n");
141 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
143 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */
146 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */
147 cx_write(TS_VALERR_CNTRL, 0x2000);
149 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
152 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __FUNCTION__,
153 cx88_boards[core->board].mpeg );
158 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET);
162 dprintk( 1, "setting the interrupt mask\n" );
163 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04);
164 cx_set(MO_TS_INTMSK, 0x1f0011);
167 cx_set(MO_DEV_CNTRL2, (1<<5));
168 cx_set(MO_TS_DMACNTRL, 0x11);
172 static int cx8802_stop_dma(struct cx8802_dev *dev)
174 struct cx88_core *core = dev->core;
175 dprintk( 1, "cx8802_stop_dma\n" );
178 cx_clear(MO_TS_DMACNTRL, 0x11);
181 cx_clear(MO_PCI_INTMSK, 0x000004);
182 cx_clear(MO_TS_INTMSK, 0x1f0011);
184 /* Reset the controller */
185 cx_write(TS_GEN_CNTRL, 0xcd);
189 static int cx8802_restart_queue(struct cx8802_dev *dev,
190 struct cx88_dmaqueue *q)
192 struct cx88_buffer *buf;
193 struct list_head *item;
195 dprintk( 1, "cx8802_restart_queue\n" );
196 if (list_empty(&q->active))
198 struct cx88_buffer *prev;
201 dprintk(1, "cx8802_restart_queue: queue is empty\n" );
204 if (list_empty(&q->queued))
206 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
208 list_del(&buf->vb.queue);
209 list_add_tail(&buf->vb.queue,&q->active);
210 cx8802_start_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(1,"[%p/%d] restart_queue - first active\n",
217 } else if (prev->vb.width == buf->vb.width &&
218 prev->vb.height == buf->vb.height &&
219 prev->fmt == buf->fmt) {
220 list_del(&buf->vb.queue);
221 list_add_tail(&buf->vb.queue,&q->active);
222 buf->vb.state = STATE_ACTIVE;
223 buf->count = q->count++;
224 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
225 dprintk(1,"[%p/%d] restart_queue - move to active\n",
235 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
236 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
238 cx8802_start_dma(dev, q, buf);
239 list_for_each(item,&q->active) {
240 buf = list_entry(item, struct cx88_buffer, vb.queue);
241 buf->count = q->count++;
243 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
247 /* ------------------------------------------------------------------ */
249 int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
250 struct cx88_buffer *buf, enum v4l2_field field)
252 int size = dev->ts_packet_size * dev->ts_packet_count;
255 dprintk(1, "%s: %p\n", __FUNCTION__, buf);
256 if (0 != buf->vb.baddr && buf->vb.bsize < size)
259 if (STATE_NEEDS_INIT == buf->vb.state) {
260 buf->vb.width = dev->ts_packet_size;
261 buf->vb.height = dev->ts_packet_count;
263 buf->vb.field = field /*V4L2_FIELD_TOP*/;
265 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
267 cx88_risc_databuffer(dev->pci, &buf->risc,
269 buf->vb.width, buf->vb.height);
271 buf->vb.state = STATE_PREPARED;
275 cx88_free_buffer(q,buf);
279 void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
281 struct cx88_buffer *prev;
282 struct cx88_dmaqueue *cx88q = &dev->mpegq;
284 dprintk( 1, "cx8802_buf_queue\n" );
285 /* add jump to stopper */
286 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
287 buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma);
289 if (list_empty(&cx88q->active)) {
290 dprintk( 1, "queue is empty - first active\n" );
291 list_add_tail(&buf->vb.queue,&cx88q->active);
292 cx8802_start_dma(dev, cx88q, buf);
293 buf->vb.state = STATE_ACTIVE;
294 buf->count = cx88q->count++;
295 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT);
296 dprintk(1,"[%p/%d] %s - first active\n",
297 buf, buf->vb.i, __FUNCTION__);
300 dprintk( 1, "queue is not empty - append to active\n" );
301 prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue);
302 list_add_tail(&buf->vb.queue,&cx88q->active);
303 buf->vb.state = STATE_ACTIVE;
304 buf->count = cx88q->count++;
305 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
306 dprintk( 1, "[%p/%d] %s - append to active\n",
307 buf, buf->vb.i, __FUNCTION__);
311 /* ----------------------------------------------------------- */
313 static void do_cancel_buffers(struct cx8802_dev *dev, char *reason, int restart)
315 struct cx88_dmaqueue *q = &dev->mpegq;
316 struct cx88_buffer *buf;
319 spin_lock_irqsave(&dev->slock,flags);
320 while (!list_empty(&q->active)) {
321 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
322 list_del(&buf->vb.queue);
323 buf->vb.state = STATE_ERROR;
324 wake_up(&buf->vb.done);
325 dprintk(1,"[%p/%d] %s - dma=0x%08lx\n",
326 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
330 dprintk(1, "restarting queue\n" );
331 cx8802_restart_queue(dev,q);
333 spin_unlock_irqrestore(&dev->slock,flags);
336 void cx8802_cancel_buffers(struct cx8802_dev *dev)
338 struct cx88_dmaqueue *q = &dev->mpegq;
340 dprintk( 1, "cx8802_cancel_buffers" );
341 del_timer_sync(&q->timeout);
342 cx8802_stop_dma(dev);
343 do_cancel_buffers(dev,"cancel",0);
346 static void cx8802_timeout(unsigned long data)
348 struct cx8802_dev *dev = (struct cx8802_dev*)data;
350 dprintk(0, "%s\n",__FUNCTION__);
353 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
354 cx8802_stop_dma(dev);
355 do_cancel_buffers(dev,"timeout",1);
358 static char *cx88_mpeg_irqs[32] = {
359 "ts_risci1", NULL, NULL, NULL,
360 "ts_risci2", NULL, NULL, NULL,
361 "ts_oflow", NULL, NULL, NULL,
362 "ts_sync", NULL, NULL, NULL,
363 "opc_err", "par_err", "rip_err", "pci_abort",
367 static void cx8802_mpeg_irq(struct cx8802_dev *dev)
369 struct cx88_core *core = dev->core;
370 u32 status, mask, count;
372 dprintk( 1, "cx8802_mpeg_irq\n" );
373 status = cx_read(MO_TS_INTSTAT);
374 mask = cx_read(MO_TS_INTMSK);
375 if (0 == (status & mask))
378 cx_write(MO_TS_INTSTAT, status);
380 if (debug || (status & mask & ~0xff))
381 cx88_print_irqbits(core->name, "irq mpeg ",
382 cx88_mpeg_irqs, status, mask);
384 /* risc op code error */
385 if (status & (1 << 16)) {
386 printk(KERN_WARNING "%s: mpeg risc op code error\n",core->name);
387 cx_clear(MO_TS_DMACNTRL, 0x11);
388 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
393 dprintk( 1, "wake up\n" );
394 spin_lock(&dev->slock);
395 count = cx_read(MO_TS_GPCNT);
396 cx88_wakeup(dev->core, &dev->mpegq, count);
397 spin_unlock(&dev->slock);
402 spin_lock(&dev->slock);
403 cx8802_restart_queue(dev,&dev->mpegq);
404 spin_unlock(&dev->slock);
407 /* other general errors */
408 if (status & 0x1f0100) {
409 dprintk( 0, "general errors: 0x%08x\n", status & 0x1f0100 );
410 spin_lock(&dev->slock);
411 cx8802_stop_dma(dev);
412 cx8802_restart_queue(dev,&dev->mpegq);
413 spin_unlock(&dev->slock);
417 #define MAX_IRQ_LOOP 10
419 static irqreturn_t cx8802_irq(int irq, void *dev_id)
421 struct cx8802_dev *dev = dev_id;
422 struct cx88_core *core = dev->core;
424 int loop, handled = 0;
426 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
427 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x04);
430 dprintk( 1, "cx8802_irq\n" );
431 dprintk( 1, " loop: %d/%d\n", loop, MAX_IRQ_LOOP );
432 dprintk( 1, " status: %d\n", status );
434 cx_write(MO_PCI_INTSTAT, status);
436 if (status & core->pci_irqmask)
437 cx88_core_irq(core,status);
439 cx8802_mpeg_irq(dev);
441 if (MAX_IRQ_LOOP == loop) {
442 dprintk( 0, "clearing mask\n" );
443 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
445 cx_write(MO_PCI_INTMSK,0);
449 return IRQ_RETVAL(handled);
452 /* ----------------------------------------------------------- */
455 int cx8802_init_common(struct cx8802_dev *dev)
457 struct cx88_core *core = dev->core;
461 if (pci_enable_device(dev->pci))
463 pci_set_master(dev->pci);
464 if (!pci_dma_supported(dev->pci,0xffffffff)) {
465 printk("%s/2: Oops: no 32bit PCI DMA ???\n",dev->core->name);
469 pci_read_config_byte(dev->pci, PCI_CLASS_REVISION, &dev->pci_rev);
470 pci_read_config_byte(dev->pci, PCI_LATENCY_TIMER, &dev->pci_lat);
471 printk(KERN_INFO "%s/2: found at %s, rev: %d, irq: %d, "
472 "latency: %d, mmio: 0x%llx\n", dev->core->name,
473 pci_name(dev->pci), dev->pci_rev, dev->pci->irq,
474 dev->pci_lat,(unsigned long long)pci_resource_start(dev->pci,0));
476 /* initialize driver struct */
477 spin_lock_init(&dev->slock);
480 INIT_LIST_HEAD(&dev->mpegq.active);
481 INIT_LIST_HEAD(&dev->mpegq.queued);
482 dev->mpegq.timeout.function = cx8802_timeout;
483 dev->mpegq.timeout.data = (unsigned long)dev;
484 init_timer(&dev->mpegq.timeout);
485 cx88_risc_stopper(dev->pci,&dev->mpegq.stopper,
486 MO_TS_DMACNTRL,0x11,0x00);
489 err = request_irq(dev->pci->irq, cx8802_irq,
490 IRQF_SHARED | IRQF_DISABLED, dev->core->name, dev);
492 printk(KERN_ERR "%s: can't get IRQ %d\n",
493 dev->core->name, dev->pci->irq);
496 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
498 /* everything worked */
499 pci_set_drvdata(dev->pci,dev);
503 void cx8802_fini_common(struct cx8802_dev *dev)
505 dprintk( 2, "cx8802_fini_common\n" );
506 cx8802_stop_dma(dev);
507 pci_disable_device(dev->pci);
509 /* unregister stuff */
510 free_irq(dev->pci->irq, dev);
511 pci_set_drvdata(dev->pci, NULL);
514 btcx_riscmem_free(dev->pci,&dev->mpegq.stopper);
517 /* ----------------------------------------------------------- */
519 int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
521 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
522 struct cx88_core *core = dev->core;
525 spin_lock(&dev->slock);
526 if (!list_empty(&dev->mpegq.active)) {
527 dprintk( 2, "suspend\n" );
528 printk("%s: suspend mpeg\n", core->name);
529 cx8802_stop_dma(dev);
530 del_timer(&dev->mpegq.timeout);
532 spin_unlock(&dev->slock);
534 /* FIXME -- shutdown device */
535 cx88_shutdown(dev->core);
537 pci_save_state(pci_dev);
538 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
539 pci_disable_device(pci_dev);
540 dev->state.disabled = 1;
545 int cx8802_resume_common(struct pci_dev *pci_dev)
547 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
548 struct cx88_core *core = dev->core;
551 if (dev->state.disabled) {
552 err=pci_enable_device(pci_dev);
554 printk(KERN_ERR "%s: can't enable device\n",
558 dev->state.disabled = 0;
560 err=pci_set_power_state(pci_dev, PCI_D0);
562 printk(KERN_ERR "%s: can't enable device\n",
564 pci_disable_device(pci_dev);
565 dev->state.disabled = 1;
569 pci_restore_state(pci_dev);
571 /* FIXME: re-initialize hardware */
572 cx88_reset(dev->core);
574 /* restart video+vbi capture */
575 spin_lock(&dev->slock);
576 if (!list_empty(&dev->mpegq.active)) {
577 printk("%s: resume mpeg\n", core->name);
578 cx8802_restart_queue(dev,&dev->mpegq);
580 spin_unlock(&dev->slock);
585 struct cx8802_dev * cx8802_get_device(struct inode *inode)
587 int minor = iminor(inode);
588 struct cx8802_dev *h = NULL;
589 struct list_head *list;
591 list_for_each(list,&cx8802_devlist) {
592 h = list_entry(list, struct cx8802_dev, devlist);
593 if (h->mpeg_dev->minor == minor)
600 struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_type btype)
602 struct cx8802_dev *h = NULL;
603 struct cx8802_driver *d = NULL;
604 struct list_head *list;
605 struct list_head *list2;
607 list_for_each(list,&cx8802_devlist) {
608 h = list_entry(list, struct cx8802_dev, devlist);
612 list_for_each(list2, &h->drvlist.devlist) {
613 d = list_entry(list2, struct cx8802_driver, devlist);
615 /* only unregister the correct driver type */
616 if (d->type_id == btype) {
625 /* Driver asked for hardware access. */
626 int cx8802_request_acquire(struct cx8802_driver *drv)
628 struct cx88_core *core = drv->core;
630 /* Fail a request for hardware if the device is busy. */
631 if (core->active_type_id != CX88_BOARD_NONE)
634 if (drv->advise_acquire)
636 core->active_type_id = drv->type_id;
637 drv->advise_acquire(drv);
639 mpeg_dbg(1,"%s() Post acquire GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO));
645 /* Driver asked to release hardware. */
646 int cx8802_request_release(struct cx8802_driver *drv)
648 struct cx88_core *core = drv->core;
650 if (drv->advise_release)
652 drv->advise_release(drv);
653 core->active_type_id = CX88_BOARD_NONE;
654 mpeg_dbg(1,"%s() Post release GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO));
660 static int cx8802_check_driver(struct cx8802_driver *drv)
665 if ((drv->type_id != CX88_MPEG_DVB) &&
666 (drv->type_id != CX88_MPEG_BLACKBIRD))
669 if ((drv->hw_access != CX8802_DRVCTL_SHARED) &&
670 (drv->hw_access != CX8802_DRVCTL_EXCLUSIVE))
673 if ((drv->probe == NULL) ||
674 (drv->remove == NULL) ||
675 (drv->advise_acquire == NULL) ||
676 (drv->advise_release == NULL))
682 int cx8802_register_driver(struct cx8802_driver *drv)
684 struct cx8802_dev *h;
685 struct cx8802_driver *driver;
686 struct list_head *list;
689 printk(KERN_INFO "%s() ->registering driver type=%s access=%s\n", __FUNCTION__ ,
690 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
691 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive");
693 if ((err = cx8802_check_driver(drv)) != 0) {
694 printk(KERN_INFO "%s() cx8802_driver is invalid\n", __FUNCTION__ );
698 list_for_each(list,&cx8802_devlist) {
699 h = list_entry(list, struct cx8802_dev, devlist);
701 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n",
702 h->core->name,h->pci->subsystem_vendor,
703 h->pci->subsystem_device,cx88_boards[h->core->board].name,
706 /* Bring up a new struct for each driver instance */
707 driver = kzalloc(sizeof(*drv),GFP_KERNEL);
711 /* Snapshot of the driver registration data */
713 drv->suspend = cx8802_suspend_common;
714 drv->resume = cx8802_resume_common;
715 drv->request_acquire = cx8802_request_acquire;
716 drv->request_release = cx8802_request_release;
717 memcpy(driver, drv, sizeof(*driver));
719 err = drv->probe(driver);
722 mutex_lock(&drv->core->lock);
723 list_add_tail(&driver->devlist,&h->drvlist.devlist);
724 mutex_unlock(&drv->core->lock);
726 printk(KERN_ERR "%s() ->probe failed err = %d\n", __FUNCTION__, err);
738 int cx8802_unregister_driver(struct cx8802_driver *drv)
740 struct cx8802_dev *h;
741 struct cx8802_driver *d;
742 struct list_head *list;
743 struct list_head *list2, *q;
746 printk(KERN_INFO "%s() ->unregistering driver type=%s\n", __FUNCTION__ ,
747 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird");
749 list_for_each(list,&cx8802_devlist) {
751 h = list_entry(list, struct cx8802_dev, devlist);
753 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n",
754 h->core->name,h->pci->subsystem_vendor,
755 h->pci->subsystem_device,cx88_boards[h->core->board].name,
758 list_for_each_safe(list2, q, &h->drvlist.devlist) {
759 d = list_entry(list2, struct cx8802_driver, devlist);
761 /* only unregister the correct driver type */
762 if (d->type_id != drv->type_id)
767 mutex_lock(&drv->core->lock);
769 mutex_unlock(&drv->core->lock);
771 printk(KERN_ERR "%s() ->remove failed err = %d\n", __FUNCTION__, err);
780 /* ----------------------------------------------------------- */
781 static int __devinit cx8802_probe(struct pci_dev *pci_dev,
782 const struct pci_device_id *pci_id)
784 struct cx8802_dev *dev;
785 struct cx88_core *core;
789 core = cx88_core_get(pci_dev);
793 printk("%s/2: cx2388x 8802 Driver Manager\n", core->name);
796 if (!cx88_boards[core->board].mpeg)
800 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
806 err = cx8802_init_common(dev);
810 INIT_LIST_HEAD(&dev->drvlist.devlist);
811 list_add_tail(&dev->devlist,&cx8802_devlist);
813 /* Maintain a reference so cx88-video can query the 8802 device. */
816 /* now autoload cx88-dvb or cx88-blackbird */
817 request_modules(dev);
823 cx88_core_put(core,pci_dev);
827 static void __devexit cx8802_remove(struct pci_dev *pci_dev)
829 struct cx8802_dev *dev;
830 struct cx8802_driver *h;
831 struct list_head *list;
833 dev = pci_get_drvdata(pci_dev);
835 dprintk( 1, "%s\n", __FUNCTION__);
837 list_for_each(list,&dev->drvlist.devlist) {
838 h = list_entry(list, struct cx8802_driver, devlist);
839 dprintk( 1, " ->driver\n");
840 if (h->remove == NULL) {
841 printk(KERN_ERR "%s .. skipping driver, no probe function\n", __FUNCTION__);
844 printk(KERN_INFO "%s .. Removing driver type %d\n", __FUNCTION__, h->type_id);
845 cx8802_unregister_driver(h);
846 list_del(&dev->drvlist.devlist);
849 /* Destroy any 8802 reference. */
850 dev->core->dvbdev = NULL;
853 cx8802_fini_common(dev);
854 cx88_core_put(dev->core,dev->pci);
858 static struct pci_device_id cx8802_pci_tbl[] = {
862 .subvendor = PCI_ANY_ID,
863 .subdevice = PCI_ANY_ID,
865 /* --- end of list --- */
868 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
870 static struct pci_driver cx8802_pci_driver = {
871 .name = "cx88-mpeg driver manager",
872 .id_table = cx8802_pci_tbl,
873 .probe = cx8802_probe,
874 .remove = __devexit_p(cx8802_remove),
877 static int cx8802_init(void)
879 printk(KERN_INFO "cx2388x cx88-mpeg Driver Manager version %d.%d.%d loaded\n",
880 (CX88_VERSION_CODE >> 16) & 0xff,
881 (CX88_VERSION_CODE >> 8) & 0xff,
882 CX88_VERSION_CODE & 0xff);
884 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
885 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
887 return pci_register_driver(&cx8802_pci_driver);
890 static void cx8802_fini(void)
892 pci_unregister_driver(&cx8802_pci_driver);
895 module_init(cx8802_init);
896 module_exit(cx8802_fini);
897 EXPORT_SYMBOL(cx8802_buf_prepare);
898 EXPORT_SYMBOL(cx8802_buf_queue);
899 EXPORT_SYMBOL(cx8802_cancel_buffers);
901 EXPORT_SYMBOL(cx8802_init_common);
902 EXPORT_SYMBOL(cx8802_fini_common);
904 EXPORT_SYMBOL(cx8802_register_driver);
905 EXPORT_SYMBOL(cx8802_unregister_driver);
906 EXPORT_SYMBOL(cx8802_get_device);
907 EXPORT_SYMBOL(cx8802_get_driver);
908 /* ----------------------------------------------------------- */
913 * 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