1 /* 2 Mantis PCI bridge driver 3 4 Copyright (C) Manu Abraham (abraham.manu@gmail.com) 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #include <linux/module.h> 22 #include <linux/kernel.h> 23 #include <linux/pci.h> 24 #include <linux/slab.h> 25 #include <asm/irq.h> 26 #include <linux/interrupt.h> 27 #include <media/rc-map.h> 28 29 #include <media/dmxdev.h> 30 #include <media/dvbdev.h> 31 #include <media/dvb_demux.h> 32 #include <media/dvb_frontend.h> 33 #include <media/dvb_net.h> 34 35 #include "mantis_common.h" 36 37 #include "mantis_vp1033.h" 38 #include "mantis_vp1034.h" 39 #include "mantis_vp1041.h" 40 #include "mantis_vp2033.h" 41 #include "mantis_vp2040.h" 42 #include "mantis_vp3030.h" 43 44 #include "mantis_dma.h" 45 #include "mantis_ca.h" 46 #include "mantis_dvb.h" 47 #include "mantis_uart.h" 48 #include "mantis_ioc.h" 49 #include "mantis_pci.h" 50 #include "mantis_i2c.h" 51 #include "mantis_reg.h" 52 #include "mantis_input.h" 53 54 static unsigned int verbose; 55 module_param(verbose, int, 0644); 56 MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)"); 57 58 static int devs; 59 60 #define DRIVER_NAME "Mantis" 61 62 static char *label[10] = { 63 "DMA", 64 "IRQ-0", 65 "IRQ-1", 66 "OCERR", 67 "PABRT", 68 "RIPRR", 69 "PPERR", 70 "FTRGT", 71 "RISCI", 72 "RACK" 73 }; 74 75 static irqreturn_t mantis_irq_handler(int irq, void *dev_id) 76 { 77 u32 stat = 0, mask = 0; 78 u32 rst_stat = 0, rst_mask = 0; 79 80 struct mantis_pci *mantis; 81 struct mantis_ca *ca; 82 83 mantis = (struct mantis_pci *) dev_id; 84 if (unlikely(mantis == NULL)) { 85 dprintk(MANTIS_ERROR, 1, "Mantis == NULL"); 86 return IRQ_NONE; 87 } 88 ca = mantis->mantis_ca; 89 90 stat = mmread(MANTIS_INT_STAT); 91 mask = mmread(MANTIS_INT_MASK); 92 if (!(stat & mask)) 93 return IRQ_NONE; 94 95 rst_mask = MANTIS_GPIF_WRACK | 96 MANTIS_GPIF_OTHERR | 97 MANTIS_SBUF_WSTO | 98 MANTIS_GPIF_EXTIRQ; 99 100 rst_stat = mmread(MANTIS_GPIF_STATUS); 101 rst_stat &= rst_mask; 102 mmwrite(rst_stat, MANTIS_GPIF_STATUS); 103 104 mantis->mantis_int_stat = stat; 105 mantis->mantis_int_mask = mask; 106 dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask); 107 if (stat & MANTIS_INT_RISCEN) { 108 dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]); 109 } 110 if (stat & MANTIS_INT_IRQ0) { 111 dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]); 112 mantis->gpif_status = rst_stat; 113 wake_up(&ca->hif_write_wq); 114 schedule_work(&ca->hif_evm_work); 115 } 116 if (stat & MANTIS_INT_IRQ1) { 117 dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); 118 spin_lock(&mantis->intmask_lock); 119 mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1, 120 MANTIS_INT_MASK); 121 spin_unlock(&mantis->intmask_lock); 122 schedule_work(&mantis->uart_work); 123 } 124 if (stat & MANTIS_INT_OCERR) { 125 dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]); 126 } 127 if (stat & MANTIS_INT_PABORT) { 128 dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]); 129 } 130 if (stat & MANTIS_INT_RIPERR) { 131 dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]); 132 } 133 if (stat & MANTIS_INT_PPERR) { 134 dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]); 135 } 136 if (stat & MANTIS_INT_FTRGT) { 137 dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]); 138 } 139 if (stat & MANTIS_INT_RISCI) { 140 dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]); 141 mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28; 142 tasklet_schedule(&mantis->tasklet); 143 } 144 if (stat & MANTIS_INT_I2CDONE) { 145 dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]); 146 wake_up(&mantis->i2c_wq); 147 } 148 mmwrite(stat, MANTIS_INT_STAT); 149 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | 150 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 | 151 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 | 152 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 | 153 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 | 154 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 | 155 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR | 156 MANTIS_INT_PABORT | MANTIS_INT_RIPERR | 157 MANTIS_INT_PPERR | MANTIS_INT_FTRGT | 158 MANTIS_INT_RISCI); 159 160 if (stat) 161 dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask); 162 163 dprintk(MANTIS_DEBUG, 0, "\n"); 164 return IRQ_HANDLED; 165 } 166 167 static int mantis_pci_probe(struct pci_dev *pdev, 168 const struct pci_device_id *pci_id) 169 { 170 struct mantis_pci_drvdata *drvdata; 171 struct mantis_pci *mantis; 172 struct mantis_hwconfig *config; 173 int err; 174 175 mantis = kzalloc(sizeof(*mantis), GFP_KERNEL); 176 if (!mantis) 177 return -ENOMEM; 178 179 drvdata = (void *)pci_id->driver_data; 180 mantis->num = devs; 181 mantis->verbose = verbose; 182 mantis->pdev = pdev; 183 config = drvdata->hwconfig; 184 config->irq_handler = &mantis_irq_handler; 185 mantis->hwconfig = config; 186 mantis->rc_map_name = drvdata->rc_map_name; 187 188 spin_lock_init(&mantis->intmask_lock); 189 190 err = mantis_pci_init(mantis); 191 if (err) { 192 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); 193 goto err_free_mantis; 194 } 195 196 err = mantis_stream_control(mantis, STREAM_TO_HIF); 197 if (err < 0) { 198 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); 199 goto err_pci_exit; 200 } 201 202 err = mantis_i2c_init(mantis); 203 if (err < 0) { 204 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); 205 goto err_pci_exit; 206 } 207 208 err = mantis_get_mac(mantis); 209 if (err < 0) { 210 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); 211 goto err_i2c_exit; 212 } 213 214 err = mantis_dma_init(mantis); 215 if (err < 0) { 216 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); 217 goto err_i2c_exit; 218 } 219 220 err = mantis_dvb_init(mantis); 221 if (err < 0) { 222 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); 223 goto err_dma_exit; 224 } 225 226 err = mantis_input_init(mantis); 227 if (err < 0) { 228 dprintk(MANTIS_ERROR, 1, 229 "ERROR: Mantis DVB initialization failed <%d>", err); 230 goto err_dvb_exit; 231 } 232 233 err = mantis_uart_init(mantis); 234 if (err < 0) { 235 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err); 236 goto err_input_exit; 237 } 238 239 devs++; 240 241 return 0; 242 243 err_input_exit: 244 mantis_input_exit(mantis); 245 246 err_dvb_exit: 247 mantis_dvb_exit(mantis); 248 249 err_dma_exit: 250 mantis_dma_exit(mantis); 251 252 err_i2c_exit: 253 mantis_i2c_exit(mantis); 254 255 err_pci_exit: 256 mantis_pci_exit(mantis); 257 258 err_free_mantis: 259 kfree(mantis); 260 261 return err; 262 } 263 264 static void mantis_pci_remove(struct pci_dev *pdev) 265 { 266 struct mantis_pci *mantis = pci_get_drvdata(pdev); 267 268 if (mantis) { 269 270 mantis_uart_exit(mantis); 271 mantis_input_exit(mantis); 272 mantis_dvb_exit(mantis); 273 mantis_dma_exit(mantis); 274 mantis_i2c_exit(mantis); 275 mantis_pci_exit(mantis); 276 kfree(mantis); 277 } 278 return; 279 } 280 281 static const struct pci_device_id mantis_pci_table[] = { 282 MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config, 283 RC_MAP_TECHNISAT_TS35), 284 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config, 285 NULL), 286 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config, 287 NULL), 288 MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config, 289 RC_MAP_TERRATEC_CINERGY_C_PCI), 290 MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config, 291 RC_MAP_TERRATEC_CINERGY_S2_HD), 292 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config, 293 NULL), 294 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config, 295 NULL), 296 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config, 297 RC_MAP_TWINHAN_DTV_CAB_CI), 298 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config, 299 RC_MAP_TWINHAN_DTV_CAB_CI), 300 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config, 301 NULL), 302 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config, 303 NULL), 304 { } 305 }; 306 307 MODULE_DEVICE_TABLE(pci, mantis_pci_table); 308 309 static struct pci_driver mantis_pci_driver = { 310 .name = DRIVER_NAME, 311 .id_table = mantis_pci_table, 312 .probe = mantis_pci_probe, 313 .remove = mantis_pci_remove, 314 }; 315 316 module_pci_driver(mantis_pci_driver); 317 318 MODULE_DESCRIPTION("MANTIS driver"); 319 MODULE_AUTHOR("Manu Abraham"); 320 MODULE_LICENSE("GPL"); 321