1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Mantis PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/kernel.h>
14 #include <linux/kmod.h>
15 #include <linux/vmalloc.h>
16 #include <linux/init.h>
17 #include <linux/device.h>
18 #include <linux/pci.h>
21 #include <linux/signal.h>
22 #include <linux/sched.h>
23 #include <linux/interrupt.h>
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>
31 #include "mantis_common.h"
32 #include "mantis_reg.h"
33 #include "mantis_pci.h"
35 #define DRIVER_NAME "Mantis Core"
37 int mantis_pci_init(struct mantis_pci
*mantis
)
40 struct mantis_hwconfig
*config
= mantis
->hwconfig
;
41 struct pci_dev
*pdev
= mantis
->pdev
;
44 dprintk(MANTIS_ERROR
, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
47 mantis
->pdev
->bus
->number
,
48 PCI_SLOT(mantis
->pdev
->devfn
),
49 PCI_FUNC(mantis
->pdev
->devfn
));
51 err
= pci_enable_device(pdev
);
54 dprintk(MANTIS_ERROR
, 1, "ERROR: PCI enable failed <%i>", err
);
58 err
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
60 dprintk(MANTIS_ERROR
, 1, "ERROR: Unable to obtain 32 bit DMA <%i>", err
);
67 if (!request_mem_region(pci_resource_start(pdev
, 0),
68 pci_resource_len(pdev
, 0),
71 dprintk(MANTIS_ERROR
, 1, "ERROR: BAR0 Request failed !");
76 mantis
->mmio
= ioremap(pci_resource_start(pdev
, 0),
77 pci_resource_len(pdev
, 0));
80 dprintk(MANTIS_ERROR
, 1, "ERROR: BAR0 remap failed !");
85 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, &latency
);
86 mantis
->latency
= latency
;
87 mantis
->revision
= pdev
->revision
;
89 dprintk(MANTIS_ERROR
, 0, " Mantis Rev %d [%04x:%04x], ",
91 mantis
->pdev
->subsystem_vendor
,
92 mantis
->pdev
->subsystem_device
);
94 dprintk(MANTIS_ERROR
, 0,
95 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
101 err
= request_irq(pdev
->irq
,
109 dprintk(MANTIS_ERROR
, 1, "ERROR: IRQ registration failed ! <%d>", err
);
114 pci_set_drvdata(pdev
, mantis
);
117 /* Error conditions */
119 dprintk(MANTIS_ERROR
, 1, "ERROR: <%d> I/O unmap", ret
);
121 iounmap(mantis
->mmio
);
124 dprintk(MANTIS_ERROR
, 1, "ERROR: <%d> releasing regions", ret
);
125 release_mem_region(pci_resource_start(pdev
, 0),
126 pci_resource_len(pdev
, 0));
129 dprintk(MANTIS_ERROR
, 1, "ERROR: <%d> disabling device", ret
);
130 pci_disable_device(pdev
);
133 dprintk(MANTIS_ERROR
, 1, "ERROR: <%d> exiting", ret
);
136 EXPORT_SYMBOL_GPL(mantis_pci_init
);
138 void mantis_pci_exit(struct mantis_pci
*mantis
)
140 struct pci_dev
*pdev
= mantis
->pdev
;
142 dprintk(MANTIS_NOTICE
, 1, " mem: 0x%p", mantis
->mmio
);
143 free_irq(pdev
->irq
, mantis
);
145 iounmap(mantis
->mmio
);
146 release_mem_region(pci_resource_start(pdev
, 0),
147 pci_resource_len(pdev
, 0));
150 pci_disable_device(pdev
);
152 EXPORT_SYMBOL_GPL(mantis_pci_exit
);
154 MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
155 MODULE_AUTHOR("Manu Abraham");
156 MODULE_LICENSE("GPL");