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, {
45 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it);
46 static int fl512_detach(struct comedi_device *dev);
48 static struct comedi_driver driver_fl512 = {
49 .driver_name = "fl512",
50 .module = THIS_MODULE,
51 .attach = fl512_attach,
52 .detach = fl512_detach,
55 COMEDI_INITCLEANUP(driver_fl512);
57 static int fl512_ai_insn(struct comedi_device *dev,
58 struct comedi_subdevice *s, struct comedi_insn *insn,
60 static int fl512_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
61 struct comedi_insn *insn, unsigned int *data);
62 static int fl512_ao_insn_readback(struct comedi_device *dev,
63 struct comedi_subdevice *s,
64 struct comedi_insn *insn, unsigned int *data);
67 * fl512_ai_insn : this is the analog input function
69 static int fl512_ai_insn(struct comedi_device *dev,
70 struct comedi_subdevice *s, struct comedi_insn *insn,
74 unsigned int lo_byte, hi_byte;
75 char chan = CR_CHAN(insn->chanspec);
76 unsigned long iobase = dev->iobase;
78 for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
79 /* XXX probably can move next step out of for() loop -- will make
80 * AI a little bit faster. */
81 outb(chan, iobase + 2); /* select chan */
82 outb(0, iobase + 3); /* start conversion */
83 /* XXX should test "done" flag instead of delay */
84 udelay(30); /* sleep 30 usec */
85 lo_byte = inb(iobase + 2); /* low 8 byte */
86 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
87 data[n] = lo_byte + (hi_byte << 8);
93 * fl512_ao_insn : used to write to a DA port n times
95 static int fl512_ao_insn(struct comedi_device *dev,
96 struct comedi_subdevice *s, struct comedi_insn *insn,
100 int chan = CR_CHAN(insn->chanspec); /* get chan to write */
101 unsigned long iobase = dev->iobase; /* get base address */
103 for (n = 0; n < insn->n; n++) { /* write n data set */
104 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan); /* write low byte */
105 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan); /* write high byte */
106 inb(iobase + 4 + 2 * chan); /* trig */
108 devpriv->ao_readback[chan] = data[n];
114 * fl512_ao_insn_readback : used to read previous values written to
117 static int fl512_ao_insn_readback(struct comedi_device *dev,
118 struct comedi_subdevice *s,
119 struct comedi_insn *insn, unsigned int *data)
122 int chan = CR_CHAN(insn->chanspec);
124 for (n = 0; n < insn->n; n++) {
125 data[n] = devpriv->ao_readback[chan];
134 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
136 unsigned long iobase;
137 struct comedi_subdevice *s; /* pointer to the subdevice:
138 Analog in, Analog out, ( not made ->and Digital IO) */
140 iobase = it->options[0];
141 printk("comedi:%d fl512: 0x%04lx", dev->minor, iobase);
142 if (!request_region(iobase, FL512_SIZE, "fl512")) {
143 printk(" I/O port conflict\n");
146 dev->iobase = iobase;
147 dev->board_name = "fl512";
148 if (alloc_private(dev, sizeof(struct fl512_private)) < 0)
152 printk("malloc ok\n");
155 if (alloc_subdevices(dev, 2) < 0)
159 * this if the definitions of the supdevices, 2 have been defined
162 s = dev->subdevices + 0;
163 s->type = COMEDI_SUBD_AI; /* define subdevice as Analog In */
164 s->subdev_flags = SDF_READABLE | SDF_GROUND; /* you can read it from userspace */
165 s->n_chan = 16; /* Number of Analog input channels */
166 s->maxdata = 0x0fff; /* accept only 12 bits of data */
167 s->range_table = &range_fl512; /* device use one of the ranges */
168 s->insn_read = fl512_ai_insn; /* function to call when read AD */
169 printk("comedi: fl512: subdevice 0 initialized\n");
172 s = dev->subdevices + 1;
173 s->type = COMEDI_SUBD_AO; /* define subdevice as Analog OUT */
174 s->subdev_flags = SDF_WRITABLE; /* you can write it from userspace */
175 s->n_chan = 2; /* Number of Analog output channels */
176 s->maxdata = 0x0fff; /* accept only 12 bits of data */
177 s->range_table = &range_fl512; /* device use one of the ranges */
178 s->insn_write = fl512_ao_insn; /* function to call when write DA */
179 s->insn_read = fl512_ao_insn_readback; /* function to call when reading DA */
180 printk("comedi: fl512: subdevice 1 initialized\n");
185 static int fl512_detach(struct comedi_device *dev)
188 release_region(dev->iobase, FL512_SIZE);
189 printk("comedi%d: fl512: dummy i detach\n", dev->minor);