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 #define devpriv ((struct fl512_private *) dev->private)
34 static const struct comedi_lrange range_fl512 = { 4, {
46 * fl512_ai_insn : this is the analog input function
48 static int fl512_ai_insn(struct comedi_device *dev,
49 struct comedi_subdevice *s, struct comedi_insn *insn,
53 unsigned int lo_byte, hi_byte;
54 char chan = CR_CHAN(insn->chanspec);
55 unsigned long iobase = dev->iobase;
57 for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
58 /* XXX probably can move next step out of for() loop -- will
59 * make AI a little bit faster. */
60 outb(chan, iobase + 2); /* select chan */
61 outb(0, iobase + 3); /* start conversion */
62 /* XXX should test "done" flag instead of delay */
63 udelay(30); /* sleep 30 usec */
64 lo_byte = inb(iobase + 2); /* low 8 byte */
65 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
66 data[n] = lo_byte + (hi_byte << 8);
72 * fl512_ao_insn : used to write to a DA port n times
74 static int fl512_ao_insn(struct comedi_device *dev,
75 struct comedi_subdevice *s, struct comedi_insn *insn,
79 int chan = CR_CHAN(insn->chanspec); /* get chan to write */
80 unsigned long iobase = dev->iobase; /* get base address */
82 for (n = 0; n < insn->n; n++) { /* write n data set */
84 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
86 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
87 inb(iobase + 4 + 2 * chan); /* trig */
89 devpriv->ao_readback[chan] = data[n];
95 * fl512_ao_insn_readback : used to read previous values written to
98 static int fl512_ao_insn_readback(struct comedi_device *dev,
99 struct comedi_subdevice *s,
100 struct comedi_insn *insn, unsigned int *data)
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 unsigned long iobase;
116 /* pointer to the subdevice: Analog in, Analog out,
117 (not made ->and Digital IO) */
118 struct comedi_subdevice *s;
120 iobase = it->options[0];
121 printk(KERN_INFO "comedi:%d fl512: 0x%04lx", dev->minor, iobase);
122 if (!request_region(iobase, FL512_SIZE, "fl512")) {
123 printk(KERN_WARNING " I/O port conflict\n");
126 dev->iobase = iobase;
127 dev->board_name = "fl512";
128 if (alloc_private(dev, sizeof(struct fl512_private)) < 0)
132 printk(KERN_DEBUG "malloc ok\n");
135 ret = comedi_alloc_subdevices(dev, 2);
140 * this if the definitions of the supdevices, 2 have been defined
143 s = dev->subdevices + 0;
144 /* define subdevice as Analog In */
145 s->type = COMEDI_SUBD_AI;
146 /* you can read it from userspace */
147 s->subdev_flags = SDF_READABLE | SDF_GROUND;
148 /* Number of Analog input channels */
150 /* accept only 12 bits of data */
152 /* device use one of the ranges */
153 s->range_table = &range_fl512;
154 /* function to call when read AD */
155 s->insn_read = fl512_ai_insn;
156 printk(KERN_INFO "comedi: fl512: subdevice 0 initialized\n");
159 s = dev->subdevices + 1;
160 /* define subdevice as Analog OUT */
161 s->type = COMEDI_SUBD_AO;
162 /* you can write it from userspace */
163 s->subdev_flags = SDF_WRITABLE;
164 /* Number of Analog output channels */
166 /* accept only 12 bits of data */
168 /* device use one of the ranges */
169 s->range_table = &range_fl512;
170 /* function to call when write DA */
171 s->insn_write = fl512_ao_insn;
172 /* function to call when reading DA */
173 s->insn_read = fl512_ao_insn_readback;
174 printk(KERN_INFO "comedi: fl512: subdevice 1 initialized\n");
179 static void fl512_detach(struct comedi_device *dev)
182 release_region(dev->iobase, FL512_SIZE);
185 static struct comedi_driver fl512_driver = {
186 .driver_name = "fl512",
187 .module = THIS_MODULE,
188 .attach = fl512_attach,
189 .detach = fl512_detach,
191 module_comedi_driver(fl512_driver);
193 MODULE_AUTHOR("Comedi http://www.comedi.org");
194 MODULE_DESCRIPTION("Comedi low-level driver");
195 MODULE_LICENSE("GPL");