3 Mini-drivers for POC (Piece of Crap) boards
4 Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net>
5 Copyright (C) 2001 David A. Schleef <ds@schleef.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 Description: Generic driver for very simple devices
25 Devices: [Keithley Metrabyte] DAC-02 (dac02), [Advantech] PCL-733 (pcl733),
27 Updated: Sat, 16 Mar 2002 17:34:48 -0800
30 This driver is indended to support very simple ISA-based devices,
32 dac02 - Keithley DAC-02 analog output board
33 pcl733 - Advantech PCL-733
34 pcl734 - Advantech PCL-734
36 Configuration options:
40 #include "../comedidev.h"
42 #include <linux/ioport.h>
44 struct boarddef_struct {
47 int (*setup) (struct comedi_device *);
51 int (*winsn) (struct comedi_device *, struct comedi_subdevice *,
52 struct comedi_insn *, unsigned int *);
53 int (*rinsn) (struct comedi_device *, struct comedi_subdevice *,
54 struct comedi_insn *, unsigned int *);
55 int (*insnbits) (struct comedi_device *, struct comedi_subdevice *,
56 struct comedi_insn *, unsigned int *);
57 const struct comedi_lrange *range;
61 unsigned int ao_readback[32];
64 static int readback_insn(struct comedi_device *dev, struct comedi_subdevice *s,
65 struct comedi_insn *insn, unsigned int *data)
67 struct poc_private *devpriv = dev->private;
70 chan = CR_CHAN(insn->chanspec);
71 data[0] = devpriv->ao_readback[chan];
76 /* DAC-02 registers */
77 #define DAC02_LSB(a) (2 * a)
78 #define DAC02_MSB(a) (2 * a + 1)
80 static int dac02_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
81 struct comedi_insn *insn, unsigned int *data)
83 struct poc_private *devpriv = dev->private;
88 chan = CR_CHAN(insn->chanspec);
89 devpriv->ao_readback[chan] = data[0];
92 /* convert to complementary binary if range is bipolar */
93 if ((CR_RANGE(insn->chanspec) & 0x2) == 0)
96 temp = (output << 4) & 0xf0;
97 outb(temp, dev->iobase + DAC02_LSB(chan));
98 temp = (output >> 4) & 0xff;
99 outb(temp, dev->iobase + DAC02_MSB(chan));
104 static int pcl733_insn_bits(struct comedi_device *dev,
105 struct comedi_subdevice *s,
106 struct comedi_insn *insn, unsigned int *data)
108 data[1] = inb(dev->iobase + 0);
109 data[1] |= (inb(dev->iobase + 1) << 8);
110 data[1] |= (inb(dev->iobase + 2) << 16);
111 data[1] |= (inb(dev->iobase + 3) << 24);
116 static int pcl734_insn_bits(struct comedi_device *dev,
117 struct comedi_subdevice *s,
118 struct comedi_insn *insn, unsigned int *data)
121 s->state &= ~data[0];
122 s->state |= (data[0] & data[1]);
123 if ((data[0] >> 0) & 0xff)
124 outb((s->state >> 0) & 0xff, dev->iobase + 0);
125 if ((data[0] >> 8) & 0xff)
126 outb((s->state >> 8) & 0xff, dev->iobase + 1);
127 if ((data[0] >> 16) & 0xff)
128 outb((s->state >> 16) & 0xff, dev->iobase + 2);
129 if ((data[0] >> 24) & 0xff)
130 outb((s->state >> 24) & 0xff, dev->iobase + 3);
137 static int poc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
139 const struct boarddef_struct *board = comedi_board(dev);
140 struct poc_private *devpriv;
141 struct comedi_subdevice *s;
144 ret = comedi_request_region(dev, it->options[0], board->iosize);
148 ret = comedi_alloc_subdevices(dev, 1);
152 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
155 dev->private = devpriv;
157 /* analog output subdevice */
158 s = &dev->subdevices[0];
159 s->type = board->type;
160 s->n_chan = board->n_chan;
161 s->maxdata = (1 << board->n_bits) - 1;
162 s->range_table = board->range;
163 s->insn_write = board->winsn;
164 s->insn_read = board->rinsn;
165 s->insn_bits = board->insnbits;
166 if (s->type == COMEDI_SUBD_AO || s->type == COMEDI_SUBD_DO)
167 s->subdev_flags = SDF_WRITABLE;
172 static const struct boarddef_struct boards[] = {
176 /* .setup = dac02_setup, */
177 .type = COMEDI_SUBD_AO,
180 .winsn = dac02_ao_winsn,
181 .rinsn = readback_insn,
182 .range = &range_unknown,
186 .type = COMEDI_SUBD_DI,
189 .insnbits = pcl733_insn_bits,
190 .range = &range_digital,
194 .type = COMEDI_SUBD_DO,
197 .insnbits = pcl734_insn_bits,
198 .range = &range_digital,
202 static struct comedi_driver poc_driver = {
203 .driver_name = "poc",
204 .module = THIS_MODULE,
205 .attach = poc_attach,
206 .detach = comedi_legacy_detach,
207 .board_name = &boards[0].name,
208 .num_names = ARRAY_SIZE(boards),
209 .offset = sizeof(boards[0]),
211 module_comedi_driver(poc_driver);
213 MODULE_AUTHOR("Comedi http://www.comedi.org");
214 MODULE_DESCRIPTION("Comedi low-level driver");
215 MODULE_LICENSE("GPL");