3 * Hardware driver for Winsystems PCM-A/D12 and PCM-A/D16
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000,2001 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.
21 * Description: Winsystems PCM-A/D12, PCM-A/D16
22 * Devices: (Winsystems) PCM-A/D12 [pcmad12]
23 * (Winsystems) PCM-A/D16 [pcmad16]
27 * This driver was written on a bet that I couldn't write a driver
28 * in less than 2 hours. I won the bet, but never got paid. =(
30 * Configuration options:
33 * [2] - Analog input reference (must match jumpers)
34 * 0 = single-ended (16 channels)
35 * 1 = differential (8 channels)
36 * [3] - Analog input encoding (must match jumpers)
37 * 0 = straight binary (0-5V input range)
38 * 1 = two's complement (+-10V input range)
41 #include <linux/module.h>
42 #include "../comedidev.h"
44 #define PCMAD_STATUS 0
47 #define PCMAD_CONVERT 1
49 struct pcmad_board_struct {
51 unsigned int ai_maxdata;
54 static const struct pcmad_board_struct pcmad_boards[] = {
66 static int pcmad_ai_wait_for_eoc(struct comedi_device *dev,
71 for (i = 0; i < timeout; i++) {
72 if ((inb(dev->iobase + PCMAD_STATUS) & 0x3) == 0x3)
78 static int pcmad_ai_insn_read(struct comedi_device *dev,
79 struct comedi_subdevice *s,
80 struct comedi_insn *insn,
83 unsigned int chan = CR_CHAN(insn->chanspec);
84 unsigned int range = CR_RANGE(insn->chanspec);
89 for (i = 0; i < insn->n; i++) {
90 outb(chan, dev->iobase + PCMAD_CONVERT);
92 ret = pcmad_ai_wait_for_eoc(dev, TIMEOUT);
96 val = inb(dev->iobase + PCMAD_LSB) |
97 (inb(dev->iobase + PCMAD_MSB) << 8);
99 /* data is shifted on the pcmad12, fix it */
100 if (s->maxdata == 0x0fff)
103 if (comedi_range_is_bipolar(s, range)) {
104 /* munge the two's complement value */
105 val ^= ((s->maxdata + 1) >> 1);
114 static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it)
116 const struct pcmad_board_struct *board = comedi_board(dev);
117 struct comedi_subdevice *s;
120 ret = comedi_request_region(dev, it->options[0], 0x04);
124 ret = comedi_alloc_subdevices(dev, 1);
128 s = &dev->subdevices[0];
129 s->type = COMEDI_SUBD_AI;
130 if (it->options[1]) {
131 /* 8 differential channels */
132 s->subdev_flags = SDF_READABLE | AREF_DIFF;
135 /* 16 single-ended channels */
136 s->subdev_flags = SDF_READABLE | AREF_GROUND;
140 s->maxdata = board->ai_maxdata;
141 s->range_table = it->options[2] ? &range_bipolar10 : &range_unipolar5;
142 s->insn_read = pcmad_ai_insn_read;
147 static struct comedi_driver pcmad_driver = {
148 .driver_name = "pcmad",
149 .module = THIS_MODULE,
150 .attach = pcmad_attach,
151 .detach = comedi_legacy_detach,
152 .board_name = &pcmad_boards[0].name,
153 .num_names = ARRAY_SIZE(pcmad_boards),
154 .offset = sizeof(pcmad_boards[0]),
156 module_comedi_driver(pcmad_driver);
158 MODULE_AUTHOR("Comedi http://www.comedi.org");
159 MODULE_DESCRIPTION("Comedi low-level driver");
160 MODULE_LICENSE("GPL");