3 * Comedi driver for DAC02 compatible boards
4 * Copyright (C) 2014 H Hartley Sweeten <hsweeten@visionengravers.com>
6 * Based on the poc driver
7 * Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net>
8 * Copyright (C) 2001 David A. Schleef <ds@schleef.org>
10 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
26 * Description: Comedi driver for DAC02 compatible boards
27 * Devices: [Keithley Metrabyte] DAC-02 (dac02)
28 * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
29 * Updated: Tue, 11 Mar 2014 11:27:19 -0700
32 * Configuration options:
36 #include <linux/module.h>
38 #include "../comedidev.h"
41 * The output range is selected by jumpering pins on the I/O connector.
43 * Range Chan # Jumper pins Output
44 * ------------- ------ ------------- -----------------
45 * 0 to 5V 0 21 to 22 24
47 * 0 to 10V 0 20 to 22 24
51 * +/-10V 0 20 to 22 23
53 * 4 to 20mA 0 21 to 22 25
55 * AC reference 0 In on pin 22 24 (2-quadrant)
56 * In on pin 22 23 (4-quadrant)
57 * 1 In on pin 16 18 (2-quadrant)
58 * In on pin 16 17 (4-quadrant)
60 static const struct comedi_lrange das02_ao_ranges = {
74 #define DAC02_AO_LSB(x) (0x00 + ((x) * 2))
75 #define DAC02_AO_MSB(x) (0x01 + ((x) * 2))
77 static int dac02_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 range = CR_RANGE(insn->chanspec);
87 for (i = 0; i < insn->n; i++) {
90 s->readback[chan] = val;
93 * Unipolar outputs are true binary encoding.
94 * Bipolar outputs are complementary offset binary
95 * (that is, 0 = +full scale, maxdata = -full scale).
97 if (comedi_range_is_bipolar(s, range))
98 val = s->maxdata - val;
101 * DACs are double-buffered.
102 * Write LSB then MSB to latch output.
104 outb((val << 4) & 0xf0, dev->iobase + DAC02_AO_LSB(chan));
105 outb((val >> 4) & 0xff, dev->iobase + DAC02_AO_MSB(chan));
111 static int dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
113 struct comedi_subdevice *s;
116 ret = comedi_request_region(dev, it->options[0], 0x08);
120 ret = comedi_alloc_subdevices(dev, 1);
124 /* Analog Output subdevice */
125 s = &dev->subdevices[0];
126 s->type = COMEDI_SUBD_AO;
127 s->subdev_flags = SDF_WRITABLE;
130 s->range_table = &das02_ao_ranges;
131 s->insn_write = dac02_ao_insn_write;
133 ret = comedi_alloc_subdev_readback(s);
140 static struct comedi_driver dac02_driver = {
141 .driver_name = "dac02",
142 .module = THIS_MODULE,
143 .attach = dac02_attach,
144 .detach = comedi_legacy_detach,
146 module_comedi_driver(dac02_driver);
148 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
149 MODULE_DESCRIPTION("Comedi driver for DAC02 compatible boards");
150 MODULE_LICENSE("GPL");