2 comedi/drivers/das16cs.c
3 Driver for Computer Boards PC-CARD DAS16/16.
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000, 2001, 2002 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 PCMCIA support code for this driver is adapted from the dummy_cs.c
19 driver of the Linux PCMCIA Card Services package.
21 The initial developer of the original code is David A. Hinds
22 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
23 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
28 Description: Computer Boards PC-CARD DAS16/16
29 Devices: [ComputerBoards] PC-CARD DAS16/16 (cb_das16_cs), PC-CARD DAS16/16-AO
31 Updated: Mon, 04 Nov 2002 20:04:21 -0800
37 #include <linux/module.h>
38 #include <linux/interrupt.h>
39 #include <linux/delay.h>
41 #include "../comedidev.h"
43 #include <pcmcia/cistpl.h>
44 #include <pcmcia/ds.h>
46 #include "comedi_fc.h"
49 #define DAS16CS_ADC_DATA 0
50 #define DAS16CS_DIO_MUX 2
51 #define DAS16CS_MISC1 4
52 #define DAS16CS_MISC2 6
53 #define DAS16CS_CTR0 8
54 #define DAS16CS_CTR1 10
55 #define DAS16CS_CTR2 12
56 #define DAS16CS_CTR_CONTROL 14
57 #define DAS16CS_DIO 16
59 struct das16cs_board {
65 static const struct das16cs_board das16cs_boards[] = {
67 .name = "PC-CARD DAS16/16-AO",
71 .name = "PCM-DAS16s/16",
75 .name = "PC-CARD DAS16/16",
76 .device_id = 0x0000, /* unknown */
81 struct das16cs_private {
82 unsigned short status1;
83 unsigned short status2;
86 static const struct comedi_lrange das16cs_ai_range = {
95 static int das16cs_ai_eoc(struct comedi_device *dev,
96 struct comedi_subdevice *s,
97 struct comedi_insn *insn,
98 unsigned long context)
102 status = inw(dev->iobase + DAS16CS_MISC1);
108 static int das16cs_ai_rinsn(struct comedi_device *dev,
109 struct comedi_subdevice *s,
110 struct comedi_insn *insn, unsigned int *data)
112 struct das16cs_private *devpriv = dev->private;
113 int chan = CR_CHAN(insn->chanspec);
114 int range = CR_RANGE(insn->chanspec);
115 int aref = CR_AREF(insn->chanspec);
119 outw(chan, dev->iobase + DAS16CS_DIO_MUX);
121 devpriv->status1 &= ~0xf320;
122 devpriv->status1 |= (aref == AREF_DIFF) ? 0 : 0x0020;
123 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
125 devpriv->status2 &= ~0xff00;
128 devpriv->status2 |= 0x800;
131 devpriv->status2 |= 0x000;
134 devpriv->status2 |= 0x100;
137 devpriv->status2 |= 0x200;
140 outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
142 for (i = 0; i < insn->n; i++) {
143 outw(0, dev->iobase + DAS16CS_ADC_DATA);
145 ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0);
149 data[i] = inw(dev->iobase + DAS16CS_ADC_DATA);
155 static int das16cs_ao_insn_write(struct comedi_device *dev,
156 struct comedi_subdevice *s,
157 struct comedi_insn *insn,
160 struct das16cs_private *devpriv = dev->private;
161 unsigned int chan = CR_CHAN(insn->chanspec);
162 unsigned int val = s->readback[chan];
163 unsigned short status1;
167 for (i = 0; i < insn->n; i++) {
170 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
173 status1 = devpriv->status1 & ~0xf;
179 outw(status1, dev->iobase + DAS16CS_MISC1);
182 for (bit = 15; bit >= 0; bit--) {
183 int b = (val >> bit) & 0x1;
186 outw(status1 | b | 0x0000, dev->iobase + DAS16CS_MISC1);
188 outw(status1 | b | 0x0004, dev->iobase + DAS16CS_MISC1);
192 * Make both DAC0CS and DAC1CS high to load
193 * the new data and update analog the output
195 outw(status1 | 0x9, dev->iobase + DAS16CS_MISC1);
197 s->readback[chan] = val;
202 static int das16cs_dio_insn_bits(struct comedi_device *dev,
203 struct comedi_subdevice *s,
204 struct comedi_insn *insn,
207 if (comedi_dio_update_state(s, data))
208 outw(s->state, dev->iobase + DAS16CS_DIO);
210 data[1] = inw(dev->iobase + DAS16CS_DIO);
215 static int das16cs_dio_insn_config(struct comedi_device *dev,
216 struct comedi_subdevice *s,
217 struct comedi_insn *insn,
220 struct das16cs_private *devpriv = dev->private;
221 unsigned int chan = CR_CHAN(insn->chanspec);
230 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
234 devpriv->status2 &= ~0x00c0;
235 devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0;
236 devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0;
238 outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
243 static const void *das16cs_find_boardinfo(struct comedi_device *dev,
244 struct pcmcia_device *link)
246 const struct das16cs_board *board;
249 for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
250 board = &das16cs_boards[i];
251 if (board->device_id == link->card_id)
258 static int das16cs_auto_attach(struct comedi_device *dev,
259 unsigned long context)
261 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
262 const struct das16cs_board *board;
263 struct das16cs_private *devpriv;
264 struct comedi_subdevice *s;
267 board = das16cs_find_boardinfo(dev, link);
270 dev->board_ptr = board;
271 dev->board_name = board->name;
273 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
274 ret = comedi_pcmcia_enable(dev, NULL);
277 dev->iobase = link->resource[0]->start;
281 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
285 ret = comedi_alloc_subdevices(dev, 3);
289 s = &dev->subdevices[0];
290 /* analog input subdevice */
291 s->type = COMEDI_SUBD_AI;
292 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
295 s->range_table = &das16cs_ai_range;
296 s->len_chanlist = 16;
297 s->insn_read = das16cs_ai_rinsn;
299 s = &dev->subdevices[1];
300 /* analog output subdevice */
301 if (board->n_ao_chans) {
302 s->type = COMEDI_SUBD_AO;
303 s->subdev_flags = SDF_WRITABLE;
304 s->n_chan = board->n_ao_chans;
306 s->range_table = &range_bipolar10;
307 s->insn_write = &das16cs_ao_insn_write;
309 ret = comedi_alloc_subdev_readback(s);
313 s->type = COMEDI_SUBD_UNUSED;
316 s = &dev->subdevices[2];
317 /* digital i/o subdevice */
318 s->type = COMEDI_SUBD_DIO;
319 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
322 s->range_table = &range_digital;
323 s->insn_bits = das16cs_dio_insn_bits;
324 s->insn_config = das16cs_dio_insn_config;
329 static struct comedi_driver driver_das16cs = {
330 .driver_name = "cb_das16_cs",
331 .module = THIS_MODULE,
332 .auto_attach = das16cs_auto_attach,
333 .detach = comedi_pcmcia_disable,
336 static int das16cs_pcmcia_attach(struct pcmcia_device *link)
338 return comedi_pcmcia_auto_config(link, &driver_das16cs);
341 static const struct pcmcia_device_id das16cs_id_table[] = {
342 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0039),
343 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4009),
346 MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
348 static struct pcmcia_driver das16cs_driver = {
349 .name = "cb_das16_cs",
350 .owner = THIS_MODULE,
351 .id_table = das16cs_id_table,
352 .probe = das16cs_pcmcia_attach,
353 .remove = comedi_pcmcia_auto_unconfig,
355 module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
357 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
358 MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16");
359 MODULE_LICENSE("GPL");