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 <linux/comedi/comedidev.h>
47 #include <linux/delay.h>
50 #define DT2815_STATUS 1
52 struct dt2815_private {
53 const struct comedi_lrange *range_type_list[8];
54 unsigned int ao_readback[8];
57 static int dt2815_ao_status(struct comedi_device *dev,
58 struct comedi_subdevice *s,
59 struct comedi_insn *insn,
60 unsigned long context)
64 status = inb(dev->iobase + DT2815_STATUS);
65 if (status == context)
70 static int dt2815_ao_insn_read(struct comedi_device *dev,
71 struct comedi_subdevice *s,
72 struct comedi_insn *insn, unsigned int *data)
74 struct dt2815_private *devpriv = dev->private;
76 int chan = CR_CHAN(insn->chanspec);
78 for (i = 0; i < insn->n; i++)
79 data[i] = devpriv->ao_readback[chan];
84 static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
85 struct comedi_insn *insn, unsigned int *data)
87 struct dt2815_private *devpriv = dev->private;
89 int chan = CR_CHAN(insn->chanspec);
93 for (i = 0; i < insn->n; i++) {
94 /* FIXME: lo bit 0 chooses voltage output or current output */
95 lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01;
96 hi = (data[i] & 0xff0) >> 4;
98 ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x00);
102 outb(lo, dev->iobase + DT2815_DATA);
104 ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x10);
108 outb(hi, dev->iobase + DT2815_DATA);
110 devpriv->ao_readback[chan] = data[i];
116 * options[0] Board base address
117 * options[1] IRQ (not applicable)
118 * options[2] Voltage unipolar/bipolar configuration
119 * 0 == unipolar 5V (0V -- +5V)
120 * 1 == bipolar 5V (-5V -- +5V)
121 * options[3] Current offset configuration
122 * 0 == disabled (0mA -- +32mAV)
123 * 1 == enabled (+4mA -- +20mAV)
124 * options[4] Firmware program configuration
125 * 0 == program 1 (see manual table 5-4)
126 * 1 == program 2 (see manual table 5-4)
127 * 2 == program 3 (see manual table 5-4)
128 * 3 == program 4 (see manual table 5-4)
129 * options[5] Analog output 0 range configuration
132 * options[6] Analog output 1 range configuration
134 * options[12] Analog output 7 range configuration
139 static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
141 struct dt2815_private *devpriv;
142 struct comedi_subdevice *s;
144 const struct comedi_lrange *current_range_type, *voltage_range_type;
147 ret = comedi_request_region(dev, it->options[0], 0x2);
151 ret = comedi_alloc_subdevices(dev, 1);
155 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
159 s = &dev->subdevices[0];
161 s->type = COMEDI_SUBD_AO;
162 s->subdev_flags = SDF_WRITABLE;
165 s->insn_write = dt2815_ao_insn;
166 s->insn_read = dt2815_ao_insn_read;
167 s->range_table_list = devpriv->range_type_list;
169 current_range_type = (it->options[3])
170 ? &range_4_20mA : &range_0_32mA;
171 voltage_range_type = (it->options[2])
172 ? &range_bipolar5 : &range_unipolar5;
173 for (i = 0; i < 8; i++) {
174 devpriv->range_type_list[i] = (it->options[5 + i])
175 ? current_range_type : voltage_range_type;
179 outb(0x00, dev->iobase + DT2815_STATUS);
180 for (i = 0; i < 100; i++) {
181 /* This is incredibly slow (approx 20 ms) */
184 usleep_range(1000, 3000);
185 status = inb(dev->iobase + DT2815_STATUS);
187 unsigned int program;
189 program = (it->options[4] & 0x3) << 3 | 0x7;
190 outb(program, dev->iobase + DT2815_DATA);
191 dev_dbg(dev->class_dev, "program: 0x%x (@t=%d)\n",
194 } else if (status != 0x00) {
195 dev_dbg(dev->class_dev,
196 "unexpected status 0x%x (@t=%d)\n",
199 outb(0x00, dev->iobase + DT2815_STATUS);
206 static struct comedi_driver dt2815_driver = {
207 .driver_name = "dt2815",
208 .module = THIS_MODULE,
209 .attach = dt2815_attach,
210 .detach = comedi_legacy_detach,
212 module_comedi_driver(dt2815_driver);
214 MODULE_AUTHOR("Comedi https://www.comedi.org");
215 MODULE_DESCRIPTION("Comedi low-level driver");
216 MODULE_LICENSE("GPL");