1 // SPDX-License-Identifier: GPL-2.0+
4 * Comedi driver for DAC02 compatible boards
5 * Copyright (C) 2014 H Hartley Sweeten <hsweeten@visionengravers.com>
7 * Based on the poc driver
8 * Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net>
9 * Copyright (C) 2001 David A. Schleef <ds@schleef.org>
11 * COMEDI - Linux Control and Measurement Device Interface
12 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
17 * Description: Comedi driver for DAC02 compatible boards
18 * Devices: [Keithley Metrabyte] DAC-02 (dac02)
19 * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
20 * Updated: Tue, 11 Mar 2014 11:27:19 -0700
23 * Configuration options:
27 #include <linux/module.h>
29 #include "../comedidev.h"
32 * The output range is selected by jumpering pins on the I/O connector.
34 * Range Chan # Jumper pins Output
35 * ------------- ------ ------------- -----------------
36 * 0 to 5V 0 21 to 22 24
38 * 0 to 10V 0 20 to 22 24
42 * +/-10V 0 20 to 22 23
44 * 4 to 20mA 0 21 to 22 25
46 * AC reference 0 In on pin 22 24 (2-quadrant)
47 * In on pin 22 23 (4-quadrant)
48 * 1 In on pin 16 18 (2-quadrant)
49 * In on pin 16 17 (4-quadrant)
51 static const struct comedi_lrange das02_ao_ranges = {
65 #define DAC02_AO_LSB(x) (0x00 + ((x) * 2))
66 #define DAC02_AO_MSB(x) (0x01 + ((x) * 2))
68 static int dac02_ao_insn_write(struct comedi_device *dev,
69 struct comedi_subdevice *s,
70 struct comedi_insn *insn,
73 unsigned int chan = CR_CHAN(insn->chanspec);
74 unsigned int range = CR_RANGE(insn->chanspec);
78 for (i = 0; i < insn->n; i++) {
81 s->readback[chan] = val;
84 * Unipolar outputs are true binary encoding.
85 * Bipolar outputs are complementary offset binary
86 * (that is, 0 = +full scale, maxdata = -full scale).
88 if (comedi_range_is_bipolar(s, range))
89 val = s->maxdata - val;
92 * DACs are double-buffered.
93 * Write LSB then MSB to latch output.
95 outb((val << 4) & 0xf0, dev->iobase + DAC02_AO_LSB(chan));
96 outb((val >> 4) & 0xff, dev->iobase + DAC02_AO_MSB(chan));
102 static int dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
104 struct comedi_subdevice *s;
107 ret = comedi_request_region(dev, it->options[0], 0x08);
111 ret = comedi_alloc_subdevices(dev, 1);
115 /* Analog Output subdevice */
116 s = &dev->subdevices[0];
117 s->type = COMEDI_SUBD_AO;
118 s->subdev_flags = SDF_WRITABLE;
121 s->range_table = &das02_ao_ranges;
122 s->insn_write = dac02_ao_insn_write;
124 return comedi_alloc_subdev_readback(s);
127 static struct comedi_driver dac02_driver = {
128 .driver_name = "dac02",
129 .module = THIS_MODULE,
130 .attach = dac02_attach,
131 .detach = comedi_legacy_detach,
133 module_comedi_driver(dac02_driver);
135 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
136 MODULE_DESCRIPTION("Comedi driver for DAC02 compatible boards");
137 MODULE_LICENSE("GPL");