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 <linux/comedidev.h>
42 #include <linux/ioport.h>
44 static int poc_attach(comedi_device *dev,comedi_devconfig *it);
45 static int poc_detach(comedi_device *dev);
46 static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
48 static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
49 static int pcl733_insn_bits(comedi_device *dev,comedi_subdevice *s,
50 comedi_insn *insn,lsampl_t *data);
51 static int pcl734_insn_bits(comedi_device *dev,comedi_subdevice *s,
52 comedi_insn *insn,lsampl_t *data);
54 struct boarddef_struct{
57 int (*setup)(comedi_device *);
61 int (*winsn)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
62 int (*rinsn)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
63 int (*insnbits)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
66 static struct boarddef_struct boards[]={
74 winsn: dac02_ao_winsn,
76 range: &range_unknown,
84 insnbits: pcl733_insn_bits,
85 range: &range_digital,
93 insnbits: pcl734_insn_bits,
94 range: &range_digital,
97 #define n_boards (sizeof(boards)/sizeof(boards[0]))
98 #define this_board ((struct boarddef_struct *)dev->board_ptr)
100 static comedi_driver driver_poc=
108 offset: sizeof(boards[0]),
111 static int poc_attach(comedi_device *dev, comedi_devconfig *it)
116 iobase = it->options[0];
117 printk("comedi%d: poc: using %s iobase 0x%x\n", dev->minor,
118 this_board->name, iobase);
120 dev->board_name = this_board->name;
124 printk("io base address required\n");
128 iosize = this_board->iosize;
129 /* check if io addresses are available */
130 if(!request_region(iobase, iosize, "dac02"))
132 printk("I/O port conflict: failed to allocate ports 0x%x to 0x%x\n",
133 iobase, iobase + iosize - 1);
136 dev->iobase = iobase;
138 if(alloc_subdevices(dev, 1) < 0)
140 if(alloc_private(dev,sizeof(lsampl_t)*this_board->n_chan) < 0)
143 /* analog output subdevice */
144 s=dev->subdevices + 0;
145 s->type = this_board->type;
146 s->n_chan = this_board->n_chan;
147 s->maxdata = (1<<this_board->n_bits)-1;
148 s->range_table = this_board->range;
149 s->insn_write = this_board->winsn;
150 s->insn_read = this_board->rinsn;
151 s->insn_bits = this_board->insnbits;
152 if(s->type==COMEDI_SUBD_AO || s->type==COMEDI_SUBD_DO){
153 s->subdev_flags = SDF_WRITABLE;
159 static int poc_detach(comedi_device *dev)
161 /* only free stuff if it has been allocated by _attach */
163 release_region(dev->iobase, this_board->iosize);
165 printk("comedi%d: dac02: remove\n", dev->minor);
170 static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
174 chan = CR_CHAN(insn->chanspec);
175 data[0]=((lsampl_t *)dev->private)[chan];
180 /* DAC-02 registers */
181 #define DAC02_LSB(a) (2 * a)
182 #define DAC02_MSB(a) (2 * a + 1)
184 static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
190 chan = CR_CHAN(insn->chanspec);
191 ((lsampl_t *)dev->private)[chan] = data[0];
194 // convert to complementary binary if range is bipolar
195 if((CR_RANGE(insn->chanspec) & 0x2) == 0)
198 temp = (output << 4) & 0xf0;
199 outb(temp, dev->iobase + DAC02_LSB(chan));
200 temp = (output >> 4) & 0xff;
201 outb(temp, dev->iobase + DAC02_MSB(chan));
206 static int pcl733_insn_bits(comedi_device *dev,comedi_subdevice *s,
207 comedi_insn *insn,lsampl_t *data)
209 if(insn->n!=2)return -EINVAL;
211 data[1] = inb(dev->iobase + 0);
212 data[1] |= (inb(dev->iobase + 1) << 8);
213 data[1] |= (inb(dev->iobase + 2) << 16);
214 data[1] |= (inb(dev->iobase + 3) << 24);
219 static int pcl734_insn_bits(comedi_device *dev,comedi_subdevice *s,
220 comedi_insn *insn,lsampl_t *data)
222 if(insn->n!=2)return -EINVAL;
224 s->state &= ~data[0];
225 s->state |= (data[0]&data[1]);
226 if((data[0]>>0)&0xff)
227 outb((s->state>>0)&0xff, dev->iobase + 0);
228 if((data[0]>>8)&0xff)
229 outb((s->state>>8)&0xff, dev->iobase + 1);
230 if((data[0]>>16)&0xff)
231 outb((s->state>>16)&0xff, dev->iobase + 2);
232 if((data[0]>>24)&0xff)
233 outb((s->state>>24)&0xff, dev->iobase + 3);
240 COMEDI_INITCLEANUP(driver_poc);