1 // SPDX-License-Identifier: GPL-2.0+
4 * Anders Gnistrup <ex18@kalman.iau.dtu.dk>
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 * Description: unknown
13 * Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk>
14 * Devices: [unknown] FL512 (fl512)
17 * Digital I/O is not supported.
19 * Configuration options:
20 * [0] - I/O port base address
23 #include <linux/module.h>
24 #include <linux/comedi/comedidev.h>
25 #include <linux/delay.h>
30 #define FL512_AI_LSB_REG 0x02
31 #define FL512_AI_MSB_REG 0x03
32 #define FL512_AI_MUX_REG 0x02
33 #define FL512_AI_START_CONV_REG 0x03
34 #define FL512_AO_DATA_REG(x) (0x04 + ((x) * 2))
35 #define FL512_AO_TRIG_REG(x) (0x04 + ((x) * 2))
37 static const struct comedi_lrange range_fl512 = {
49 static int fl512_ai_insn_read(struct comedi_device *dev,
50 struct comedi_subdevice *s,
51 struct comedi_insn *insn,
54 unsigned int chan = CR_CHAN(insn->chanspec);
58 outb(chan, dev->iobase + FL512_AI_MUX_REG);
60 for (i = 0; i < insn->n; i++) {
61 outb(0, dev->iobase + FL512_AI_START_CONV_REG);
63 /* XXX should test "done" flag instead of delay */
64 usleep_range(30, 100);
66 val = inb(dev->iobase + FL512_AI_LSB_REG);
67 val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8);
76 static int fl512_ao_insn_write(struct comedi_device *dev,
77 struct comedi_subdevice *s,
78 struct comedi_insn *insn,
81 unsigned int chan = CR_CHAN(insn->chanspec);
82 unsigned int val = s->readback[chan];
85 for (i = 0; i < insn->n; i++) {
88 /* write LSB, MSB then trigger conversion */
89 outb(val & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan));
90 outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan));
91 inb(dev->iobase + FL512_AO_TRIG_REG(chan));
93 s->readback[chan] = val;
98 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
100 struct comedi_subdevice *s;
103 ret = comedi_request_region(dev, it->options[0], 0x10);
107 ret = comedi_alloc_subdevices(dev, 2);
111 /* Analog Input subdevice */
112 s = &dev->subdevices[0];
113 s->type = COMEDI_SUBD_AI;
114 s->subdev_flags = SDF_READABLE | SDF_GROUND;
117 s->range_table = &range_fl512;
118 s->insn_read = fl512_ai_insn_read;
120 /* Analog Output subdevice */
121 s = &dev->subdevices[1];
122 s->type = COMEDI_SUBD_AO;
123 s->subdev_flags = SDF_WRITABLE;
126 s->range_table = &range_fl512;
127 s->insn_write = fl512_ao_insn_write;
129 return comedi_alloc_subdev_readback(s);
132 static struct comedi_driver fl512_driver = {
133 .driver_name = "fl512",
134 .module = THIS_MODULE,
135 .attach = fl512_attach,
136 .detach = comedi_legacy_detach,
138 module_comedi_driver(fl512_driver);
140 MODULE_AUTHOR("Comedi https://www.comedi.org");
141 MODULE_DESCRIPTION("Comedi low-level driver");
142 MODULE_LICENSE("GPL");