GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / comedi / drivers / pcl730.c
blobc9682d614e0e3daa688c51a67c1965fdc9e9f817
1 /*
2 * comedi/drivers/pcl730.c
3 * Driver for Advantech PCL-730 and clones
4 * José Luis Sánchez
5 */
6 /*
7 Driver: pcl730
8 Description: Advantech PCL-730 (& compatibles)
9 Author: José Luis Sánchez (jsanchezv@teleline.es)
10 Status: untested
11 Devices: [Advantech] PCL-730 (pcl730), [ICP] ISO-730 (iso730),
12 [Adlink] ACL-7130 (acl7130)
14 Interrupts are not supported.
15 The ACL-7130 card have an 8254 timer/counter not supported by this driver.
18 #include "../comedidev.h"
20 #include <linux/ioport.h>
22 #define PCL730_SIZE 4
23 #define ACL7130_SIZE 8
24 #define PCL730_IDIO_LO 0 /* Isolated Digital I/O low byte (ID0-ID7) */
25 #define PCL730_IDIO_HI 1 /* Isolated Digital I/O high byte (ID8-ID15) */
26 #define PCL730_DIO_LO 2 /* TTL Digital I/O low byte (D0-D7) */
27 #define PCL730_DIO_HI 3 /* TTL Digital I/O high byte (D8-D15) */
29 static int pcl730_attach(struct comedi_device *dev,
30 struct comedi_devconfig *it);
31 static int pcl730_detach(struct comedi_device *dev);
33 struct pcl730_board {
35 const char *name; /* board name */
36 unsigned int io_range; /* len of I/O space */
39 static const struct pcl730_board boardtypes[] = {
40 {"pcl730", PCL730_SIZE,},
41 {"iso730", PCL730_SIZE,},
42 {"acl7130", ACL7130_SIZE,},
45 #define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl730_board))
46 #define this_board ((const struct pcl730_board *)dev->board_ptr)
48 static struct comedi_driver driver_pcl730 = {
49 .driver_name = "pcl730",
50 .module = THIS_MODULE,
51 .attach = pcl730_attach,
52 .detach = pcl730_detach,
53 .board_name = &boardtypes[0].name,
54 .num_names = n_boardtypes,
55 .offset = sizeof(struct pcl730_board),
58 static int __init driver_pcl730_init_module(void)
60 return comedi_driver_register(&driver_pcl730);
63 static void __exit driver_pcl730_cleanup_module(void)
65 comedi_driver_unregister(&driver_pcl730);
68 module_init(driver_pcl730_init_module);
69 module_exit(driver_pcl730_cleanup_module);
71 static int pcl730_do_insn(struct comedi_device *dev, struct comedi_subdevice *s,
72 struct comedi_insn *insn, unsigned int *data)
74 if (insn->n != 2)
75 return -EINVAL;
77 if (data[0]) {
78 s->state &= ~data[0];
79 s->state |= (data[0] & data[1]);
81 if (data[0] & 0x00ff)
82 outb(s->state & 0xff,
83 dev->iobase + ((unsigned long)s->private));
84 if (data[0] & 0xff00)
85 outb((s->state >> 8),
86 dev->iobase + ((unsigned long)s->private) + 1);
88 data[1] = s->state;
90 return 2;
93 static int pcl730_di_insn(struct comedi_device *dev, struct comedi_subdevice *s,
94 struct comedi_insn *insn, unsigned int *data)
96 if (insn->n != 2)
97 return -EINVAL;
99 data[1] = inb(dev->iobase + ((unsigned long)s->private)) |
100 (inb(dev->iobase + ((unsigned long)s->private) + 1) << 8);
102 return 2;
105 static int pcl730_attach(struct comedi_device *dev, struct comedi_devconfig *it)
107 struct comedi_subdevice *s;
108 unsigned long iobase;
109 unsigned int iorange;
111 iobase = it->options[0];
112 iorange = this_board->io_range;
113 printk(KERN_INFO "comedi%d: pcl730: board=%s 0x%04lx ", dev->minor,
114 this_board->name, iobase);
115 if (!request_region(iobase, iorange, "pcl730")) {
116 printk("I/O port conflict\n");
117 return -EIO;
119 dev->board_name = this_board->name;
120 dev->iobase = iobase;
121 dev->irq = 0;
123 if (alloc_subdevices(dev, 4) < 0)
124 return -ENOMEM;
126 s = dev->subdevices + 0;
127 /* Isolated do */
128 s->type = COMEDI_SUBD_DO;
129 s->subdev_flags = SDF_WRITABLE;
130 s->maxdata = 1;
131 s->n_chan = 16;
132 s->insn_bits = pcl730_do_insn;
133 s->range_table = &range_digital;
134 s->private = (void *)PCL730_IDIO_LO;
136 s = dev->subdevices + 1;
137 /* Isolated di */
138 s->type = COMEDI_SUBD_DI;
139 s->subdev_flags = SDF_READABLE;
140 s->maxdata = 1;
141 s->n_chan = 16;
142 s->insn_bits = pcl730_di_insn;
143 s->range_table = &range_digital;
144 s->private = (void *)PCL730_IDIO_LO;
146 s = dev->subdevices + 2;
147 /* TTL do */
148 s->type = COMEDI_SUBD_DO;
149 s->subdev_flags = SDF_WRITABLE;
150 s->maxdata = 1;
151 s->n_chan = 16;
152 s->insn_bits = pcl730_do_insn;
153 s->range_table = &range_digital;
154 s->private = (void *)PCL730_DIO_LO;
156 s = dev->subdevices + 3;
157 /* TTL di */
158 s->type = COMEDI_SUBD_DI;
159 s->subdev_flags = SDF_READABLE;
160 s->maxdata = 1;
161 s->n_chan = 16;
162 s->insn_bits = pcl730_di_insn;
163 s->range_table = &range_digital;
164 s->private = (void *)PCL730_DIO_LO;
166 printk(KERN_INFO "\n");
168 return 0;
171 static int pcl730_detach(struct comedi_device *dev)
173 printk(KERN_INFO "comedi%d: pcl730: remove\n", dev->minor);
175 if (dev->iobase)
176 release_region(dev->iobase, this_board->io_range);
178 return 0;
181 MODULE_AUTHOR("Comedi http://www.comedi.org");
182 MODULE_DESCRIPTION("Comedi low-level driver");
183 MODULE_LICENSE("GPL");