blob: 3bfb3e99c93a88d2895bb00167d951bb81c461e6 [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Manu Abrahambd1fcac2009-12-02 22:06:15 -03002/*
3 Mantis PCI bridge driver
4
Manu Abraham8825a092009-12-15 09:13:49 -03005 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
Manu Abrahambd1fcac2009-12-02 22:06:15 -03006
Manu Abrahambd1fcac2009-12-02 22:06:15 -03007*/
8
Manu Abrahamb3b96142009-12-04 05:41:11 -03009#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <linux/kernel.h>
Manu Abrahambd1fcac2009-12-02 22:06:15 -030012#include <asm/io.h>
Manu Abrahambd1fcac2009-12-02 22:06:15 -030013#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 Abrahamb3b96142009-12-04 05:41:11 -030018#include <linux/pci.h>
Manu Abrahambd1fcac2009-12-02 22:06:15 -030019
20#include <asm/irq.h>
21#include <linux/signal.h>
22#include <linux/sched.h>
23#include <linux/interrupt.h>
24
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -050025#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 Abrahambd1fcac2009-12-02 22:06:15 -030030
Manu Abrahamb3b96142009-12-04 05:41:11 -030031#include "mantis_common.h"
32#include "mantis_reg.h"
33#include "mantis_pci.h"
Manu Abrahambd1fcac2009-12-02 22:06:15 -030034
Manu Abrahamb3b96142009-12-04 05:41:11 -030035#define DRIVER_NAME "Mantis Core"
Manu Abrahambd1fcac2009-12-02 22:06:15 -030036
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -080037int mantis_pci_init(struct mantis_pci *mantis)
Manu Abrahambd1fcac2009-12-02 22:06:15 -030038{
Bjørn Morkabd34d82011-03-21 11:35:56 -030039 u8 latency;
Manu Abrahamb3b96142009-12-04 05:41:11 -030040 struct mantis_hwconfig *config = mantis->hwconfig;
41 struct pci_dev *pdev = mantis->pdev;
42 int err, ret = 0;
Manu Abrahambd1fcac2009-12-02 22:06:15 -030043
Manu Abrahamb3b96142009-12-04 05:41:11 -030044 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 Chehab184ac752009-12-17 00:06:04 -020058 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Manu Abrahamb3b96142009-12-04 05:41:11 -030059 if (err != 0) {
60 dprintk(MANTIS_ERROR, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err);
Manu Abrahambd1fcac2009-12-02 22:06:15 -030061 ret = -ENOMEM;
Manu Abrahamb3b96142009-12-04 05:41:11 -030062 goto fail1;
Manu Abrahambd1fcac2009-12-02 22:06:15 -030063 }
64
Manu Abrahambd1fcac2009-12-02 22:06:15 -030065 pci_set_master(pdev);
Manu Abrahamb3b96142009-12-04 05:41:11 -030066
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 Abrahambd1fcac2009-12-02 22:06:15 -030085 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
Manu Abrahambd1fcac2009-12-02 22:06:15 -030086 mantis->latency = latency;
Bjørn Morkabd34d82011-03-21 11:35:56 -030087 mantis->revision = pdev->revision;
Manu Abrahambd1fcac2009-12-02 22:06:15 -030088
Manu Abrahamb3b96142009-12-04 05:41:11 -030089 dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
90 mantis->revision,
91 mantis->pdev->subsystem_vendor,
92 mantis->pdev->subsystem_device);
Manu Abrahambd1fcac2009-12-02 22:06:15 -030093
Manu Abrahamb3b96142009-12-04 05:41:11 -030094 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 Abrahambd1fcac2009-12-02 22:06:15 -0300100
Manu Abrahamb3b96142009-12-04 05:41:11 -0300101 err = request_irq(pdev->irq,
102 config->irq_handler,
103 IRQF_SHARED,
104 DRIVER_NAME,
105 mantis);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300106
Manu Abrahamb3b96142009-12-04 05:41:11 -0300107 if (err != 0) {
108
109 dprintk(MANTIS_ERROR, 1, "ERROR: IRQ registration failed ! <%d>", err);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300110 ret = -ENODEV;
Manu Abrahamb3b96142009-12-04 05:41:11 -0300111 goto fail3;
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300112 }
113
Manu Abrahamb3b96142009-12-04 05:41:11 -0300114 pci_set_drvdata(pdev, mantis);
115 return ret;
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300116
Manu Abrahamb3b96142009-12-04 05:41:11 -0300117 /* Error conditions */
118fail3:
119 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> I/O unmap", ret);
120 if (mantis->mmio)
121 iounmap(mantis->mmio);
122
123fail2:
124 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> releasing regions", ret);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300125 release_mem_region(pci_resource_start(pdev, 0),
Manu Abrahamb3b96142009-12-04 05:41:11 -0300126 pci_resource_len(pdev, 0));
127
128fail1:
129 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> disabling device", ret);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300130 pci_disable_device(pdev);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300131
132fail0:
133 dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300134 return ret;
135}
Manu Abrahamb3b96142009-12-04 05:41:11 -0300136EXPORT_SYMBOL_GPL(mantis_pci_init);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300137
Mauro Carvalho Chehab4cf0b3f2009-12-18 09:58:46 -0200138void mantis_pci_exit(struct mantis_pci *mantis)
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300139{
Manu Abrahamb3b96142009-12-04 05:41:11 -0300140 struct pci_dev *pdev = mantis->pdev;
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300141
Manu Abrahamb3b96142009-12-04 05:41:11 -0300142 dprintk(MANTIS_NOTICE, 1, " mem: 0x%p", mantis->mmio);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300143 free_irq(pdev->irq, mantis);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300144 if (mantis->mmio) {
145 iounmap(mantis->mmio);
146 release_mem_region(pci_resource_start(pdev, 0),
147 pci_resource_len(pdev, 0));
148 }
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300149
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300150 pci_disable_device(pdev);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300151}
Manu Abrahamb3b96142009-12-04 05:41:11 -0300152EXPORT_SYMBOL_GPL(mantis_pci_exit);
Manu Abrahambd1fcac2009-12-02 22:06:15 -0300153
154MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
155MODULE_AUTHOR("Manu Abraham");
156MODULE_LICENSE("GPL");