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