staging: comedi: remove FSF address from boilerplate text
[deliverable/linux.git] / drivers / staging / comedi / drivers / adl_pci7x3x.c
1 /*
2 * COMEDI driver for the ADLINK PCI-723x/743x series boards.
3 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
4 *
5 * Based on the adl_pci7230 driver written by:
6 * David Fernandez <dfcastelao@gmail.com>
7 * and the adl_pci7432 driver written by:
8 * Michel Lachaine <mike@mikelachaine.ca>
9 *
10 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23
24 /*
25 Driver: adl_pci7x3x
26 Description: 32/64-Channel Isolated Digital I/O Boards
27 Devices: (ADLink) PCI-7230 [adl_pci7230] - 16 input / 16 output
28 (ADLink) PCI-7233 [adl_pci7233] - 32 input
29 (ADLink) PCI-7234 [adl_pci7234] - 32 output
30 (ADLink) PCI-7432 [adl_pci7432] - 32 input / 32 output
31 (ADLink) PCI-7433 [adl_pci7433] - 64 input
32 (ADLink) PCI-7434 [adl_pci7434] - 64 output
33 Author: H Hartley Sweeten <hsweeten@visionengravers.com>
34 Updated: Thu, 02 Aug 2012 14:27:46 -0700
35 Status: untested
36
37 The PCI-7230, PCI-7432 and PCI-7433 boards also support external
38 interrupt signals on digital input channels 0 and 1. The PCI-7233
39 has dual-interrupt sources for change-of-state (COS) on any 16
40 digital input channels of LSB and for COS on any 16 digital input
41 lines of MSB. Interrupts are not currently supported by this
42 driver.
43
44 Configuration Options: not applicable, uses comedi PCI auto config
45 */
46
47 #include <linux/pci.h>
48
49 #include "../comedidev.h"
50
51 /*
52 * Register I/O map (32-bit access only)
53 */
54 #define PCI7X3X_DIO_REG 0x00
55 #define PCI743X_DIO_REG 0x04
56
57 enum apci1516_boardid {
58 BOARD_PCI7230,
59 BOARD_PCI7233,
60 BOARD_PCI7234,
61 BOARD_PCI7432,
62 BOARD_PCI7433,
63 BOARD_PCI7434,
64 };
65
66 struct adl_pci7x3x_boardinfo {
67 const char *name;
68 int nsubdevs;
69 int di_nchan;
70 int do_nchan;
71 };
72
73 static const struct adl_pci7x3x_boardinfo adl_pci7x3x_boards[] = {
74 [BOARD_PCI7230] = {
75 .name = "adl_pci7230",
76 .nsubdevs = 2,
77 .di_nchan = 16,
78 .do_nchan = 16,
79 },
80 [BOARD_PCI7233] = {
81 .name = "adl_pci7233",
82 .nsubdevs = 1,
83 .di_nchan = 32,
84 },
85 [BOARD_PCI7234] = {
86 .name = "adl_pci7234",
87 .nsubdevs = 1,
88 .do_nchan = 32,
89 },
90 [BOARD_PCI7432] = {
91 .name = "adl_pci7432",
92 .nsubdevs = 2,
93 .di_nchan = 32,
94 .do_nchan = 32,
95 },
96 [BOARD_PCI7433] = {
97 .name = "adl_pci7433",
98 .nsubdevs = 2,
99 .di_nchan = 64,
100 },
101 [BOARD_PCI7434] = {
102 .name = "adl_pci7434",
103 .nsubdevs = 2,
104 .do_nchan = 64,
105 }
106 };
107
108 static int adl_pci7x3x_do_insn_bits(struct comedi_device *dev,
109 struct comedi_subdevice *s,
110 struct comedi_insn *insn,
111 unsigned int *data)
112 {
113 unsigned long reg = (unsigned long)s->private;
114 unsigned int mask = data[0];
115 unsigned int bits = data[1];
116
117 if (mask) {
118 s->state &= ~mask;
119 s->state |= (bits & mask);
120
121 outl(s->state, dev->iobase + reg);
122 }
123
124 /*
125 * NOTE: The output register is not readable.
126 * This returned state will not be correct until all the
127 * outputs have been updated.
128 */
129 data[1] = s->state;
130
131 return insn->n;
132 }
133
134 static int adl_pci7x3x_di_insn_bits(struct comedi_device *dev,
135 struct comedi_subdevice *s,
136 struct comedi_insn *insn,
137 unsigned int *data)
138 {
139 unsigned long reg = (unsigned long)s->private;
140
141 data[1] = inl(dev->iobase + reg);
142
143 return insn->n;
144 }
145
146 static int adl_pci7x3x_auto_attach(struct comedi_device *dev,
147 unsigned long context)
148 {
149 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
150 const struct adl_pci7x3x_boardinfo *board = NULL;
151 struct comedi_subdevice *s;
152 int subdev;
153 int nchan;
154 int ret;
155
156 if (context < ARRAY_SIZE(adl_pci7x3x_boards))
157 board = &adl_pci7x3x_boards[context];
158 if (!board)
159 return -ENODEV;
160 dev->board_ptr = board;
161 dev->board_name = board->name;
162
163 ret = comedi_pci_enable(dev);
164 if (ret)
165 return ret;
166 dev->iobase = pci_resource_start(pcidev, 2);
167
168 /*
169 * One or two subdevices are setup by this driver depending on
170 * the number of digital inputs and/or outputs provided by the
171 * board. Each subdevice has a maximum of 32 channels.
172 *
173 * PCI-7230 - 2 subdevices: 0 - 16 input, 1 - 16 output
174 * PCI-7233 - 1 subdevice: 0 - 32 input
175 * PCI-7234 - 1 subdevice: 0 - 32 output
176 * PCI-7432 - 2 subdevices: 0 - 32 input, 1 - 32 output
177 * PCI-7433 - 2 subdevices: 0 - 32 input, 1 - 32 input
178 * PCI-7434 - 2 subdevices: 0 - 32 output, 1 - 32 output
179 */
180 ret = comedi_alloc_subdevices(dev, board->nsubdevs);
181 if (ret)
182 return ret;
183
184 subdev = 0;
185
186 if (board->di_nchan) {
187 nchan = min(board->di_nchan, 32);
188
189 s = &dev->subdevices[subdev];
190 /* Isolated digital inputs 0 to 15/31 */
191 s->type = COMEDI_SUBD_DI;
192 s->subdev_flags = SDF_READABLE;
193 s->n_chan = nchan;
194 s->maxdata = 1;
195 s->insn_bits = adl_pci7x3x_di_insn_bits;
196 s->range_table = &range_digital;
197
198 s->private = (void *)PCI7X3X_DIO_REG;
199
200 subdev++;
201
202 nchan = board->di_nchan - nchan;
203 if (nchan) {
204 s = &dev->subdevices[subdev];
205 /* Isolated digital inputs 32 to 63 */
206 s->type = COMEDI_SUBD_DI;
207 s->subdev_flags = SDF_READABLE;
208 s->n_chan = nchan;
209 s->maxdata = 1;
210 s->insn_bits = adl_pci7x3x_di_insn_bits;
211 s->range_table = &range_digital;
212
213 s->private = (void *)PCI743X_DIO_REG;
214
215 subdev++;
216 }
217 }
218
219 if (board->do_nchan) {
220 nchan = min(board->do_nchan, 32);
221
222 s = &dev->subdevices[subdev];
223 /* Isolated digital outputs 0 to 15/31 */
224 s->type = COMEDI_SUBD_DO;
225 s->subdev_flags = SDF_WRITABLE;
226 s->n_chan = nchan;
227 s->maxdata = 1;
228 s->insn_bits = adl_pci7x3x_do_insn_bits;
229 s->range_table = &range_digital;
230
231 s->private = (void *)PCI7X3X_DIO_REG;
232
233 subdev++;
234
235 nchan = board->do_nchan - nchan;
236 if (nchan) {
237 s = &dev->subdevices[subdev];
238 /* Isolated digital outputs 32 to 63 */
239 s->type = COMEDI_SUBD_DO;
240 s->subdev_flags = SDF_WRITABLE;
241 s->n_chan = nchan;
242 s->maxdata = 1;
243 s->insn_bits = adl_pci7x3x_do_insn_bits;
244 s->range_table = &range_digital;
245
246 s->private = (void *)PCI743X_DIO_REG;
247
248 subdev++;
249 }
250 }
251
252 dev_info(dev->class_dev, "%s attached (%d inputs/%d outputs)\n",
253 dev->board_name, board->di_nchan, board->do_nchan);
254
255 return 0;
256 }
257
258 static struct comedi_driver adl_pci7x3x_driver = {
259 .driver_name = "adl_pci7x3x",
260 .module = THIS_MODULE,
261 .auto_attach = adl_pci7x3x_auto_attach,
262 .detach = comedi_pci_disable,
263 };
264
265 static int adl_pci7x3x_pci_probe(struct pci_dev *dev,
266 const struct pci_device_id *id)
267 {
268 return comedi_pci_auto_config(dev, &adl_pci7x3x_driver,
269 id->driver_data);
270 }
271
272 static DEFINE_PCI_DEVICE_TABLE(adl_pci7x3x_pci_table) = {
273 { PCI_VDEVICE(ADLINK, 0x7230), BOARD_PCI7230 },
274 { PCI_VDEVICE(ADLINK, 0x7233), BOARD_PCI7233 },
275 { PCI_VDEVICE(ADLINK, 0x7234), BOARD_PCI7234 },
276 { PCI_VDEVICE(ADLINK, 0x7432), BOARD_PCI7432 },
277 { PCI_VDEVICE(ADLINK, 0x7433), BOARD_PCI7433 },
278 { PCI_VDEVICE(ADLINK, 0x7434), BOARD_PCI7434 },
279 { 0 }
280 };
281 MODULE_DEVICE_TABLE(pci, adl_pci7x3x_pci_table);
282
283 static struct pci_driver adl_pci7x3x_pci_driver = {
284 .name = "adl_pci7x3x",
285 .id_table = adl_pci7x3x_pci_table,
286 .probe = adl_pci7x3x_pci_probe,
287 .remove = comedi_pci_auto_unconfig,
288 };
289 module_comedi_pci_driver(adl_pci7x3x_driver, adl_pci7x3x_pci_driver);
290
291 MODULE_DESCRIPTION("ADLINK PCI-723x/743x Isolated Digital I/O boards");
292 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
293 MODULE_LICENSE("GPL");
This page took 0.037561 seconds and 5 git commands to generate.