2 * ddbridge.c: Digital Devices PCIe bridge driver
4 * Copyright (C) 2010-2017 Digital Devices GmbH
5 * Ralph Metzler <rjkm@metzlerbros.de>
6 * Marcus Metzler <mocm@metzlerbros.de>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 only, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/poll.h>
28 #include <linux/pci.h>
29 #include <linux/pci_ids.h>
30 #include <linux/timer.h>
31 #include <linux/i2c.h>
32 #include <linux/swab.h>
33 #include <linux/vmalloc.h>
36 #include "ddbridge-i2c.h"
37 #include "ddbridge-regs.h"
38 #include "ddbridge-hw.h"
39 #include "ddbridge-io.h"
41 /****************************************************************************/
42 /* module parameters */
45 #ifdef CONFIG_DVB_DDBRIDGE_MSIENABLE
50 module_param(msi
, int, 0444);
51 #ifdef CONFIG_DVB_DDBRIDGE_MSIENABLE
52 MODULE_PARM_DESC(msi
, "Control MSI interrupts: 0-disable, 1-enable (default)");
54 MODULE_PARM_DESC(msi
, "Control MSI interrupts: 0-disable (default), 1-enable");
58 int ci_bitrate
= 70000;
59 module_param(ci_bitrate
, int, 0444);
60 MODULE_PARM_DESC(ci_bitrate
, " Bitrate in KHz for output to CI.");
63 module_param(ts_loop
, int, 0444);
64 MODULE_PARM_DESC(ts_loop
, "TS in/out test loop on port ts_loop");
67 module_param(xo2_speed
, int, 0444);
68 MODULE_PARM_DESC(xo2_speed
, "default transfer speed for xo2 based duoflex, 0=55,1=75,2=90,3=104 MBit/s, default=2, use attribute to change for individual cards");
75 module_param(alt_dma
, int, 0444);
76 MODULE_PARM_DESC(alt_dma
, "use alternative DMA buffer handling");
79 module_param(no_init
, int, 0444);
80 MODULE_PARM_DESC(no_init
, "do not initialize most devices");
83 module_param(stv0910_single
, int, 0444);
84 MODULE_PARM_DESC(stv0910_single
, "use stv0910 cards as single demods");
86 /****************************************************************************/
87 /****************************************************************************/
88 /****************************************************************************/
90 static void ddb_irq_disable(struct ddb
*dev
)
92 ddbwritel(dev
, 0, INTERRUPT_ENABLE
);
93 ddbwritel(dev
, 0, MSI1_ENABLE
);
96 static void ddb_irq_exit(struct ddb
*dev
)
100 free_irq(dev
->pdev
->irq
+ 1, dev
);
101 free_irq(dev
->pdev
->irq
, dev
);
102 #ifdef CONFIG_PCI_MSI
104 pci_disable_msi(dev
->pdev
);
108 static void ddb_remove(struct pci_dev
*pdev
)
110 struct ddb
*dev
= (struct ddb
*)pci_get_drvdata(pdev
);
112 ddb_device_destroy(dev
);
113 ddb_ports_detach(dev
);
114 ddb_i2c_release(dev
);
117 ddb_ports_release(dev
);
118 ddb_buffers_free(dev
);
121 pci_set_drvdata(pdev
, NULL
);
122 pci_disable_device(pdev
);
125 #ifdef CONFIG_PCI_MSI
126 static void ddb_irq_msi(struct ddb
*dev
, int nr
)
130 if (msi
&& pci_msi_enabled()) {
131 stat
= pci_alloc_irq_vectors(dev
->pdev
, 1, nr
, PCI_IRQ_MSI
);
134 dev_info(dev
->dev
, "using %d MSI interrupt(s)\n",
137 dev_info(dev
->dev
, "MSI not available.\n");
143 static int ddb_irq_init(struct ddb
*dev
)
146 int irq_flag
= IRQF_SHARED
;
148 ddbwritel(dev
, 0x00000000, INTERRUPT_ENABLE
);
149 ddbwritel(dev
, 0x00000000, MSI1_ENABLE
);
150 ddbwritel(dev
, 0x00000000, MSI2_ENABLE
);
151 ddbwritel(dev
, 0x00000000, MSI3_ENABLE
);
152 ddbwritel(dev
, 0x00000000, MSI4_ENABLE
);
153 ddbwritel(dev
, 0x00000000, MSI5_ENABLE
);
154 ddbwritel(dev
, 0x00000000, MSI6_ENABLE
);
155 ddbwritel(dev
, 0x00000000, MSI7_ENABLE
);
157 #ifdef CONFIG_PCI_MSI
163 stat
= request_irq(dev
->pdev
->irq
, ddb_irq_handler0
,
164 irq_flag
, "ddbridge", (void *)dev
);
167 stat
= request_irq(dev
->pdev
->irq
+ 1, ddb_irq_handler1
,
168 irq_flag
, "ddbridge", (void *)dev
);
170 free_irq(dev
->pdev
->irq
, dev
);
176 stat
= request_irq(dev
->pdev
->irq
, ddb_irq_handler
,
177 irq_flag
, "ddbridge", (void *)dev
);
182 ddbwritel(dev
, 0x0fffff00, INTERRUPT_ENABLE
);
183 ddbwritel(dev
, 0x0000000f, MSI1_ENABLE
);
185 ddbwritel(dev
, 0x0fffff0f, INTERRUPT_ENABLE
);
186 ddbwritel(dev
, 0x00000000, MSI1_ENABLE
);
191 static int ddb_probe(struct pci_dev
*pdev
,
192 const struct pci_device_id
*id
)
197 if (pci_enable_device(pdev
) < 0)
200 pci_set_master(pdev
);
202 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)))
203 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)))
206 dev
= vzalloc(sizeof(*dev
));
210 mutex_init(&dev
->mutex
);
213 dev
->dev
= &pdev
->dev
;
214 pci_set_drvdata(pdev
, dev
);
216 dev
->link
[0].ids
.vendor
= id
->vendor
;
217 dev
->link
[0].ids
.device
= id
->device
;
218 dev
->link
[0].ids
.subvendor
= id
->subvendor
;
219 dev
->link
[0].ids
.subdevice
= pdev
->subsystem_device
;
221 dev
->link
[0].dev
= dev
;
222 dev
->link
[0].info
= get_ddb_info(id
->vendor
, id
->device
,
223 id
->subvendor
, pdev
->subsystem_device
);
225 dev_info(&pdev
->dev
, "detected %s\n", dev
->link
[0].info
->name
);
227 dev
->regs_len
= pci_resource_len(dev
->pdev
, 0);
228 dev
->regs
= ioremap(pci_resource_start(dev
->pdev
, 0),
229 pci_resource_len(dev
->pdev
, 0));
232 dev_err(&pdev
->dev
, "not enough memory for register map\n");
236 if (ddbreadl(dev
, 0) == 0xffffffff) {
237 dev_err(&pdev
->dev
, "cannot read registers\n");
242 dev
->link
[0].ids
.hwid
= ddbreadl(dev
, 0);
243 dev
->link
[0].ids
.regmapid
= ddbreadl(dev
, 4);
245 dev_info(&pdev
->dev
, "HW %08x REGMAP %08x\n",
246 dev
->link
[0].ids
.hwid
, dev
->link
[0].ids
.regmapid
);
248 ddbwritel(dev
, 0, DMA_BASE_READ
);
249 ddbwritel(dev
, 0, DMA_BASE_WRITE
);
251 stat
= ddb_irq_init(dev
);
255 if (ddb_init(dev
) == 0)
260 dev_err(&pdev
->dev
, "fail0\n");
262 pci_disable_msi(dev
->pdev
);
264 dev_err(&pdev
->dev
, "fail\n");
267 pci_set_drvdata(pdev
, NULL
);
268 pci_disable_device(pdev
);
272 /****************************************************************************/
273 /****************************************************************************/
274 /****************************************************************************/
276 #define DDB_DEVICE_ANY(_device) \
277 { PCI_DEVICE_SUB(DDVID, _device, DDVID, PCI_ANY_ID) }
279 static const struct pci_device_id ddb_id_table
[] = {
280 DDB_DEVICE_ANY(0x0002),
281 DDB_DEVICE_ANY(0x0003),
282 DDB_DEVICE_ANY(0x0005),
283 DDB_DEVICE_ANY(0x0006),
284 DDB_DEVICE_ANY(0x0007),
285 DDB_DEVICE_ANY(0x0008),
286 DDB_DEVICE_ANY(0x0011),
287 DDB_DEVICE_ANY(0x0012),
288 DDB_DEVICE_ANY(0x0013),
289 DDB_DEVICE_ANY(0x0201),
290 DDB_DEVICE_ANY(0x0203),
291 DDB_DEVICE_ANY(0x0210),
292 DDB_DEVICE_ANY(0x0220),
293 DDB_DEVICE_ANY(0x0320),
294 DDB_DEVICE_ANY(0x0321),
295 DDB_DEVICE_ANY(0x0322),
296 DDB_DEVICE_ANY(0x0323),
297 DDB_DEVICE_ANY(0x0328),
298 DDB_DEVICE_ANY(0x0329),
302 MODULE_DEVICE_TABLE(pci
, ddb_id_table
);
304 static struct pci_driver ddb_pci_driver
= {
306 .id_table
= ddb_id_table
,
308 .remove
= ddb_remove
,
311 static __init
int module_init_ddbridge(void)
315 pr_info("Digital Devices PCIE bridge driver "
317 ", Copyright (C) 2010-17 Digital Devices GmbH\n");
318 if (ddb_class_create() < 0)
320 ddb_wq
= create_workqueue("ddbridge");
323 stat
= pci_register_driver(&ddb_pci_driver
);
328 destroy_workqueue(ddb_wq
);
334 static __exit
void module_exit_ddbridge(void)
336 pci_unregister_driver(&ddb_pci_driver
);
337 destroy_workqueue(ddb_wq
);
341 module_init(module_init_ddbridge
);
342 module_exit(module_exit_ddbridge
);
344 MODULE_DESCRIPTION("Digital Devices PCIe Bridge");
345 MODULE_AUTHOR("Ralph and Marcus Metzler, Metzler Brothers Systementwicklung GbR");
346 MODULE_LICENSE("GPL");
347 MODULE_VERSION(DDBRIDGE_VERSION
);