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),
32 * Updated: Mon, 04 Nov 2002 20:04:21 -0800
33 * Status: experimental
36 #include <linux/module.h>
37 #include <linux/interrupt.h>
38 #include <linux/delay.h>
40 #include "../comedi_pcmcia.h"
42 #include "comedi_8254.h"
47 #define DAS16CS_AI_DATA_REG 0x00
48 #define DAS16CS_AI_MUX_REG 0x02
49 #define DAS16CS_AI_MUX_HI_CHAN(x) (((x) & 0xf) << 4)
50 #define DAS16CS_AI_MUX_LO_CHAN(x) (((x) & 0xf) << 0)
51 #define DAS16CS_AI_MUX_SINGLE_CHAN(x) (DAS16CS_AI_MUX_HI_CHAN(x) | \
52 DAS16CS_AI_MUX_LO_CHAN(x))
53 #define DAS16CS_MISC1_REG 0x04
54 #define DAS16CS_MISC1_INTE BIT(15) /* 1=enable; 0=disable */
55 #define DAS16CS_MISC1_INT_SRC(x) (((x) & 0x7) << 12) /* interrupt src */
56 #define DAS16CS_MISC1_INT_SRC_NONE DAS16CS_MISC1_INT_SRC(0)
57 #define DAS16CS_MISC1_INT_SRC_PACER DAS16CS_MISC1_INT_SRC(1)
58 #define DAS16CS_MISC1_INT_SRC_EXT DAS16CS_MISC1_INT_SRC(2)
59 #define DAS16CS_MISC1_INT_SRC_FNE DAS16CS_MISC1_INT_SRC(3)
60 #define DAS16CS_MISC1_INT_SRC_FHF DAS16CS_MISC1_INT_SRC(4)
61 #define DAS16CS_MISC1_INT_SRC_EOS DAS16CS_MISC1_INT_SRC(5)
62 #define DAS16CS_MISC1_INT_SRC_MASK DAS16CS_MISC1_INT_SRC(7)
63 #define DAS16CS_MISC1_OVR BIT(10) /* ro - 1=FIFO overflow */
64 #define DAS16CS_MISC1_AI_CONV(x) (((x) & 0x3) << 8) /* AI convert src */
65 #define DAS16CS_MISC1_AI_CONV_SW DAS16CS_MISC1_AI_CONV(0)
66 #define DAS16CS_MISC1_AI_CONV_EXT_NEG DAS16CS_MISC1_AI_CONV(1)
67 #define DAS16CS_MISC1_AI_CONV_EXT_POS DAS16CS_MISC1_AI_CONV(2)
68 #define DAS16CS_MISC1_AI_CONV_PACER DAS16CS_MISC1_AI_CONV(3)
69 #define DAS16CS_MISC1_AI_CONV_MASK DAS16CS_MISC1_AI_CONV(3)
70 #define DAS16CS_MISC1_EOC BIT(7) /* ro - 0=busy; 1=ready */
71 #define DAS16CS_MISC1_SEDIFF BIT(5) /* 0=diff; 1=se */
72 #define DAS16CS_MISC1_INTB BIT(4) /* ro - 0=latched; 1=cleared */
73 #define DAS16CS_MISC1_MA_MASK (0xf << 0) /* ro - current ai mux */
74 #define DAS16CS_MISC1_DAC1CS BIT(3) /* wo - DAC1 chip select */
75 #define DAS16CS_MISC1_DACCLK BIT(2) /* wo - Serial DAC clock */
76 #define DAS16CS_MISC1_DACSD BIT(1) /* wo - Serial DAC data */
77 #define DAS16CS_MISC1_DAC0CS BIT(0) /* wo - DAC0 chip select */
78 #define DAS16CS_MISC1_DAC_MASK (0x0f << 0)
79 #define DAS16CS_MISC2_REG 0x06
80 #define DAS16CS_MISC2_BME BIT(14) /* 1=burst enable; 0=disable */
81 #define DAS16CS_MISC2_AI_GAIN(x) (((x) & 0xf) << 8) /* AI gain */
82 #define DAS16CS_MISC2_AI_GAIN_1 DAS16CS_MISC2_AI_GAIN(4) /* +/-10V */
83 #define DAS16CS_MISC2_AI_GAIN_2 DAS16CS_MISC2_AI_GAIN(0) /* +/-5V */
84 #define DAS16CS_MISC2_AI_GAIN_4 DAS16CS_MISC2_AI_GAIN(1) /* +/-2.5V */
85 #define DAS16CS_MISC2_AI_GAIN_8 DAS16CS_MISC2_AI_GAIN(2) /* +-1.25V */
86 #define DAS16CS_MISC2_AI_GAIN_MASK DAS16CS_MISC2_AI_GAIN(0xf)
87 #define DAS16CS_MISC2_UDIR BIT(7) /* 1=dio7:4 output; 0=input */
88 #define DAS16CS_MISC2_LDIR BIT(6) /* 1=dio3:0 output; 0=input */
89 #define DAS16CS_MISC2_TRGPOL BIT(5) /* 1=active lo; 0=hi */
90 #define DAS16CS_MISC2_TRGSEL BIT(4) /* 1=edge; 0=level */
91 #define DAS16CS_MISC2_FFNE BIT(3) /* ro - 1=FIFO not empty */
92 #define DAS16CS_MISC2_TRGCLR BIT(3) /* wo - 1=clr (monstable) */
93 #define DAS16CS_MISC2_CLK2 BIT(2) /* 1=10 MHz; 0=1 MHz */
94 #define DAS16CS_MISC2_CTR1 BIT(1) /* 1=int. 100 kHz; 0=ext. clk */
95 #define DAS16CS_MISC2_TRG0 BIT(0) /* 1=enable; 0=disable */
96 #define DAS16CS_TIMER_BASE 0x08
97 #define DAS16CS_DIO_REG 0x10
99 struct das16cs_board {
102 unsigned int has_ao:1;
105 static const struct das16cs_board das16cs_boards[] = {
107 .name = "PC-CARD DAS16/16-AO",
111 .name = "PCM-DAS16s/16",
114 .name = "PC-CARD DAS16/16",
115 .device_id = 0x0000, /* unknown */
119 struct das16cs_private {
120 unsigned short status1;
121 unsigned short status2;
124 static const struct comedi_lrange das16cs_ai_range = {
133 static int das16cs_ai_eoc(struct comedi_device *dev,
134 struct comedi_subdevice *s,
135 struct comedi_insn *insn,
136 unsigned long context)
140 status = inw(dev->iobase + DAS16CS_MISC1_REG);
141 if (status & DAS16CS_MISC1_EOC)
146 static int das16cs_ai_rinsn(struct comedi_device *dev,
147 struct comedi_subdevice *s,
148 struct comedi_insn *insn, unsigned int *data)
150 struct das16cs_private *devpriv = dev->private;
151 int chan = CR_CHAN(insn->chanspec);
152 int range = CR_RANGE(insn->chanspec);
153 int aref = CR_AREF(insn->chanspec);
157 outw(DAS16CS_AI_MUX_SINGLE_CHAN(chan),
158 dev->iobase + DAS16CS_AI_MUX_REG);
160 /* disable interrupts, software convert */
161 devpriv->status1 &= ~(DAS16CS_MISC1_INTE | DAS16CS_MISC1_INT_SRC_MASK |
162 DAS16CS_MISC1_AI_CONV_MASK);
163 if (aref == AREF_DIFF)
164 devpriv->status1 &= ~DAS16CS_MISC1_SEDIFF;
166 devpriv->status1 |= DAS16CS_MISC1_SEDIFF;
167 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1_REG);
169 devpriv->status2 &= ~(DAS16CS_MISC2_BME | DAS16CS_MISC2_AI_GAIN_MASK);
172 devpriv->status2 |= DAS16CS_MISC2_AI_GAIN_1;
175 devpriv->status2 |= DAS16CS_MISC2_AI_GAIN_2;
178 devpriv->status2 |= DAS16CS_MISC2_AI_GAIN_4;
181 devpriv->status2 |= DAS16CS_MISC2_AI_GAIN_8;
184 outw(devpriv->status2, dev->iobase + DAS16CS_MISC2_REG);
186 for (i = 0; i < insn->n; i++) {
187 outw(0, dev->iobase + DAS16CS_AI_DATA_REG);
189 ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0);
193 data[i] = inw(dev->iobase + DAS16CS_AI_DATA_REG);
199 static int das16cs_ao_insn_write(struct comedi_device *dev,
200 struct comedi_subdevice *s,
201 struct comedi_insn *insn,
204 struct das16cs_private *devpriv = dev->private;
205 unsigned int chan = CR_CHAN(insn->chanspec);
206 unsigned int val = s->readback[chan];
207 unsigned short status1;
211 for (i = 0; i < insn->n; i++) {
214 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1_REG);
217 /* raise the DACxCS line for the non-selected channel */
218 status1 = devpriv->status1 & ~DAS16CS_MISC1_DAC_MASK;
220 status1 |= DAS16CS_MISC1_DAC0CS;
222 status1 |= DAS16CS_MISC1_DAC1CS;
224 outw(status1, dev->iobase + DAS16CS_MISC1_REG);
227 for (bit = 15; bit >= 0; bit--) {
228 if ((val >> bit) & 0x1)
229 status1 |= DAS16CS_MISC1_DACSD;
231 status1 &= ~DAS16CS_MISC1_DACSD;
232 outw(status1, dev->iobase + DAS16CS_MISC1_REG);
234 outw(status1 | DAS16CS_MISC1_DACCLK,
235 dev->iobase + DAS16CS_MISC1_REG);
239 * Make both DAC0CS and DAC1CS high to load
240 * the new data and update analog the output
242 outw(status1 | DAS16CS_MISC1_DAC0CS | DAS16CS_MISC1_DAC1CS,
243 dev->iobase + DAS16CS_MISC1_REG);
245 s->readback[chan] = val;
250 static int das16cs_dio_insn_bits(struct comedi_device *dev,
251 struct comedi_subdevice *s,
252 struct comedi_insn *insn,
255 if (comedi_dio_update_state(s, data))
256 outw(s->state, dev->iobase + DAS16CS_DIO_REG);
258 data[1] = inw(dev->iobase + DAS16CS_DIO_REG);
263 static int das16cs_dio_insn_config(struct comedi_device *dev,
264 struct comedi_subdevice *s,
265 struct comedi_insn *insn,
268 struct das16cs_private *devpriv = dev->private;
269 unsigned int chan = CR_CHAN(insn->chanspec);
278 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
282 if (s->io_bits & 0xf0)
283 devpriv->status2 |= DAS16CS_MISC2_UDIR;
285 devpriv->status2 &= ~DAS16CS_MISC2_UDIR;
286 if (s->io_bits & 0x0f)
287 devpriv->status2 |= DAS16CS_MISC2_LDIR;
289 devpriv->status2 &= ~DAS16CS_MISC2_LDIR;
290 outw(devpriv->status2, dev->iobase + DAS16CS_MISC2_REG);
295 static const void *das16cs_find_boardinfo(struct comedi_device *dev,
296 struct pcmcia_device *link)
298 const struct das16cs_board *board;
301 for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
302 board = &das16cs_boards[i];
303 if (board->device_id == link->card_id)
310 static int das16cs_auto_attach(struct comedi_device *dev,
311 unsigned long context)
313 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
314 const struct das16cs_board *board;
315 struct das16cs_private *devpriv;
316 struct comedi_subdevice *s;
319 board = das16cs_find_boardinfo(dev, link);
322 dev->board_ptr = board;
323 dev->board_name = board->name;
325 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
326 ret = comedi_pcmcia_enable(dev, NULL);
329 dev->iobase = link->resource[0]->start;
333 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
337 dev->pacer = comedi_8254_init(dev->iobase + DAS16CS_TIMER_BASE,
338 I8254_OSC_BASE_10MHZ, I8254_IO16, 0);
342 ret = comedi_alloc_subdevices(dev, 3);
346 s = &dev->subdevices[0];
347 /* analog input subdevice */
348 s->type = COMEDI_SUBD_AI;
349 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
352 s->range_table = &das16cs_ai_range;
353 s->len_chanlist = 16;
354 s->insn_read = das16cs_ai_rinsn;
356 s = &dev->subdevices[1];
357 /* analog output subdevice */
359 s->type = COMEDI_SUBD_AO;
360 s->subdev_flags = SDF_WRITABLE;
363 s->range_table = &range_bipolar10;
364 s->insn_write = &das16cs_ao_insn_write;
366 ret = comedi_alloc_subdev_readback(s);
370 s->type = COMEDI_SUBD_UNUSED;
373 s = &dev->subdevices[2];
374 /* digital i/o subdevice */
375 s->type = COMEDI_SUBD_DIO;
376 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
379 s->range_table = &range_digital;
380 s->insn_bits = das16cs_dio_insn_bits;
381 s->insn_config = das16cs_dio_insn_config;
386 static struct comedi_driver driver_das16cs = {
387 .driver_name = "cb_das16_cs",
388 .module = THIS_MODULE,
389 .auto_attach = das16cs_auto_attach,
390 .detach = comedi_pcmcia_disable,
393 static int das16cs_pcmcia_attach(struct pcmcia_device *link)
395 return comedi_pcmcia_auto_config(link, &driver_das16cs);
398 static const struct pcmcia_device_id das16cs_id_table[] = {
399 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0039),
400 PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4009),
403 MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
405 static struct pcmcia_driver das16cs_driver = {
406 .name = "cb_das16_cs",
407 .owner = THIS_MODULE,
408 .id_table = das16cs_id_table,
409 .probe = das16cs_pcmcia_attach,
410 .remove = comedi_pcmcia_auto_unconfig,
412 module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
414 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
415 MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16");
416 MODULE_LICENSE("GPL");