Path: blob/master/drivers/media/dvb/mantis/hopper_cards.c
15112 views
/*1Hopper 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"35#include "hopper_vp3028.h"36#include "mantis_dma.h"37#include "mantis_dvb.h"38#include "mantis_uart.h"39#include "mantis_ioc.h"40#include "mantis_pci.h"41#include "mantis_i2c.h"42#include "mantis_reg.h"4344static unsigned int verbose;45module_param(verbose, int, 0644);46MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)");4748#define DRIVER_NAME "Hopper"4950static char *label[10] = {51"DMA",52"IRQ-0",53"IRQ-1",54"OCERR",55"PABRT",56"RIPRR",57"PPERR",58"FTRGT",59"RISCI",60"RACK"61};6263static int devs;6465static irqreturn_t hopper_irq_handler(int irq, void *dev_id)66{67u32 stat = 0, mask = 0, lstat = 0, mstat = 0;68u32 rst_stat = 0, rst_mask = 0;6970struct mantis_pci *mantis;71struct mantis_ca *ca;7273mantis = (struct mantis_pci *) dev_id;74if (unlikely(mantis == NULL)) {75dprintk(MANTIS_ERROR, 1, "Mantis == NULL");76return IRQ_NONE;77}78ca = mantis->mantis_ca;7980stat = mmread(MANTIS_INT_STAT);81mask = mmread(MANTIS_INT_MASK);82mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;83if (!(stat & mask))84return IRQ_NONE;8586rst_mask = MANTIS_GPIF_WRACK |87MANTIS_GPIF_OTHERR |88MANTIS_SBUF_WSTO |89MANTIS_GPIF_EXTIRQ;9091rst_stat = mmread(MANTIS_GPIF_STATUS);92rst_stat &= rst_mask;93mmwrite(rst_stat, MANTIS_GPIF_STATUS);9495mantis->mantis_int_stat = stat;96mantis->mantis_int_mask = mask;97dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);98if (stat & MANTIS_INT_RISCEN) {99dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);100}101if (stat & MANTIS_INT_IRQ0) {102dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);103mantis->gpif_status = rst_stat;104wake_up(&ca->hif_write_wq);105schedule_work(&ca->hif_evm_work);106}107if (stat & MANTIS_INT_IRQ1) {108dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]);109schedule_work(&mantis->uart_work);110}111if (stat & MANTIS_INT_OCERR) {112dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);113}114if (stat & MANTIS_INT_PABORT) {115dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);116}117if (stat & MANTIS_INT_RIPERR) {118dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);119}120if (stat & MANTIS_INT_PPERR) {121dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);122}123if (stat & MANTIS_INT_FTRGT) {124dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);125}126if (stat & MANTIS_INT_RISCI) {127dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);128mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;129tasklet_schedule(&mantis->tasklet);130}131if (stat & MANTIS_INT_I2CDONE) {132dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);133wake_up(&mantis->i2c_wq);134}135mmwrite(stat, MANTIS_INT_STAT);136stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |137MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |138MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |139MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |140MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |141MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |142MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |143MANTIS_INT_PABORT | MANTIS_INT_RIPERR |144MANTIS_INT_PPERR | MANTIS_INT_FTRGT |145MANTIS_INT_RISCI);146147if (stat)148dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);149150dprintk(MANTIS_DEBUG, 0, "\n");151return IRQ_HANDLED;152}153154static int __devinit hopper_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)155{156struct mantis_pci *mantis;157struct mantis_hwconfig *config;158int err = 0;159160mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);161if (mantis == NULL) {162printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);163err = -ENOMEM;164goto fail0;165}166167mantis->num = devs;168mantis->verbose = verbose;169mantis->pdev = pdev;170config = (struct mantis_hwconfig *) pci_id->driver_data;171config->irq_handler = &hopper_irq_handler;172mantis->hwconfig = config;173174err = mantis_pci_init(mantis);175if (err) {176dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);177goto fail1;178}179180err = mantis_stream_control(mantis, STREAM_TO_HIF);181if (err < 0) {182dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);183goto fail1;184}185186err = mantis_i2c_init(mantis);187if (err < 0) {188dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);189goto fail2;190}191192err = mantis_get_mac(mantis);193if (err < 0) {194dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);195goto fail2;196}197198err = mantis_dma_init(mantis);199if (err < 0) {200dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);201goto fail3;202}203204err = mantis_dvb_init(mantis);205if (err < 0) {206dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);207goto fail4;208}209devs++;210211return err;212213fail4:214dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);215mantis_dma_exit(mantis);216217fail3:218dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);219mantis_i2c_exit(mantis);220221fail2:222dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);223mantis_pci_exit(mantis);224225fail1:226dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);227kfree(mantis);228229fail0:230return err;231}232233static void __devexit hopper_pci_remove(struct pci_dev *pdev)234{235struct mantis_pci *mantis = pci_get_drvdata(pdev);236237if (mantis) {238mantis_dvb_exit(mantis);239mantis_dma_exit(mantis);240mantis_i2c_exit(mantis);241mantis_pci_exit(mantis);242kfree(mantis);243}244return;245246}247248static struct pci_device_id hopper_pci_table[] = {249MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3028_DVB_T, &vp3028_config),250{ }251};252253MODULE_DEVICE_TABLE(pci, hopper_pci_table);254255static struct pci_driver hopper_pci_driver = {256.name = DRIVER_NAME,257.id_table = hopper_pci_table,258.probe = hopper_pci_probe,259.remove = hopper_pci_remove,260};261262static int __devinit hopper_init(void)263{264return pci_register_driver(&hopper_pci_driver);265}266267static void __devexit hopper_exit(void)268{269return pci_unregister_driver(&hopper_pci_driver);270}271272module_init(hopper_init);273module_exit(hopper_exit);274275MODULE_DESCRIPTION("HOPPER driver");276MODULE_AUTHOR("Manu Abraham");277MODULE_LICENSE("GPL");278279280