1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Mantis PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/pci.h>
12 #include <linux/slab.h>
14 #include <linux/interrupt.h>
15 #include <media/rc-map.h>
17 #include <media/dmxdev.h>
18 #include <media/dvbdev.h>
19 #include <media/dvb_demux.h>
20 #include <media/dvb_frontend.h>
21 #include <media/dvb_net.h>
23 #include "mantis_common.h"
25 #include "mantis_vp1033.h"
26 #include "mantis_vp1034.h"
27 #include "mantis_vp1041.h"
28 #include "mantis_vp2033.h"
29 #include "mantis_vp2040.h"
30 #include "mantis_vp3030.h"
32 #include "mantis_dma.h"
33 #include "mantis_ca.h"
34 #include "mantis_dvb.h"
35 #include "mantis_uart.h"
36 #include "mantis_ioc.h"
37 #include "mantis_pci.h"
38 #include "mantis_i2c.h"
39 #include "mantis_reg.h"
40 #include "mantis_input.h"
42 static unsigned int verbose
;
43 module_param(verbose
, int, 0644);
44 MODULE_PARM_DESC(verbose
, "verbose startup messages, default is 0 (no)");
48 #define DRIVER_NAME "Mantis"
50 static char *label
[10] = {
63 static irqreturn_t
mantis_irq_handler(int irq
, void *dev_id
)
65 u32 stat
= 0, mask
= 0;
66 u32 rst_stat
= 0, rst_mask
= 0;
68 struct mantis_pci
*mantis
;
71 mantis
= (struct mantis_pci
*) dev_id
;
72 if (unlikely(!mantis
))
74 ca
= mantis
->mantis_ca
;
76 stat
= mmread(MANTIS_INT_STAT
);
77 mask
= mmread(MANTIS_INT_MASK
);
81 rst_mask
= MANTIS_GPIF_WRACK
|
86 rst_stat
= mmread(MANTIS_GPIF_STATUS
);
88 mmwrite(rst_stat
, MANTIS_GPIF_STATUS
);
90 mantis
->mantis_int_stat
= stat
;
91 mantis
->mantis_int_mask
= mask
;
92 dprintk(MANTIS_DEBUG
, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat
, mask
);
93 if (stat
& MANTIS_INT_RISCEN
) {
94 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[0]);
96 if (stat
& MANTIS_INT_IRQ0
) {
97 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[1]);
98 mantis
->gpif_status
= rst_stat
;
99 wake_up(&ca
->hif_write_wq
);
100 schedule_work(&ca
->hif_evm_work
);
102 if (stat
& MANTIS_INT_IRQ1
) {
103 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[2]);
104 spin_lock(&mantis
->intmask_lock
);
105 mmwrite(mmread(MANTIS_INT_MASK
) & ~MANTIS_INT_IRQ1
,
107 spin_unlock(&mantis
->intmask_lock
);
108 schedule_work(&mantis
->uart_work
);
110 if (stat
& MANTIS_INT_OCERR
) {
111 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[3]);
113 if (stat
& MANTIS_INT_PABORT
) {
114 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[4]);
116 if (stat
& MANTIS_INT_RIPERR
) {
117 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[5]);
119 if (stat
& MANTIS_INT_PPERR
) {
120 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[6]);
122 if (stat
& MANTIS_INT_FTRGT
) {
123 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[7]);
125 if (stat
& MANTIS_INT_RISCI
) {
126 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[8]);
127 mantis
->busy_block
= (stat
& MANTIS_INT_RISCSTAT
) >> 28;
128 tasklet_schedule(&mantis
->tasklet
);
130 if (stat
& MANTIS_INT_I2CDONE
) {
131 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[9]);
132 wake_up(&mantis
->i2c_wq
);
134 mmwrite(stat
, MANTIS_INT_STAT
);
135 stat
&= ~(MANTIS_INT_RISCEN
| MANTIS_INT_I2CDONE
|
136 MANTIS_INT_I2CRACK
| MANTIS_INT_PCMCIA7
|
137 MANTIS_INT_PCMCIA6
| MANTIS_INT_PCMCIA5
|
138 MANTIS_INT_PCMCIA4
| MANTIS_INT_PCMCIA3
|
139 MANTIS_INT_PCMCIA2
| MANTIS_INT_PCMCIA1
|
140 MANTIS_INT_PCMCIA0
| MANTIS_INT_IRQ1
|
141 MANTIS_INT_IRQ0
| MANTIS_INT_OCERR
|
142 MANTIS_INT_PABORT
| MANTIS_INT_RIPERR
|
143 MANTIS_INT_PPERR
| MANTIS_INT_FTRGT
|
147 dprintk(MANTIS_DEBUG
, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat
, mask
);
149 dprintk(MANTIS_DEBUG
, 0, "\n");
153 static int mantis_pci_probe(struct pci_dev
*pdev
,
154 const struct pci_device_id
*pci_id
)
156 struct mantis_pci_drvdata
*drvdata
;
157 struct mantis_pci
*mantis
;
158 struct mantis_hwconfig
*config
;
161 mantis
= kzalloc(sizeof(*mantis
), GFP_KERNEL
);
165 drvdata
= (void *)pci_id
->driver_data
;
167 mantis
->verbose
= verbose
;
169 config
= drvdata
->hwconfig
;
170 config
->irq_handler
= &mantis_irq_handler
;
171 mantis
->hwconfig
= config
;
172 mantis
->rc_map_name
= drvdata
->rc_map_name
;
174 spin_lock_init(&mantis
->intmask_lock
);
176 err
= mantis_pci_init(mantis
);
178 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis PCI initialization failed <%d>", err
);
179 goto err_free_mantis
;
182 err
= mantis_stream_control(mantis
, STREAM_TO_HIF
);
184 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis stream control failed <%d>", err
);
188 err
= mantis_i2c_init(mantis
);
190 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis I2C initialization failed <%d>", err
);
194 err
= mantis_get_mac(mantis
);
196 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis MAC address read failed <%d>", err
);
200 err
= mantis_dma_init(mantis
);
202 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis DMA initialization failed <%d>", err
);
206 err
= mantis_dvb_init(mantis
);
208 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis DVB initialization failed <%d>", err
);
212 err
= mantis_input_init(mantis
);
214 dprintk(MANTIS_ERROR
, 1,
215 "ERROR: Mantis DVB initialization failed <%d>", err
);
219 err
= mantis_uart_init(mantis
);
221 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis UART initialization failed <%d>", err
);
230 mantis_input_exit(mantis
);
233 mantis_dvb_exit(mantis
);
236 mantis_dma_exit(mantis
);
239 mantis_i2c_exit(mantis
);
242 mantis_pci_exit(mantis
);
250 static void mantis_pci_remove(struct pci_dev
*pdev
)
252 struct mantis_pci
*mantis
= pci_get_drvdata(pdev
);
256 mantis_uart_exit(mantis
);
257 mantis_input_exit(mantis
);
258 mantis_dvb_exit(mantis
);
259 mantis_dma_exit(mantis
);
260 mantis_i2c_exit(mantis
);
261 mantis_pci_exit(mantis
);
267 static const struct pci_device_id mantis_pci_table
[] = {
268 MAKE_ENTRY(TECHNISAT
, CABLESTAR_HD2
, &vp2040_config
,
269 RC_MAP_TECHNISAT_TS35
),
270 MAKE_ENTRY(TECHNISAT
, SKYSTAR_HD2_10
, &vp1041_config
,
272 MAKE_ENTRY(TECHNISAT
, SKYSTAR_HD2_20
, &vp1041_config
,
274 MAKE_ENTRY(TERRATEC
, CINERGY_C
, &vp2040_config
,
275 RC_MAP_TERRATEC_CINERGY_C_PCI
),
276 MAKE_ENTRY(TERRATEC
, CINERGY_S2_PCI_HD
, &vp1041_config
,
277 RC_MAP_TERRATEC_CINERGY_S2_HD
),
278 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_1033_DVB_S
, &vp1033_config
,
280 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_1034_DVB_S
, &vp1034_config
,
282 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_1041_DVB_S2
, &vp1041_config
,
283 RC_MAP_TWINHAN_DTV_CAB_CI
),
284 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_2033_DVB_C
, &vp2033_config
,
285 RC_MAP_TWINHAN_DTV_CAB_CI
),
286 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_2040_DVB_C
, &vp2040_config
,
288 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_3030_DVB_T
, &vp3030_config
,
293 MODULE_DEVICE_TABLE(pci
, mantis_pci_table
);
295 static struct pci_driver mantis_pci_driver
= {
297 .id_table
= mantis_pci_table
,
298 .probe
= mantis_pci_probe
,
299 .remove
= mantis_pci_remove
,
302 module_pci_driver(mantis_pci_driver
);
304 MODULE_DESCRIPTION("MANTIS driver");
305 MODULE_AUTHOR("Manu Abraham");
306 MODULE_LICENSE("GPL");