2 comedi/drivers/rti802.c
3 Hardware driver for Analog Devices RTI-802 board
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
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: Analog Devices RTI-802
26 Author: Anders Blomdell <anders.blomdell@control.lth.se>
27 Devices: [Analog Devices] RTI-802 (rti802)
30 Configuration Options:
33 [2] - dac#0 0=two's comp, 1=straight
34 [3] - dac#0 0=bipolar, 1=unipolar
40 #include "../comedidev.h"
42 #include <linux/ioport.h>
46 #define RTI802_SELECT 0
47 #define RTI802_DATALOW 1
48 #define RTI802_DATAHIGH 2
50 struct rti802_private {
52 dac_2comp, dac_straight
54 const struct comedi_lrange *range_type_list[8];
55 unsigned int ao_readback[8];
58 #define devpriv ((struct rti802_private *)dev->private)
60 static int rti802_ao_insn_read(struct comedi_device *dev,
61 struct comedi_subdevice *s,
62 struct comedi_insn *insn, unsigned int *data)
66 for (i = 0; i < insn->n; i++)
67 data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)];
72 static int rti802_ao_insn_write(struct comedi_device *dev,
73 struct comedi_subdevice *s,
74 struct comedi_insn *insn, unsigned int *data)
77 int chan = CR_CHAN(insn->chanspec);
79 for (i = 0; i < insn->n; i++) {
80 d = devpriv->ao_readback[chan] = data[i];
81 if (devpriv->dac_coding[chan] == dac_2comp)
83 outb(chan, dev->iobase + RTI802_SELECT);
84 outb(d & 0xff, dev->iobase + RTI802_DATALOW);
85 outb(d >> 8, dev->iobase + RTI802_DATAHIGH);
90 static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it)
92 struct comedi_subdevice *s;
97 iobase = it->options[0];
98 printk(KERN_INFO "comedi%d: rti802: 0x%04lx ", dev->minor, iobase);
99 if (!request_region(iobase, RTI802_SIZE, "rti802")) {
100 printk(KERN_WARNING "I/O port conflict\n");
103 dev->iobase = iobase;
105 dev->board_name = "rti802";
107 if (alloc_private(dev, sizeof(struct rti802_private)))
110 ret = comedi_alloc_subdevices(dev, 1);
114 s = &dev->subdevices[0];
116 s->type = COMEDI_SUBD_AO;
117 s->subdev_flags = SDF_WRITABLE;
120 s->insn_read = rti802_ao_insn_read;
121 s->insn_write = rti802_ao_insn_write;
122 s->range_table_list = devpriv->range_type_list;
124 for (i = 0; i < 8; i++) {
125 devpriv->dac_coding[i] = (it->options[3 + 2 * i])
128 devpriv->range_type_list[i] = (it->options[2 + 2 * i])
129 ? &range_unipolar10 : &range_bipolar10;
135 static void rti802_detach(struct comedi_device *dev)
138 release_region(dev->iobase, RTI802_SIZE);
141 static struct comedi_driver rti802_driver = {
142 .driver_name = "rti802",
143 .module = THIS_MODULE,
144 .attach = rti802_attach,
145 .detach = rti802_detach,
147 module_comedi_driver(rti802_driver);
149 MODULE_AUTHOR("Comedi http://www.comedi.org");
150 MODULE_DESCRIPTION("Comedi low-level driver");
151 MODULE_LICENSE("GPL");