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.
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/uio_driver.h>
18 #ifndef PCI_DEVICE_ID_PLX_9030
19 #define PCI_DEVICE_ID_PLX_9030 0x9030
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
37 if ((ioread8(plx_intscr
) & INT1_ENABLED_AND_ACTIVE
)
38 != INT1_ENABLED_AND_ACTIVE
)
41 /* Disable interrupt */
42 iowrite8(ioread8(plx_intscr
) & ~INTSCR_INT1_ENABLE
, plx_intscr
);
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
);
55 if (pci_enable_device(dev
))
58 if (pci_request_regions(dev
, "hilscher"))
61 info
->mem
[0].addr
= pci_resource_start(dev
, 0);
62 if (!info
->mem
[0].addr
)
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
)
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";
78 case CIF_SUBDEVICE_DEVICENET
:
79 info
->name
= "CIF_Devicenet";
82 info
->name
= "CIF_???";
84 info
->version
= "0.0.1";
86 info
->irq_flags
= IRQF_DISABLED
| IRQF_SHARED
;
87 info
->handler
= hilscher_handler
;
89 if (uio_register_device(&dev
->dev
, info
))
92 pci_set_drvdata(dev
, info
);
96 iounmap(info
->mem
[0].internal_addr
);
98 pci_release_regions(dev
);
100 pci_disable_device(dev
);
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
);
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
,
135 static struct pci_driver hilscher_pci_driver
= {
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");