1 // SPDX-License-Identifier: GPL-2.0+
3 * comedi/drivers/cb_pcimdda.c
4 * Computer Boards PCIM-DDA06-16 Comedi driver
5 * Author: Calin Culianu <calin@ajvar.org>
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 * Description: Measurement Computing PCIM-DDA06-16
13 * Devices: [Measurement Computing] PCIM-DDA06-16 (cb_pcimdda)
14 * Author: Calin Culianu <calin@ajvar.org>
15 * Updated: Mon, 14 Apr 2008 15:15:51 +0100
18 * All features of the PCIM-DDA06-16 board are supported.
19 * This board has 6 16-bit AO channels, and the usual 8255 DIO setup.
20 * (24 channels, configurable in banks of 8 and 4, etc.).
21 * This board does not support commands.
23 * The board has a peculiar way of specifying AO gain/range settings -- You have
24 * 1 jumper bank on the card, which either makes all 6 AO channels either
25 * 5 Volt unipolar, 5V bipolar, 10 Volt unipolar or 10V bipolar.
27 * Since there is absolutely _no_ way to tell in software how this jumper is set
28 * (well, at least according to the rather thin spec. from Measurement Computing
29 * that comes with the board), the driver assumes the jumper is at its factory
30 * default setting of +/-5V.
32 * Also of note is the fact that this board features another jumper, whose
33 * state is also completely invisible to software. It toggles two possible AO
34 * output modes on the board:
36 * - Update Mode: Writing to an AO channel instantaneously updates the actual
37 * signal output by the DAC on the board (this is the factory default).
38 * - Simultaneous XFER Mode: Writing to an AO channel has no effect until
39 * you read from any one of the AO channels. This is useful for loading
40 * all 6 AO values, and then reading from any one of the AO channels on the
41 * device to instantly update all 6 AO values in unison. Useful for some
42 * control apps, I would assume? If your jumper is in this setting, then you
43 * need to issue your comedi_data_write()s to load all the values you want,
44 * then issue one comedi_data_read() on any channel on the AO subdevice
45 * to initiate the simultaneous XFER.
47 * Configuration Options: not applicable, uses PCI auto config
51 * This is a driver for the Computer Boards PCIM-DDA06-16 Analog Output
52 * card. This board has a unique register layout and as such probably
53 * deserves its own driver file.
55 * It is theoretically possible to integrate this board into the cb_pcidda
56 * file, but since that isn't my code, I didn't want to significantly
57 * modify that file to support this board (I thought it impolite to do so).
59 * At any rate, if you feel ambitious, please feel free to take
60 * the code out of this file and combine it with a more unified driver
63 * I would like to thank Timothy Curry <Timothy.Curry@rdec.redstone.army.mil>
64 * for lending me a board so that I could write this driver.
66 * -Calin Culianu <calin@ajvar.org>
69 #include <linux/module.h>
71 #include "../comedi_pci.h"
75 /* device ids of the cards we support -- currently only 1 card supported */
76 #define PCI_ID_PCIM_DDA06_16 0x0053
79 * Register map, 8-bit access only
81 #define PCIMDDA_DA_CHAN(x) (0x00 + (x) * 2)
82 #define PCIMDDA_8255_BASE_REG 0x0c
84 static int cb_pcimdda_ao_insn_write(struct comedi_device *dev,
85 struct comedi_subdevice *s,
86 struct comedi_insn *insn,
89 unsigned int chan = CR_CHAN(insn->chanspec);
90 unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
91 unsigned int val = s->readback[chan];
94 for (i = 0; i < insn->n; i++) {
98 * Write the LSB then MSB.
100 * If the simultaneous xfer mode is selected by the
101 * jumper on the card, a read instruction is needed
102 * in order to initiate the simultaneous transfer.
103 * Otherwise, the DAC will be updated when the MSB
106 outb(val & 0x00ff, offset);
107 outb((val >> 8) & 0x00ff, offset + 1);
109 s->readback[chan] = val;
114 static int cb_pcimdda_ao_insn_read(struct comedi_device *dev,
115 struct comedi_subdevice *s,
116 struct comedi_insn *insn,
119 unsigned int chan = CR_CHAN(insn->chanspec);
121 /* Initiate the simultaneous transfer */
122 inw(dev->iobase + PCIMDDA_DA_CHAN(chan));
124 return comedi_readback_insn_read(dev, s, insn, data);
127 static int cb_pcimdda_auto_attach(struct comedi_device *dev,
128 unsigned long context_unused)
130 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
131 struct comedi_subdevice *s;
134 ret = comedi_pci_enable(dev);
137 dev->iobase = pci_resource_start(pcidev, 3);
139 ret = comedi_alloc_subdevices(dev, 2);
143 s = &dev->subdevices[0];
144 /* analog output subdevice */
145 s->type = COMEDI_SUBD_AO;
146 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
149 s->range_table = &range_bipolar5;
150 s->insn_write = cb_pcimdda_ao_insn_write;
151 s->insn_read = cb_pcimdda_ao_insn_read;
153 ret = comedi_alloc_subdev_readback(s);
157 s = &dev->subdevices[1];
158 /* digital i/o subdevice */
159 return subdev_8255_init(dev, s, NULL, PCIMDDA_8255_BASE_REG);
162 static struct comedi_driver cb_pcimdda_driver = {
163 .driver_name = "cb_pcimdda",
164 .module = THIS_MODULE,
165 .auto_attach = cb_pcimdda_auto_attach,
166 .detach = comedi_pci_detach,
169 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
170 const struct pci_device_id *id)
172 return comedi_pci_auto_config(dev, &cb_pcimdda_driver,
176 static const struct pci_device_id cb_pcimdda_pci_table[] = {
177 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) },
180 MODULE_DEVICE_TABLE(pci, cb_pcimdda_pci_table);
182 static struct pci_driver cb_pcimdda_driver_pci_driver = {
183 .name = "cb_pcimdda",
184 .id_table = cb_pcimdda_pci_table,
185 .probe = cb_pcimdda_pci_probe,
186 .remove = comedi_pci_auto_unconfig,
188 module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
190 MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
191 MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA series. Currently only supports PCIM-DDA06-16 (which also happens to be the only board in this series. :) ) ");
192 MODULE_LICENSE("GPL");