]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/comedi/drivers/cb_pcimdda.c
Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / comedi / drivers / cb_pcimdda.c
1 /*
2 comedi/drivers/cb_pcimdda.c
3 Computer Boards PCIM-DDA06-16 Comedi driver
4 Author: Calin Culianu <calin@ajvar.org>
5
6 COMEDI - Linux Control and Measurement Device Interface
7 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8
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.
13
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.
18
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.
22
23 */
24 /*
25 Driver: cb_pcimdda
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
30 Status: works
31
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.
35
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.
39
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.
44
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:
48
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.
59
60 Configuration Options: not applicable, uses PCI auto config
61 */
62
63 /*
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.
67
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).
71
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
74 file.
75
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.
78
79 -Calin Culianu <calin@ajvar.org>
80 */
81
82 #include "../comedidev.h"
83
84 #include "8255.h"
85
86 /* device ids of the cards we support -- currently only 1 card supported */
87 #define PCI_ID_PCIM_DDA06_16 0x0053
88
89 /*
90 * Register map, 8-bit access only
91 */
92 #define PCIMDDA_DA_CHAN(x) (0x00 + (x) * 2)
93 #define PCIMDDA_8255_BASE_REG 0x0c
94
95 #define MAX_AO_READBACK_CHANNELS 6
96
97 struct cb_pcimdda_private {
98 unsigned int ao_readback[MAX_AO_READBACK_CHANNELS];
99 };
100
101 static int cb_pcimdda_ao_winsn(struct comedi_device *dev,
102 struct comedi_subdevice *s,
103 struct comedi_insn *insn,
104 unsigned int *data)
105 {
106 struct cb_pcimdda_private *devpriv = dev->private;
107 unsigned int chan = CR_CHAN(insn->chanspec);
108 unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
109 unsigned int val = 0;
110 int i;
111
112 for (i = 0; i < insn->n; i++) {
113 val = data[i];
114
115 /*
116 * Write the LSB then MSB.
117 *
118 * If the simultaneous xfer mode is selected by the
119 * jumper on the card, a read instruction is needed
120 * in order to initiate the simultaneous transfer.
121 * Otherwise, the DAC will be updated when the MSB
122 * is written.
123 */
124 outb(val & 0x00ff, offset);
125 outb((val >> 8) & 0x00ff, offset + 1);
126 }
127
128 /* Cache the last value for readback */
129 devpriv->ao_readback[chan] = val;
130
131 return insn->n;
132 }
133
134 static int cb_pcimdda_ao_rinsn(struct comedi_device *dev,
135 struct comedi_subdevice *s,
136 struct comedi_insn *insn,
137 unsigned int *data)
138 {
139 struct cb_pcimdda_private *devpriv = dev->private;
140 int chan = CR_CHAN(insn->chanspec);
141 unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
142 int i;
143
144 for (i = 0; i < insn->n; i++) {
145 /* Initiate the simultaneous transfer */
146 inw(offset);
147
148 data[i] = devpriv->ao_readback[chan];
149 }
150
151 return insn->n;
152 }
153
154 static int cb_pcimdda_auto_attach(struct comedi_device *dev,
155 unsigned long context_unused)
156 {
157 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
158 struct cb_pcimdda_private *devpriv;
159 struct comedi_subdevice *s;
160 int ret;
161
162 dev->board_name = dev->driver->driver_name;
163
164 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
165 if (!devpriv)
166 return -ENOMEM;
167 dev->private = devpriv;
168
169 ret = comedi_pci_enable(pcidev, dev->board_name);
170 if (ret)
171 return ret;
172 dev->iobase = pci_resource_start(pcidev, 3);
173
174 ret = comedi_alloc_subdevices(dev, 2);
175 if (ret)
176 return ret;
177
178 s = &dev->subdevices[0];
179 /* analog output subdevice */
180 s->type = COMEDI_SUBD_AO;
181 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
182 s->n_chan = 6;
183 s->maxdata = 0xffff;
184 s->range_table = &range_bipolar5;
185 s->insn_write = cb_pcimdda_ao_winsn;
186 s->insn_read = cb_pcimdda_ao_rinsn;
187
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);
192 if (ret)
193 return ret;
194
195 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
196
197 return 1;
198 }
199
200 static void cb_pcimdda_detach(struct comedi_device *dev)
201 {
202 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
203
204 if (dev->subdevices)
205 subdev_8255_cleanup(dev, &dev->subdevices[1]);
206 if (pcidev) {
207 if (dev->iobase)
208 comedi_pci_disable(pcidev);
209 }
210 }
211
212 static struct comedi_driver cb_pcimdda_driver = {
213 .driver_name = "cb_pcimdda",
214 .module = THIS_MODULE,
215 .auto_attach = cb_pcimdda_auto_attach,
216 .detach = cb_pcimdda_detach,
217 };
218
219 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
220 const struct pci_device_id *ent)
221 {
222 return comedi_pci_auto_config(dev, &cb_pcimdda_driver);
223 }
224
225 static void cb_pcimdda_pci_remove(struct pci_dev *dev)
226 {
227 comedi_pci_auto_unconfig(dev);
228 }
229
230 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = {
231 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) },
232 { 0 }
233 };
234 MODULE_DEVICE_TABLE(pci, cb_pcimdda_pci_table);
235
236 static struct pci_driver cb_pcimdda_driver_pci_driver = {
237 .name = "cb_pcimdda",
238 .id_table = cb_pcimdda_pci_table,
239 .probe = cb_pcimdda_pci_probe,
240 .remove = cb_pcimdda_pci_remove,
241 };
242 module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
243
244 MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
245 MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA "
246 "series. Currently only supports PCIM-DDA06-16 (which "
247 "also happens to be the only board in this series. :) ) ");
248 MODULE_LICENSE("GPL");