mantis_cards.c 8.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
	Mantis PCI bridge driver

	Copyright (C) Manu Abraham (abraham.manu@gmail.com)

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

21 22 23 24
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/pci.h>
25
#include <linux/slab.h>
26 27
#include <asm/irq.h>
#include <linux/interrupt.h>
28
#include <media/rc-map.h>
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

#include "dmxdev.h"
#include "dvbdev.h"
#include "dvb_demux.h"
#include "dvb_frontend.h"
#include "dvb_net.h"

#include "mantis_common.h"

#include "mantis_vp1033.h"
#include "mantis_vp1034.h"
#include "mantis_vp1041.h"
#include "mantis_vp2033.h"
#include "mantis_vp2040.h"
#include "mantis_vp3030.h"

#include "mantis_dma.h"
#include "mantis_ca.h"
#include "mantis_dvb.h"
#include "mantis_uart.h"
#include "mantis_ioc.h"
#include "mantis_pci.h"
#include "mantis_i2c.h"
#include "mantis_reg.h"
53
#include "mantis_input.h"
54 55 56

static unsigned int verbose;
module_param(verbose, int, 0644);
57
MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)");
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

static int devs;

#define DRIVER_NAME	"Mantis"

static char *label[10] = {
	"DMA",
	"IRQ-0",
	"IRQ-1",
	"OCERR",
	"PABRT",
	"RIPRR",
	"PPERR",
	"FTRGT",
	"RISCI",
	"RACK"
};

static irqreturn_t mantis_irq_handler(int irq, void *dev_id)
{
78
	u32 stat = 0, mask = 0;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
	u32 rst_stat = 0, rst_mask = 0;

	struct mantis_pci *mantis;
	struct mantis_ca *ca;

	mantis = (struct mantis_pci *) dev_id;
	if (unlikely(mantis == NULL)) {
		dprintk(MANTIS_ERROR, 1, "Mantis == NULL");
		return IRQ_NONE;
	}
	ca = mantis->mantis_ca;

	stat = mmread(MANTIS_INT_STAT);
	mask = mmread(MANTIS_INT_MASK);
	if (!(stat & mask))
		return IRQ_NONE;

	rst_mask  = MANTIS_GPIF_WRACK  |
		    MANTIS_GPIF_OTHERR |
		    MANTIS_SBUF_WSTO   |
		    MANTIS_GPIF_EXTIRQ;

	rst_stat  = mmread(MANTIS_GPIF_STATUS);
	rst_stat &= rst_mask;
	mmwrite(rst_stat, MANTIS_GPIF_STATUS);

	mantis->mantis_int_stat = stat;
	mantis->mantis_int_mask = mask;
	dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
	if (stat & MANTIS_INT_RISCEN) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
	}
	if (stat & MANTIS_INT_IRQ0) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
		mantis->gpif_status = rst_stat;
		wake_up(&ca->hif_write_wq);
		schedule_work(&ca->hif_evm_work);
	}
	if (stat & MANTIS_INT_IRQ1) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);
119
		spin_lock(&mantis->intmask_lock);
120 121
		mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ1,
			MANTIS_INT_MASK);
122
		spin_unlock(&mantis->intmask_lock);
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
		schedule_work(&mantis->uart_work);
	}
	if (stat & MANTIS_INT_OCERR) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
	}
	if (stat & MANTIS_INT_PABORT) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
	}
	if (stat & MANTIS_INT_RIPERR) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
	}
	if (stat & MANTIS_INT_PPERR) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
	}
	if (stat & MANTIS_INT_FTRGT) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
	}
	if (stat & MANTIS_INT_RISCI) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
142
		mantis->busy_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
		tasklet_schedule(&mantis->tasklet);
	}
	if (stat & MANTIS_INT_I2CDONE) {
		dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
		wake_up(&mantis->i2c_wq);
	}
	mmwrite(stat, MANTIS_INT_STAT);
	stat &= ~(MANTIS_INT_RISCEN   | MANTIS_INT_I2CDONE |
		  MANTIS_INT_I2CRACK  | MANTIS_INT_PCMCIA7 |
		  MANTIS_INT_PCMCIA6  | MANTIS_INT_PCMCIA5 |
		  MANTIS_INT_PCMCIA4  | MANTIS_INT_PCMCIA3 |
		  MANTIS_INT_PCMCIA2  | MANTIS_INT_PCMCIA1 |
		  MANTIS_INT_PCMCIA0  | MANTIS_INT_IRQ1	   |
		  MANTIS_INT_IRQ0     | MANTIS_INT_OCERR   |
		  MANTIS_INT_PABORT   | MANTIS_INT_RIPERR  |
		  MANTIS_INT_PPERR    | MANTIS_INT_FTRGT   |
		  MANTIS_INT_RISCI);

	if (stat)
		dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);

	dprintk(MANTIS_DEBUG, 0, "\n");
	return IRQ_HANDLED;
}

168 169
static int mantis_pci_probe(struct pci_dev *pdev,
			    const struct pci_device_id *pci_id)
170
{
171
	struct mantis_pci_drvdata *drvdata;
172 173
	struct mantis_pci *mantis;
	struct mantis_hwconfig *config;
174
	int err;
175

176
	mantis = kzalloc(sizeof(*mantis), GFP_KERNEL);
177
	if (!mantis)
178
		return -ENOMEM;
179

180
	drvdata			= (void *)pci_id->driver_data;
181 182 183
	mantis->num		= devs;
	mantis->verbose		= verbose;
	mantis->pdev		= pdev;
184
	config			= drvdata->hwconfig;
185 186
	config->irq_handler	= &mantis_irq_handler;
	mantis->hwconfig	= config;
187 188 189
	mantis->rc_map_name	= drvdata->rc_map_name;

	spin_lock_init(&mantis->intmask_lock);
190 191 192 193

	err = mantis_pci_init(mantis);
	if (err) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
194
		goto err_free_mantis;
195 196 197 198 199
	}

	err = mantis_stream_control(mantis, STREAM_TO_HIF);
	if (err < 0) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
200
		goto err_pci_exit;
201 202 203 204 205
	}

	err = mantis_i2c_init(mantis);
	if (err < 0) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
206
		goto err_pci_exit;
207 208 209 210 211
	}

	err = mantis_get_mac(mantis);
	if (err < 0) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
212
		goto err_i2c_exit;
213 214 215 216 217
	}

	err = mantis_dma_init(mantis);
	if (err < 0) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
218
		goto err_i2c_exit;
219 220 221 222 223
	}

	err = mantis_dvb_init(mantis);
	if (err < 0) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
224
		goto err_dma_exit;
225
	}
226

227 228
	err = mantis_input_init(mantis);
	if (err < 0) {
229 230
		dprintk(MANTIS_ERROR, 1,
			"ERROR: Mantis DVB initialization failed <%d>", err);
231 232 233
		goto err_dvb_exit;
	}

234 235 236
	err = mantis_uart_init(mantis);
	if (err < 0) {
		dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);
237
		goto err_input_exit;
238 239
	}

240 241
	devs++;

242
	return 0;
243

244 245 246
err_input_exit:
	mantis_input_exit(mantis);

247 248
err_dvb_exit:
	mantis_dvb_exit(mantis);
249

250
err_dma_exit:
251 252
	mantis_dma_exit(mantis);

253
err_i2c_exit:
254 255
	mantis_i2c_exit(mantis);

256
err_pci_exit:
257 258
	mantis_pci_exit(mantis);

259
err_free_mantis:
260 261 262 263 264
	kfree(mantis);

	return err;
}

265
static void mantis_pci_remove(struct pci_dev *pdev)
266 267 268 269
{
	struct mantis_pci *mantis = pci_get_drvdata(pdev);

	if (mantis) {
270 271

		mantis_uart_exit(mantis);
272
		mantis_input_exit(mantis);
273 274 275 276 277 278 279 280 281
		mantis_dvb_exit(mantis);
		mantis_dma_exit(mantis);
		mantis_i2c_exit(mantis);
		mantis_pci_exit(mantis);
		kfree(mantis);
	}
	return;
}

282
static const struct pci_device_id mantis_pci_table[] = {
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),
305 306 307
	{ }
};

308 309
MODULE_DEVICE_TABLE(pci, mantis_pci_table);

310 311 312 313 314 315 316
static struct pci_driver mantis_pci_driver = {
	.name		= DRIVER_NAME,
	.id_table	= mantis_pci_table,
	.probe		= mantis_pci_probe,
	.remove		= mantis_pci_remove,
};

317
module_pci_driver(mantis_pci_driver);
318 319 320 321

MODULE_DESCRIPTION("MANTIS driver");
MODULE_AUTHOR("Manu Abraham");
MODULE_LICENSE("GPL");