diff options
| author | Ian Abbott <abbotti@mev.co.uk> | 2012-09-21 07:05:47 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-09-26 12:35:51 -0400 |
| commit | 198b0fa48b25b60e4857132a7c55c9e6e18748d9 (patch) | |
| tree | f25af9b04cf96a91b0be530bc7a6c236e69713bd | |
| parent | 08351926d23577711c48ef63168b1255702c6c77 (diff) | |
staging: comedi: ni_daq_700: add AI subdevice
Add subdevice 1 as an analog input (AI) subdevice. It currently only
supports basic, software-triggered acquisitions.
This is mostly the work of Fred Brooks (MODULE_AUTHOR), but he based his
update on an older version of the driver. I applied the relevant
changes with a few tweaks: adding an explicit `udelay(1)` in a timeout
loop, replacing binary constants with hex, renaming functions, replacing
`printk()` calls, removing exported symbols, removing (very) incomplete
comedi "command" support, and making some coding-style changes.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | drivers/staging/comedi/drivers/ni_daq_700.c | 136 |
1 files changed, 126 insertions, 10 deletions
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c index 231846351192..2ba0ade45c64 100644 --- a/drivers/staging/comedi/drivers/ni_daq_700.c +++ b/drivers/staging/comedi/drivers/ni_daq_700.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * comedi/drivers/ni_daq_700.c | 2 | * comedi/drivers/ni_daq_700.c |
| 3 | * Driver for DAQCard-700 DIO only | 3 | * Driver for DAQCard-700 DIO/AI |
| 4 | * copied from 8255 | 4 | * copied from 8255 |
| 5 | * | 5 | * |
| 6 | * COMEDI - Linux Control and Measurement Device Interface | 6 | * COMEDI - Linux Control and Measurement Device Interface |
| @@ -29,14 +29,25 @@ Author: Fred Brooks <nsaspook@nsaspook.com>, | |||
| 29 | based on ni_daq_dio24 by Daniel Vecino Castel <dvecino@able.es> | 29 | based on ni_daq_dio24 by Daniel Vecino Castel <dvecino@able.es> |
| 30 | Devices: [National Instruments] PCMCIA DAQ-Card-700 (ni_daq_700) | 30 | Devices: [National Instruments] PCMCIA DAQ-Card-700 (ni_daq_700) |
| 31 | Status: works | 31 | Status: works |
| 32 | Updated: Thu, 21 Feb 2008 12:07:20 +0000 | 32 | Updated: Wed, 19 Sep 2012 12:07:20 +0000 |
| 33 | 33 | ||
| 34 | The daqcard-700 appears in Comedi as a single digital I/O subdevice with | 34 | The daqcard-700 appears in Comedi as a digital I/O subdevice (0) with |
| 35 | 16 channels. The channel 0 corresponds to the daqcard-700's output | 35 | 16 channels and a analog input subdevice (1) with 16 single-ended channels. |
| 36 | |||
| 37 | Digital: The channel 0 corresponds to the daqcard-700's output | ||
| 36 | port, bit 0; channel 8 corresponds to the input port, bit 0. | 38 | port, bit 0; channel 8 corresponds to the input port, bit 0. |
| 37 | 39 | ||
| 38 | Direction configuration: channels 0-7 output, 8-15 input (8225 device | 40 | Digital direction configuration: channels 0-7 output, 8-15 input (8225 device |
| 39 | emu as port A output, port B input, port C N/A). | 41 | emu as port A output, port B input, port C N/A). |
| 42 | |||
| 43 | Analog: The input range is 0 to 4095 for -10 to +10 volts | ||
| 44 | IRQ is assigned but not used. | ||
| 45 | |||
| 46 | Version 0.1 Original DIO only driver | ||
| 47 | Version 0.2 DIO and basic AI analog input support on 16 se channels | ||
| 48 | |||
| 49 | Manuals: Register level: http://www.ni.com/pdf/manuals/340698.pdf | ||
| 50 | User Manual: http://www.ni.com/pdf/manuals/320676d.pdf | ||
| 40 | */ | 51 | */ |
| 41 | 52 | ||
| 42 | #include <linux/interrupt.h> | 53 | #include <linux/interrupt.h> |
| @@ -55,8 +66,21 @@ struct daq700_board { | |||
| 55 | const char *name; | 66 | const char *name; |
| 56 | }; | 67 | }; |
| 57 | 68 | ||
| 58 | #define DIO_W 0x04 | 69 | /* daqcard700 registers */ |
| 59 | #define DIO_R 0x05 | 70 | #define DIO_W 0x04 /* WO 8bit */ |
| 71 | #define DIO_R 0x05 /* RO 8bit */ | ||
| 72 | #define CMD_R1 0x00 /* WO 8bit */ | ||
| 73 | #define CMD_R2 0x07 /* RW 8bit */ | ||
| 74 | #define CMD_R3 0x05 /* W0 8bit */ | ||
| 75 | #define STA_R1 0x00 /* RO 8bit */ | ||
| 76 | #define STA_R2 0x01 /* RO 8bit */ | ||
| 77 | #define ADFIFO_R 0x02 /* RO 16bit */ | ||
| 78 | #define ADCLEAR_R 0x01 /* WO 8bit */ | ||
| 79 | #define CDA_R0 0x08 /* RW 8bit */ | ||
| 80 | #define CDA_R1 0x09 /* RW 8bit */ | ||
| 81 | #define CDA_R2 0x0A /* RW 8bit */ | ||
| 82 | #define CMO_R 0x0B /* RO 8bit */ | ||
| 83 | #define TIC_R 0x06 /* WO 8bit */ | ||
| 60 | 84 | ||
| 61 | static int daq700_dio_insn_bits(struct comedi_device *dev, | 85 | static int daq700_dio_insn_bits(struct comedi_device *dev, |
| 62 | struct comedi_subdevice *s, | 86 | struct comedi_subdevice *s, |
| @@ -97,6 +121,87 @@ static int daq700_dio_insn_config(struct comedi_device *dev, | |||
| 97 | return insn->n; | 121 | return insn->n; |
| 98 | } | 122 | } |
| 99 | 123 | ||
| 124 | static int daq700_ai_rinsn(struct comedi_device *dev, | ||
| 125 | struct comedi_subdevice *s, | ||
| 126 | struct comedi_insn *insn, unsigned int *data) | ||
| 127 | { | ||
| 128 | int n, i, chan; | ||
| 129 | int d; | ||
| 130 | unsigned int status; | ||
| 131 | enum { TIMEOUT = 100 }; | ||
| 132 | |||
| 133 | chan = CR_CHAN(insn->chanspec); | ||
| 134 | /* write channel to multiplexer */ | ||
| 135 | /* set mask scan bit high to disable scanning */ | ||
| 136 | outb(chan | 0x80, dev->iobase + CMD_R1); | ||
| 137 | |||
| 138 | /* convert n samples */ | ||
| 139 | for (n = 0; n < insn->n; n++) { | ||
| 140 | /* trigger conversion with out0 L to H */ | ||
| 141 | outb(0x00, dev->iobase + CMD_R2); /* enable ADC conversions */ | ||
| 142 | outb(0x30, dev->iobase + CMO_R); /* mode 0 out0 L, from H */ | ||
| 143 | /* mode 1 out0 H, L to H, start conversion */ | ||
| 144 | outb(0x32, dev->iobase + CMO_R); | ||
| 145 | /* wait for conversion to end */ | ||
| 146 | for (i = 0; i < TIMEOUT; i++) { | ||
| 147 | status = inb(dev->iobase + STA_R2); | ||
| 148 | if ((status & 0x03) != 0) { | ||
| 149 | dev_info(dev->class_dev, | ||
| 150 | "Overflow/run Error\n"); | ||
| 151 | return -EOVERFLOW; | ||
| 152 | } | ||
| 153 | status = inb(dev->iobase + STA_R1); | ||
| 154 | if ((status & 0x02) != 0) { | ||
| 155 | dev_info(dev->class_dev, "Data Error\n"); | ||
| 156 | return -ENODATA; | ||
| 157 | } | ||
| 158 | if ((status & 0x11) == 0x01) { | ||
| 159 | /* ADC conversion complete */ | ||
| 160 | break; | ||
| 161 | } | ||
| 162 | udelay(1); | ||
| 163 | } | ||
| 164 | if (i == TIMEOUT) { | ||
| 165 | dev_info(dev->class_dev, | ||
| 166 | "timeout during ADC conversion\n"); | ||
| 167 | return -ETIMEDOUT; | ||
| 168 | } | ||
| 169 | /* read data */ | ||
| 170 | d = inw(dev->iobase + ADFIFO_R); | ||
| 171 | /* mangle the data as necessary */ | ||
| 172 | /* Bipolar Offset Binary: 0 to 4095 for -10 to +10 */ | ||
| 173 | d &= 0x0fff; | ||
| 174 | d ^= 0x0800; | ||
| 175 | data[n] = d; | ||
| 176 | } | ||
| 177 | return n; | ||
| 178 | } | ||
| 179 | |||
| 180 | /* | ||
| 181 | * Data acquisition is enabled. | ||
| 182 | * The counter 0 output is high. | ||
| 183 | * The I/O connector pin CLK1 drives counter 1 source. | ||
| 184 | * Multiple-channel scanning is disabled. | ||
| 185 | * All interrupts are disabled. | ||
| 186 | * The analog input range is set to +-10 V | ||
| 187 | * The analog input mode is single-ended. | ||
| 188 | * The analog input circuitry is initialized to channel 0. | ||
| 189 | * The A/D FIFO is cleared. | ||
| 190 | */ | ||
| 191 | static void daq700_ai_config(struct comedi_device *dev, | ||
| 192 | struct comedi_subdevice *s) | ||
| 193 | { | ||
| 194 | unsigned long iobase = dev->iobase; | ||
| 195 | |||
| 196 | outb(0x80, iobase + CMD_R1); /* disable scanning, ADC to chan 0 */ | ||
| 197 | outb(0x00, iobase + CMD_R2); /* clear all bits */ | ||
| 198 | outb(0x00, iobase + CMD_R3); /* set +-10 range */ | ||
| 199 | outb(0x32, iobase + CMO_R); /* config counter mode1, out0 to H */ | ||
| 200 | outb(0x00, iobase + TIC_R); /* clear counter interrupt */ | ||
| 201 | outb(0x00, iobase + ADCLEAR_R); /* clear the ADC FIFO */ | ||
| 202 | inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */ | ||
| 203 | } | ||
| 204 | |||
| 100 | static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) | 205 | static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
| 101 | { | 206 | { |
| 102 | const struct daq700_board *thisboard = comedi_board(dev); | 207 | const struct daq700_board *thisboard = comedi_board(dev); |
| @@ -116,7 +221,7 @@ static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) | |||
| 116 | 221 | ||
| 117 | dev->board_name = thisboard->name; | 222 | dev->board_name = thisboard->name; |
| 118 | 223 | ||
| 119 | ret = comedi_alloc_subdevices(dev, 1); | 224 | ret = comedi_alloc_subdevices(dev, 2); |
| 120 | if (ret) | 225 | if (ret) |
| 121 | return ret; | 226 | return ret; |
| 122 | 227 | ||
| @@ -129,10 +234,20 @@ static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) | |||
| 129 | s->maxdata = 1; | 234 | s->maxdata = 1; |
| 130 | s->insn_bits = daq700_dio_insn_bits; | 235 | s->insn_bits = daq700_dio_insn_bits; |
| 131 | s->insn_config = daq700_dio_insn_config; | 236 | s->insn_config = daq700_dio_insn_config; |
| 132 | |||
| 133 | s->state = 0; | 237 | s->state = 0; |
| 134 | s->io_bits = 0x00ff; | 238 | s->io_bits = 0x00ff; |
| 135 | 239 | ||
| 240 | /* DAQCard-700 ai */ | ||
| 241 | s = &dev->subdevices[1]; | ||
| 242 | s->type = COMEDI_SUBD_AI; | ||
| 243 | /* we support single-ended (ground) */ | ||
| 244 | s->subdev_flags = SDF_READABLE | SDF_GROUND; | ||
| 245 | s->n_chan = 16; | ||
| 246 | s->maxdata = (1 << 12) - 1; | ||
| 247 | s->range_table = &range_bipolar10; | ||
| 248 | s->insn_read = daq700_ai_rinsn; | ||
| 249 | daq700_ai_config(dev, s); | ||
| 250 | |||
| 136 | dev_info(dev->class_dev, "%s: %s, io 0x%lx\n", | 251 | dev_info(dev->class_dev, "%s: %s, io 0x%lx\n", |
| 137 | dev->driver->driver_name, | 252 | dev->driver->driver_name, |
| 138 | dev->board_name, | 253 | dev->board_name, |
| @@ -246,5 +361,6 @@ module_exit(daq700_cs_exit); | |||
| 246 | 361 | ||
| 247 | MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>"); | 362 | MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>"); |
| 248 | MODULE_DESCRIPTION( | 363 | MODULE_DESCRIPTION( |
| 249 | "Comedi driver for National Instruments PCMCIA DAQCard-700 DIO"); | 364 | "Comedi driver for National Instruments PCMCIA DAQCard-700 DIO/AI"); |
| 365 | MODULE_VERSION("0.2.00"); | ||
| 250 | MODULE_LICENSE("GPL"); | 366 | MODULE_LICENSE("GPL"); |
