Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/moduleparam.h> |
| 3 | #include <linux/kernel.h> |
| 4 | #include <linux/pci.h> |
| 5 | #include <asm/irq.h> |
| 6 | #include <linux/interrupt.h> |
| 7 | |
| 8 | #include "dmxdev.h" |
| 9 | #include "dvbdev.h" |
| 10 | #include "dvb_demux.h" |
| 11 | #include "dvb_frontend.h" |
| 12 | #include "dvb_net.h" |
| 13 | |
| 14 | #include "mantis_common.h" |
| 15 | |
| 16 | #include "mantis_vp1033.h" |
| 17 | #include "mantis_vp1034.h" |
| 18 | #include "mantis_vp1041.h" |
| 19 | #include "mantis_vp2033.h" |
| 20 | #include "mantis_vp2040.h" |
| 21 | #include "mantis_vp3030.h" |
| 22 | |
| 23 | #include "mantis_dma.h" |
| 24 | #include "mantis_ca.h" |
| 25 | #include "mantis_dvb.h" |
| 26 | #include "mantis_uart.h" |
| 27 | #include "mantis_ioc.h" |
| 28 | #include "mantis_pci.h" |
| 29 | #include "mantis_i2c.h" |
| 30 | #include "mantis_reg.h" |
| 31 | |
| 32 | static unsigned int verbose; |
| 33 | module_param(verbose, int, 0644); |
| 34 | MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); |
| 35 | |
| 36 | static int devs; |
| 37 | |
| 38 | #define DRIVER_NAME "Mantis" |
| 39 | |
| 40 | static char *label[10] = { |
| 41 | "DMA", |
| 42 | "IRQ-0", |
| 43 | "IRQ-1", |
| 44 | "OCERR", |
| 45 | "PABRT", |
| 46 | "RIPRR", |
| 47 | "PPERR", |
| 48 | "FTRGT", |
| 49 | "RISCI", |
| 50 | "RACK" |
| 51 | }; |
| 52 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 53 | static irqreturn_t mantis_irq_handler(int irq, void *dev_id) |
| 54 | { |
| 55 | u32 stat = 0, mask = 0, lstat = 0, mstat = 0; |
| 56 | u32 rst_stat = 0, rst_mask = 0; |
| 57 | |
| 58 | struct mantis_pci *mantis; |
| 59 | struct mantis_ca *ca; |
| 60 | |
| 61 | mantis = (struct mantis_pci *) dev_id; |
| 62 | if (unlikely(mantis == NULL)) { |
| 63 | dprintk(MANTIS_ERROR, 1, "Mantis == NULL"); |
| 64 | return IRQ_NONE; |
| 65 | } |
| 66 | ca = mantis->mantis_ca; |
| 67 | |
| 68 | stat = mmread(MANTIS_INT_STAT); |
| 69 | mask = mmread(MANTIS_INT_MASK); |
| 70 | mstat = lstat = stat & ~MANTIS_INT_RISCSTAT; |
| 71 | if (!(stat & mask)) |
| 72 | return IRQ_NONE; |
| 73 | |
| 74 | rst_mask = MANTIS_GPIF_WRACK | |
| 75 | MANTIS_GPIF_OTHERR | |
| 76 | MANTIS_SBUF_WSTO | |
| 77 | MANTIS_GPIF_EXTIRQ; |
| 78 | |
| 79 | rst_stat = mmread(MANTIS_GPIF_STATUS); |
| 80 | rst_stat &= rst_mask; |
| 81 | mmwrite(rst_stat, MANTIS_GPIF_STATUS); |
| 82 | |
| 83 | mantis->mantis_int_stat = stat; |
| 84 | mantis->mantis_int_mask = mask; |
| 85 | dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask); |
| 86 | if (stat & MANTIS_INT_RISCEN) { |
| 87 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]); |
| 88 | } |
| 89 | if (stat & MANTIS_INT_IRQ0) { |
| 90 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]); |
| 91 | mantis->gpif_status = rst_stat; |
| 92 | wake_up(&ca->hif_write_wq); |
| 93 | schedule_work(&ca->hif_evm_work); |
| 94 | } |
| 95 | if (stat & MANTIS_INT_IRQ1) { |
| 96 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); |
| 97 | schedule_work(&mantis->uart_work); |
| 98 | } |
| 99 | if (stat & MANTIS_INT_OCERR) { |
| 100 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]); |
| 101 | } |
| 102 | if (stat & MANTIS_INT_PABORT) { |
| 103 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]); |
| 104 | } |
| 105 | if (stat & MANTIS_INT_RIPERR) { |
| 106 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]); |
| 107 | } |
| 108 | if (stat & MANTIS_INT_PPERR) { |
| 109 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]); |
| 110 | } |
| 111 | if (stat & MANTIS_INT_FTRGT) { |
| 112 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]); |
| 113 | } |
| 114 | if (stat & MANTIS_INT_RISCI) { |
| 115 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]); |
| 116 | mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28; |
| 117 | tasklet_schedule(&mantis->tasklet); |
| 118 | } |
| 119 | if (stat & MANTIS_INT_I2CDONE) { |
| 120 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]); |
| 121 | wake_up(&mantis->i2c_wq); |
| 122 | } |
| 123 | mmwrite(stat, MANTIS_INT_STAT); |
| 124 | stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | |
| 125 | MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 | |
| 126 | MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 | |
| 127 | MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 | |
| 128 | MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 | |
| 129 | MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 | |
| 130 | MANTIS_INT_IRQ0 | MANTIS_INT_OCERR | |
| 131 | MANTIS_INT_PABORT | MANTIS_INT_RIPERR | |
| 132 | MANTIS_INT_PPERR | MANTIS_INT_FTRGT | |
| 133 | MANTIS_INT_RISCI); |
| 134 | |
| 135 | if (stat) |
| 136 | dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask); |
| 137 | |
| 138 | dprintk(MANTIS_DEBUG, 0, "\n"); |
| 139 | return IRQ_HANDLED; |
| 140 | } |
| 141 | |
| 142 | static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) |
| 143 | { |
| 144 | struct mantis_pci *mantis; |
| 145 | struct mantis_hwconfig *config; |
| 146 | int err = 0; |
| 147 | |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame^] | 148 | mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 149 | if (mantis == NULL) { |
| 150 | printk(KERN_ERR "%s ERROR: Out of memory\n", __func__); |
| 151 | err = -ENOMEM; |
| 152 | goto fail0; |
| 153 | } |
| 154 | |
| 155 | mantis->num = devs; |
| 156 | mantis->verbose = verbose; |
| 157 | mantis->pdev = pdev; |
| 158 | config = (struct mantis_hwconfig *) pci_id->driver_data; |
| 159 | config->irq_handler = &mantis_irq_handler; |
| 160 | mantis->hwconfig = config; |
| 161 | |
| 162 | err = mantis_pci_init(mantis); |
| 163 | if (err) { |
| 164 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); |
| 165 | goto fail1; |
| 166 | } |
| 167 | |
| 168 | err = mantis_stream_control(mantis, STREAM_TO_HIF); |
| 169 | if (err < 0) { |
| 170 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); |
| 171 | goto fail1; |
| 172 | } |
| 173 | |
| 174 | err = mantis_i2c_init(mantis); |
| 175 | if (err < 0) { |
| 176 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); |
| 177 | goto fail2; |
| 178 | } |
| 179 | |
| 180 | err = mantis_get_mac(mantis); |
| 181 | if (err < 0) { |
| 182 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); |
| 183 | goto fail2; |
| 184 | } |
| 185 | |
| 186 | err = mantis_dma_init(mantis); |
| 187 | if (err < 0) { |
| 188 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); |
| 189 | goto fail3; |
| 190 | } |
| 191 | |
| 192 | err = mantis_dvb_init(mantis); |
| 193 | if (err < 0) { |
| 194 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); |
| 195 | goto fail4; |
| 196 | } |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 197 | err = mantis_uart_init(mantis); |
| 198 | if (err < 0) { |
| 199 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err); |
| 200 | goto fail6; |
| 201 | } |
| 202 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 203 | devs++; |
| 204 | |
| 205 | return err; |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 206 | |
| 207 | |
| 208 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err); |
| 209 | mantis_uart_exit(mantis); |
| 210 | |
| 211 | fail6: |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 212 | fail4: |
| 213 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err); |
| 214 | mantis_dma_exit(mantis); |
| 215 | |
| 216 | fail3: |
| 217 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err); |
| 218 | mantis_i2c_exit(mantis); |
| 219 | |
| 220 | fail2: |
| 221 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err); |
| 222 | mantis_pci_exit(mantis); |
| 223 | |
| 224 | fail1: |
| 225 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err); |
| 226 | kfree(mantis); |
| 227 | |
| 228 | fail0: |
| 229 | return err; |
| 230 | } |
| 231 | |
| 232 | static void __devexit mantis_pci_remove(struct pci_dev *pdev) |
| 233 | { |
| 234 | struct mantis_pci *mantis = pci_get_drvdata(pdev); |
| 235 | |
| 236 | if (mantis) { |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 237 | |
| 238 | mantis_uart_exit(mantis); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 239 | mantis_dvb_exit(mantis); |
| 240 | mantis_dma_exit(mantis); |
| 241 | mantis_i2c_exit(mantis); |
| 242 | mantis_pci_exit(mantis); |
| 243 | kfree(mantis); |
| 244 | } |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | static struct pci_device_id mantis_pci_table[] = { |
| 249 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config), |
| 250 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config), |
| 251 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config), |
| 252 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config), |
| 253 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config), |
| 254 | MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config), |
| 255 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config), |
| 256 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config), |
| 257 | MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config), |
| 258 | MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config), |
| 259 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config), |
| 260 | { } |
| 261 | }; |
| 262 | |
| 263 | static struct pci_driver mantis_pci_driver = { |
| 264 | .name = DRIVER_NAME, |
| 265 | .id_table = mantis_pci_table, |
| 266 | .probe = mantis_pci_probe, |
| 267 | .remove = mantis_pci_remove, |
| 268 | }; |
| 269 | |
| 270 | static int __devinit mantis_init(void) |
| 271 | { |
| 272 | return pci_register_driver(&mantis_pci_driver); |
| 273 | } |
| 274 | |
| 275 | static void __devexit mantis_exit(void) |
| 276 | { |
| 277 | return pci_unregister_driver(&mantis_pci_driver); |
| 278 | } |
| 279 | |
| 280 | module_init(mantis_init); |
| 281 | module_exit(mantis_exit); |
| 282 | |
| 283 | MODULE_DESCRIPTION("MANTIS driver"); |
| 284 | MODULE_AUTHOR("Manu Abraham"); |
| 285 | MODULE_LICENSE("GPL"); |