3 * Support for the mpeg transport stream transfers
4 * PCI function #2 of the cx2388x.
6 * (c) 2004 Jelle Foks <jelle@foks.us>
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.
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/init.h>
26 #include <linux/device.h>
27 #include <linux/dma-mapping.h>
28 #include <linux/interrupt.h>
29 #include <linux/delay.h>
31 /* ------------------------------------------------------------------ */
33 MODULE_DESCRIPTION("mpeg driver for cx2388x based TV cards");
34 MODULE_AUTHOR("Jelle Foks <jelle@foks.us>");
35 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
36 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
37 MODULE_LICENSE("GPL");
38 MODULE_VERSION(CX88_VERSION
);
40 static unsigned int debug
;
41 module_param(debug
, int, 0644);
42 MODULE_PARM_DESC(debug
, "enable debug messages [mpeg]");
44 #define dprintk(level, fmt, arg...) do { \
45 if (debug + 1 > level) \
46 printk(KERN_DEBUG pr_fmt("%s: mpeg:" fmt), \
50 #if defined(CONFIG_MODULES) && defined(MODULE)
51 static void request_module_async(struct work_struct
*work
)
53 struct cx8802_dev
*dev
= container_of(work
, struct cx8802_dev
,
56 if (dev
->core
->board
.mpeg
& CX88_MPEG_DVB
)
57 request_module("cx88-dvb");
58 if (dev
->core
->board
.mpeg
& CX88_MPEG_BLACKBIRD
)
59 request_module("cx88-blackbird");
62 static void request_modules(struct cx8802_dev
*dev
)
64 INIT_WORK(&dev
->request_module_wk
, request_module_async
);
65 schedule_work(&dev
->request_module_wk
);
68 static void flush_request_modules(struct cx8802_dev
*dev
)
70 flush_work(&dev
->request_module_wk
);
73 #define request_modules(dev)
74 #define flush_request_modules(dev)
75 #endif /* CONFIG_MODULES */
77 static LIST_HEAD(cx8802_devlist
);
78 static DEFINE_MUTEX(cx8802_mutex
);
79 /* ------------------------------------------------------------------ */
81 int cx8802_start_dma(struct cx8802_dev
*dev
,
82 struct cx88_dmaqueue
*q
,
83 struct cx88_buffer
*buf
)
85 struct cx88_core
*core
= dev
->core
;
87 dprintk(1, "w: %d, h: %d, f: %d\n",
88 core
->width
, core
->height
, core
->field
);
90 /* setup fifo + format */
91 cx88_sram_channel_setup(core
, &cx88_sram_channels
[SRAM_CH28
],
92 dev
->ts_packet_size
, buf
->risc
.dma
);
94 /* write TS length to chip */
95 cx_write(MO_TS_LNGTH
, dev
->ts_packet_size
);
98 * FIXME: this needs a review.
99 * also: move to cx88-blackbird + cx88-dvb source files?
102 dprintk(1, "core->active_type_id = 0x%08x\n", core
->active_type_id
);
104 if ((core
->active_type_id
== CX88_MPEG_DVB
) &&
105 (core
->board
.mpeg
& CX88_MPEG_DVB
)) {
106 dprintk(1, "cx8802_start_dma doing .dvb\n");
107 /* negedge driven & software reset */
108 cx_write(TS_GEN_CNTRL
, 0x0040 | dev
->ts_gen_cntrl
);
110 cx_write(MO_PINMUX_IO
, 0x00);
111 cx_write(TS_HW_SOP_CNTRL
, 0x47 << 16 | 188 << 4 | 0x01);
112 switch (core
->boardnr
) {
113 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q
:
114 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T
:
115 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD
:
116 case CX88_BOARD_PCHDTV_HD5500
:
117 cx_write(TS_SOP_STAT
, 1 << 13);
119 case CX88_BOARD_SAMSUNG_SMT_7020
:
120 cx_write(TS_SOP_STAT
, 0x00);
122 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1
:
123 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1
:
124 /* Enable MPEG parallel IO and video signal pins */
125 cx_write(MO_PINMUX_IO
, 0x88);
128 case CX88_BOARD_HAUPPAUGE_HVR1300
:
129 /* Enable MPEG parallel IO and video signal pins */
130 cx_write(MO_PINMUX_IO
, 0x88);
131 cx_write(TS_SOP_STAT
, 0);
132 cx_write(TS_VALERR_CNTRL
, 0);
134 case CX88_BOARD_PINNACLE_PCTV_HD_800i
:
135 /* Enable MPEG parallel IO and video signal pins */
136 cx_write(MO_PINMUX_IO
, 0x88);
137 cx_write(TS_HW_SOP_CNTRL
, (0x47 << 16) | (188 << 4));
138 dev
->ts_gen_cntrl
= 5;
139 cx_write(TS_SOP_STAT
, 0);
140 cx_write(TS_VALERR_CNTRL
, 0);
144 cx_write(TS_SOP_STAT
, 0x00);
147 cx_write(TS_GEN_CNTRL
, dev
->ts_gen_cntrl
);
149 } else if ((core
->active_type_id
== CX88_MPEG_BLACKBIRD
) &&
150 (core
->board
.mpeg
& CX88_MPEG_BLACKBIRD
)) {
151 dprintk(1, "cx8802_start_dma doing .blackbird\n");
152 cx_write(MO_PINMUX_IO
, 0x88); /* enable MPEG parallel IO */
154 /* punctured clock TS & posedge driven & software reset */
155 cx_write(TS_GEN_CNTRL
, 0x46);
158 cx_write(TS_HW_SOP_CNTRL
, 0x408); /* mpeg start byte */
159 cx_write(TS_VALERR_CNTRL
, 0x2000);
161 /* punctured clock TS & posedge driven */
162 cx_write(TS_GEN_CNTRL
, 0x06);
165 pr_err("%s() Failed. Unsupported value in .mpeg (0x%08x)\n",
166 __func__
, core
->board
.mpeg
);
171 cx_write(MO_TS_GPCNTRL
, GP_COUNT_CONTROL_RESET
);
175 dprintk(1, "setting the interrupt mask\n");
176 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
| PCI_INT_TSINT
);
177 cx_set(MO_TS_INTMSK
, 0x1f0011);
180 cx_set(MO_DEV_CNTRL2
, (1 << 5));
181 cx_set(MO_TS_DMACNTRL
, 0x11);
184 EXPORT_SYMBOL(cx8802_start_dma
);
186 static int cx8802_stop_dma(struct cx8802_dev
*dev
)
188 struct cx88_core
*core
= dev
->core
;
193 cx_clear(MO_TS_DMACNTRL
, 0x11);
196 cx_clear(MO_PCI_INTMSK
, PCI_INT_TSINT
);
197 cx_clear(MO_TS_INTMSK
, 0x1f0011);
199 /* Reset the controller */
200 cx_write(TS_GEN_CNTRL
, 0xcd);
204 static int cx8802_restart_queue(struct cx8802_dev
*dev
,
205 struct cx88_dmaqueue
*q
)
207 struct cx88_buffer
*buf
;
210 if (list_empty(&q
->active
))
213 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, list
);
214 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
215 buf
, buf
->vb
.vb2_buf
.index
);
216 cx8802_start_dma(dev
, q
, buf
);
220 /* ------------------------------------------------------------------ */
222 int cx8802_buf_prepare(struct vb2_queue
*q
, struct cx8802_dev
*dev
,
223 struct cx88_buffer
*buf
)
225 int size
= dev
->ts_packet_size
* dev
->ts_packet_count
;
226 struct sg_table
*sgt
= vb2_dma_sg_plane_desc(&buf
->vb
.vb2_buf
, 0);
227 struct cx88_riscmem
*risc
= &buf
->risc
;
230 if (vb2_plane_size(&buf
->vb
.vb2_buf
, 0) < size
)
232 vb2_set_plane_payload(&buf
->vb
.vb2_buf
, 0, size
);
234 rc
= cx88_risc_databuffer(dev
->pci
, risc
, sgt
->sgl
,
235 dev
->ts_packet_size
, dev
->ts_packet_count
, 0);
238 pci_free_consistent(dev
->pci
, risc
->size
,
239 risc
->cpu
, risc
->dma
);
240 memset(risc
, 0, sizeof(*risc
));
245 EXPORT_SYMBOL(cx8802_buf_prepare
);
247 void cx8802_buf_queue(struct cx8802_dev
*dev
, struct cx88_buffer
*buf
)
249 struct cx88_buffer
*prev
;
250 struct cx88_dmaqueue
*cx88q
= &dev
->mpegq
;
253 /* add jump to start */
254 buf
->risc
.cpu
[1] = cpu_to_le32(buf
->risc
.dma
+ 8);
255 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_CNT_INC
);
256 buf
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
+ 8);
258 if (list_empty(&cx88q
->active
)) {
259 dprintk(1, "queue is empty - first active\n");
260 list_add_tail(&buf
->list
, &cx88q
->active
);
261 dprintk(1, "[%p/%d] %s - first active\n",
262 buf
, buf
->vb
.vb2_buf
.index
, __func__
);
265 buf
->risc
.cpu
[0] |= cpu_to_le32(RISC_IRQ1
);
266 dprintk(1, "queue is not empty - append to active\n");
267 prev
= list_entry(cx88q
->active
.prev
, struct cx88_buffer
, list
);
268 list_add_tail(&buf
->list
, &cx88q
->active
);
269 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
270 dprintk(1, "[%p/%d] %s - append to active\n",
271 buf
, buf
->vb
.vb2_buf
.index
, __func__
);
274 EXPORT_SYMBOL(cx8802_buf_queue
);
276 /* ----------------------------------------------------------- */
278 static void do_cancel_buffers(struct cx8802_dev
*dev
)
280 struct cx88_dmaqueue
*q
= &dev
->mpegq
;
281 struct cx88_buffer
*buf
;
284 spin_lock_irqsave(&dev
->slock
, flags
);
285 while (!list_empty(&q
->active
)) {
286 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, list
);
287 list_del(&buf
->list
);
288 vb2_buffer_done(&buf
->vb
.vb2_buf
, VB2_BUF_STATE_ERROR
);
290 spin_unlock_irqrestore(&dev
->slock
, flags
);
293 void cx8802_cancel_buffers(struct cx8802_dev
*dev
)
296 cx8802_stop_dma(dev
);
297 do_cancel_buffers(dev
);
299 EXPORT_SYMBOL(cx8802_cancel_buffers
);
301 static const char *cx88_mpeg_irqs
[32] = {
302 "ts_risci1", NULL
, NULL
, NULL
,
303 "ts_risci2", NULL
, NULL
, NULL
,
304 "ts_oflow", NULL
, NULL
, NULL
,
305 "ts_sync", NULL
, NULL
, NULL
,
306 "opc_err", "par_err", "rip_err", "pci_abort",
310 static void cx8802_mpeg_irq(struct cx8802_dev
*dev
)
312 struct cx88_core
*core
= dev
->core
;
313 u32 status
, mask
, count
;
316 status
= cx_read(MO_TS_INTSTAT
);
317 mask
= cx_read(MO_TS_INTMSK
);
318 if (0 == (status
& mask
))
321 cx_write(MO_TS_INTSTAT
, status
);
323 if (debug
|| (status
& mask
& ~0xff))
324 cx88_print_irqbits("irq mpeg ",
325 cx88_mpeg_irqs
, ARRAY_SIZE(cx88_mpeg_irqs
),
328 /* risc op code error */
329 if (status
& (1 << 16)) {
330 pr_warn("mpeg risc op code error\n");
331 cx_clear(MO_TS_DMACNTRL
, 0x11);
332 cx88_sram_channel_dump(dev
->core
,
333 &cx88_sram_channels
[SRAM_CH28
]);
338 dprintk(1, "wake up\n");
339 spin_lock(&dev
->slock
);
340 count
= cx_read(MO_TS_GPCNT
);
341 cx88_wakeup(dev
->core
, &dev
->mpegq
, count
);
342 spin_unlock(&dev
->slock
);
345 /* other general errors */
346 if (status
& 0x1f0100) {
347 dprintk(0, "general errors: 0x%08x\n", status
& 0x1f0100);
348 spin_lock(&dev
->slock
);
349 cx8802_stop_dma(dev
);
350 spin_unlock(&dev
->slock
);
354 #define MAX_IRQ_LOOP 10
356 static irqreturn_t
cx8802_irq(int irq
, void *dev_id
)
358 struct cx8802_dev
*dev
= dev_id
;
359 struct cx88_core
*core
= dev
->core
;
361 int loop
, handled
= 0;
363 for (loop
= 0; loop
< MAX_IRQ_LOOP
; loop
++) {
364 status
= cx_read(MO_PCI_INTSTAT
) &
365 (core
->pci_irqmask
| PCI_INT_TSINT
);
368 dprintk(1, "cx8802_irq\n");
369 dprintk(1, " loop: %d/%d\n", loop
, MAX_IRQ_LOOP
);
370 dprintk(1, " status: %d\n", status
);
372 cx_write(MO_PCI_INTSTAT
, status
);
374 if (status
& core
->pci_irqmask
)
375 cx88_core_irq(core
, status
);
376 if (status
& PCI_INT_TSINT
)
377 cx8802_mpeg_irq(dev
);
379 if (loop
== MAX_IRQ_LOOP
) {
380 dprintk(0, "clearing mask\n");
381 pr_warn("irq loop -- clearing mask\n");
382 cx_write(MO_PCI_INTMSK
, 0);
386 return IRQ_RETVAL(handled
);
389 static int cx8802_init_common(struct cx8802_dev
*dev
)
391 struct cx88_core
*core
= dev
->core
;
395 if (pci_enable_device(dev
->pci
))
397 pci_set_master(dev
->pci
);
398 err
= pci_set_dma_mask(dev
->pci
, DMA_BIT_MASK(32));
400 pr_err("Oops: no 32bit PCI DMA ???\n");
404 dev
->pci_rev
= dev
->pci
->revision
;
405 pci_read_config_byte(dev
->pci
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
406 pr_info("found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
407 pci_name(dev
->pci
), dev
->pci_rev
, dev
->pci
->irq
,
409 (unsigned long long)pci_resource_start(dev
->pci
, 0));
411 /* initialize driver struct */
412 spin_lock_init(&dev
->slock
);
415 INIT_LIST_HEAD(&dev
->mpegq
.active
);
418 err
= request_irq(dev
->pci
->irq
, cx8802_irq
,
419 IRQF_SHARED
, dev
->core
->name
, dev
);
421 pr_err("can't get IRQ %d\n", dev
->pci
->irq
);
424 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
);
426 /* everything worked */
427 pci_set_drvdata(dev
->pci
, dev
);
431 static void cx8802_fini_common(struct cx8802_dev
*dev
)
434 cx8802_stop_dma(dev
);
435 pci_disable_device(dev
->pci
);
437 /* unregister stuff */
438 free_irq(dev
->pci
->irq
, dev
);
441 /* ----------------------------------------------------------- */
443 static int cx8802_suspend_common(struct pci_dev
*pci_dev
, pm_message_t state
)
445 struct cx8802_dev
*dev
= pci_get_drvdata(pci_dev
);
449 spin_lock_irqsave(&dev
->slock
, flags
);
450 if (!list_empty(&dev
->mpegq
.active
)) {
451 dprintk(2, "suspend\n");
452 pr_info("suspend mpeg\n");
453 cx8802_stop_dma(dev
);
455 spin_unlock_irqrestore(&dev
->slock
, flags
);
457 /* FIXME -- shutdown device */
458 cx88_shutdown(dev
->core
);
460 pci_save_state(pci_dev
);
461 if (pci_set_power_state(pci_dev
,
462 pci_choose_state(pci_dev
, state
)) != 0) {
463 pci_disable_device(pci_dev
);
464 dev
->state
.disabled
= 1;
469 static int cx8802_resume_common(struct pci_dev
*pci_dev
)
471 struct cx8802_dev
*dev
= pci_get_drvdata(pci_dev
);
475 if (dev
->state
.disabled
) {
476 err
= pci_enable_device(pci_dev
);
478 pr_err("can't enable device\n");
481 dev
->state
.disabled
= 0;
483 err
= pci_set_power_state(pci_dev
, PCI_D0
);
485 pr_err("can't enable device\n");
486 pci_disable_device(pci_dev
);
487 dev
->state
.disabled
= 1;
491 pci_restore_state(pci_dev
);
493 /* FIXME: re-initialize hardware */
494 cx88_reset(dev
->core
);
496 /* restart video+vbi capture */
497 spin_lock_irqsave(&dev
->slock
, flags
);
498 if (!list_empty(&dev
->mpegq
.active
)) {
499 pr_info("resume mpeg\n");
500 cx8802_restart_queue(dev
, &dev
->mpegq
);
502 spin_unlock_irqrestore(&dev
->slock
, flags
);
507 struct cx8802_driver
*cx8802_get_driver(struct cx8802_dev
*dev
,
508 enum cx88_board_type btype
)
510 struct cx8802_driver
*d
;
512 list_for_each_entry(d
, &dev
->drvlist
, drvlist
)
513 if (d
->type_id
== btype
)
518 EXPORT_SYMBOL(cx8802_get_driver
);
520 /* Driver asked for hardware access. */
521 static int cx8802_request_acquire(struct cx8802_driver
*drv
)
523 struct cx88_core
*core
= drv
->core
;
526 /* Fail a request for hardware if the device is busy. */
527 if (core
->active_type_id
!= CX88_BOARD_NONE
&&
528 core
->active_type_id
!= drv
->type_id
)
531 if (drv
->type_id
== CX88_MPEG_DVB
) {
532 /* When switching to DVB, always set the input to the tuner */
533 core
->last_analog_input
= core
->input
;
536 i
< (sizeof(core
->board
.input
) /
537 sizeof(struct cx88_input
));
539 if (core
->board
.input
[i
].type
== CX88_VMUX_DVB
) {
546 if (drv
->advise_acquire
) {
548 if (core
->active_type_id
== CX88_BOARD_NONE
) {
549 core
->active_type_id
= drv
->type_id
;
550 drv
->advise_acquire(drv
);
553 dprintk(1, "Post acquire GPIO=%x\n", cx_read(MO_GP0_IO
));
559 /* Driver asked to release hardware. */
560 static int cx8802_request_release(struct cx8802_driver
*drv
)
562 struct cx88_core
*core
= drv
->core
;
564 if (drv
->advise_release
&& --core
->active_ref
== 0) {
565 if (drv
->type_id
== CX88_MPEG_DVB
) {
567 * If the DVB driver is releasing, reset the input
568 * state to the last configured analog input
570 core
->input
= core
->last_analog_input
;
573 drv
->advise_release(drv
);
574 core
->active_type_id
= CX88_BOARD_NONE
;
575 dprintk(1, "Post release GPIO=%x\n", cx_read(MO_GP0_IO
));
581 static int cx8802_check_driver(struct cx8802_driver
*drv
)
586 if ((drv
->type_id
!= CX88_MPEG_DVB
) &&
587 (drv
->type_id
!= CX88_MPEG_BLACKBIRD
))
590 if ((drv
->hw_access
!= CX8802_DRVCTL_SHARED
) &&
591 (drv
->hw_access
!= CX8802_DRVCTL_EXCLUSIVE
))
596 (!drv
->advise_acquire
) ||
597 (!drv
->advise_release
))
603 int cx8802_register_driver(struct cx8802_driver
*drv
)
605 struct cx8802_dev
*dev
;
606 struct cx8802_driver
*driver
;
609 pr_info("registering cx8802 driver, type: %s access: %s\n",
610 drv
->type_id
== CX88_MPEG_DVB
? "dvb" : "blackbird",
611 drv
->hw_access
== CX8802_DRVCTL_SHARED
?
612 "shared" : "exclusive");
614 err
= cx8802_check_driver(drv
);
616 pr_err("cx8802_driver is invalid\n");
620 mutex_lock(&cx8802_mutex
);
622 list_for_each_entry(dev
, &cx8802_devlist
, devlist
) {
623 pr_info("subsystem: %04x:%04x, board: %s [card=%d]\n",
624 dev
->pci
->subsystem_vendor
,
625 dev
->pci
->subsystem_device
, dev
->core
->board
.name
,
628 /* Bring up a new struct for each driver instance */
629 driver
= kzalloc(sizeof(*drv
), GFP_KERNEL
);
635 /* Snapshot of the driver registration data */
636 drv
->core
= dev
->core
;
637 drv
->suspend
= cx8802_suspend_common
;
638 drv
->resume
= cx8802_resume_common
;
639 drv
->request_acquire
= cx8802_request_acquire
;
640 drv
->request_release
= cx8802_request_release
;
641 memcpy(driver
, drv
, sizeof(*driver
));
643 mutex_lock(&drv
->core
->lock
);
644 err
= drv
->probe(driver
);
647 list_add_tail(&driver
->drvlist
, &dev
->drvlist
);
649 pr_err("cx8802 probe failed, err = %d\n", err
);
651 mutex_unlock(&drv
->core
->lock
);
654 err
= i
? 0 : -ENODEV
;
656 mutex_unlock(&cx8802_mutex
);
659 EXPORT_SYMBOL(cx8802_register_driver
);
661 int cx8802_unregister_driver(struct cx8802_driver
*drv
)
663 struct cx8802_dev
*dev
;
664 struct cx8802_driver
*d
, *dtmp
;
667 pr_info("unregistering cx8802 driver, type: %s access: %s\n",
668 drv
->type_id
== CX88_MPEG_DVB
? "dvb" : "blackbird",
669 drv
->hw_access
== CX8802_DRVCTL_SHARED
?
670 "shared" : "exclusive");
672 mutex_lock(&cx8802_mutex
);
674 list_for_each_entry(dev
, &cx8802_devlist
, devlist
) {
675 pr_info("subsystem: %04x:%04x, board: %s [card=%d]\n",
676 dev
->pci
->subsystem_vendor
,
677 dev
->pci
->subsystem_device
, dev
->core
->board
.name
,
680 mutex_lock(&dev
->core
->lock
);
682 list_for_each_entry_safe(d
, dtmp
, &dev
->drvlist
, drvlist
) {
683 /* only unregister the correct driver type */
684 if (d
->type_id
!= drv
->type_id
)
689 list_del(&d
->drvlist
);
692 pr_err("cx8802 driver remove failed (%d)\n",
696 mutex_unlock(&dev
->core
->lock
);
699 mutex_unlock(&cx8802_mutex
);
703 EXPORT_SYMBOL(cx8802_unregister_driver
);
705 /* ----------------------------------------------------------- */
706 static int cx8802_probe(struct pci_dev
*pci_dev
,
707 const struct pci_device_id
*pci_id
)
709 struct cx8802_dev
*dev
;
710 struct cx88_core
*core
;
714 core
= cx88_core_get(pci_dev
);
718 pr_info("cx2388x 8802 Driver Manager\n");
721 if (!core
->board
.mpeg
)
725 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
731 /* Maintain a reference so cx88-video can query the 8802 device. */
734 err
= cx8802_init_common(dev
);
738 INIT_LIST_HEAD(&dev
->drvlist
);
739 mutex_lock(&cx8802_mutex
);
740 list_add_tail(&dev
->devlist
, &cx8802_devlist
);
741 mutex_unlock(&cx8802_mutex
);
743 /* now autoload cx88-dvb or cx88-blackbird */
744 request_modules(dev
);
751 cx88_core_put(core
, pci_dev
);
755 static void cx8802_remove(struct pci_dev
*pci_dev
)
757 struct cx8802_dev
*dev
;
759 dev
= pci_get_drvdata(pci_dev
);
761 dprintk(1, "%s\n", __func__
);
763 flush_request_modules(dev
);
765 mutex_lock(&dev
->core
->lock
);
767 if (!list_empty(&dev
->drvlist
)) {
768 struct cx8802_driver
*drv
, *tmp
;
771 pr_warn("Trying to remove cx8802 driver while cx8802 sub-drivers still loaded?!\n");
773 list_for_each_entry_safe(drv
, tmp
, &dev
->drvlist
, drvlist
) {
774 err
= drv
->remove(drv
);
776 list_del(&drv
->drvlist
);
778 pr_err("cx8802 driver remove failed (%d)\n",
784 mutex_unlock(&dev
->core
->lock
);
786 /* Destroy any 8802 reference. */
787 dev
->core
->dvbdev
= NULL
;
790 cx8802_fini_common(dev
);
791 cx88_core_put(dev
->core
, dev
->pci
);
795 static const struct pci_device_id cx8802_pci_tbl
[] = {
799 .subvendor
= PCI_ANY_ID
,
800 .subdevice
= PCI_ANY_ID
,
802 /* --- end of list --- */
805 MODULE_DEVICE_TABLE(pci
, cx8802_pci_tbl
);
807 static struct pci_driver cx8802_pci_driver
= {
808 .name
= "cx88-mpeg driver manager",
809 .id_table
= cx8802_pci_tbl
,
810 .probe
= cx8802_probe
,
811 .remove
= cx8802_remove
,
814 module_pci_driver(cx8802_pci_driver
);