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 static LIST_HEAD(cx8802_devlist);
53 /* ------------------------------------------------------------------ */
55 static int cx8802_start_dma(struct cx8802_dev *dev,
56 struct cx88_dmaqueue *q,
57 struct cx88_buffer *buf)
59 struct cx88_core *core = dev->core;
61 dprintk(1, "cx8802_start_dma w: %d, h: %d, f: %d\n", dev->width, dev->height, buf->vb.field);
63 /* setup fifo + format */
64 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
65 dev->ts_packet_size, buf->risc.dma);
67 /* write TS length to chip */
68 cx_write(MO_TS_LNGTH, buf->vb.width);
70 /* FIXME: this needs a review.
71 * also: move to cx88-blackbird + cx88-dvb source files? */
73 dprintk( 1, "core->active_type_id = 0x%08x\n", core->active_type_id);
75 if ( (core->active_type_id == CX88_MPEG_DVB) &&
76 (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) ) {
78 dprintk( 1, "cx8802_start_dma doing .dvb\n");
79 /* negedge driven & software reset */
80 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
82 cx_write(MO_PINMUX_IO, 0x00);
83 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
84 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:
88 case CX88_BOARD_PCHDTV_HD5500:
89 cx_write(TS_SOP_STAT, 1<<13);
91 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 */
96 case CX88_BOARD_HAUPPAUGE_HVR1300:
99 cx_write(TS_SOP_STAT, 0x00);
102 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
104 } else if ( (core->active_type_id == CX88_MPEG_BLACKBIRD) &&
105 (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) ) {
106 dprintk( 1, "cx8802_start_dma doing .blackbird\n");
107 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
109 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */
112 cx_write(TS_HW_SOP_CNTRL, 0x408); /* mpeg start byte */
113 cx_write(TS_VALERR_CNTRL, 0x2000);
115 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
118 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __FUNCTION__,
119 cx88_boards[core->board].mpeg );
124 cx_write(MO_TS_GPCNTRL, GP_COUNT_CONTROL_RESET);
128 dprintk( 1, "setting the interrupt mask\n" );
129 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04);
130 cx_set(MO_TS_INTMSK, 0x1f0011);
133 cx_set(MO_DEV_CNTRL2, (1<<5));
134 cx_set(MO_TS_DMACNTRL, 0x11);
138 static int cx8802_stop_dma(struct cx8802_dev *dev)
140 struct cx88_core *core = dev->core;
141 dprintk( 1, "cx8802_stop_dma\n" );
144 cx_clear(MO_TS_DMACNTRL, 0x11);
147 cx_clear(MO_PCI_INTMSK, 0x000004);
148 cx_clear(MO_TS_INTMSK, 0x1f0011);
150 /* Reset the controller */
151 cx_write(TS_GEN_CNTRL, 0xcd);
155 static int cx8802_restart_queue(struct cx8802_dev *dev,
156 struct cx88_dmaqueue *q)
158 struct cx88_buffer *buf;
159 struct list_head *item;
161 dprintk( 1, "cx8802_restart_queue\n" );
162 if (list_empty(&q->active))
164 struct cx88_buffer *prev;
167 dprintk(1, "cx8802_restart_queue: queue is empty\n" );
170 if (list_empty(&q->queued))
172 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
174 list_del(&buf->vb.queue);
175 list_add_tail(&buf->vb.queue,&q->active);
176 cx8802_start_dma(dev, q, buf);
177 buf->vb.state = STATE_ACTIVE;
178 buf->count = q->count++;
179 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
180 dprintk(1,"[%p/%d] restart_queue - first active\n",
183 } else if (prev->vb.width == buf->vb.width &&
184 prev->vb.height == buf->vb.height &&
185 prev->fmt == buf->fmt) {
186 list_del(&buf->vb.queue);
187 list_add_tail(&buf->vb.queue,&q->active);
188 buf->vb.state = STATE_ACTIVE;
189 buf->count = q->count++;
190 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
191 dprintk(1,"[%p/%d] restart_queue - move to active\n",
201 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
202 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
204 cx8802_start_dma(dev, q, buf);
205 list_for_each(item,&q->active) {
206 buf = list_entry(item, struct cx88_buffer, vb.queue);
207 buf->count = q->count++;
209 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
213 /* ------------------------------------------------------------------ */
215 int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
216 struct cx88_buffer *buf, enum v4l2_field field)
218 int size = dev->ts_packet_size * dev->ts_packet_count;
221 dprintk(1, "%s: %p\n", __FUNCTION__, buf);
222 if (0 != buf->vb.baddr && buf->vb.bsize < size)
225 if (STATE_NEEDS_INIT == buf->vb.state) {
226 buf->vb.width = dev->ts_packet_size;
227 buf->vb.height = dev->ts_packet_count;
229 buf->vb.field = field /*V4L2_FIELD_TOP*/;
231 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
233 cx88_risc_databuffer(dev->pci, &buf->risc,
235 buf->vb.width, buf->vb.height);
237 buf->vb.state = STATE_PREPARED;
241 cx88_free_buffer(q,buf);
245 void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
247 struct cx88_buffer *prev;
248 struct cx88_dmaqueue *cx88q = &dev->mpegq;
250 dprintk( 1, "cx8802_buf_queue\n" );
251 /* add jump to stopper */
252 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
253 buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma);
255 if (list_empty(&cx88q->active)) {
256 dprintk( 1, "queue is empty - first active\n" );
257 list_add_tail(&buf->vb.queue,&cx88q->active);
258 cx8802_start_dma(dev, cx88q, buf);
259 buf->vb.state = STATE_ACTIVE;
260 buf->count = cx88q->count++;
261 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT);
262 dprintk(1,"[%p/%d] %s - first active\n",
263 buf, buf->vb.i, __FUNCTION__);
266 dprintk( 1, "queue is not empty - append to active\n" );
267 prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue);
268 list_add_tail(&buf->vb.queue,&cx88q->active);
269 buf->vb.state = STATE_ACTIVE;
270 buf->count = cx88q->count++;
271 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
272 dprintk( 1, "[%p/%d] %s - append to active\n",
273 buf, buf->vb.i, __FUNCTION__);
277 /* ----------------------------------------------------------- */
279 static void do_cancel_buffers(struct cx8802_dev *dev, char *reason, int restart)
281 struct cx88_dmaqueue *q = &dev->mpegq;
282 struct cx88_buffer *buf;
285 spin_lock_irqsave(&dev->slock,flags);
286 while (!list_empty(&q->active)) {
287 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
288 list_del(&buf->vb.queue);
289 buf->vb.state = STATE_ERROR;
290 wake_up(&buf->vb.done);
291 dprintk(1,"[%p/%d] %s - dma=0x%08lx\n",
292 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
296 dprintk(1, "restarting queue\n" );
297 cx8802_restart_queue(dev,q);
299 spin_unlock_irqrestore(&dev->slock,flags);
302 void cx8802_cancel_buffers(struct cx8802_dev *dev)
304 struct cx88_dmaqueue *q = &dev->mpegq;
306 dprintk( 1, "cx8802_cancel_buffers" );
307 del_timer_sync(&q->timeout);
308 cx8802_stop_dma(dev);
309 do_cancel_buffers(dev,"cancel",0);
312 static void cx8802_timeout(unsigned long data)
314 struct cx8802_dev *dev = (struct cx8802_dev*)data;
316 dprintk(0, "%s\n",__FUNCTION__);
319 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
320 cx8802_stop_dma(dev);
321 do_cancel_buffers(dev,"timeout",1);
324 static char *cx88_mpeg_irqs[32] = {
325 "ts_risci1", NULL, NULL, NULL,
326 "ts_risci2", NULL, NULL, NULL,
327 "ts_oflow", NULL, NULL, NULL,
328 "ts_sync", NULL, NULL, NULL,
329 "opc_err", "par_err", "rip_err", "pci_abort",
333 static void cx8802_mpeg_irq(struct cx8802_dev *dev)
335 struct cx88_core *core = dev->core;
336 u32 status, mask, count;
338 dprintk( 1, "cx8802_mpeg_irq\n" );
339 status = cx_read(MO_TS_INTSTAT);
340 mask = cx_read(MO_TS_INTMSK);
341 if (0 == (status & mask))
344 cx_write(MO_TS_INTSTAT, status);
346 if (debug || (status & mask & ~0xff))
347 cx88_print_irqbits(core->name, "irq mpeg ",
348 cx88_mpeg_irqs, status, mask);
350 /* risc op code error */
351 if (status & (1 << 16)) {
352 printk(KERN_WARNING "%s: mpeg risc op code error\n",core->name);
353 cx_clear(MO_TS_DMACNTRL, 0x11);
354 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
359 dprintk( 1, "wake up\n" );
360 spin_lock(&dev->slock);
361 count = cx_read(MO_TS_GPCNT);
362 cx88_wakeup(dev->core, &dev->mpegq, count);
363 spin_unlock(&dev->slock);
368 spin_lock(&dev->slock);
369 cx8802_restart_queue(dev,&dev->mpegq);
370 spin_unlock(&dev->slock);
373 /* other general errors */
374 if (status & 0x1f0100) {
375 dprintk( 0, "general errors: 0x%08x\n", status & 0x1f0100 );
376 spin_lock(&dev->slock);
377 cx8802_stop_dma(dev);
378 cx8802_restart_queue(dev,&dev->mpegq);
379 spin_unlock(&dev->slock);
383 #define MAX_IRQ_LOOP 10
385 static irqreturn_t cx8802_irq(int irq, void *dev_id)
387 struct cx8802_dev *dev = dev_id;
388 struct cx88_core *core = dev->core;
390 int loop, handled = 0;
392 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
393 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x04);
396 dprintk( 1, "cx8802_irq\n" );
397 dprintk( 1, " loop: %d/%d\n", loop, MAX_IRQ_LOOP );
398 dprintk( 1, " status: %d\n", status );
400 cx_write(MO_PCI_INTSTAT, status);
402 if (status & core->pci_irqmask)
403 cx88_core_irq(core,status);
405 cx8802_mpeg_irq(dev);
407 if (MAX_IRQ_LOOP == loop) {
408 dprintk( 0, "clearing mask\n" );
409 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
411 cx_write(MO_PCI_INTMSK,0);
415 return IRQ_RETVAL(handled);
418 /* ----------------------------------------------------------- */
421 int cx8802_init_common(struct cx8802_dev *dev)
423 struct cx88_core *core = dev->core;
427 if (pci_enable_device(dev->pci))
429 pci_set_master(dev->pci);
430 if (!pci_dma_supported(dev->pci,0xffffffff)) {
431 printk("%s/2: Oops: no 32bit PCI DMA ???\n",dev->core->name);
435 pci_read_config_byte(dev->pci, PCI_CLASS_REVISION, &dev->pci_rev);
436 pci_read_config_byte(dev->pci, PCI_LATENCY_TIMER, &dev->pci_lat);
437 printk(KERN_INFO "%s/2: found at %s, rev: %d, irq: %d, "
438 "latency: %d, mmio: 0x%llx\n", dev->core->name,
439 pci_name(dev->pci), dev->pci_rev, dev->pci->irq,
440 dev->pci_lat,(unsigned long long)pci_resource_start(dev->pci,0));
442 /* initialize driver struct */
443 spin_lock_init(&dev->slock);
446 INIT_LIST_HEAD(&dev->mpegq.active);
447 INIT_LIST_HEAD(&dev->mpegq.queued);
448 dev->mpegq.timeout.function = cx8802_timeout;
449 dev->mpegq.timeout.data = (unsigned long)dev;
450 init_timer(&dev->mpegq.timeout);
451 cx88_risc_stopper(dev->pci,&dev->mpegq.stopper,
452 MO_TS_DMACNTRL,0x11,0x00);
455 err = request_irq(dev->pci->irq, cx8802_irq,
456 IRQF_SHARED | IRQF_DISABLED, dev->core->name, dev);
458 printk(KERN_ERR "%s: can't get IRQ %d\n",
459 dev->core->name, dev->pci->irq);
462 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
464 /* everything worked */
465 pci_set_drvdata(dev->pci,dev);
469 void cx8802_fini_common(struct cx8802_dev *dev)
471 dprintk( 2, "cx8802_fini_common\n" );
472 cx8802_stop_dma(dev);
473 pci_disable_device(dev->pci);
475 /* unregister stuff */
476 free_irq(dev->pci->irq, dev);
477 pci_set_drvdata(dev->pci, NULL);
480 btcx_riscmem_free(dev->pci,&dev->mpegq.stopper);
483 /* ----------------------------------------------------------- */
485 int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state)
487 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
488 struct cx88_core *core = dev->core;
491 spin_lock(&dev->slock);
492 if (!list_empty(&dev->mpegq.active)) {
493 dprintk( 2, "suspend\n" );
494 printk("%s: suspend mpeg\n", core->name);
495 cx8802_stop_dma(dev);
496 del_timer(&dev->mpegq.timeout);
498 spin_unlock(&dev->slock);
500 /* FIXME -- shutdown device */
501 cx88_shutdown(dev->core);
503 pci_save_state(pci_dev);
504 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
505 pci_disable_device(pci_dev);
506 dev->state.disabled = 1;
511 int cx8802_resume_common(struct pci_dev *pci_dev)
513 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
514 struct cx88_core *core = dev->core;
517 if (dev->state.disabled) {
518 err=pci_enable_device(pci_dev);
520 printk(KERN_ERR "%s: can't enable device\n",
524 dev->state.disabled = 0;
526 err=pci_set_power_state(pci_dev, PCI_D0);
528 printk(KERN_ERR "%s: can't enable device\n",
530 pci_disable_device(pci_dev);
531 dev->state.disabled = 1;
535 pci_restore_state(pci_dev);
537 /* FIXME: re-initialize hardware */
538 cx88_reset(dev->core);
540 /* restart video+vbi capture */
541 spin_lock(&dev->slock);
542 if (!list_empty(&dev->mpegq.active)) {
543 printk("%s: resume mpeg\n", core->name);
544 cx8802_restart_queue(dev,&dev->mpegq);
546 spin_unlock(&dev->slock);
551 struct cx8802_dev * cx8802_get_device(struct inode *inode)
553 int minor = iminor(inode);
554 struct cx8802_dev *h = NULL;
555 struct list_head *list;
557 list_for_each(list,&cx8802_devlist) {
558 h = list_entry(list, struct cx8802_dev, devlist);
559 if (h->mpeg_dev->minor == minor)
566 struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_type btype)
568 struct cx8802_dev *h = NULL;
569 struct cx8802_driver *d = NULL;
570 struct list_head *list;
571 struct list_head *list2;
573 list_for_each(list,&cx8802_devlist) {
574 h = list_entry(list, struct cx8802_dev, devlist);
578 list_for_each(list2, &h->drvlist.devlist) {
579 d = list_entry(list2, struct cx8802_driver, devlist);
581 /* only unregister the correct driver type */
582 if (d->type_id == btype) {
591 /* Driver asked for hardware access. */
592 int cx8802_request_acquire(struct cx8802_driver *drv)
594 struct cx88_core *core = drv->core;
596 /* Fail a request for hardware if the device is busy. */
597 if (core->active_type_id != CX88_BOARD_NONE)
600 if (drv->advise_acquire)
602 core->active_type_id = drv->type_id;
603 drv->advise_acquire(drv);
605 mpeg_dbg(1,"%s() Post acquire GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO));
611 /* Driver asked to release hardware. */
612 int cx8802_request_release(struct cx8802_driver *drv)
614 struct cx88_core *core = drv->core;
616 if (drv->advise_release)
618 drv->advise_release(drv);
619 core->active_type_id = CX88_BOARD_NONE;
620 mpeg_dbg(1,"%s() Post release GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO));
626 static int cx8802_check_driver(struct cx8802_driver *drv)
631 if ((drv->type_id != CX88_MPEG_DVB) &&
632 (drv->type_id != CX88_MPEG_BLACKBIRD))
635 if ((drv->hw_access != CX8802_DRVCTL_SHARED) &&
636 (drv->hw_access != CX8802_DRVCTL_EXCLUSIVE))
639 if ((drv->probe == NULL) ||
640 (drv->remove == NULL) ||
641 (drv->advise_acquire == NULL) ||
642 (drv->advise_release == NULL))
648 int cx8802_register_driver(struct cx8802_driver *drv)
650 struct cx8802_dev *h;
651 struct cx8802_driver *driver;
652 struct list_head *list;
655 printk(KERN_INFO "%s() ->registering driver type=%s access=%s\n", __FUNCTION__ ,
656 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
657 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive");
659 if ((err = cx8802_check_driver(drv)) != 0) {
660 printk(KERN_INFO "%s() cx8802_driver is invalid\n", __FUNCTION__ );
664 list_for_each(list,&cx8802_devlist) {
665 h = list_entry(list, struct cx8802_dev, devlist);
667 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n",
668 h->core->name,h->pci->subsystem_vendor,
669 h->pci->subsystem_device,cx88_boards[h->core->board].name,
672 /* Bring up a new struct for each driver instance */
673 driver = kzalloc(sizeof(*drv),GFP_KERNEL);
677 /* Snapshot of the driver registration data */
679 drv->suspend = cx8802_suspend_common;
680 drv->resume = cx8802_resume_common;
681 drv->request_acquire = cx8802_request_acquire;
682 drv->request_release = cx8802_request_release;
683 memcpy(driver, drv, sizeof(*driver));
685 err = drv->probe(driver);
688 mutex_lock(&drv->core->lock);
689 list_add_tail(&driver->devlist,&h->drvlist.devlist);
690 mutex_unlock(&drv->core->lock);
692 printk(KERN_ERR "%s() ->probe failed err = %d\n", __FUNCTION__, err);
704 int cx8802_unregister_driver(struct cx8802_driver *drv)
706 struct cx8802_dev *h;
707 struct cx8802_driver *d;
708 struct list_head *list;
709 struct list_head *list2, *q;
712 printk(KERN_INFO "%s() ->unregistering driver type=%s\n", __FUNCTION__ ,
713 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird");
715 list_for_each(list,&cx8802_devlist) {
717 h = list_entry(list, struct cx8802_dev, devlist);
719 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n",
720 h->core->name,h->pci->subsystem_vendor,
721 h->pci->subsystem_device,cx88_boards[h->core->board].name,
724 list_for_each_safe(list2, q, &h->drvlist.devlist) {
725 d = list_entry(list2, struct cx8802_driver, devlist);
727 /* only unregister the correct driver type */
728 if (d->type_id != drv->type_id)
733 mutex_lock(&drv->core->lock);
735 mutex_unlock(&drv->core->lock);
737 printk(KERN_ERR "%s() ->remove failed err = %d\n", __FUNCTION__, err);
746 /* ----------------------------------------------------------- */
747 static int __devinit cx8802_probe(struct pci_dev *pci_dev,
748 const struct pci_device_id *pci_id)
750 struct cx8802_dev *dev;
751 struct cx88_core *core;
755 core = cx88_core_get(pci_dev);
759 printk("%s/2: cx2388x 8802 Driver Manager\n", core->name);
762 if (!cx88_boards[core->board].mpeg)
766 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
772 err = cx8802_init_common(dev);
776 INIT_LIST_HEAD(&dev->drvlist.devlist);
777 list_add_tail(&dev->devlist,&cx8802_devlist);
779 /* Maintain a reference so cx88-video can query the 8802 device. */
786 cx88_core_put(core,pci_dev);
790 static void __devexit cx8802_remove(struct pci_dev *pci_dev)
792 struct cx8802_dev *dev;
793 struct cx8802_driver *h;
794 struct list_head *list;
796 dev = pci_get_drvdata(pci_dev);
798 dprintk( 1, "%s\n", __FUNCTION__);
800 list_for_each(list,&dev->drvlist.devlist) {
801 h = list_entry(list, struct cx8802_driver, devlist);
802 dprintk( 1, " ->driver\n");
803 if (h->remove == NULL) {
804 printk(KERN_ERR "%s .. skipping driver, no probe function\n", __FUNCTION__);
807 printk(KERN_INFO "%s .. Removing driver type %d\n", __FUNCTION__, h->type_id);
808 cx8802_unregister_driver(h);
809 list_del(&dev->drvlist.devlist);
812 /* Destroy any 8802 reference. */
813 dev->core->dvbdev = NULL;
816 cx8802_fini_common(dev);
817 cx88_core_put(dev->core,dev->pci);
821 static struct pci_device_id cx8802_pci_tbl[] = {
825 .subvendor = PCI_ANY_ID,
826 .subdevice = PCI_ANY_ID,
828 /* --- end of list --- */
831 MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
833 static struct pci_driver cx8802_pci_driver = {
834 .name = "cx88-mpeg driver manager",
835 .id_table = cx8802_pci_tbl,
836 .probe = cx8802_probe,
837 .remove = __devexit_p(cx8802_remove),
840 static int cx8802_init(void)
842 printk(KERN_INFO "cx2388x cx88-mpeg Driver Manager version %d.%d.%d loaded\n",
843 (CX88_VERSION_CODE >> 16) & 0xff,
844 (CX88_VERSION_CODE >> 8) & 0xff,
845 CX88_VERSION_CODE & 0xff);
847 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
848 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
850 return pci_register_driver(&cx8802_pci_driver);
853 static void cx8802_fini(void)
855 pci_unregister_driver(&cx8802_pci_driver);
858 module_init(cx8802_init);
859 module_exit(cx8802_fini);
860 EXPORT_SYMBOL(cx8802_buf_prepare);
861 EXPORT_SYMBOL(cx8802_buf_queue);
862 EXPORT_SYMBOL(cx8802_cancel_buffers);
864 EXPORT_SYMBOL(cx8802_init_common);
865 EXPORT_SYMBOL(cx8802_fini_common);
867 EXPORT_SYMBOL(cx8802_register_driver);
868 EXPORT_SYMBOL(cx8802_unregister_driver);
869 EXPORT_SYMBOL(cx8802_get_device);
870 EXPORT_SYMBOL(cx8802_get_driver);
871 /* ----------------------------------------------------------- */
876 * 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