1 #include <linux/module.h>
2 #include <linux/moduleparam.h>
3 #include <linux/kernel.h>
6 #include <linux/interrupt.h>
10 #include "dvb_demux.h"
11 #include "dvb_frontend.h"
14 #include "mantis_common.h"
15 #include "hopper_vp3028.h"
16 #include "mantis_dma.h"
17 #include "mantis_dvb.h"
18 #include "mantis_uart.h"
19 #include "mantis_ioc.h"
20 #include "mantis_pci.h"
21 #include "mantis_i2c.h"
22 #include "mantis_reg.h"
24 static unsigned int verbose;
25 module_param(verbose, int, 0644);
26 MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
28 #define DRIVER_NAME "Hopper"
30 static char *label[10] = {
45 static irqreturn_t hopper_irq_handler(int irq, void *dev_id)
47 u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
48 u32 rst_stat = 0, rst_mask = 0;
50 struct mantis_pci *mantis;
53 mantis = (struct mantis_pci *) dev_id;
54 if (unlikely(mantis == NULL)) {
55 dprintk(MANTIS_ERROR, 1, "Mantis == NULL");
58 ca = mantis->mantis_ca;
60 stat = mmread(MANTIS_INT_STAT);
61 mask = mmread(MANTIS_INT_MASK);
62 mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
66 rst_mask = MANTIS_GPIF_WRACK |
71 rst_stat = mmread(MANTIS_GPIF_STATUS);
73 mmwrite(rst_stat, MANTIS_GPIF_STATUS);
75 mantis->mantis_int_stat = stat;
76 mantis->mantis_int_mask = mask;
77 dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
78 if (stat & MANTIS_INT_RISCEN) {
79 dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
81 if (stat & MANTIS_INT_IRQ0) {
82 dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
83 mantis->gpif_status = rst_stat;
84 wake_up(&ca->hif_write_wq);
85 schedule_work(&ca->hif_evm_work);
87 if (stat & MANTIS_INT_IRQ1) {
88 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
89 schedule_work(&mantis->uart_work);
91 if (stat & MANTIS_INT_OCERR) {
92 dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
94 if (stat & MANTIS_INT_PABORT) {
95 dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
97 if (stat & MANTIS_INT_RIPERR) {
98 dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
100 if (stat & MANTIS_INT_PPERR) {
101 dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
103 if (stat & MANTIS_INT_FTRGT) {
104 dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
106 if (stat & MANTIS_INT_RISCI) {
107 dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
108 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
109 tasklet_schedule(&mantis->tasklet);
111 if (stat & MANTIS_INT_I2CDONE) {
112 dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
113 wake_up(&mantis->i2c_wq);
115 mmwrite(stat, MANTIS_INT_STAT);
116 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
117 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
118 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
119 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
120 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
121 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
122 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
123 MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
124 MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
128 dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
130 dprintk(MANTIS_DEBUG, 0, "\n");
134 static int __devinit hopper_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
136 struct mantis_pci *mantis;
137 struct mantis_hwconfig *config;
140 mantis = kzalloc(sizeof (struct mantis_pci), GFP_KERNEL);
141 if (mantis == NULL) {
142 printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
148 mantis->verbose = verbose;
150 config = (struct mantis_hwconfig *) pci_id->driver_data;
151 config->irq_handler = &hopper_irq_handler;
152 mantis->hwconfig = config;
154 err = mantis_pci_init(mantis);
156 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
160 err = mantis_stream_control(mantis, STREAM_TO_HIF);
162 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
166 err = mantis_i2c_init(mantis);
168 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
172 err = mantis_get_mac(mantis);
174 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
178 err = mantis_dma_init(mantis);
180 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
184 err = mantis_dvb_init(mantis);
186 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
194 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err);
195 mantis_dvb_exit(mantis);
198 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
199 mantis_dma_exit(mantis);
202 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
203 mantis_i2c_exit(mantis);
206 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
207 mantis_pci_exit(mantis);
210 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
217 static void __devexit hopper_pci_remove(struct pci_dev *pdev)
219 struct mantis_pci *mantis = pci_get_drvdata(pdev);
222 mantis_dvb_exit(mantis);
223 mantis_dma_exit(mantis);
224 mantis_i2c_exit(mantis);
225 mantis_pci_exit(mantis);
232 static struct pci_device_id hopper_pci_table[] = {
233 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config),
237 static struct pci_driver hopper_pci_driver = {
239 .id_table = hopper_pci_table,
240 .probe = hopper_pci_probe,
241 .remove = hopper_pci_remove,
244 static int __devinit hopper_init(void)
246 return pci_register_driver(&hopper_pci_driver);
249 static void __devexit hopper_exit(void)
251 return pci_unregister_driver(&hopper_pci_driver);
254 module_init(hopper_init);
255 module_exit(hopper_exit);
257 MODULE_DESCRIPTION("HOPPER driver");
258 MODULE_AUTHOR("Manu Abraham");
259 MODULE_LICENSE("GPL");