1 // SPDX-License-Identifier: GPL-2.0+
3 * comedi/drivers/dt2815.c
4 * Hardware driver for Data Translation DT2815
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
11 * Description: Data Translation DT2815
13 * Status: mostly complete, untested
14 * Devices: [Data Translation] DT2815 (dt2815)
16 * I'm not sure anyone has ever tested this board. If you have information
17 * contrary, please update.
19 * Configuration options:
20 * [0] - I/O port base base address
22 * [2] - Voltage unipolar/bipolar configuration
23 * 0 == unipolar 5V (0V -- +5V)
24 * 1 == bipolar 5V (-5V -- +5V)
25 * [3] - Current offset configuration
26 * 0 == disabled (0mA -- +32mAV)
27 * 1 == enabled (+4mA -- +20mAV)
28 * [4] - Firmware program configuration
29 * 0 == program 1 (see manual table 5-4)
30 * 1 == program 2 (see manual table 5-4)
31 * 2 == program 3 (see manual table 5-4)
32 * 3 == program 4 (see manual table 5-4)
33 * [5] - Analog output 0 range configuration
36 * [6] - Analog output 1 range configuration (same options)
37 * [7] - Analog output 2 range configuration (same options)
38 * [8] - Analog output 3 range configuration (same options)
39 * [9] - Analog output 4 range configuration (same options)
40 * [10] - Analog output 5 range configuration (same options)
41 * [11] - Analog output 6 range configuration (same options)
42 * [12] - Analog output 7 range configuration (same options)
45 #include <linux/module.h>
46 #include "../comedidev.h"
48 #include <linux/delay.h>
51 #define DT2815_STATUS 1
53 struct dt2815_private {
54 const struct comedi_lrange *range_type_list[8];
55 unsigned int ao_readback[8];
58 static int dt2815_ao_status(struct comedi_device *dev,
59 struct comedi_subdevice *s,
60 struct comedi_insn *insn,
61 unsigned long context)
65 status = inb(dev->iobase + DT2815_STATUS);
66 if (status == context)
71 static int dt2815_ao_insn_read(struct comedi_device *dev,
72 struct comedi_subdevice *s,
73 struct comedi_insn *insn, unsigned int *data)
75 struct dt2815_private *devpriv = dev->private;
77 int chan = CR_CHAN(insn->chanspec);
79 for (i = 0; i < insn->n; i++)
80 data[i] = devpriv->ao_readback[chan];
85 static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
86 struct comedi_insn *insn, unsigned int *data)
88 struct dt2815_private *devpriv = dev->private;
90 int chan = CR_CHAN(insn->chanspec);
94 for (i = 0; i < insn->n; i++) {
95 /* FIXME: lo bit 0 chooses voltage output or current output */
96 lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01;
97 hi = (data[i] & 0xff0) >> 4;
99 ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x00);
103 outb(lo, dev->iobase + DT2815_DATA);
105 ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x10);
109 outb(hi, dev->iobase + DT2815_DATA);
111 devpriv->ao_readback[chan] = data[i];
117 * options[0] Board base address
118 * options[1] IRQ (not applicable)
119 * options[2] Voltage unipolar/bipolar configuration
120 * 0 == unipolar 5V (0V -- +5V)
121 * 1 == bipolar 5V (-5V -- +5V)
122 * options[3] Current offset configuration
123 * 0 == disabled (0mA -- +32mAV)
124 * 1 == enabled (+4mA -- +20mAV)
125 * options[4] Firmware program configuration
126 * 0 == program 1 (see manual table 5-4)
127 * 1 == program 2 (see manual table 5-4)
128 * 2 == program 3 (see manual table 5-4)
129 * 3 == program 4 (see manual table 5-4)
130 * options[5] Analog output 0 range configuration
133 * options[6] Analog output 1 range configuration
135 * options[12] Analog output 7 range configuration
140 static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
142 struct dt2815_private *devpriv;
143 struct comedi_subdevice *s;
145 const struct comedi_lrange *current_range_type, *voltage_range_type;
148 ret = comedi_request_region(dev, it->options[0], 0x2);
152 ret = comedi_alloc_subdevices(dev, 1);
156 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
160 s = &dev->subdevices[0];
162 s->type = COMEDI_SUBD_AO;
163 s->subdev_flags = SDF_WRITABLE;
166 s->insn_write = dt2815_ao_insn;
167 s->insn_read = dt2815_ao_insn_read;
168 s->range_table_list = devpriv->range_type_list;
170 current_range_type = (it->options[3])
171 ? &range_4_20mA : &range_0_32mA;
172 voltage_range_type = (it->options[2])
173 ? &range_bipolar5 : &range_unipolar5;
174 for (i = 0; i < 8; i++) {
175 devpriv->range_type_list[i] = (it->options[5 + i])
176 ? current_range_type : voltage_range_type;
180 outb(0x00, dev->iobase + DT2815_STATUS);
181 for (i = 0; i < 100; i++) {
182 /* This is incredibly slow (approx 20 ms) */
185 usleep_range(1000, 3000);
186 status = inb(dev->iobase + DT2815_STATUS);
188 unsigned int program;
190 program = (it->options[4] & 0x3) << 3 | 0x7;
191 outb(program, dev->iobase + DT2815_DATA);
192 dev_dbg(dev->class_dev, "program: 0x%x (@t=%d)\n",
195 } else if (status != 0x00) {
196 dev_dbg(dev->class_dev,
197 "unexpected status 0x%x (@t=%d)\n",
200 outb(0x00, dev->iobase + DT2815_STATUS);
207 static struct comedi_driver dt2815_driver = {
208 .driver_name = "dt2815",
209 .module = THIS_MODULE,
210 .attach = dt2815_attach,
211 .detach = comedi_legacy_detach,
213 module_comedi_driver(dt2815_driver);
215 MODULE_AUTHOR("Comedi https://www.comedi.org");
216 MODULE_DESCRIPTION("Comedi low-level driver");
217 MODULE_LICENSE("GPL");