Manu Abraham | 8825a09 | 2009-12-15 09:13:49 -0300 | [diff] [blame] | 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 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 26 | #include <asm/irq.h> |
| 27 | #include <linux/interrupt.h> |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 28 | #include <media/rc-map.h> |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 29 | |
| 30 | #include "dmxdev.h" |
| 31 | #include "dvbdev.h" |
| 32 | #include "dvb_demux.h" |
| 33 | #include "dvb_frontend.h" |
| 34 | #include "dvb_net.h" |
| 35 | |
| 36 | #include "mantis_common.h" |
| 37 | |
| 38 | #include "mantis_vp1033.h" |
| 39 | #include "mantis_vp1034.h" |
| 40 | #include "mantis_vp1041.h" |
| 41 | #include "mantis_vp2033.h" |
| 42 | #include "mantis_vp2040.h" |
| 43 | #include "mantis_vp3030.h" |
| 44 | |
| 45 | #include "mantis_dma.h" |
| 46 | #include "mantis_ca.h" |
| 47 | #include "mantis_dvb.h" |
| 48 | #include "mantis_uart.h" |
| 49 | #include "mantis_ioc.h" |
| 50 | #include "mantis_pci.h" |
| 51 | #include "mantis_i2c.h" |
| 52 | #include "mantis_reg.h" |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 53 | #include "mantis_input.h" |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 54 | |
| 55 | static unsigned int verbose; |
| 56 | module_param(verbose, int, 0644); |
Bjørn Mork | 0618ece | 2011-03-22 10:22:17 -0300 | [diff] [blame] | 57 | MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)"); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 58 | |
| 59 | static int devs; |
| 60 | |
| 61 | #define DRIVER_NAME "Mantis" |
| 62 | |
| 63 | static char *label[10] = { |
| 64 | "DMA", |
| 65 | "IRQ-0", |
| 66 | "IRQ-1", |
| 67 | "OCERR", |
| 68 | "PABRT", |
| 69 | "RIPRR", |
| 70 | "PPERR", |
| 71 | "FTRGT", |
| 72 | "RISCI", |
| 73 | "RACK" |
| 74 | }; |
| 75 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 76 | static irqreturn_t mantis_irq_handler(int irq, void *dev_id) |
| 77 | { |
Hans Verkuil | 5becbc5 | 2012-05-14 10:22:58 -0300 | [diff] [blame] | 78 | u32 stat = 0, mask = 0; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 79 | u32 rst_stat = 0, rst_mask = 0; |
| 80 | |
| 81 | struct mantis_pci *mantis; |
| 82 | struct mantis_ca *ca; |
| 83 | |
| 84 | mantis = (struct mantis_pci *) dev_id; |
| 85 | if (unlikely(mantis == NULL)) { |
| 86 | dprintk(MANTIS_ERROR, 1, "Mantis == NULL"); |
| 87 | return IRQ_NONE; |
| 88 | } |
| 89 | ca = mantis->mantis_ca; |
| 90 | |
| 91 | stat = mmread(MANTIS_INT_STAT); |
| 92 | mask = mmread(MANTIS_INT_MASK); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 93 | if (!(stat & mask)) |
| 94 | return IRQ_NONE; |
| 95 | |
| 96 | rst_mask = MANTIS_GPIF_WRACK | |
| 97 | MANTIS_GPIF_OTHERR | |
| 98 | MANTIS_SBUF_WSTO | |
| 99 | MANTIS_GPIF_EXTIRQ; |
| 100 | |
| 101 | rst_stat = mmread(MANTIS_GPIF_STATUS); |
| 102 | rst_stat &= rst_mask; |
| 103 | mmwrite(rst_stat, MANTIS_GPIF_STATUS); |
| 104 | |
| 105 | mantis->mantis_int_stat = stat; |
| 106 | mantis->mantis_int_mask = mask; |
| 107 | dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask); |
| 108 | if (stat & MANTIS_INT_RISCEN) { |
| 109 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]); |
| 110 | } |
| 111 | if (stat & MANTIS_INT_IRQ0) { |
| 112 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]); |
| 113 | mantis->gpif_status = rst_stat; |
| 114 | wake_up(&ca->hif_write_wq); |
| 115 | schedule_work(&ca->hif_evm_work); |
| 116 | } |
| 117 | if (stat & MANTIS_INT_IRQ1) { |
| 118 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 119 | spin_lock(&mantis->intmask_lock); |
| 120 | mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1, MANTIS_INT_MASK); |
| 121 | spin_unlock(&mantis->intmask_lock); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 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]); |
Marko Ristola | 79d06d4 | 2010-08-07 08:16:15 -0300 | [diff] [blame] | 141 | mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 167 | static int mantis_pci_probe(struct pci_dev *pdev, |
| 168 | const struct pci_device_id *pci_id) |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 169 | { |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 170 | struct mantis_pci_drvdata *drvdata; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 171 | struct mantis_pci *mantis; |
| 172 | struct mantis_hwconfig *config; |
| 173 | int err = 0; |
| 174 | |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 175 | mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 176 | if (mantis == NULL) { |
| 177 | printk(KERN_ERR "%s ERROR: Out of memory\n", __func__); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 178 | return -ENOMEM; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 179 | } |
| 180 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 181 | drvdata = (struct mantis_pci_drvdata *) pci_id->driver_data; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 182 | mantis->num = devs; |
| 183 | mantis->verbose = verbose; |
| 184 | mantis->pdev = pdev; |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 185 | config = drvdata->hwconfig; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 186 | config->irq_handler = &mantis_irq_handler; |
| 187 | mantis->hwconfig = config; |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 188 | mantis->rc_map_name = drvdata->rc_map_name; |
| 189 | |
| 190 | spin_lock_init(&mantis->intmask_lock); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 191 | |
| 192 | err = mantis_pci_init(mantis); |
| 193 | if (err) { |
| 194 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 195 | goto err_free_mantis; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | err = mantis_stream_control(mantis, STREAM_TO_HIF); |
| 199 | if (err < 0) { |
| 200 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 201 | goto err_pci_exit; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | err = mantis_i2c_init(mantis); |
| 205 | if (err < 0) { |
| 206 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 207 | goto err_pci_exit; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | err = mantis_get_mac(mantis); |
| 211 | if (err < 0) { |
| 212 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 213 | goto err_i2c_exit; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | err = mantis_dma_init(mantis); |
| 217 | if (err < 0) { |
| 218 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 219 | goto err_i2c_exit; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | err = mantis_dvb_init(mantis); |
| 223 | if (err < 0) { |
| 224 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 225 | goto err_dma_exit; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 226 | } |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 227 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 228 | err = mantis_input_init(mantis); |
| 229 | if (err < 0) { |
| 230 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); |
| 231 | goto err_dvb_exit; |
| 232 | } |
| 233 | |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 234 | err = mantis_uart_init(mantis); |
| 235 | if (err < 0) { |
| 236 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err); |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 237 | goto err_input_exit; |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 238 | } |
| 239 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 240 | devs++; |
| 241 | |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 242 | return 0; |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 243 | |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 244 | err_input_exit: |
| 245 | mantis_input_exit(mantis); |
| 246 | |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 247 | err_dvb_exit: |
| 248 | mantis_dvb_exit(mantis); |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 249 | |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 250 | err_dma_exit: |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 251 | mantis_dma_exit(mantis); |
| 252 | |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 253 | err_i2c_exit: |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 254 | mantis_i2c_exit(mantis); |
| 255 | |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 256 | err_pci_exit: |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 257 | mantis_pci_exit(mantis); |
| 258 | |
Silvan Jegen | b2624ff | 2015-03-23 13:25:53 -0300 | [diff] [blame] | 259 | err_free_mantis: |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 260 | kfree(mantis); |
| 261 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 262 | return err; |
| 263 | } |
| 264 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 265 | static void mantis_pci_remove(struct pci_dev *pdev) |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 266 | { |
| 267 | struct mantis_pci *mantis = pci_get_drvdata(pdev); |
| 268 | |
| 269 | if (mantis) { |
Manu Abraham | a149735 | 2009-12-11 20:41:07 -0300 | [diff] [blame] | 270 | |
| 271 | mantis_uart_exit(mantis); |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 272 | mantis_input_exit(mantis); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 273 | mantis_dvb_exit(mantis); |
| 274 | mantis_dma_exit(mantis); |
| 275 | mantis_i2c_exit(mantis); |
| 276 | mantis_pci_exit(mantis); |
| 277 | kfree(mantis); |
| 278 | } |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | static struct pci_device_id mantis_pci_table[] = { |
Jan Klötzke | a96762d | 2015-06-06 16:58:13 -0300 | [diff] [blame^] | 283 | MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config, |
| 284 | RC_MAP_TECHNISAT_TS35), |
| 285 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config, |
| 286 | NULL), |
| 287 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config, |
| 288 | NULL), |
| 289 | MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2040_config, |
| 290 | RC_MAP_TERRATEC_CINERGY_C_PCI), |
| 291 | MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config, |
| 292 | RC_MAP_TERRATEC_CINERGY_S2_HD), |
| 293 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config, |
| 294 | NULL), |
| 295 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config, |
| 296 | NULL), |
| 297 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config, |
| 298 | RC_MAP_TWINHAN_DTV_CAB_CI), |
| 299 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config, |
| 300 | RC_MAP_TWINHAN_DTV_CAB_CI), |
| 301 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config, |
| 302 | NULL), |
| 303 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config, |
| 304 | NULL), |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 305 | { } |
| 306 | }; |
| 307 | |
Manu Abraham | 116d588 | 2010-02-11 04:11:05 -0300 | [diff] [blame] | 308 | MODULE_DEVICE_TABLE(pci, mantis_pci_table); |
| 309 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 310 | static struct pci_driver mantis_pci_driver = { |
| 311 | .name = DRIVER_NAME, |
| 312 | .id_table = mantis_pci_table, |
| 313 | .probe = mantis_pci_probe, |
| 314 | .remove = mantis_pci_remove, |
| 315 | }; |
| 316 | |
Libo Chen | a19b56e | 2013-05-26 22:31:39 -0300 | [diff] [blame] | 317 | module_pci_driver(mantis_pci_driver); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 318 | |
| 319 | MODULE_DESCRIPTION("MANTIS driver"); |
| 320 | MODULE_AUTHOR("Manu Abraham"); |
| 321 | MODULE_LICENSE("GPL"); |