1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * comedi/drivers/cb_pcimdda.c
4 * Computer Boards PCIM-DDA06-16 Comedi driver
5 * Author: Calin Culianu <calin@ajvar.org>
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9 */
10/*
11 * Driver: cb_pcimdda
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
16 * Status: works
17 *
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.
22 *
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.
26 *
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.
31 *
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:
35 *
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.
46 *
47 * Configuration Options: not applicable, uses PCI auto config
48 */
49
50/*
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.
54 *
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).
58 *
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
61 * file.
62 *
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.
65 *
66 * -Calin Culianu <calin@ajvar.org>
67 */
68
69#include <linux/module.h>
70#include <linux/comedi/comedi_pci.h>
71#include <linux/comedi/comedi_8255.h>
72
73/* device ids of the cards we support -- currently only 1 card supported */
74#define PCI_ID_PCIM_DDA06_16 0x0053
75
76/*
77 * Register map, 8-bit access only
78 */
79#define PCIMDDA_DA_CHAN(x) (0x00 + (x) * 2)
80#define PCIMDDA_8255_BASE_REG 0x0c
81
82static int cb_pcimdda_ao_insn_write(struct comedi_device *dev,
83 struct comedi_subdevice *s,
84 struct comedi_insn *insn,
85 unsigned int *data)
86{
87 unsigned int chan = CR_CHAN(insn->chanspec);
88 unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
89 unsigned int val = s->readback[chan];
90 int i;
91
92 for (i = 0; i < insn->n; i++) {
93 val = data[i];
94
95 /*
96 * Write the LSB then MSB.
97 *
98 * If the simultaneous xfer mode is selected by the
99 * jumper on the card, a read instruction is needed
100 * in order to initiate the simultaneous transfer.
101 * Otherwise, the DAC will be updated when the MSB
102 * is written.
103 */
104 outb(value: val & 0x00ff, port: offset);
105 outb(value: (val >> 8) & 0x00ff, port: offset + 1);
106 }
107 s->readback[chan] = val;
108
109 return insn->n;
110}
111
112static int cb_pcimdda_ao_insn_read(struct comedi_device *dev,
113 struct comedi_subdevice *s,
114 struct comedi_insn *insn,
115 unsigned int *data)
116{
117 unsigned int chan = CR_CHAN(insn->chanspec);
118
119 /* Initiate the simultaneous transfer */
120 inw(port: dev->iobase + PCIMDDA_DA_CHAN(chan));
121
122 return comedi_readback_insn_read(dev, s, insn, data);
123}
124
125static int cb_pcimdda_auto_attach(struct comedi_device *dev,
126 unsigned long context_unused)
127{
128 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
129 struct comedi_subdevice *s;
130 int ret;
131
132 ret = comedi_pci_enable(dev);
133 if (ret)
134 return ret;
135 dev->iobase = pci_resource_start(pcidev, 3);
136
137 ret = comedi_alloc_subdevices(dev, num_subdevices: 2);
138 if (ret)
139 return ret;
140
141 s = &dev->subdevices[0];
142 /* analog output subdevice */
143 s->type = COMEDI_SUBD_AO;
144 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
145 s->n_chan = 6;
146 s->maxdata = 0xffff;
147 s->range_table = &range_bipolar5;
148 s->insn_write = cb_pcimdda_ao_insn_write;
149 s->insn_read = cb_pcimdda_ao_insn_read;
150
151 ret = comedi_alloc_subdev_readback(s);
152 if (ret)
153 return ret;
154
155 s = &dev->subdevices[1];
156 /* digital i/o subdevice */
157 return subdev_8255_io_init(dev, s, PCIMDDA_8255_BASE_REG);
158}
159
160static struct comedi_driver cb_pcimdda_driver = {
161 .driver_name = "cb_pcimdda",
162 .module = THIS_MODULE,
163 .auto_attach = cb_pcimdda_auto_attach,
164 .detach = comedi_pci_detach,
165};
166
167static int cb_pcimdda_pci_probe(struct pci_dev *dev,
168 const struct pci_device_id *id)
169{
170 return comedi_pci_auto_config(pcidev: dev, driver: &cb_pcimdda_driver,
171 context: id->driver_data);
172}
173
174static const struct pci_device_id cb_pcimdda_pci_table[] = {
175 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) },
176 { 0 }
177};
178MODULE_DEVICE_TABLE(pci, cb_pcimdda_pci_table);
179
180static struct pci_driver cb_pcimdda_driver_pci_driver = {
181 .name = "cb_pcimdda",
182 .id_table = cb_pcimdda_pci_table,
183 .probe = cb_pcimdda_pci_probe,
184 .remove = comedi_pci_auto_unconfig,
185};
186module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
187
188MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
189MODULE_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. :) ) ");
190MODULE_LICENSE("GPL");
191

source code of linux/drivers/comedi/drivers/cb_pcimdda.c