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
35 #include <linux/module.h>
36 #include <linux/interrupt.h>
37 #include <linux/delay.h>
39 #include "../comedi_pcmcia.h"
41 #include "comedi_8254.h"
43 #define DAS16CS_ADC_DATA 0
44 #define DAS16CS_DIO_MUX 2
45 #define DAS16CS_MISC1 4
46 #define DAS16CS_MISC2 6
47 #define DAS16CS_TIMER_BASE 8
48 #define DAS16CS_DIO 16
50 struct das16cs_board {
56 static const struct das16cs_board das16cs_boards[] = {
58 .name = "PC-CARD DAS16/16-AO",
62 .name = "PCM-DAS16s/16",
66 .name = "PC-CARD DAS16/16",
67 .device_id = 0x0000, /* unknown */
72 struct das16cs_private {
73 unsigned short status1;
74 unsigned short status2;
77 static const struct comedi_lrange das16cs_ai_range = {
86 static int das16cs_ai_eoc(struct comedi_device *dev,
87 struct comedi_subdevice *s,
88 struct comedi_insn *insn,
89 unsigned long context)
93 status = inw(dev->iobase + DAS16CS_MISC1);
99 static int das16cs_ai_rinsn(struct comedi_device *dev,
100 struct comedi_subdevice *s,
101 struct comedi_insn *insn, unsigned int *data)
103 struct das16cs_private *devpriv = dev->private;
104 int chan = CR_CHAN(insn->chanspec);
105 int range = CR_RANGE(insn->chanspec);
106 int aref = CR_AREF(insn->chanspec);
110 outw(chan, dev->iobase + DAS16CS_DIO_MUX);
112 devpriv->status1 &= ~0xf320;
113 devpriv->status1 |= (aref == AREF_DIFF) ? 0 : 0x0020;
114 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
116 devpriv->status2 &= ~0xff00;
119 devpriv->status2 |= 0x800;
122 devpriv->status2 |= 0x000;
125 devpriv->status2 |= 0x100;
128 devpriv->status2 |= 0x200;
131 outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
133 for (i = 0; i < insn->n; i++) {
134 outw(0, dev->iobase + DAS16CS_ADC_DATA);
136 ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0);
140 data[i] = inw(dev->iobase + DAS16CS_ADC_DATA);
146 static int das16cs_ao_insn_write(struct comedi_device *dev,
147 struct comedi_subdevice *s,
148 struct comedi_insn *insn,
151 struct das16cs_private *devpriv = dev->private;
152 unsigned int chan = CR_CHAN(insn->chanspec);
153 unsigned int val = s->readback[chan];
154 unsigned short status1;
158 for (i = 0; i < insn->n; i++) {
161 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
164 status1 = devpriv->status1 & ~0xf;
170 outw(status1, dev->iobase + DAS16CS_MISC1);
173 for (bit = 15; bit >= 0; bit--) {
174 int b = (val >> bit) & 0x1;
177 outw(status1 | b | 0x0000, dev->iobase + DAS16CS_MISC1);
179 outw(status1 | b | 0x0004, dev->iobase + DAS16CS_MISC1);
183 * Make both DAC0CS and DAC1CS high to load
184 * the new data and update analog the output
186 outw(status1 | 0x9, dev->iobase + DAS16CS_MISC1);
188 s->readback[chan] = val;
193 static int das16cs_dio_insn_bits(struct comedi_device *dev,
194 struct comedi_subdevice *s,
195 struct comedi_insn *insn,
198 if (comedi_dio_update_state(s, data))
199 outw(s->state, dev->iobase + DAS16CS_DIO);
201 data[1] = inw(dev->iobase + DAS16CS_DIO);
206 static int das16cs_dio_insn_config(struct comedi_device *dev,
207 struct comedi_subdevice *s,
208 struct comedi_insn *insn,
211 struct das16cs_private *devpriv = dev->private;
212 unsigned int chan = CR_CHAN(insn->chanspec);
221 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
225 devpriv->status2 &= ~0x00c0;
226 devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0;
227 devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0;
229 outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
234 static const void *das16cs_find_boardinfo(struct comedi_device *dev,
235 struct pcmcia_device *link)
237 const struct das16cs_board *board;
240 for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
241 board = &das16cs_boards[i];
242 if (board->device_id == link->card_id)
249 static int das16cs_auto_attach(struct comedi_device *dev,
250 unsigned long context)
252 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
253 const struct das16cs_board *board;
254 struct das16cs_private *devpriv;
255 struct comedi_subdevice *s;
258 board = das16cs_find_boardinfo(dev, link);
261 dev->board_ptr = board;
262 dev->board_name = board->name;
264 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
265 ret = comedi_pcmcia_enable(dev, NULL);
268 dev->iobase = link->resource[0]->start;
272 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
276 dev->pacer = comedi_8254_init(dev->iobase + DAS16CS_TIMER_BASE,
277 I8254_OSC_BASE_10MHZ, I8254_IO16, 0);
281 ret = comedi_alloc_subdevices(dev, 3);
285 s = &dev->subdevices[0];
286 /* analog input subdevice */
287 s->type = COMEDI_SUBD_AI;
288 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
291 s->range_table = &das16cs_ai_range;
292 s->len_chanlist = 16;
293 s->insn_read = das16cs_ai_rinsn;
295 s = &dev->subdevices[1];
296 /* analog output subdevice */
297 if (board->n_ao_chans) {
298 s->type = COMEDI_SUBD_AO;
299 s->subdev_flags = SDF_WRITABLE;
300 s->n_chan = board->n_ao_chans;
302 s->range_table = &range_bipolar10;
303 s->insn_write = &das16cs_ao_insn_write;
305 ret = comedi_alloc_subdev_readback(s);
309 s->type = COMEDI_SUBD_UNUSED;
312 s = &dev->subdevices[2];
313 /* digital i/o subdevice */
314 s->type = COMEDI_SUBD_DIO;
315 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
318 s->range_table = &range_digital;
319 s->insn_bits = das16cs_dio_insn_bits;
320 s->insn_config = das16cs_dio_insn_config;
325 static struct comedi_driver driver_das16cs = {
326 .driver_name = "cb_das16_cs",
327 .module = THIS_MODULE,
328 .auto_attach = das16cs_auto_attach,
329 .detach = comedi_pcmcia_disable,
332 static int das16cs_pcmcia_attach(struct pcmcia_device *link)
334 return comedi_pcmcia_auto_config(link, &driver_das16cs);
337 static const struct pcmcia_device_id das16cs_id_table[] = {
338 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0039),
339 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4009),
342 MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
344 static struct pcmcia_driver das16cs_driver = {
345 .name = "cb_das16_cs",
346 .owner = THIS_MODULE,
347 .id_table = das16cs_id_table,
348 .probe = das16cs_pcmcia_attach,
349 .remove = comedi_pcmcia_auto_unconfig,
351 module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
353 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
354 MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16");
355 MODULE_LICENSE("GPL");