1 // SPDX-License-Identifier: GPL-2.0+
4 * Driver for Winsystems PC-104 based PCM-D/A-12 8-channel AO board.
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2006 Calin A. Culianu <calin@ajvar.org>
12 * Description: A driver for the Winsystems PCM-D/A-12
13 * Devices: [Winsystems] PCM-D/A-12 (pcmda12)
14 * Author: Calin Culianu <calin@ajvar.org>
15 * Updated: Fri, 13 Jan 2006 12:01:01 -0500
18 * A driver for the relatively straightforward-to-program PCM-D/A-12.
19 * This board doesn't support commands, and the only way to set its
20 * analog output range is to jumper the board. As such,
21 * comedi_data_write() ignores the range value specified.
23 * The board uses 16 consecutive I/O addresses starting at the I/O port
24 * base address. Each address corresponds to the LSB then MSB of a
25 * particular channel from 0-7.
27 * Note that the board is not ISA-PNP capable and thus needs the I/O
28 * port comedi_config parameter.
30 * Note that passing a nonzero value as the second config option will
31 * enable "simultaneous xfer" mode for this board, in which AO writes
32 * will not take effect until a subsequent read of any AO channel. This
33 * is so that one can speed up programming by preloading all AO registers
34 * with values before simultaneously setting them to take effect with one
37 * Configuration Options:
38 * [0] - I/O port base address
39 * [1] - Do Simultaneous Xfer (see description)
42 #include <linux/module.h>
43 #include <linux/comedi/comedidev.h>
45 /* AI range is not configurable, it's set by jumpers on the board */
46 static const struct comedi_lrange pcmda12_ranges = {
54 struct pcmda12_private {
55 int simultaneous_xfer_mode;
58 static int pcmda12_ao_insn_write(struct comedi_device *dev,
59 struct comedi_subdevice *s,
60 struct comedi_insn *insn,
63 struct pcmda12_private *devpriv = dev->private;
64 unsigned int chan = CR_CHAN(insn->chanspec);
65 unsigned int val = s->readback[chan];
66 unsigned long ioreg = dev->iobase + (chan * 2);
69 for (i = 0; i < insn->n; ++i) {
71 outb(val & 0xff, ioreg);
72 outb((val >> 8) & 0xff, ioreg + 1);
75 * Initiate transfer if not in simultaneaous xfer
76 * mode by reading one of the AO registers.
78 if (!devpriv->simultaneous_xfer_mode)
81 s->readback[chan] = val;
86 static int pcmda12_ao_insn_read(struct comedi_device *dev,
87 struct comedi_subdevice *s,
88 struct comedi_insn *insn,
91 struct pcmda12_private *devpriv = dev->private;
94 * Initiate simultaneaous xfer mode by reading one of the
95 * AO registers. All analog outputs will then be updated.
97 if (devpriv->simultaneous_xfer_mode)
100 return comedi_readback_insn_read(dev, s, insn, data);
103 static void pcmda12_ao_reset(struct comedi_device *dev,
104 struct comedi_subdevice *s)
108 for (i = 0; i < s->n_chan; ++i) {
109 outb(0, dev->iobase + (i * 2));
110 outb(0, dev->iobase + (i * 2) + 1);
112 /* Initiate transfer by reading one of the AO registers. */
116 static int pcmda12_attach(struct comedi_device *dev,
117 struct comedi_devconfig *it)
119 struct pcmda12_private *devpriv;
120 struct comedi_subdevice *s;
123 ret = comedi_request_region(dev, it->options[0], 0x10);
127 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
131 devpriv->simultaneous_xfer_mode = it->options[1];
133 ret = comedi_alloc_subdevices(dev, 1);
137 s = &dev->subdevices[0];
138 s->type = COMEDI_SUBD_AO;
139 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
142 s->range_table = &pcmda12_ranges;
143 s->insn_write = pcmda12_ao_insn_write;
144 s->insn_read = pcmda12_ao_insn_read;
146 ret = comedi_alloc_subdev_readback(s);
150 pcmda12_ao_reset(dev, s);
155 static struct comedi_driver pcmda12_driver = {
156 .driver_name = "pcmda12",
157 .module = THIS_MODULE,
158 .attach = pcmda12_attach,
159 .detach = comedi_legacy_detach,
161 module_comedi_driver(pcmda12_driver);
163 MODULE_AUTHOR("Comedi https://www.comedi.org");
164 MODULE_DESCRIPTION("Comedi low-level driver");
165 MODULE_LICENSE("GPL");