1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Hopper PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <linux/slab.h>
15 #include <linux/interrupt.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"
24 #include "hopper_vp3028.h"
25 #include "mantis_dma.h"
26 #include "mantis_dvb.h"
27 #include "mantis_uart.h"
28 #include "mantis_ioc.h"
29 #include "mantis_pci.h"
30 #include "mantis_i2c.h"
31 #include "mantis_reg.h"
33 static unsigned int verbose
;
34 module_param(verbose
, int, 0644);
35 MODULE_PARM_DESC(verbose
, "verbose startup messages, default is 0 (no)");
37 #define DRIVER_NAME "Hopper"
39 static char *label
[10] = {
54 static irqreturn_t
hopper_irq_handler(int irq
, void *dev_id
)
56 u32 stat
= 0, mask
= 0;
57 u32 rst_stat
= 0, rst_mask
= 0;
59 struct mantis_pci
*mantis
;
62 mantis
= (struct mantis_pci
*) dev_id
;
63 if (unlikely(!mantis
))
65 ca
= mantis
->mantis_ca
;
67 stat
= mmread(MANTIS_INT_STAT
);
68 mask
= mmread(MANTIS_INT_MASK
);
72 rst_mask
= MANTIS_GPIF_WRACK
|
77 rst_stat
= mmread(MANTIS_GPIF_STATUS
);
79 mmwrite(rst_stat
, MANTIS_GPIF_STATUS
);
81 mantis
->mantis_int_stat
= stat
;
82 mantis
->mantis_int_mask
= mask
;
83 dprintk(MANTIS_DEBUG
, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat
, mask
);
84 if (stat
& MANTIS_INT_RISCEN
) {
85 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[0]);
87 if (stat
& MANTIS_INT_IRQ0
) {
88 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[1]);
89 mantis
->gpif_status
= rst_stat
;
90 wake_up(&ca
->hif_write_wq
);
91 schedule_work(&ca
->hif_evm_work
);
93 if (stat
& MANTIS_INT_IRQ1
) {
94 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[2]);
95 spin_lock(&mantis
->intmask_lock
);
96 mmwrite(mmread(MANTIS_INT_MASK
) & ~MANTIS_INT_IRQ1
,
98 spin_unlock(&mantis
->intmask_lock
);
99 schedule_work(&mantis
->uart_work
);
101 if (stat
& MANTIS_INT_OCERR
) {
102 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[3]);
104 if (stat
& MANTIS_INT_PABORT
) {
105 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[4]);
107 if (stat
& MANTIS_INT_RIPERR
) {
108 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[5]);
110 if (stat
& MANTIS_INT_PPERR
) {
111 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[6]);
113 if (stat
& MANTIS_INT_FTRGT
) {
114 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[7]);
116 if (stat
& MANTIS_INT_RISCI
) {
117 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[8]);
118 mantis
->busy_block
= (stat
& MANTIS_INT_RISCSTAT
) >> 28;
119 tasklet_schedule(&mantis
->tasklet
);
121 if (stat
& MANTIS_INT_I2CDONE
) {
122 dprintk(MANTIS_DEBUG
, 0, "<%s>", label
[9]);
123 wake_up(&mantis
->i2c_wq
);
125 mmwrite(stat
, MANTIS_INT_STAT
);
126 stat
&= ~(MANTIS_INT_RISCEN
| MANTIS_INT_I2CDONE
|
127 MANTIS_INT_I2CRACK
| MANTIS_INT_PCMCIA7
|
128 MANTIS_INT_PCMCIA6
| MANTIS_INT_PCMCIA5
|
129 MANTIS_INT_PCMCIA4
| MANTIS_INT_PCMCIA3
|
130 MANTIS_INT_PCMCIA2
| MANTIS_INT_PCMCIA1
|
131 MANTIS_INT_PCMCIA0
| MANTIS_INT_IRQ1
|
132 MANTIS_INT_IRQ0
| MANTIS_INT_OCERR
|
133 MANTIS_INT_PABORT
| MANTIS_INT_RIPERR
|
134 MANTIS_INT_PPERR
| MANTIS_INT_FTRGT
|
138 dprintk(MANTIS_DEBUG
, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat
, mask
);
140 dprintk(MANTIS_DEBUG
, 0, "\n");
144 static int hopper_pci_probe(struct pci_dev
*pdev
,
145 const struct pci_device_id
*pci_id
)
147 struct mantis_pci_drvdata
*drvdata
;
148 struct mantis_pci
*mantis
;
149 struct mantis_hwconfig
*config
;
152 mantis
= kzalloc(sizeof(*mantis
), GFP_KERNEL
);
158 drvdata
= (void *)pci_id
->driver_data
;
160 mantis
->verbose
= verbose
;
162 config
= drvdata
->hwconfig
;
163 config
->irq_handler
= &hopper_irq_handler
;
164 mantis
->hwconfig
= config
;
165 mantis
->rc_map_name
= drvdata
->rc_map_name
;
167 spin_lock_init(&mantis
->intmask_lock
);
169 err
= mantis_pci_init(mantis
);
171 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis PCI initialization failed <%d>", err
);
175 err
= mantis_stream_control(mantis
, STREAM_TO_HIF
);
177 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis stream control failed <%d>", err
);
181 err
= mantis_i2c_init(mantis
);
183 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis I2C initialization failed <%d>", err
);
187 err
= mantis_get_mac(mantis
);
189 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis MAC address read failed <%d>", err
);
193 err
= mantis_dma_init(mantis
);
195 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis DMA initialization failed <%d>", err
);
199 err
= mantis_dvb_init(mantis
);
201 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis DVB initialization failed <%d>", err
);
209 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis DMA exit! <%d>", err
);
210 mantis_dma_exit(mantis
);
213 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis I2C exit! <%d>", err
);
214 mantis_i2c_exit(mantis
);
217 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis PCI exit! <%d>", err
);
218 mantis_pci_exit(mantis
);
221 dprintk(MANTIS_ERROR
, 1, "ERROR: Mantis free! <%d>", err
);
228 static void hopper_pci_remove(struct pci_dev
*pdev
)
230 struct mantis_pci
*mantis
= pci_get_drvdata(pdev
);
233 mantis_dvb_exit(mantis
);
234 mantis_dma_exit(mantis
);
235 mantis_i2c_exit(mantis
);
236 mantis_pci_exit(mantis
);
243 static const struct pci_device_id hopper_pci_table
[] = {
244 MAKE_ENTRY(TWINHAN_TECHNOLOGIES
, MANTIS_VP_3028_DVB_T
, &vp3028_config
,
249 MODULE_DEVICE_TABLE(pci
, hopper_pci_table
);
251 static struct pci_driver hopper_pci_driver
= {
253 .id_table
= hopper_pci_table
,
254 .probe
= hopper_pci_probe
,
255 .remove
= hopper_pci_remove
,
258 module_pci_driver(hopper_pci_driver
);
260 MODULE_DESCRIPTION("HOPPER driver");
261 MODULE_AUTHOR("Manu Abraham");
262 MODULE_LICENSE("GPL");