2 comedi/drivers/cb_pcimdda.c
3 Computer Boards PCIM-DDA06-16 Comedi driver
4 Author: Calin Culianu <calin@ajvar.org>
6 COMEDI - Linux Control and Measurement Device Interface
7 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 Description: Measurement Computing PCIM-DDA06-16
27 Devices: [Measurement Computing] PCIM-DDA06-16 (cb_pcimdda)
28 Author: Calin Culianu <calin@ajvar.org>
29 Updated: Mon, 14 Apr 2008 15:15:51 +0100
32 All features of the PCIM-DDA06-16 board are supported. This board
33 has 6 16-bit AO channels, and the usual 8255 DIO setup. (24 channels,
34 configurable in banks of 8 and 4, etc.). This board does not support commands.
36 The board has a peculiar way of specifying AO gain/range settings -- You have
37 1 jumper bank on the card, which either makes all 6 AO channels either
38 5 Volt unipolar, 5V bipolar, 10 Volt unipolar or 10V bipolar.
40 Since there is absolutely _no_ way to tell in software how this jumper is set
41 (well, at least according to the rather thin spec. from Measurement Computing
42 that comes with the board), the driver assumes the jumper is at its factory
43 default setting of +/-5V.
45 Also of note is the fact that this board features another jumper, whose
46 state is also completely invisible to software. It toggles two possible AO
47 output modes on the board:
49 - Update Mode: Writing to an AO channel instantaneously updates the actual
50 signal output by the DAC on the board (this is the factory default).
51 - Simultaneous XFER Mode: Writing to an AO channel has no effect until
52 you read from any one of the AO channels. This is useful for loading
53 all 6 AO values, and then reading from any one of the AO channels on the
54 device to instantly update all 6 AO values in unison. Useful for some
55 control apps, I would assume? If your jumper is in this setting, then you
56 need to issue your comedi_data_write()s to load all the values you want,
57 then issue one comedi_data_read() on any channel on the AO subdevice
58 to initiate the simultaneous XFER.
60 Configuration Options: not applicable, uses PCI auto config
64 This is a driver for the Computer Boards PCIM-DDA06-16 Analog Output
65 card. This board has a unique register layout and as such probably
66 deserves its own driver file.
68 It is theoretically possible to integrate this board into the cb_pcidda
69 file, but since that isn't my code, I didn't want to significantly
70 modify that file to support this board (I thought it impolite to do so).
72 At any rate, if you feel ambitious, please feel free to take
73 the code out of this file and combine it with a more unified driver
76 I would like to thank Timothy Curry <Timothy.Curry@rdec.redstone.army.mil>
77 for lending me a board so that I could write this driver.
79 -Calin Culianu <calin@ajvar.org>
82 #include <linux/pci.h>
84 #include "../comedidev.h"
88 /* device ids of the cards we support -- currently only 1 card supported */
89 #define PCI_ID_PCIM_DDA06_16 0x0053
92 * Register map, 8-bit access only
94 #define PCIMDDA_DA_CHAN(x) (0x00 + (x) * 2)
95 #define PCIMDDA_8255_BASE_REG 0x0c
97 #define MAX_AO_READBACK_CHANNELS 6
99 struct cb_pcimdda_private {
100 unsigned int ao_readback[MAX_AO_READBACK_CHANNELS];
103 static int cb_pcimdda_ao_winsn(struct comedi_device *dev,
104 struct comedi_subdevice *s,
105 struct comedi_insn *insn,
108 struct cb_pcimdda_private *devpriv = dev->private;
109 unsigned int chan = CR_CHAN(insn->chanspec);
110 unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
111 unsigned int val = 0;
114 for (i = 0; i < insn->n; i++) {
118 * Write the LSB then MSB.
120 * If the simultaneous xfer mode is selected by the
121 * jumper on the card, a read instruction is needed
122 * in order to initiate the simultaneous transfer.
123 * Otherwise, the DAC will be updated when the MSB
126 outb(val & 0x00ff, offset);
127 outb((val >> 8) & 0x00ff, offset + 1);
130 /* Cache the last value for readback */
131 devpriv->ao_readback[chan] = val;
136 static int cb_pcimdda_ao_rinsn(struct comedi_device *dev,
137 struct comedi_subdevice *s,
138 struct comedi_insn *insn,
141 struct cb_pcimdda_private *devpriv = dev->private;
142 int chan = CR_CHAN(insn->chanspec);
143 unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
146 for (i = 0; i < insn->n; i++) {
147 /* Initiate the simultaneous transfer */
150 data[i] = devpriv->ao_readback[chan];
156 static int cb_pcimdda_auto_attach(struct comedi_device *dev,
157 unsigned long context_unused)
159 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
160 struct cb_pcimdda_private *devpriv;
161 struct comedi_subdevice *s;
164 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
167 dev->private = devpriv;
169 ret = comedi_pci_enable(dev);
172 dev->iobase = pci_resource_start(pcidev, 3);
174 ret = comedi_alloc_subdevices(dev, 2);
178 s = &dev->subdevices[0];
179 /* analog output subdevice */
180 s->type = COMEDI_SUBD_AO;
181 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
184 s->range_table = &range_bipolar5;
185 s->insn_write = cb_pcimdda_ao_winsn;
186 s->insn_read = cb_pcimdda_ao_rinsn;
188 s = &dev->subdevices[1];
189 /* digital i/o subdevice */
190 ret = subdev_8255_init(dev, s, NULL,
191 dev->iobase + PCIMDDA_8255_BASE_REG);
195 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
200 static void cb_pcimdda_detach(struct comedi_device *dev)
202 comedi_spriv_free(dev, 1);
203 comedi_pci_disable(dev);
206 static struct comedi_driver cb_pcimdda_driver = {
207 .driver_name = "cb_pcimdda",
208 .module = THIS_MODULE,
209 .auto_attach = cb_pcimdda_auto_attach,
210 .detach = cb_pcimdda_detach,
213 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
214 const struct pci_device_id *id)
216 return comedi_pci_auto_config(dev, &cb_pcimdda_driver,
220 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = {
221 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) },
224 MODULE_DEVICE_TABLE(pci, cb_pcimdda_pci_table);
226 static struct pci_driver cb_pcimdda_driver_pci_driver = {
227 .name = "cb_pcimdda",
228 .id_table = cb_pcimdda_pci_table,
229 .probe = cb_pcimdda_pci_probe,
230 .remove = comedi_pci_auto_unconfig,
232 module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
234 MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
235 MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA "
236 "series. Currently only supports PCIM-DDA06-16 (which "
237 "also happens to be the only board in this series. :) ) ");
238 MODULE_LICENSE("GPL");