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 "../comedidev.h"
26 #include <linux/delay.h>
31 #define FL512_AI_LSB_REG 0x02
32 #define FL512_AI_MSB_REG 0x03
33 #define FL512_AI_MUX_REG 0x02
34 #define FL512_AI_START_CONV_REG 0x03
35 #define FL512_AO_DATA_REG(x) (0x04 + ((x) * 2))
36 #define FL512_AO_TRIG_REG(x) (0x04 + ((x) * 2))
38 static const struct comedi_lrange range_fl512 = {
50 static int fl512_ai_insn_read(struct comedi_device *dev,
51 struct comedi_subdevice *s,
52 struct comedi_insn *insn,
55 unsigned int chan = CR_CHAN(insn->chanspec);
59 outb(chan, dev->iobase + FL512_AI_MUX_REG);
61 for (i = 0; i < insn->n; i++) {
62 outb(0, dev->iobase + FL512_AI_START_CONV_REG);
64 /* XXX should test "done" flag instead of delay */
65 usleep_range(30, 100);
67 val = inb(dev->iobase + FL512_AI_LSB_REG);
68 val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8);
77 static int fl512_ao_insn_write(struct comedi_device *dev,
78 struct comedi_subdevice *s,
79 struct comedi_insn *insn,
82 unsigned int chan = CR_CHAN(insn->chanspec);
83 unsigned int val = s->readback[chan];
86 for (i = 0; i < insn->n; i++) {
89 /* write LSB, MSB then trigger conversion */
90 outb(val & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan));
91 outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan));
92 inb(dev->iobase + FL512_AO_TRIG_REG(chan));
94 s->readback[chan] = val;
99 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
101 struct comedi_subdevice *s;
104 ret = comedi_request_region(dev, it->options[0], 0x10);
108 ret = comedi_alloc_subdevices(dev, 2);
112 /* Analog Input subdevice */
113 s = &dev->subdevices[0];
114 s->type = COMEDI_SUBD_AI;
115 s->subdev_flags = SDF_READABLE | SDF_GROUND;
118 s->range_table = &range_fl512;
119 s->insn_read = fl512_ai_insn_read;
121 /* Analog Output subdevice */
122 s = &dev->subdevices[1];
123 s->type = COMEDI_SUBD_AO;
124 s->subdev_flags = SDF_WRITABLE;
127 s->range_table = &range_fl512;
128 s->insn_write = fl512_ao_insn_write;
130 return comedi_alloc_subdev_readback(s);
133 static struct comedi_driver fl512_driver = {
134 .driver_name = "fl512",
135 .module = THIS_MODULE,
136 .attach = fl512_attach,
137 .detach = comedi_legacy_detach,
139 module_comedi_driver(fl512_driver);
141 MODULE_AUTHOR("Comedi https://www.comedi.org");
142 MODULE_DESCRIPTION("Comedi low-level driver");
143 MODULE_LICENSE("GPL");