Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / uio / uio_netx.c
blob2319d6de8d0421dc433a2ba2ed4aa4e1c0ce9160
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * UIO driver for Hilscher NetX based fieldbus cards (cifX, comX).
4 * See http://www.hilscher.com for details.
6 * (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
7 * (C) 2008 Manuel Traut <manut@linutronix.de>
9 */
11 #include <linux/device.h>
12 #include <linux/io.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/slab.h>
16 #include <linux/uio_driver.h>
18 #define PCI_VENDOR_ID_HILSCHER 0x15CF
19 #define PCI_DEVICE_ID_HILSCHER_NETX 0x0000
20 #define PCI_DEVICE_ID_HILSCHER_NETPLC 0x0010
21 #define PCI_SUBDEVICE_ID_NETPLC_RAM 0x0000
22 #define PCI_SUBDEVICE_ID_NETPLC_FLASH 0x0001
23 #define PCI_SUBDEVICE_ID_NXSB_PCA 0x3235
24 #define PCI_SUBDEVICE_ID_NXPCA 0x3335
26 #define DPM_HOST_INT_EN0 0xfff0
27 #define DPM_HOST_INT_STAT0 0xffe0
29 #define DPM_HOST_INT_MASK 0xe600ffff
30 #define DPM_HOST_INT_GLOBAL_EN 0x80000000
32 static irqreturn_t netx_handler(int irq, struct uio_info *dev_info)
34 void __iomem *int_enable_reg = dev_info->mem[0].internal_addr
35 + DPM_HOST_INT_EN0;
36 void __iomem *int_status_reg = dev_info->mem[0].internal_addr
37 + DPM_HOST_INT_STAT0;
39 /* Is one of our interrupts enabled and active ? */
40 if (!(ioread32(int_enable_reg) & ioread32(int_status_reg)
41 & DPM_HOST_INT_MASK))
42 return IRQ_NONE;
44 /* Disable interrupt */
45 iowrite32(ioread32(int_enable_reg) & ~DPM_HOST_INT_GLOBAL_EN,
46 int_enable_reg);
47 return IRQ_HANDLED;
50 static int netx_pci_probe(struct pci_dev *dev,
51 const struct pci_device_id *id)
53 struct uio_info *info;
54 int bar;
56 info = devm_kzalloc(&dev->dev, sizeof(struct uio_info), GFP_KERNEL);
57 if (!info)
58 return -ENOMEM;
60 if (pci_enable_device(dev))
61 return -ENODEV;
63 if (pci_request_regions(dev, "netx"))
64 goto out_disable;
66 switch (id->device) {
67 case PCI_DEVICE_ID_HILSCHER_NETX:
68 bar = 0;
69 info->name = "netx";
70 break;
71 case PCI_DEVICE_ID_HILSCHER_NETPLC:
72 bar = 0;
73 info->name = "netplc";
74 break;
75 default:
76 bar = 2;
77 info->name = "netx_plx";
80 /* BAR0 or 2 points to the card's dual port memory */
81 info->mem[0].addr = pci_resource_start(dev, bar);
82 if (!info->mem[0].addr)
83 goto out_release;
84 info->mem[0].internal_addr = ioremap(pci_resource_start(dev, bar),
85 pci_resource_len(dev, bar));
87 if (!info->mem[0].internal_addr)
88 goto out_release;
90 info->mem[0].size = pci_resource_len(dev, bar);
91 info->mem[0].memtype = UIO_MEM_PHYS;
92 info->irq = dev->irq;
93 info->irq_flags = IRQF_SHARED;
94 info->handler = netx_handler;
95 info->version = "0.0.1";
97 /* Make sure all interrupts are disabled */
98 iowrite32(0, info->mem[0].internal_addr + DPM_HOST_INT_EN0);
100 if (uio_register_device(&dev->dev, info))
101 goto out_unmap;
103 pci_set_drvdata(dev, info);
104 dev_info(&dev->dev, "Found %s card, registered UIO device.\n",
105 info->name);
107 return 0;
109 out_unmap:
110 iounmap(info->mem[0].internal_addr);
111 out_release:
112 pci_release_regions(dev);
113 out_disable:
114 pci_disable_device(dev);
115 return -ENODEV;
118 static void netx_pci_remove(struct pci_dev *dev)
120 struct uio_info *info = pci_get_drvdata(dev);
122 /* Disable all interrupts */
123 iowrite32(0, info->mem[0].internal_addr + DPM_HOST_INT_EN0);
124 uio_unregister_device(info);
125 pci_release_regions(dev);
126 pci_disable_device(dev);
127 iounmap(info->mem[0].internal_addr);
130 static struct pci_device_id netx_pci_ids[] = {
132 .vendor = PCI_VENDOR_ID_HILSCHER,
133 .device = PCI_DEVICE_ID_HILSCHER_NETX,
134 .subvendor = 0,
135 .subdevice = 0,
138 .vendor = PCI_VENDOR_ID_HILSCHER,
139 .device = PCI_DEVICE_ID_HILSCHER_NETPLC,
140 .subvendor = PCI_VENDOR_ID_HILSCHER,
141 .subdevice = PCI_SUBDEVICE_ID_NETPLC_RAM,
144 .vendor = PCI_VENDOR_ID_HILSCHER,
145 .device = PCI_DEVICE_ID_HILSCHER_NETPLC,
146 .subvendor = PCI_VENDOR_ID_HILSCHER,
147 .subdevice = PCI_SUBDEVICE_ID_NETPLC_FLASH,
150 .vendor = PCI_VENDOR_ID_PLX,
151 .device = PCI_DEVICE_ID_PLX_9030,
152 .subvendor = PCI_VENDOR_ID_PLX,
153 .subdevice = PCI_SUBDEVICE_ID_NXSB_PCA,
156 .vendor = PCI_VENDOR_ID_PLX,
157 .device = PCI_DEVICE_ID_PLX_9030,
158 .subvendor = PCI_VENDOR_ID_PLX,
159 .subdevice = PCI_SUBDEVICE_ID_NXPCA,
161 { 0, }
164 static struct pci_driver netx_pci_driver = {
165 .name = "netx",
166 .id_table = netx_pci_ids,
167 .probe = netx_pci_probe,
168 .remove = netx_pci_remove,
171 module_pci_driver(netx_pci_driver);
172 MODULE_DEVICE_TABLE(pci, netx_pci_ids);
173 MODULE_LICENSE("GPL v2");
174 MODULE_AUTHOR("Hans J. Koch, Manuel Traut");