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 <linux/module.h>
22 #include "../comedidev.h"
24 #include <linux/delay.h>
26 #define FL512_SIZE 16 /* the size of the used memory */
27 struct fl512_private {
28 unsigned short ao_readback[2];
31 static const struct comedi_lrange range_fl512 = { 4, {
43 * fl512_ai_insn : this is the analog input function
45 static int fl512_ai_insn(struct comedi_device *dev,
46 struct comedi_subdevice *s, struct comedi_insn *insn,
50 unsigned int lo_byte, hi_byte;
51 char chan = CR_CHAN(insn->chanspec);
52 unsigned long iobase = dev->iobase;
54 for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
55 /* XXX probably can move next step out of for() loop -- will
56 * make AI a little bit faster. */
57 outb(chan, iobase + 2); /* select chan */
58 outb(0, iobase + 3); /* start conversion */
59 /* XXX should test "done" flag instead of delay */
60 udelay(30); /* sleep 30 usec */
61 lo_byte = inb(iobase + 2); /* low 8 byte */
62 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
63 data[n] = lo_byte + (hi_byte << 8);
69 * fl512_ao_insn : used to write to a DA port n times
71 static int fl512_ao_insn(struct comedi_device *dev,
72 struct comedi_subdevice *s, struct comedi_insn *insn,
75 struct fl512_private *devpriv = dev->private;
77 int chan = CR_CHAN(insn->chanspec); /* get chan to write */
78 unsigned long iobase = dev->iobase; /* get base address */
80 for (n = 0; n < insn->n; n++) { /* write n data set */
82 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
84 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
85 inb(iobase + 4 + 2 * chan); /* trig */
87 devpriv->ao_readback[chan] = data[n];
93 * fl512_ao_insn_readback : used to read previous values written to
96 static int fl512_ao_insn_readback(struct comedi_device *dev,
97 struct comedi_subdevice *s,
98 struct comedi_insn *insn, unsigned int *data)
100 struct fl512_private *devpriv = dev->private;
102 int chan = CR_CHAN(insn->chanspec);
104 for (n = 0; n < insn->n; n++)
105 data[n] = devpriv->ao_readback[chan];
110 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
112 struct fl512_private *devpriv;
113 struct comedi_subdevice *s;
116 ret = comedi_request_region(dev, it->options[0], FL512_SIZE);
120 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
124 ret = comedi_alloc_subdevices(dev, 2);
129 * this if the definitions of the supdevices, 2 have been defined
132 s = &dev->subdevices[0];
133 /* define subdevice as Analog In */
134 s->type = COMEDI_SUBD_AI;
135 /* you can read it from userspace */
136 s->subdev_flags = SDF_READABLE | SDF_GROUND;
137 /* Number of Analog input channels */
139 /* accept only 12 bits of data */
141 /* device use one of the ranges */
142 s->range_table = &range_fl512;
143 /* function to call when read AD */
144 s->insn_read = fl512_ai_insn;
147 s = &dev->subdevices[1];
148 /* define subdevice as Analog OUT */
149 s->type = COMEDI_SUBD_AO;
150 /* you can write it from userspace */
151 s->subdev_flags = SDF_WRITABLE;
152 /* Number of Analog output channels */
154 /* accept only 12 bits of data */
156 /* device use one of the ranges */
157 s->range_table = &range_fl512;
158 /* function to call when write DA */
159 s->insn_write = fl512_ao_insn;
160 /* function to call when reading DA */
161 s->insn_read = fl512_ao_insn_readback;
166 static struct comedi_driver fl512_driver = {
167 .driver_name = "fl512",
168 .module = THIS_MODULE,
169 .attach = fl512_attach,
170 .detach = comedi_legacy_detach,
172 module_comedi_driver(fl512_driver);
174 MODULE_AUTHOR("Comedi http://www.comedi.org");
175 MODULE_DESCRIPTION("Comedi low-level driver");
176 MODULE_LICENSE("GPL");