2 comedi/drivers/pcl724.c
4 Michal Dobes <dobes@tesnet.cz>
6 hardware driver for Advantech cards:
7 card: PCL-724, PCL-722, PCL-731
8 driver: pcl724, pcl722, pcl731
10 card: ACL-7122, ACL-7124, PET-48DIO
11 driver: acl7122, acl7124, pet48dio
13 Options for PCL-724, PCL-731, ACL-7124 and PET-48DIO:
16 Options for PCL-722 and ACL-7122:
18 [1] - IRQ (0=disable IRQ) IRQ isn't supported at this time!
20 0, 144: 144 DIO configuration
21 1, 96: 96 DIO configuration
25 Description: Advantech PCL-724, PCL-722, PCL-731 ADLink ACL-7122, ACL-7124,
27 Author: Michal Dobes <dobes@tesnet.cz>
28 Devices: [Advantech] PCL-724 (pcl724), PCL-722 (pcl722), PCL-731 (pcl731),
29 [ADLink] ACL-7122 (acl7122), ACL-7124 (acl7124), PET-48DIO (pet48dio)
32 This is driver for digital I/O boards PCL-722/724/731 with 144/24/48 DIO
33 and for digital I/O boards ACL-7122/7124/PET-48DIO with 144/24/48 DIO.
34 It need 8255.o for operations and only immediate mode is supported.
35 See the source for configuration details.
38 * check_driver overrides:
42 #include "../comedidev.h"
44 #include <linux/ioport.h>
45 #include <linux/delay.h>
49 #define PCL722_SIZE 32
50 #define PCL722_96_SIZE 16
57 /* #define PCL724_IRQ 1 no IRQ support now */
61 const char *name; /* board name */
62 int dio; /* num of DIO */
63 int numofports; /* num of 8255 subdevices */
64 unsigned int IRQbits; /* allowed interrupts */
65 unsigned int io_range; /* len of IO space */
70 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
72 unsigned long iobase = arg;
75 outb(data, iobase + port);
78 return inb(iobase + port);
82 static int subdev_8255mapped_cb(int dir, int port, int data,
85 int movport = SIZE_8255 * (iobase >> 12);
90 outb(port + movport, iobase);
91 outb(data, iobase + 1);
94 outb(port + movport, iobase);
95 return inb(iobase + 1);
99 static int pcl724_attach(struct comedi_device *dev, struct comedi_devconfig *it)
101 const struct pcl724_board *board = comedi_board(dev);
102 struct comedi_subdevice *s;
103 unsigned long iobase;
104 unsigned int iorange;
105 int ret, i, n_subdevices;
110 iobase = it->options[0];
111 iorange = board->io_range;
112 if ((board->can_have96) && ((it->options[1] == 1)
113 || (it->options[1] == 96)))
114 iorange = PCL722_96_SIZE; /* PCL-724 in 96 DIO configuration */
115 printk(KERN_INFO "comedi%d: pcl724: board=%s, 0x%03lx ", dev->minor,
116 board->name, iobase);
117 if (!request_region(iobase, iorange, "pcl724")) {
118 printk("I/O port conflict\n");
122 dev->iobase = iobase;
124 dev->board_name = board->name;
128 if (board->IRQbits != 0) { /* board support IRQ */
129 irq = it->options[1];
130 if (irq) { /* we want to use IRQ */
131 if (((1 << irq) & board->IRQbits) == 0) {
133 ", IRQ %u is out of allowed range, "
134 "DISABLING IT", irq);
135 irq = 0; /* Bad IRQ */
138 (irq, interrupt_pcl724, 0, "pcl724", dev)) {
140 ", unable to allocate IRQ %u, "
141 "DISABLING IT", irq);
142 irq = 0; /* Can't use IRQ */
144 printk(", irq=%u", irq);
155 n_subdevices = board->numofports;
156 if ((board->can_have96) && ((it->options[1] == 1)
157 || (it->options[1] == 96)))
158 n_subdevices = 4; /* PCL-724 in 96 DIO configuration */
160 ret = comedi_alloc_subdevices(dev, n_subdevices);
164 for (i = 0; i < dev->n_subdevices; i++) {
165 s = &dev->subdevices[i];
166 if (board->is_pet48) {
167 subdev_8255_init(dev, s, subdev_8255mapped_cb,
168 (unsigned long)(dev->iobase +
171 subdev_8255_init(dev, s, subdev_8255_cb,
172 (unsigned long)(dev->iobase +
179 static void pcl724_detach(struct comedi_device *dev)
181 const struct pcl724_board *board = comedi_board(dev);
182 struct comedi_subdevice *s;
185 for (i = 0; i < dev->n_subdevices; i++) {
186 s = &dev->subdevices[i];
187 subdev_8255_cleanup(dev, s);
191 free_irq(dev->irq, dev);
193 release_region(dev->iobase, board->io_range);
196 static const struct pcl724_board boardtypes[] = {
197 { "pcl724", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, },
198 { "pcl722", 144, 6, 0x00fc, PCL722_SIZE, 1, 0, },
199 { "pcl731", 48, 2, 0x9cfc, PCL731_SIZE, 0, 0, },
200 { "acl7122", 144, 6, 0x9ee8, PCL722_SIZE, 1, 0, },
201 { "acl7124", 24, 1, 0x00fc, PCL724_SIZE, 0, 0, },
202 { "pet48dio", 48, 2, 0x9eb8, PET48_SIZE, 0, 1, },
205 static struct comedi_driver pcl724_driver = {
206 .driver_name = "pcl724",
207 .module = THIS_MODULE,
208 .attach = pcl724_attach,
209 .detach = pcl724_detach,
210 .board_name = &boardtypes[0].name,
211 .num_names = ARRAY_SIZE(boardtypes),
212 .offset = sizeof(struct pcl724_board),
214 module_comedi_driver(pcl724_driver);
216 MODULE_AUTHOR("Comedi http://www.comedi.org");
217 MODULE_DESCRIPTION("Comedi low-level driver");
218 MODULE_LICENSE("GPL");