Path: blob/master/drivers/media/dvb/mantis/mantis_cards.c
15112 views
/*1Mantis PCI bridge driver23Copyright (C) Manu Abraham ([email protected])45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*/1920#include <linux/module.h>21#include <linux/moduleparam.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>2728#include "dmxdev.h"29#include "dvbdev.h"30#include "dvb_demux.h"31#include "dvb_frontend.h"32#include "dvb_net.h"3334#include "mantis_common.h"3536#include "mantis_vp1033.h"37#include "mantis_vp1034.h"38#include "mantis_vp1041.h"39#include "mantis_vp2033.h"40#include "mantis_vp2040.h"41#include "mantis_vp3030.h"4243#include "mantis_dma.h"44#include "mantis_ca.h"45#include "mantis_dvb.h"46#include "mantis_uart.h"47#include "mantis_ioc.h"48#include "mantis_pci.h"49#include "mantis_i2c.h"50#include "mantis_reg.h"5152static unsigned int verbose;53module_param(verbose, int, 0644);54MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)");5556static int devs;5758#define DRIVER_NAME "Mantis"5960static char *label[10] = {61"DMA",62"IRQ-0",63"IRQ-1",64"OCERR",65"PABRT",66"RIPRR",67"PPERR",68"FTRGT",69"RISCI",70"RACK"71};7273static irqreturn_t mantis_irq_handler(int irq, void *dev_id)74{75u32 stat = 0, mask = 0, lstat = 0, mstat = 0;76u32 rst_stat = 0, rst_mask = 0;7778struct mantis_pci *mantis;79struct mantis_ca *ca;8081mantis = (struct mantis_pci *) dev_id;82if (unlikely(mantis == NULL)) {83dprintk(MANTIS_ERROR, 1, "Mantis == NULL");84return IRQ_NONE;85}86ca = mantis->mantis_ca;8788stat = mmread(MANTIS_INT_STAT);89mask = mmread(MANTIS_INT_MASK);90mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;91if (!(stat & mask))92return IRQ_NONE;9394rst_mask = MANTIS_GPIF_WRACK |95MANTIS_GPIF_OTHERR |96MANTIS_SBUF_WSTO |97MANTIS_GPIF_EXTIRQ;9899rst_stat = mmread(MANTIS_GPIF_STATUS);100rst_stat &= rst_mask;101mmwrite(rst_stat, MANTIS_GPIF_STATUS);102103mantis->mantis_int_stat = stat;104mantis->mantis_int_mask = mask;105dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);106if (stat & MANTIS_INT_RISCEN) {107dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);108}109if (stat & MANTIS_INT_IRQ0) {110dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);111mantis->gpif_status = rst_stat;112wake_up(&ca->hif_write_wq);113schedule_work(&ca->hif_evm_work);114}115if (stat & MANTIS_INT_IRQ1) {116dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);117schedule_work(&mantis->uart_work);118}119if (stat & MANTIS_INT_OCERR) {120dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);121}122if (stat & MANTIS_INT_PABORT) {123dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);124}125if (stat & MANTIS_INT_RIPERR) {126dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);127}128if (stat & MANTIS_INT_PPERR) {129dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);130}131if (stat & MANTIS_INT_FTRGT) {132dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);133}134if (stat & MANTIS_INT_RISCI) {135dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);136mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;137tasklet_schedule(&mantis->tasklet);138}139if (stat & MANTIS_INT_I2CDONE) {140dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);141wake_up(&mantis->i2c_wq);142}143mmwrite(stat, MANTIS_INT_STAT);144stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |145MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |146MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |147MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |148MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |149MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |150MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |151MANTIS_INT_PABORT | MANTIS_INT_RIPERR |152MANTIS_INT_PPERR | MANTIS_INT_FTRGT |153MANTIS_INT_RISCI);154155if (stat)156dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);157158dprintk(MANTIS_DEBUG, 0, "\n");159return IRQ_HANDLED;160}161162static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)163{164struct mantis_pci *mantis;165struct mantis_hwconfig *config;166int err = 0;167168mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);169if (mantis == NULL) {170printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);171err = -ENOMEM;172goto fail0;173}174175mantis->num = devs;176mantis->verbose = verbose;177mantis->pdev = pdev;178config = (struct mantis_hwconfig *) pci_id->driver_data;179config->irq_handler = &mantis_irq_handler;180mantis->hwconfig = config;181182err = mantis_pci_init(mantis);183if (err) {184dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);185goto fail1;186}187188err = mantis_stream_control(mantis, STREAM_TO_HIF);189if (err < 0) {190dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);191goto fail1;192}193194err = mantis_i2c_init(mantis);195if (err < 0) {196dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);197goto fail2;198}199200err = mantis_get_mac(mantis);201if (err < 0) {202dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);203goto fail2;204}205206err = mantis_dma_init(mantis);207if (err < 0) {208dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);209goto fail3;210}211212err = mantis_dvb_init(mantis);213if (err < 0) {214dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);215goto fail4;216}217err = mantis_uart_init(mantis);218if (err < 0) {219dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err);220goto fail6;221}222223devs++;224225return err;226227228dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err);229mantis_uart_exit(mantis);230231fail6:232fail4:233dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);234mantis_dma_exit(mantis);235236fail3:237dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);238mantis_i2c_exit(mantis);239240fail2:241dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);242mantis_pci_exit(mantis);243244fail1:245dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);246kfree(mantis);247248fail0:249return err;250}251252static void __devexit mantis_pci_remove(struct pci_dev *pdev)253{254struct mantis_pci *mantis = pci_get_drvdata(pdev);255256if (mantis) {257258mantis_uart_exit(mantis);259mantis_dvb_exit(mantis);260mantis_dma_exit(mantis);261mantis_i2c_exit(mantis);262mantis_pci_exit(mantis);263kfree(mantis);264}265return;266}267268static struct pci_device_id mantis_pci_table[] = {269MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config),270MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config),271MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config),272MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config),273MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config),274MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config),275MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config),276MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config),277MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config),278MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config),279MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config),280{ }281};282283MODULE_DEVICE_TABLE(pci, mantis_pci_table);284285static struct pci_driver mantis_pci_driver = {286.name = DRIVER_NAME,287.id_table = mantis_pci_table,288.probe = mantis_pci_probe,289.remove = mantis_pci_remove,290};291292static int __devinit mantis_init(void)293{294return pci_register_driver(&mantis_pci_driver);295}296297static void __devexit mantis_exit(void)298{299return pci_unregister_driver(&mantis_pci_driver);300}301302module_init(mantis_init);303module_exit(mantis_exit);304305MODULE_DESCRIPTION("MANTIS driver");306MODULE_AUTHOR("Manu Abraham");307MODULE_LICENSE("GPL");308309310