2 comedi/drivers/dt2817.c
3 Hardware driver for Data Translation DT2817
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998 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 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 Description: Data Translation DT2817
28 Devices: [Data Translation] DT2817 (dt2817)
30 A very simple digital I/O card. Four banks of 8 lines, each bank
31 is configurable for input or output. One wonders why it takes a
32 50 page manual to describe this thing.
34 The driver (which, btw, is much less than 50 pages) has 1 subdevice
35 with 32 channels, configurable in groups of 8.
37 Configuration options:
38 [0] - I/O port base base address
41 #include "../comedidev.h"
43 #include <linux/ioport.h>
50 static int dt2817_attach(struct comedi_device *dev,
51 struct comedi_devconfig *it);
52 static int dt2817_detach(struct comedi_device *dev);
53 static struct comedi_driver driver_dt2817 = {
54 .driver_name = "dt2817",
55 .module = THIS_MODULE,
56 .attach = dt2817_attach,
57 .detach = dt2817_detach,
60 COMEDI_INITCLEANUP(driver_dt2817);
62 static int dt2817_dio_insn_config(struct comedi_device *dev,
63 struct comedi_subdevice *s,
64 struct comedi_insn *insn, unsigned int *data)
73 chan = CR_CHAN(insn->chanspec);
76 } else if (chan < 16) {
78 } else if (chan < 24) {
87 if (s->io_bits & 0x000000ff)
89 if (s->io_bits & 0x0000ff00)
91 if (s->io_bits & 0x00ff0000)
93 if (s->io_bits & 0xff000000)
96 outb(oe, dev->iobase + DT2817_CR);
101 static int dt2817_dio_insn_bits(struct comedi_device *dev,
102 struct comedi_subdevice *s,
103 struct comedi_insn *insn, unsigned int *data)
105 unsigned int changed;
107 /* It's questionable whether it is more important in
108 * a driver like this to be deterministic or fast.
113 s->state &= ~data[0];
114 s->state |= (data[0] & data[1]);
116 changed &= s->io_bits;
117 if (changed & 0x000000ff)
118 outb(s->state & 0xff, dev->iobase + DT2817_DATA + 0);
119 if (changed & 0x0000ff00)
120 outb((s->state >> 8) & 0xff,
121 dev->iobase + DT2817_DATA + 1);
122 if (changed & 0x00ff0000)
123 outb((s->state >> 16) & 0xff,
124 dev->iobase + DT2817_DATA + 2);
125 if (changed & 0xff000000)
126 outb((s->state >> 24) & 0xff,
127 dev->iobase + DT2817_DATA + 3);
129 data[1] = inb(dev->iobase + DT2817_DATA + 0);
130 data[1] |= (inb(dev->iobase + DT2817_DATA + 1) << 8);
131 data[1] |= (inb(dev->iobase + DT2817_DATA + 2) << 16);
132 data[1] |= (inb(dev->iobase + DT2817_DATA + 3) << 24);
137 static int dt2817_attach(struct comedi_device *dev, struct comedi_devconfig *it)
140 struct comedi_subdevice *s;
141 unsigned long iobase;
143 iobase = it->options[0];
144 printk("comedi%d: dt2817: 0x%04lx ", dev->minor, iobase);
145 if (!request_region(iobase, DT2817_SIZE, "dt2817")) {
146 printk("I/O port conflict\n");
149 dev->iobase = iobase;
150 dev->board_name = "dt2817";
152 ret = alloc_subdevices(dev, 1);
156 s = dev->subdevices + 0;
159 s->type = COMEDI_SUBD_DIO;
160 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
161 s->range_table = &range_digital;
163 s->insn_bits = dt2817_dio_insn_bits;
164 s->insn_config = dt2817_dio_insn_config;
167 outb(0, dev->iobase + DT2817_CR);
174 static int dt2817_detach(struct comedi_device *dev)
176 printk("comedi%d: dt2817: remove\n", dev->minor);
179 release_region(dev->iobase, DT2817_SIZE);