2 * UIO driver for Hilscher NetX based fieldbus cards (cifX, comX).
3 * See http://www.hilscher.com for details.
5 * (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
6 * (C) 2008 Manuel Traut <manut@linutronix.de>
8 * Licensed under GPL version 2 only.
12 #include <linux/device.h>
14 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/slab.h>
17 #include <linux/uio_driver.h>
19 #define PCI_VENDOR_ID_HILSCHER 0x15CF
20 #define PCI_DEVICE_ID_HILSCHER_NETX 0x0000
21 #define PCI_DEVICE_ID_HILSCHER_NETPLC 0x0010
22 #define PCI_SUBDEVICE_ID_NETPLC_RAM 0x0000
23 #define PCI_SUBDEVICE_ID_NETPLC_FLASH 0x0001
24 #define PCI_SUBDEVICE_ID_NXSB_PCA 0x3235
25 #define PCI_SUBDEVICE_ID_NXPCA 0x3335
27 #define DPM_HOST_INT_EN0 0xfff0
28 #define DPM_HOST_INT_STAT0 0xffe0
30 #define DPM_HOST_INT_MASK 0xe600ffff
31 #define DPM_HOST_INT_GLOBAL_EN 0x80000000
33 static irqreturn_t
netx_handler(int irq
, struct uio_info
*dev_info
)
35 void __iomem
*int_enable_reg
= dev_info
->mem
[0].internal_addr
37 void __iomem
*int_status_reg
= dev_info
->mem
[0].internal_addr
40 /* Is one of our interrupts enabled and active ? */
41 if (!(ioread32(int_enable_reg
) & ioread32(int_status_reg
)
45 /* Disable interrupt */
46 iowrite32(ioread32(int_enable_reg
) & ~DPM_HOST_INT_GLOBAL_EN
,
51 static int netx_pci_probe(struct pci_dev
*dev
,
52 const struct pci_device_id
*id
)
54 struct uio_info
*info
;
57 info
= kzalloc(sizeof(struct uio_info
), GFP_KERNEL
);
61 if (pci_enable_device(dev
))
64 if (pci_request_regions(dev
, "netx"))
68 case PCI_DEVICE_ID_HILSCHER_NETX
:
72 case PCI_DEVICE_ID_HILSCHER_NETPLC
:
74 info
->name
= "netplc";
78 info
->name
= "netx_plx";
81 /* BAR0 or 2 points to the card's dual port memory */
82 info
->mem
[0].addr
= pci_resource_start(dev
, bar
);
83 if (!info
->mem
[0].addr
)
85 info
->mem
[0].internal_addr
= ioremap(pci_resource_start(dev
, bar
),
86 pci_resource_len(dev
, bar
));
88 if (!info
->mem
[0].internal_addr
)
91 info
->mem
[0].size
= pci_resource_len(dev
, bar
);
92 info
->mem
[0].memtype
= UIO_MEM_PHYS
;
94 info
->irq_flags
= IRQF_SHARED
;
95 info
->handler
= netx_handler
;
96 info
->version
= "0.0.1";
98 /* Make sure all interrupts are disabled */
99 iowrite32(0, info
->mem
[0].internal_addr
+ DPM_HOST_INT_EN0
);
101 if (uio_register_device(&dev
->dev
, info
))
104 pci_set_drvdata(dev
, info
);
105 dev_info(&dev
->dev
, "Found %s card, registered UIO device.\n",
111 iounmap(info
->mem
[0].internal_addr
);
113 pci_release_regions(dev
);
115 pci_disable_device(dev
);
121 static void netx_pci_remove(struct pci_dev
*dev
)
123 struct uio_info
*info
= pci_get_drvdata(dev
);
125 /* Disable all interrupts */
126 iowrite32(0, info
->mem
[0].internal_addr
+ DPM_HOST_INT_EN0
);
127 uio_unregister_device(info
);
128 pci_release_regions(dev
);
129 pci_disable_device(dev
);
130 pci_set_drvdata(dev
, NULL
);
131 iounmap(info
->mem
[0].internal_addr
);
136 static struct pci_device_id netx_pci_ids
[] = {
138 .vendor
= PCI_VENDOR_ID_HILSCHER
,
139 .device
= PCI_DEVICE_ID_HILSCHER_NETX
,
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_RAM
,
150 .vendor
= PCI_VENDOR_ID_HILSCHER
,
151 .device
= PCI_DEVICE_ID_HILSCHER_NETPLC
,
152 .subvendor
= PCI_VENDOR_ID_HILSCHER
,
153 .subdevice
= PCI_SUBDEVICE_ID_NETPLC_FLASH
,
156 .vendor
= PCI_VENDOR_ID_PLX
,
157 .device
= PCI_DEVICE_ID_PLX_9030
,
158 .subvendor
= PCI_VENDOR_ID_PLX
,
159 .subdevice
= PCI_SUBDEVICE_ID_NXSB_PCA
,
162 .vendor
= PCI_VENDOR_ID_PLX
,
163 .device
= PCI_DEVICE_ID_PLX_9030
,
164 .subvendor
= PCI_VENDOR_ID_PLX
,
165 .subdevice
= PCI_SUBDEVICE_ID_NXPCA
,
170 static struct pci_driver netx_pci_driver
= {
172 .id_table
= netx_pci_ids
,
173 .probe
= netx_pci_probe
,
174 .remove
= netx_pci_remove
,
177 module_pci_driver(netx_pci_driver
);
178 MODULE_DEVICE_TABLE(pci
, netx_pci_ids
);
179 MODULE_LICENSE("GPL v2");
180 MODULE_AUTHOR("Hans J. Koch, Manuel Traut");