Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[wrt350n-kernel.git] / drivers / uio / uio_cif.c
blob838bae4608318857df5ac5500fe9e69dd7b30f24
1 /*
2 * UIO Hilscher CIF card driver
4 * (C) 2007 Hans J. Koch <hjk@linutronix.de>
5 * Original code (C) 2005 Benedikt Spranger <b.spranger@linutronix.de>
7 * Licensed under GPL version 2 only.
9 */
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/uio_driver.h>
16 #include <asm/io.h>
18 #ifndef PCI_DEVICE_ID_PLX_9030
19 #define PCI_DEVICE_ID_PLX_9030 0x9030
20 #endif
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)
27 #define PCI_SUBVENDOR_ID_PEP 0x1518
28 #define CIF_SUBDEVICE_PROFIBUS 0x430
29 #define CIF_SUBDEVICE_DEVICENET 0x432
32 static irqreturn_t hilscher_handler(int irq, struct uio_info *dev_info)
34 void __iomem *plx_intscr = dev_info->mem[0].internal_addr
35 + PLX9030_INTCSR;
37 if ((ioread8(plx_intscr) & INT1_ENABLED_AND_ACTIVE)
38 != INT1_ENABLED_AND_ACTIVE)
39 return IRQ_NONE;
41 /* Disable interrupt */
42 iowrite8(ioread8(plx_intscr) & ~INTSCR_INT1_ENABLE, plx_intscr);
43 return IRQ_HANDLED;
46 static int __devinit hilscher_pci_probe(struct pci_dev *dev,
47 const struct pci_device_id *id)
49 struct uio_info *info;
51 info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
52 if (!info)
53 return -ENOMEM;
55 if (pci_enable_device(dev))
56 goto out_free;
58 if (pci_request_regions(dev, "hilscher"))
59 goto out_disable;
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;
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_???";
84 info->version = "0.0.1";
85 info->irq = dev->irq;
86 info->irq_flags = IRQF_DISABLED | IRQF_SHARED;
87 info->handler = hilscher_handler;
89 if (uio_register_device(&dev->dev, info))
90 goto out_unmap;
92 pci_set_drvdata(dev, info);
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;
106 static void hilscher_pci_remove(struct pci_dev *dev)
108 struct uio_info *info = pci_get_drvdata(dev);
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);
116 kfree (info);
119 static struct pci_device_id hilscher_pci_ids[] = {
121 .vendor = PCI_VENDOR_ID_PLX,
122 .device = PCI_DEVICE_ID_PLX_9030,
123 .subvendor = PCI_SUBVENDOR_ID_PEP,
124 .subdevice = CIF_SUBDEVICE_PROFIBUS,
127 .vendor = PCI_VENDOR_ID_PLX,
128 .device = PCI_DEVICE_ID_PLX_9030,
129 .subvendor = PCI_SUBVENDOR_ID_PEP,
130 .subdevice = CIF_SUBDEVICE_DEVICENET,
132 { 0, }
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,
142 static int __init hilscher_init_module(void)
144 return pci_register_driver(&hilscher_pci_driver);
147 static void __exit hilscher_exit_module(void)
149 pci_unregister_driver(&hilscher_pci_driver);
152 module_init(hilscher_init_module);
153 module_exit(hilscher_exit_module);
155 MODULE_LICENSE("GPL v2");
156 MODULE_AUTHOR("Hans J. Koch, Benedikt Spranger");