diff options
-rw-r--r-- | drivers/uio/Kconfig | 13 | ||||
-rw-r--r-- | drivers/uio/Makefile | 3 | ||||
-rw-r--r-- | drivers/uio/uio_cif.c | 156 |
3 files changed, 171 insertions, 1 deletions
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig index 6b1a62d45e46..b778ed71f636 100644 --- a/drivers/uio/Kconfig +++ b/drivers/uio/Kconfig | |||
@@ -13,4 +13,17 @@ config UIO | |||
13 | 13 | ||
14 | If you don't know what to do here, say N. | 14 | If you don't know what to do here, say N. |
15 | 15 | ||
16 | config UIO_CIF | ||
17 | tristate "generic Hilscher CIF Card driver" | ||
18 | depends on UIO && PCI | ||
19 | default n | ||
20 | help | ||
21 | Driver for Hilscher CIF DeviceNet and Profibus cards. This | ||
22 | driver requires a userspace component that handles all of the | ||
23 | heavy lifting and can be found at: | ||
24 | http://www.osadl.org/projects/downloads/UIO/user/cif-* | ||
25 | |||
26 | To compile this driver as a module, choose M here: the module | ||
27 | will be called uio_cif. | ||
28 | |||
16 | endmenu | 29 | endmenu |
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile index 9b7c83063e15..7fecfb459da5 100644 --- a/drivers/uio/Makefile +++ b/drivers/uio/Makefile | |||
@@ -1 +1,2 @@ | |||
1 | obj-$(CONFIG_UIO) += uio.o | 1 | obj-$(CONFIG_UIO) += uio.o |
2 | obj-$(CONFIG_UIO_CIF) += uio_cif.o | ||
diff --git a/drivers/uio/uio_cif.c b/drivers/uio/uio_cif.c new file mode 100644 index 000000000000..838bae460831 --- /dev/null +++ b/drivers/uio/uio_cif.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * UIO Hilscher CIF card driver | ||
3 | * | ||
4 | * (C) 2007 Hans J. Koch <hjk@linutronix.de> | ||
5 | * Original code (C) 2005 Benedikt Spranger <b.spranger@linutronix.de> | ||
6 | * | ||
7 | * Licensed under GPL version 2 only. | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <linux/device.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/pci.h> | ||
14 | #include <linux/uio_driver.h> | ||
15 | |||
16 | #include <asm/io.h> | ||
17 | |||
18 | #ifndef PCI_DEVICE_ID_PLX_9030 | ||
19 | #define PCI_DEVICE_ID_PLX_9030 0x9030 | ||
20 | #endif | ||
21 | |||
22 | #define PLX9030_INTCSR 0x4C | ||
23 | #define INTSCR_INT1_ENABLE 0x01 | ||
24 | #define INTSCR_INT1_STATUS 0x04 | ||
25 | #define INT1_ENABLED_AND_ACTIVE (INTSCR_INT1_ENABLE | INTSCR_INT1_STATUS) | ||
26 | |||
27 | #define PCI_SUBVENDOR_ID_PEP 0x1518 | ||
28 | #define CIF_SUBDEVICE_PROFIBUS 0x430 | ||
29 | #define CIF_SUBDEVICE_DEVICENET 0x432 | ||
30 | |||
31 | |||
32 | static irqreturn_t hilscher_handler(int irq, struct uio_info *dev_info) | ||
33 | { | ||
34 | void __iomem *plx_intscr = dev_info->mem[0].internal_addr | ||
35 | + PLX9030_INTCSR; | ||
36 | |||
37 | if ((ioread8(plx_intscr) & INT1_ENABLED_AND_ACTIVE) | ||
38 | != INT1_ENABLED_AND_ACTIVE) | ||
39 | return IRQ_NONE; | ||
40 | |||
41 | /* Disable interrupt */ | ||
42 | iowrite8(ioread8(plx_intscr) & ~INTSCR_INT1_ENABLE, plx_intscr); | ||
43 | return IRQ_HANDLED; | ||
44 | } | ||
45 | |||
46 | static int __devinit hilscher_pci_probe(struct pci_dev *dev, | ||
47 | const struct pci_device_id *id) | ||
48 | { | ||
49 | struct uio_info *info; | ||
50 | |||
51 | info = kzalloc(sizeof(struct uio_info), GFP_KERNEL); | ||
52 | if (!info) | ||
53 | return -ENOMEM; | ||
54 | |||
55 | if (pci_enable_device(dev)) | ||
56 | goto out_free; | ||
57 | |||
58 | if (pci_request_regions(dev, "hilscher")) | ||
59 | goto out_disable; | ||
60 | |||
61 | info->mem[0].addr = pci_resource_start(dev, 0); | ||
62 | if (!info->mem[0].addr) | ||
63 | goto out_release; | ||
64 | info->mem[0].internal_addr = ioremap(pci_resource_start(dev, 0), | ||
65 | pci_resource_len(dev, 0)); | ||
66 | if (!info->mem[0].internal_addr) | ||
67 | goto out_release; | ||
68 | |||
69 | info->mem[0].size = pci_resource_len(dev, 0); | ||
70 | info->mem[0].memtype = UIO_MEM_PHYS; | ||
71 | info->mem[1].addr = pci_resource_start(dev, 2); | ||
72 | info->mem[1].size = pci_resource_len(dev, 2); | ||
73 | info->mem[1].memtype = UIO_MEM_PHYS; | ||
74 | switch (id->subdevice) { | ||
75 | case CIF_SUBDEVICE_PROFIBUS: | ||
76 | info->name = "CIF_Profibus"; | ||
77 | break; | ||
78 | case CIF_SUBDEVICE_DEVICENET: | ||
79 | info->name = "CIF_Devicenet"; | ||
80 | break; | ||
81 | default: | ||
82 | info->name = "CIF_???"; | ||
83 | } | ||
84 | info->version = "0.0.1"; | ||
85 | info->irq = dev->irq; | ||
86 | info->irq_flags = IRQF_DISABLED | IRQF_SHARED; | ||
87 | info->handler = hilscher_handler; | ||
88 | |||
89 | if (uio_register_device(&dev->dev, info)) | ||
90 | goto out_unmap; | ||
91 | |||
92 | pci_set_drvdata(dev, info); | ||
93 | |||
94 | return 0; | ||
95 | out_unmap: | ||
96 | iounmap(info->mem[0].internal_addr); | ||
97 | out_release: | ||
98 | pci_release_regions(dev); | ||
99 | out_disable: | ||
100 | pci_disable_device(dev); | ||
101 | out_free: | ||
102 | kfree (info); | ||
103 | return -ENODEV; | ||
104 | } | ||
105 | |||
106 | static void hilscher_pci_remove(struct pci_dev *dev) | ||
107 | { | ||
108 | struct uio_info *info = pci_get_drvdata(dev); | ||
109 | |||
110 | uio_unregister_device(info); | ||
111 | pci_release_regions(dev); | ||
112 | pci_disable_device(dev); | ||
113 | pci_set_drvdata(dev, NULL); | ||
114 | iounmap(info->mem[0].internal_addr); | ||
115 | |||
116 | kfree (info); | ||
117 | } | ||
118 | |||
119 | static struct pci_device_id hilscher_pci_ids[] = { | ||
120 | { | ||
121 | .vendor = PCI_VENDOR_ID_PLX, | ||
122 | .device = PCI_DEVICE_ID_PLX_9030, | ||
123 | .subvendor = PCI_SUBVENDOR_ID_PEP, | ||
124 | .subdevice = CIF_SUBDEVICE_PROFIBUS, | ||
125 | }, | ||
126 | { | ||
127 | .vendor = PCI_VENDOR_ID_PLX, | ||
128 | .device = PCI_DEVICE_ID_PLX_9030, | ||
129 | .subvendor = PCI_SUBVENDOR_ID_PEP, | ||
130 | .subdevice = CIF_SUBDEVICE_DEVICENET, | ||
131 | }, | ||
132 | { 0, } | ||
133 | }; | ||
134 | |||
135 | static struct pci_driver hilscher_pci_driver = { | ||
136 | .name = "hilscher", | ||
137 | .id_table = hilscher_pci_ids, | ||
138 | .probe = hilscher_pci_probe, | ||
139 | .remove = hilscher_pci_remove, | ||
140 | }; | ||
141 | |||
142 | static int __init hilscher_init_module(void) | ||
143 | { | ||
144 | return pci_register_driver(&hilscher_pci_driver); | ||
145 | } | ||
146 | |||
147 | static void __exit hilscher_exit_module(void) | ||
148 | { | ||
149 | pci_unregister_driver(&hilscher_pci_driver); | ||
150 | } | ||
151 | |||
152 | module_init(hilscher_init_module); | ||
153 | module_exit(hilscher_exit_module); | ||
154 | |||
155 | MODULE_LICENSE("GPL v2"); | ||
156 | MODULE_AUTHOR("Hans J. Koch, Benedikt Spranger"); | ||