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