3 Anders Gnistrup <ex18@kalman.iau.dtu.dk>
9 Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk>
10 Devices: [unknown] FL512 (fl512)
13 Digital I/O is not supported.
15 Configuration options:
16 [0] - I/O port base address
21 #include "../comedidev.h"
23 #include <linux/delay.h>
24 #include <linux/ioport.h>
26 #define FL512_SIZE 16 /* the size of the used memory */
27 struct fl512_private {
32 static const struct comedi_lrange range_fl512 = { 4, {
44 * fl512_ai_insn : this is the analog input function
46 static int fl512_ai_insn(struct comedi_device *dev,
47 struct comedi_subdevice *s, struct comedi_insn *insn,
51 unsigned int lo_byte, hi_byte;
52 char chan = CR_CHAN(insn->chanspec);
53 unsigned long iobase = dev->iobase;
55 for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
56 /* XXX probably can move next step out of for() loop -- will
57 * make AI a little bit faster. */
58 outb(chan, iobase + 2); /* select chan */
59 outb(0, iobase + 3); /* start conversion */
60 /* XXX should test "done" flag instead of delay */
61 udelay(30); /* sleep 30 usec */
62 lo_byte = inb(iobase + 2); /* low 8 byte */
63 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
64 data[n] = lo_byte + (hi_byte << 8);
70 * fl512_ao_insn : used to write to a DA port n times
72 static int fl512_ao_insn(struct comedi_device *dev,
73 struct comedi_subdevice *s, struct comedi_insn *insn,
76 struct fl512_private *devpriv = dev->private;
78 int chan = CR_CHAN(insn->chanspec); /* get chan to write */
79 unsigned long iobase = dev->iobase; /* get base address */
81 for (n = 0; n < insn->n; n++) { /* write n data set */
83 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
85 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
86 inb(iobase + 4 + 2 * chan); /* trig */
88 devpriv->ao_readback[chan] = data[n];
94 * fl512_ao_insn_readback : used to read previous values written to
97 static int fl512_ao_insn_readback(struct comedi_device *dev,
98 struct comedi_subdevice *s,
99 struct comedi_insn *insn, unsigned int *data)
101 struct fl512_private *devpriv = dev->private;
103 int chan = CR_CHAN(insn->chanspec);
105 for (n = 0; n < insn->n; n++)
106 data[n] = devpriv->ao_readback[chan];
111 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
113 struct fl512_private *devpriv;
114 struct comedi_subdevice *s;
117 ret = comedi_request_region(dev, it->options[0], FL512_SIZE);
121 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
124 dev->private = devpriv;
126 ret = comedi_alloc_subdevices(dev, 2);
131 * this if the definitions of the supdevices, 2 have been defined
134 s = &dev->subdevices[0];
135 /* define subdevice as Analog In */
136 s->type = COMEDI_SUBD_AI;
137 /* you can read it from userspace */
138 s->subdev_flags = SDF_READABLE | SDF_GROUND;
139 /* Number of Analog input channels */
141 /* accept only 12 bits of data */
143 /* device use one of the ranges */
144 s->range_table = &range_fl512;
145 /* function to call when read AD */
146 s->insn_read = fl512_ai_insn;
149 s = &dev->subdevices[1];
150 /* define subdevice as Analog OUT */
151 s->type = COMEDI_SUBD_AO;
152 /* you can write it from userspace */
153 s->subdev_flags = SDF_WRITABLE;
154 /* Number of Analog output channels */
156 /* accept only 12 bits of data */
158 /* device use one of the ranges */
159 s->range_table = &range_fl512;
160 /* function to call when write DA */
161 s->insn_write = fl512_ao_insn;
162 /* function to call when reading DA */
163 s->insn_read = fl512_ao_insn_readback;
168 static struct comedi_driver fl512_driver = {
169 .driver_name = "fl512",
170 .module = THIS_MODULE,
171 .attach = fl512_attach,
172 .detach = comedi_legacy_detach,
174 module_comedi_driver(fl512_driver);
176 MODULE_AUTHOR("Comedi http://www.comedi.org");
177 MODULE_DESCRIPTION("Comedi low-level driver");
178 MODULE_LICENSE("GPL");