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 | |
| 53 | |
| 54 | static irqreturn_t mantis_irq_handler(int irq, void *dev_id) |
| 55 | { |
| 56 | u32 stat = 0, mask = 0, lstat = 0, mstat = 0; |
| 57 | u32 rst_stat = 0, rst_mask = 0; |
| 58 | |
| 59 | struct mantis_pci *mantis; |
| 60 | struct mantis_ca *ca; |
| 61 | |
| 62 | mantis = (struct mantis_pci *) dev_id; |
| 63 | if (unlikely(mantis == NULL)) { |
| 64 | dprintk(MANTIS_ERROR, 1, "Mantis == NULL"); |
| 65 | return IRQ_NONE; |
| 66 | } |
| 67 | ca = mantis->mantis_ca; |
| 68 | |
| 69 | stat = mmread(MANTIS_INT_STAT); |
| 70 | mask = mmread(MANTIS_INT_MASK); |
| 71 | mstat = lstat = stat & ~MANTIS_INT_RISCSTAT; |
| 72 | if (!(stat & mask)) |
| 73 | return IRQ_NONE; |
| 74 | |
| 75 | rst_mask = MANTIS_GPIF_WRACK | |
| 76 | MANTIS_GPIF_OTHERR | |
| 77 | MANTIS_SBUF_WSTO | |
| 78 | MANTIS_GPIF_EXTIRQ; |
| 79 | |
| 80 | rst_stat = mmread(MANTIS_GPIF_STATUS); |
| 81 | rst_stat &= rst_mask; |
| 82 | mmwrite(rst_stat, MANTIS_GPIF_STATUS); |
| 83 | |
| 84 | mantis->mantis_int_stat = stat; |
| 85 | mantis->mantis_int_mask = mask; |
| 86 | dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask); |
| 87 | if (stat & MANTIS_INT_RISCEN) { |
| 88 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]); |
| 89 | } |
| 90 | if (stat & MANTIS_INT_IRQ0) { |
| 91 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]); |
| 92 | mantis->gpif_status = rst_stat; |
| 93 | wake_up(&ca->hif_write_wq); |
| 94 | schedule_work(&ca->hif_evm_work); |
| 95 | } |
| 96 | if (stat & MANTIS_INT_IRQ1) { |
| 97 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); |
| 98 | schedule_work(&mantis->uart_work); |
| 99 | } |
| 100 | if (stat & MANTIS_INT_OCERR) { |
| 101 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]); |
| 102 | } |
| 103 | if (stat & MANTIS_INT_PABORT) { |
| 104 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]); |
| 105 | } |
| 106 | if (stat & MANTIS_INT_RIPERR) { |
| 107 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]); |
| 108 | } |
| 109 | if (stat & MANTIS_INT_PPERR) { |
| 110 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]); |
| 111 | } |
| 112 | if (stat & MANTIS_INT_FTRGT) { |
| 113 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]); |
| 114 | } |
| 115 | if (stat & MANTIS_INT_RISCI) { |
| 116 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]); |
| 117 | mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28; |
| 118 | tasklet_schedule(&mantis->tasklet); |
| 119 | } |
| 120 | if (stat & MANTIS_INT_I2CDONE) { |
| 121 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]); |
| 122 | wake_up(&mantis->i2c_wq); |
| 123 | } |
| 124 | mmwrite(stat, MANTIS_INT_STAT); |
| 125 | stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | |
| 126 | MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 | |
| 127 | MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 | |
| 128 | MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 | |
| 129 | MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 | |
| 130 | MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 | |
| 131 | MANTIS_INT_IRQ0 | MANTIS_INT_OCERR | |
| 132 | MANTIS_INT_PABORT | MANTIS_INT_RIPERR | |
| 133 | MANTIS_INT_PPERR | MANTIS_INT_FTRGT | |
| 134 | MANTIS_INT_RISCI); |
| 135 | |
| 136 | if (stat) |
| 137 | dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask); |
| 138 | |
| 139 | dprintk(MANTIS_DEBUG, 0, "\n"); |
| 140 | return IRQ_HANDLED; |
| 141 | } |
| 142 | |
| 143 | static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) |
| 144 | { |
| 145 | struct mantis_pci *mantis; |
| 146 | struct mantis_hwconfig *config; |
| 147 | int err = 0; |
| 148 | |
| 149 | mantis = kzalloc(sizeof (struct mantis_pci), GFP_KERNEL); |
| 150 | if (mantis == NULL) { |
| 151 | printk(KERN_ERR "%s ERROR: Out of memory\n", __func__); |
| 152 | err = -ENOMEM; |
| 153 | goto fail0; |
| 154 | } |
| 155 | |
| 156 | mantis->num = devs; |
| 157 | mantis->verbose = verbose; |
| 158 | mantis->pdev = pdev; |
| 159 | config = (struct mantis_hwconfig *) pci_id->driver_data; |
| 160 | config->irq_handler = &mantis_irq_handler; |
| 161 | mantis->hwconfig = config; |
| 162 | |
| 163 | err = mantis_pci_init(mantis); |
| 164 | if (err) { |
| 165 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); |
| 166 | goto fail1; |
| 167 | } |
| 168 | |
| 169 | err = mantis_stream_control(mantis, STREAM_TO_HIF); |
| 170 | if (err < 0) { |
| 171 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); |
| 172 | goto fail1; |
| 173 | } |
| 174 | |
| 175 | err = mantis_i2c_init(mantis); |
| 176 | if (err < 0) { |
| 177 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); |
| 178 | goto fail2; |
| 179 | } |
| 180 | |
| 181 | err = mantis_get_mac(mantis); |
| 182 | if (err < 0) { |
| 183 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); |
| 184 | goto fail2; |
| 185 | } |
| 186 | |
| 187 | err = mantis_dma_init(mantis); |
| 188 | if (err < 0) { |
| 189 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); |
| 190 | goto fail3; |
| 191 | } |
| 192 | |
| 193 | err = mantis_dvb_init(mantis); |
| 194 | if (err < 0) { |
| 195 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); |
| 196 | goto fail4; |
| 197 | } |
| 198 | devs++; |
| 199 | |
| 200 | return err; |
| 201 | |
| 202 | fail5: |
| 203 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB exit! <%d>", err); |
| 204 | mantis_dvb_exit(mantis); |
| 205 | |
| 206 | fail4: |
| 207 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err); |
| 208 | mantis_dma_exit(mantis); |
| 209 | |
| 210 | fail3: |
| 211 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err); |
| 212 | mantis_i2c_exit(mantis); |
| 213 | |
| 214 | fail2: |
| 215 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err); |
| 216 | mantis_pci_exit(mantis); |
| 217 | |
| 218 | fail1: |
| 219 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err); |
| 220 | kfree(mantis); |
| 221 | |
| 222 | fail0: |
| 223 | return err; |
| 224 | } |
| 225 | |
| 226 | static void __devexit mantis_pci_remove(struct pci_dev *pdev) |
| 227 | { |
| 228 | struct mantis_pci *mantis = pci_get_drvdata(pdev); |
| 229 | |
| 230 | if (mantis) { |
| 231 | mantis_uart_exit(mantis); |
| 232 | // mantis_ca_exit(mantis); |
| 233 | mantis_dvb_exit(mantis); |
| 234 | mantis_dma_exit(mantis); |
| 235 | mantis_i2c_exit(mantis); |
| 236 | mantis_pci_exit(mantis); |
| 237 | kfree(mantis); |
| 238 | } |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | static struct pci_device_id mantis_pci_table[] = { |
| 243 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config), |
| 244 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config), |
| 245 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config), |
| 246 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config), |
| 247 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config), |
| 248 | MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config), |
| 249 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config), |
| 250 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config), |
| 251 | MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config), |
| 252 | MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config), |
| 253 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config), |
| 254 | { } |
| 255 | }; |
| 256 | |
| 257 | static struct pci_driver mantis_pci_driver = { |
| 258 | .name = DRIVER_NAME, |
| 259 | .id_table = mantis_pci_table, |
| 260 | .probe = mantis_pci_probe, |
| 261 | .remove = mantis_pci_remove, |
| 262 | }; |
| 263 | |
| 264 | static int __devinit mantis_init(void) |
| 265 | { |
| 266 | return pci_register_driver(&mantis_pci_driver); |
| 267 | } |
| 268 | |
| 269 | static void __devexit mantis_exit(void) |
| 270 | { |
| 271 | return pci_unregister_driver(&mantis_pci_driver); |
| 272 | } |
| 273 | |
| 274 | module_init(mantis_init); |
| 275 | module_exit(mantis_exit); |
| 276 | |
| 277 | MODULE_DESCRIPTION("MANTIS driver"); |
| 278 | MODULE_AUTHOR("Manu Abraham"); |
| 279 | MODULE_LICENSE("GPL"); |