]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/cb_pcimdda.c
Merge tag 'regmap-v3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[karo-tx-linux.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 /*
20 Driver: cb_pcimdda
21 Description: Measurement Computing PCIM-DDA06-16
22 Devices: [Measurement Computing] PCIM-DDA06-16 (cb_pcimdda)
23 Author: Calin Culianu <calin@ajvar.org>
24 Updated: Mon, 14 Apr 2008 15:15:51 +0100
25 Status: works
26
27 All features of the PCIM-DDA06-16 board are supported.  This board
28 has 6 16-bit AO channels, and the usual 8255 DIO setup.  (24 channels,
29 configurable in banks of 8 and 4, etc.).  This board does not support commands.
30
31 The board has a peculiar way of specifying AO gain/range settings -- You have
32 1 jumper bank on the card, which either makes all 6 AO channels either
33 5 Volt unipolar, 5V bipolar, 10 Volt unipolar or 10V bipolar.
34
35 Since there is absolutely _no_ way to tell in software how this jumper is set
36 (well, at least according  to the rather thin spec. from Measurement Computing
37  that comes with the board), the driver assumes the jumper is at its factory
38 default setting of +/-5V.
39
40 Also of note is the fact that this board features another jumper, whose
41 state is also completely invisible to software.  It toggles two possible AO
42 output modes on the board:
43
44   - Update Mode: Writing to an AO channel instantaneously updates the actual
45     signal output by the DAC on the board (this is the factory default).
46   - Simultaneous XFER Mode: Writing to an AO channel has no effect until
47     you read from any one of the AO channels.  This is useful for loading
48     all 6 AO values, and then reading from any one of the AO channels on the
49     device to instantly update all 6 AO values in unison.  Useful for some
50     control apps, I would assume?  If your jumper is in this setting, then you
51     need to issue your comedi_data_write()s to load all the values you want,
52     then issue one comedi_data_read() on any channel on the AO subdevice
53     to initiate the simultaneous XFER.
54
55 Configuration Options: not applicable, uses PCI auto config
56 */
57
58 /*
59     This is a driver for the Computer Boards PCIM-DDA06-16 Analog Output
60     card.  This board has a unique register layout and as such probably
61     deserves its own driver file.
62
63     It is theoretically possible to integrate this board into the cb_pcidda
64     file, but since that isn't my code, I didn't want to significantly
65     modify that file to support this board (I thought it impolite to do so).
66
67     At any rate, if you feel ambitious, please feel free to take
68     the code out of this file and combine it with a more unified driver
69     file.
70
71     I would like to thank Timothy Curry <Timothy.Curry@rdec.redstone.army.mil>
72     for lending me a board so that I could write this driver.
73
74     -Calin Culianu <calin@ajvar.org>
75  */
76
77 #include <linux/pci.h>
78
79 #include "../comedidev.h"
80
81 #include "8255.h"
82
83 /* device ids of the cards we support -- currently only 1 card supported */
84 #define PCI_ID_PCIM_DDA06_16            0x0053
85
86 /*
87  * Register map, 8-bit access only
88  */
89 #define PCIMDDA_DA_CHAN(x)              (0x00 + (x) * 2)
90 #define PCIMDDA_8255_BASE_REG           0x0c
91
92 #define MAX_AO_READBACK_CHANNELS        6
93
94 struct cb_pcimdda_private {
95         unsigned int ao_readback[MAX_AO_READBACK_CHANNELS];
96 };
97
98 static int cb_pcimdda_ao_winsn(struct comedi_device *dev,
99                                struct comedi_subdevice *s,
100                                struct comedi_insn *insn,
101                                unsigned int *data)
102 {
103         struct cb_pcimdda_private *devpriv = dev->private;
104         unsigned int chan = CR_CHAN(insn->chanspec);
105         unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
106         unsigned int val = 0;
107         int i;
108
109         for (i = 0; i < insn->n; i++) {
110                 val = data[i];
111
112                 /*
113                  * Write the LSB then MSB.
114                  *
115                  * If the simultaneous xfer mode is selected by the
116                  * jumper on the card, a read instruction is needed
117                  * in order to initiate the simultaneous transfer.
118                  * Otherwise, the DAC will be updated when the MSB
119                  * is written.
120                  */
121                 outb(val & 0x00ff, offset);
122                 outb((val >> 8) & 0x00ff, offset + 1);
123         }
124
125         /* Cache the last value for readback */
126         devpriv->ao_readback[chan] = val;
127
128         return insn->n;
129 }
130
131 static int cb_pcimdda_ao_rinsn(struct comedi_device *dev,
132                                struct comedi_subdevice *s,
133                                struct comedi_insn *insn,
134                                unsigned int *data)
135 {
136         struct cb_pcimdda_private *devpriv = dev->private;
137         int chan = CR_CHAN(insn->chanspec);
138         unsigned long offset = dev->iobase + PCIMDDA_DA_CHAN(chan);
139         int i;
140
141         for (i = 0; i < insn->n; i++) {
142                 /* Initiate the simultaneous transfer */
143                 inw(offset);
144
145                 data[i] = devpriv->ao_readback[chan];
146         }
147
148         return insn->n;
149 }
150
151 static int cb_pcimdda_auto_attach(struct comedi_device *dev,
152                                             unsigned long context_unused)
153 {
154         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
155         struct cb_pcimdda_private *devpriv;
156         struct comedi_subdevice *s;
157         int ret;
158
159         devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
160         if (!devpriv)
161                 return -ENOMEM;
162         dev->private = devpriv;
163
164         ret = comedi_pci_enable(dev);
165         if (ret)
166                 return ret;
167         dev->iobase = pci_resource_start(pcidev, 3);
168
169         ret = comedi_alloc_subdevices(dev, 2);
170         if (ret)
171                 return ret;
172
173         s = &dev->subdevices[0];
174         /* analog output subdevice */
175         s->type         = COMEDI_SUBD_AO;
176         s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
177         s->n_chan       = 6;
178         s->maxdata      = 0xffff;
179         s->range_table  = &range_bipolar5;
180         s->insn_write   = cb_pcimdda_ao_winsn;
181         s->insn_read    = cb_pcimdda_ao_rinsn;
182
183         s = &dev->subdevices[1];
184         /* digital i/o subdevice */
185         ret = subdev_8255_init(dev, s, NULL,
186                         dev->iobase + PCIMDDA_8255_BASE_REG);
187         if (ret)
188                 return ret;
189
190         dev_info(dev->class_dev, "%s attached\n", dev->board_name);
191
192         return 1;
193 }
194
195 static struct comedi_driver cb_pcimdda_driver = {
196         .driver_name    = "cb_pcimdda",
197         .module         = THIS_MODULE,
198         .auto_attach    = cb_pcimdda_auto_attach,
199         .detach         = comedi_pci_disable,
200 };
201
202 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
203                                 const struct pci_device_id *id)
204 {
205         return comedi_pci_auto_config(dev, &cb_pcimdda_driver,
206                                       id->driver_data);
207 }
208
209 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = {
210         { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) },
211         { 0 }
212 };
213 MODULE_DEVICE_TABLE(pci, cb_pcimdda_pci_table);
214
215 static struct pci_driver cb_pcimdda_driver_pci_driver = {
216         .name           = "cb_pcimdda",
217         .id_table       = cb_pcimdda_pci_table,
218         .probe          = cb_pcimdda_pci_probe,
219         .remove         = comedi_pci_auto_unconfig,
220 };
221 module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
222
223 MODULE_AUTHOR("Calin A. Culianu <calin@rtlab.org>");
224 MODULE_DESCRIPTION("Comedi low-level driver for the Computerboards PCIM-DDA "
225                    "series.  Currently only supports PCIM-DDA06-16 (which "
226                    "also happens to be the only board in this series. :) ) ");
227 MODULE_LICENSE("GPL");