Path: blob/master/drivers/media/dvb/mantis/mantis_pci.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 <asm/io.h>24#include <asm/page.h>25#include <linux/kmod.h>26#include <linux/vmalloc.h>27#include <linux/init.h>28#include <linux/device.h>29#include <linux/pci.h>3031#include <asm/irq.h>32#include <linux/signal.h>33#include <linux/sched.h>34#include <linux/interrupt.h>3536#include "dmxdev.h"37#include "dvbdev.h"38#include "dvb_demux.h"39#include "dvb_frontend.h"40#include "dvb_net.h"4142#include "mantis_common.h"43#include "mantis_reg.h"44#include "mantis_pci.h"4546#define DRIVER_NAME "Mantis Core"4748int __devinit mantis_pci_init(struct mantis_pci *mantis)49{50u8 latency;51struct mantis_hwconfig *config = mantis->hwconfig;52struct pci_dev *pdev = mantis->pdev;53int err, ret = 0;5455dprintk(MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",56config->model_name,57config->dev_type,58mantis->pdev->bus->number,59PCI_SLOT(mantis->pdev->devfn),60PCI_FUNC(mantis->pdev->devfn));6162err = pci_enable_device(pdev);63if (err != 0) {64ret = -ENODEV;65dprintk(MANTIS_ERROR, 1, "ERROR: PCI enable failed <%i>", err);66goto fail0;67}6869err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));70if (err != 0) {71dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err);72ret = -ENOMEM;73goto fail1;74}7576pci_set_master(pdev);7778if (!request_mem_region(pci_resource_start(pdev, 0),79pci_resource_len(pdev, 0),80DRIVER_NAME)) {8182dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 Request failed !");83ret = -ENODEV;84goto fail1;85}8687mantis->mmio = ioremap(pci_resource_start(pdev, 0),88pci_resource_len(pdev, 0));8990if (!mantis->mmio) {91dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 remap failed !");92ret = -ENODEV;93goto fail2;94}9596pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);97mantis->latency = latency;98mantis->revision = pdev->revision;99100dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",101mantis->revision,102mantis->pdev->subsystem_vendor,103mantis->pdev->subsystem_device);104105dprintk(MANTIS_ERROR, 0,106"irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",107mantis->pdev->irq,108mantis->latency,109mantis->mantis_addr,110mantis->mmio);111112err = request_irq(pdev->irq,113config->irq_handler,114IRQF_SHARED,115DRIVER_NAME,116mantis);117118if (err != 0) {119120dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err);121ret = -ENODEV;122goto fail3;123}124125pci_set_drvdata(pdev, mantis);126return ret;127128/* Error conditions */129fail3:130dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret);131if (mantis->mmio)132iounmap(mantis->mmio);133134fail2:135dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret);136release_mem_region(pci_resource_start(pdev, 0),137pci_resource_len(pdev, 0));138139fail1:140dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret);141pci_disable_device(pdev);142143fail0:144dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);145pci_set_drvdata(pdev, NULL);146return ret;147}148EXPORT_SYMBOL_GPL(mantis_pci_init);149150void mantis_pci_exit(struct mantis_pci *mantis)151{152struct pci_dev *pdev = mantis->pdev;153154dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio);155free_irq(pdev->irq, mantis);156if (mantis->mmio) {157iounmap(mantis->mmio);158release_mem_region(pci_resource_start(pdev, 0),159pci_resource_len(pdev, 0));160}161162pci_disable_device(pdev);163pci_set_drvdata(pdev, NULL);164}165EXPORT_SYMBOL_GPL(mantis_pci_exit);166167MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");168MODULE_AUTHOR("Manu Abraham");169MODULE_LICENSE("GPL");170171172