Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 1 | /* |
| 2 | Mantis PCI bridge driver |
| 3 | |
Manu Abraham | 8825a09 | 2009-12-15 09:13:49 -0300 | [diff] [blame] | 4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 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> |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 24 | #include <asm/io.h> |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 25 | #include <asm/page.h> |
| 26 | #include <linux/kmod.h> |
| 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/device.h> |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 30 | #include <linux/pci.h> |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 31 | |
| 32 | #include <asm/irq.h> |
| 33 | #include <linux/signal.h> |
| 34 | #include <linux/sched.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 37 | #include "dmxdev.h" |
| 38 | #include "dvbdev.h" |
| 39 | #include "dvb_demux.h" |
| 40 | #include "dvb_frontend.h" |
| 41 | #include "dvb_net.h" |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 42 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 43 | #include "mantis_common.h" |
| 44 | #include "mantis_reg.h" |
| 45 | #include "mantis_pci.h" |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 46 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 47 | #define DRIVER_NAME "Mantis Core" |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 48 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 49 | int mantis_pci_init(struct mantis_pci *mantis) |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 50 | { |
Bjørn Mork | abd34d8 | 2011-03-21 11:35:56 -0300 | [diff] [blame] | 51 | u8 latency; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 52 | struct mantis_hwconfig *config = mantis->hwconfig; |
| 53 | struct pci_dev *pdev = mantis->pdev; |
| 54 | int err, ret = 0; |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 55 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 56 | dprintk(MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n", |
| 57 | config->model_name, |
| 58 | config->dev_type, |
| 59 | mantis->pdev->bus->number, |
| 60 | PCI_SLOT(mantis->pdev->devfn), |
| 61 | PCI_FUNC(mantis->pdev->devfn)); |
| 62 | |
| 63 | err = pci_enable_device(pdev); |
| 64 | if (err != 0) { |
| 65 | ret = -ENODEV; |
| 66 | dprintk(MANTIS_ERROR, 1, "ERROR: PCI enable failed <%i>", err); |
| 67 | goto fail0; |
| 68 | } |
| 69 | |
Mauro Carvalho Chehab | 184ac75 | 2009-12-17 00:06:04 -0200 | [diff] [blame] | 70 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 71 | if (err != 0) { |
| 72 | dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 73 | ret = -ENOMEM; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 74 | goto fail1; |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 75 | } |
| 76 | |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 77 | pci_set_master(pdev); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 78 | |
| 79 | if (!request_mem_region(pci_resource_start(pdev, 0), |
| 80 | pci_resource_len(pdev, 0), |
| 81 | DRIVER_NAME)) { |
| 82 | |
| 83 | dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 Request failed !"); |
| 84 | ret = -ENODEV; |
| 85 | goto fail1; |
| 86 | } |
| 87 | |
| 88 | mantis->mmio = ioremap(pci_resource_start(pdev, 0), |
| 89 | pci_resource_len(pdev, 0)); |
| 90 | |
| 91 | if (!mantis->mmio) { |
| 92 | dprintk(MANTIS_ERROR, 1, "ERROR: BAR0 remap failed !"); |
| 93 | ret = -ENODEV; |
| 94 | goto fail2; |
| 95 | } |
| 96 | |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 97 | pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 98 | mantis->latency = latency; |
Bjørn Mork | abd34d8 | 2011-03-21 11:35:56 -0300 | [diff] [blame] | 99 | mantis->revision = pdev->revision; |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 100 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 101 | dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ", |
| 102 | mantis->revision, |
| 103 | mantis->pdev->subsystem_vendor, |
| 104 | mantis->pdev->subsystem_device); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 105 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 106 | dprintk(MANTIS_ERROR, 0, |
| 107 | "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n", |
| 108 | mantis->pdev->irq, |
| 109 | mantis->latency, |
| 110 | mantis->mantis_addr, |
| 111 | mantis->mmio); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 112 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 113 | err = request_irq(pdev->irq, |
| 114 | config->irq_handler, |
| 115 | IRQF_SHARED, |
| 116 | DRIVER_NAME, |
| 117 | mantis); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 118 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 119 | if (err != 0) { |
| 120 | |
| 121 | dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 122 | ret = -ENODEV; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 123 | goto fail3; |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 124 | } |
| 125 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 126 | pci_set_drvdata(pdev, mantis); |
| 127 | return ret; |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 128 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 129 | /* Error conditions */ |
| 130 | fail3: |
| 131 | dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret); |
| 132 | if (mantis->mmio) |
| 133 | iounmap(mantis->mmio); |
| 134 | |
| 135 | fail2: |
| 136 | dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 137 | release_mem_region(pci_resource_start(pdev, 0), |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 138 | pci_resource_len(pdev, 0)); |
| 139 | |
| 140 | fail1: |
| 141 | dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 142 | pci_disable_device(pdev); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 143 | |
| 144 | fail0: |
| 145 | dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 146 | return ret; |
| 147 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 148 | EXPORT_SYMBOL_GPL(mantis_pci_init); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 149 | |
Mauro Carvalho Chehab | 4cf0b3f | 2009-12-18 09:58:46 -0200 | [diff] [blame] | 150 | void mantis_pci_exit(struct mantis_pci *mantis) |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 151 | { |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 152 | struct pci_dev *pdev = mantis->pdev; |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 153 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 154 | dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 155 | free_irq(pdev->irq, mantis); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 156 | if (mantis->mmio) { |
| 157 | iounmap(mantis->mmio); |
| 158 | release_mem_region(pci_resource_start(pdev, 0), |
| 159 | pci_resource_len(pdev, 0)); |
| 160 | } |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 161 | |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 162 | pci_disable_device(pdev); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 163 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 164 | EXPORT_SYMBOL_GPL(mantis_pci_exit); |
Manu Abraham | bd1fcac | 2009-12-02 22:06:15 -0300 | [diff] [blame] | 165 | |
| 166 | MODULE_DESCRIPTION("Mantis PCI DTV bridge driver"); |
| 167 | MODULE_AUTHOR("Manu Abraham"); |
| 168 | MODULE_LICENSE("GPL"); |