1 // SPDX-License-Identifier: GPL-2.0+
3 * comedi/drivers/ni_daq_700.c
4 * Driver for DAQCard-700 DIO/AI
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
13 * Description: National Instruments PCMCIA DAQCard-700
14 * Author: Fred Brooks <nsaspook@nsaspook.com>,
15 * based on ni_daq_dio24 by Daniel Vecino Castel <dvecino@able.es>
16 * Devices: [National Instruments] PCMCIA DAQ-Card-700 (ni_daq_700)
18 * Updated: Wed, 21 May 2014 12:07:20 +0000
20 * The daqcard-700 appears in Comedi as a digital I/O subdevice (0) with
21 * 16 channels and a analog input subdevice (1) with 16 single-ended channels
22 * or 8 differential channels, and three input ranges.
24 * Digital: The channel 0 corresponds to the daqcard-700's output
25 * port, bit 0; channel 8 corresponds to the input port, bit 0.
27 * Digital direction configuration: channels 0-7 output, 8-15 input.
29 * Analog: The input range is 0 to 4095 with a default of -10 to +10 volts.
31 * 0 for -10 to 10V bipolar
32 * 1 for -5 to 5V bipolar
33 * 2 for -2.5 to 2.5V bipolar
35 * IRQ is assigned but not used.
37 * Manuals: Register level: https://www.ni.com/pdf/manuals/340698.pdf
38 * User Manual: https://www.ni.com/pdf/manuals/320676d.pdf
41 #include <linux/module.h>
42 #include <linux/delay.h>
43 #include <linux/interrupt.h>
45 #include "../comedi_pcmcia.h"
47 /* daqcard700 registers */
48 #define DIO_W 0x04 /* WO 8bit */
49 #define DIO_R 0x05 /* RO 8bit */
50 #define CMD_R1 0x00 /* WO 8bit */
51 #define CMD_R2 0x07 /* RW 8bit */
52 #define CMD_R3 0x05 /* W0 8bit */
53 #define STA_R1 0x00 /* RO 8bit */
54 #define STA_R2 0x01 /* RO 8bit */
55 #define ADFIFO_R 0x02 /* RO 16bit */
56 #define ADCLEAR_R 0x01 /* WO 8bit */
57 #define CDA_R0 0x08 /* RW 8bit */
58 #define CDA_R1 0x09 /* RW 8bit */
59 #define CDA_R2 0x0A /* RW 8bit */
60 #define CMO_R 0x0B /* RO 8bit */
61 #define TIC_R 0x06 /* WO 8bit */
62 /* daqcard700 modes */
63 #define CMD_R3_DIFF 0x04 /* diff mode */
65 static const struct comedi_lrange range_daq700_ai = {
74 static int daq700_dio_insn_bits(struct comedi_device *dev,
75 struct comedi_subdevice *s,
76 struct comedi_insn *insn,
82 mask = comedi_dio_update_state(s, data);
85 outb(s->state & 0xff, dev->iobase + DIO_W);
88 val = s->state & 0xff;
89 val |= inb(dev->iobase + DIO_R) << 8;
96 static int daq700_dio_insn_config(struct comedi_device *dev,
97 struct comedi_subdevice *s,
98 struct comedi_insn *insn,
103 ret = comedi_dio_insn_config(dev, s, insn, data, 0);
107 /* The DIO channels are not configurable, fix the io_bits */
113 static int daq700_ai_eoc(struct comedi_device *dev,
114 struct comedi_subdevice *s,
115 struct comedi_insn *insn,
116 unsigned long context)
120 status = inb(dev->iobase + STA_R2);
123 status = inb(dev->iobase + STA_R1);
126 if ((status & 0x11) == 0x01)
131 static int daq700_ai_rinsn(struct comedi_device *dev,
132 struct comedi_subdevice *s,
133 struct comedi_insn *insn, unsigned int *data)
138 unsigned int chan = CR_CHAN(insn->chanspec);
139 unsigned int aref = CR_AREF(insn->chanspec);
140 unsigned int range = CR_RANGE(insn->chanspec);
141 unsigned int r3_bits = 0;
143 /* set channel input modes */
144 if (aref == AREF_DIFF)
145 r3_bits |= CMD_R3_DIFF;
146 /* write channel mode/range */
148 range++; /* convert range to hardware value */
149 outb(r3_bits | (range & 0x03), dev->iobase + CMD_R3);
151 /* write channel to multiplexer */
152 /* set mask scan bit high to disable scanning */
153 outb(chan | 0x80, dev->iobase + CMD_R1);
154 /* mux needs 2us to really settle [Fred Brooks]. */
157 /* convert n samples */
158 for (n = 0; n < insn->n; n++) {
159 /* trigger conversion with out0 L to H */
160 outb(0x00, dev->iobase + CMD_R2); /* enable ADC conversions */
161 outb(0x30, dev->iobase + CMO_R); /* mode 0 out0 L, from H */
162 outb(0x00, dev->iobase + ADCLEAR_R); /* clear the ADC FIFO */
163 /* read 16bit junk from FIFO to clear */
164 inw(dev->iobase + ADFIFO_R);
165 /* mode 1 out0 H, L to H, start conversion */
166 outb(0x32, dev->iobase + CMO_R);
168 /* wait for conversion to end */
169 ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
174 d = inw(dev->iobase + ADFIFO_R);
175 /* mangle the data as necessary */
176 /* Bipolar Offset Binary: 0 to 4095 for -10 to +10 */
185 * Data acquisition is enabled.
186 * The counter 0 output is high.
187 * The I/O connector pin CLK1 drives counter 1 source.
188 * Multiple-channel scanning is disabled.
189 * All interrupts are disabled.
190 * The analog input range is set to +-10 V
191 * The analog input mode is single-ended.
192 * The analog input circuitry is initialized to channel 0.
193 * The A/D FIFO is cleared.
195 static void daq700_ai_config(struct comedi_device *dev,
196 struct comedi_subdevice *s)
198 unsigned long iobase = dev->iobase;
200 outb(0x80, iobase + CMD_R1); /* disable scanning, ADC to chan 0 */
201 outb(0x00, iobase + CMD_R2); /* clear all bits */
202 outb(0x00, iobase + CMD_R3); /* set +-10 range */
203 outb(0x32, iobase + CMO_R); /* config counter mode1, out0 to H */
204 outb(0x00, iobase + TIC_R); /* clear counter interrupt */
205 outb(0x00, iobase + ADCLEAR_R); /* clear the ADC FIFO */
206 inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */
209 static int daq700_auto_attach(struct comedi_device *dev,
210 unsigned long context)
212 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
213 struct comedi_subdevice *s;
216 link->config_flags |= CONF_AUTO_SET_IO;
217 ret = comedi_pcmcia_enable(dev, NULL);
220 dev->iobase = link->resource[0]->start;
222 ret = comedi_alloc_subdevices(dev, 2);
226 /* DAQCard-700 dio */
227 s = &dev->subdevices[0];
228 s->type = COMEDI_SUBD_DIO;
229 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
231 s->range_table = &range_digital;
233 s->insn_bits = daq700_dio_insn_bits;
234 s->insn_config = daq700_dio_insn_config;
238 s = &dev->subdevices[1];
239 s->type = COMEDI_SUBD_AI;
240 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
242 s->maxdata = BIT(12) - 1;
243 s->range_table = &range_daq700_ai;
244 s->insn_read = daq700_ai_rinsn;
245 daq700_ai_config(dev, s);
250 static struct comedi_driver daq700_driver = {
251 .driver_name = "ni_daq_700",
252 .module = THIS_MODULE,
253 .auto_attach = daq700_auto_attach,
254 .detach = comedi_pcmcia_disable,
257 static int daq700_cs_attach(struct pcmcia_device *link)
259 return comedi_pcmcia_auto_config(link, &daq700_driver);
262 static const struct pcmcia_device_id daq700_cs_ids[] = {
263 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x4743),
266 MODULE_DEVICE_TABLE(pcmcia, daq700_cs_ids);
268 static struct pcmcia_driver daq700_cs_driver = {
269 .name = "ni_daq_700",
270 .owner = THIS_MODULE,
271 .id_table = daq700_cs_ids,
272 .probe = daq700_cs_attach,
273 .remove = comedi_pcmcia_auto_unconfig,
275 module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver);
277 MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>");
279 "Comedi driver for National Instruments PCMCIA DAQCard-700 DIO/AI");
280 MODULE_LICENSE("GPL");