WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / pci / mantis / hopper_cards.c
blobc0bd5d7e148bb13c82d9a34a04fbd6551a5d130d
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 Hopper PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
7 */
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>
14 #include <asm/irq.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] = {
40 "DMA",
41 "IRQ-0",
42 "IRQ-1",
43 "OCERR",
44 "PABRT",
45 "RIPRR",
46 "PPERR",
47 "FTRGT",
48 "RISCI",
49 "RACK"
52 static int devs;
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;
60 struct mantis_ca *ca;
62 mantis = (struct mantis_pci *) dev_id;
63 if (unlikely(!mantis))
64 return IRQ_NONE;
65 ca = mantis->mantis_ca;
67 stat = mmread(MANTIS_INT_STAT);
68 mask = mmread(MANTIS_INT_MASK);
69 if (!(stat & mask))
70 return IRQ_NONE;
72 rst_mask = MANTIS_GPIF_WRACK |
73 MANTIS_GPIF_OTHERR |
74 MANTIS_SBUF_WSTO |
75 MANTIS_GPIF_EXTIRQ;
77 rst_stat = mmread(MANTIS_GPIF_STATUS);
78 rst_stat &= rst_mask;
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,
97 MANTIS_INT_MASK);
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 |
135 MANTIS_INT_RISCI);
137 if (stat)
138 dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
140 dprintk(MANTIS_DEBUG, 0, "\n");
141 return IRQ_HANDLED;
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;
150 int err;
152 mantis = kzalloc(sizeof(*mantis), GFP_KERNEL);
153 if (!mantis) {
154 err = -ENOMEM;
155 goto fail0;
158 drvdata = (void *)pci_id->driver_data;
159 mantis->num = devs;
160 mantis->verbose = verbose;
161 mantis->pdev = pdev;
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);
170 if (err) {
171 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
172 goto fail1;
175 err = mantis_stream_control(mantis, STREAM_TO_HIF);
176 if (err < 0) {
177 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
178 goto fail1;
181 err = mantis_i2c_init(mantis);
182 if (err < 0) {
183 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
184 goto fail2;
187 err = mantis_get_mac(mantis);
188 if (err < 0) {
189 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
190 goto fail2;
193 err = mantis_dma_init(mantis);
194 if (err < 0) {
195 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
196 goto fail3;
199 err = mantis_dvb_init(mantis);
200 if (err < 0) {
201 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
202 goto fail4;
204 devs++;
206 return err;
208 fail4:
209 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
210 mantis_dma_exit(mantis);
212 fail3:
213 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
214 mantis_i2c_exit(mantis);
216 fail2:
217 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
218 mantis_pci_exit(mantis);
220 fail1:
221 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
222 kfree(mantis);
224 fail0:
225 return err;
228 static void hopper_pci_remove(struct pci_dev *pdev)
230 struct mantis_pci *mantis = pci_get_drvdata(pdev);
232 if (mantis) {
233 mantis_dvb_exit(mantis);
234 mantis_dma_exit(mantis);
235 mantis_i2c_exit(mantis);
236 mantis_pci_exit(mantis);
237 kfree(mantis);
239 return;
243 static const struct pci_device_id hopper_pci_table[] = {
244 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config,
245 NULL),
249 MODULE_DEVICE_TABLE(pci, hopper_pci_table);
251 static struct pci_driver hopper_pci_driver = {
252 .name = DRIVER_NAME,
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");