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 *);
64 const comedi_lrange *range;
66 static const 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 ((const struct boarddef_struct *)dev->board_ptr)
100 static comedi_driver driver_poc=
106 board_name: &boards[0].name,
108 offset: sizeof(boards[0]),
111 static int poc_attach(comedi_device *dev, comedi_devconfig *it)
114 unsigned long iobase;
117 iobase = it->options[0];
118 printk("comedi%d: poc: using %s iobase 0x%lx\n", dev->minor,
119 this_board->name, iobase);
121 dev->board_name = this_board->name;
125 printk("io base address required\n");
129 iosize = this_board->iosize;
130 /* check if io addresses are available */
131 if(!request_region(iobase, iosize, "dac02"))
133 printk("I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
134 iobase, iobase + iosize - 1);
137 dev->iobase = iobase;
139 if(alloc_subdevices(dev, 1) < 0)
141 if(alloc_private(dev,sizeof(lsampl_t)*this_board->n_chan) < 0)
144 /* analog output subdevice */
145 s=dev->subdevices + 0;
146 s->type = this_board->type;
147 s->n_chan = this_board->n_chan;
148 s->maxdata = (1<<this_board->n_bits)-1;
149 s->range_table = this_board->range;
150 s->insn_write = this_board->winsn;
151 s->insn_read = this_board->rinsn;
152 s->insn_bits = this_board->insnbits;
153 if(s->type==COMEDI_SUBD_AO || s->type==COMEDI_SUBD_DO){
154 s->subdev_flags = SDF_WRITABLE;
160 static int poc_detach(comedi_device *dev)
162 /* only free stuff if it has been allocated by _attach */
164 release_region(dev->iobase, this_board->iosize);
166 printk("comedi%d: dac02: remove\n", dev->minor);
171 static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
175 chan = CR_CHAN(insn->chanspec);
176 data[0]=((lsampl_t *)dev->private)[chan];
181 /* DAC-02 registers */
182 #define DAC02_LSB(a) (2 * a)
183 #define DAC02_MSB(a) (2 * a + 1)
185 static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
191 chan = CR_CHAN(insn->chanspec);
192 ((lsampl_t *)dev->private)[chan] = data[0];
195 // convert to complementary binary if range is bipolar
196 if((CR_RANGE(insn->chanspec) & 0x2) == 0)
199 temp = (output << 4) & 0xf0;
200 outb(temp, dev->iobase + DAC02_LSB(chan));
201 temp = (output >> 4) & 0xff;
202 outb(temp, dev->iobase + DAC02_MSB(chan));
207 static int pcl733_insn_bits(comedi_device *dev,comedi_subdevice *s,
208 comedi_insn *insn,lsampl_t *data)
210 if(insn->n!=2)return -EINVAL;
212 data[1] = inb(dev->iobase + 0);
213 data[1] |= (inb(dev->iobase + 1) << 8);
214 data[1] |= (inb(dev->iobase + 2) << 16);
215 data[1] |= (inb(dev->iobase + 3) << 24);
220 static int pcl734_insn_bits(comedi_device *dev,comedi_subdevice *s,
221 comedi_insn *insn,lsampl_t *data)
223 if(insn->n!=2)return -EINVAL;
225 s->state &= ~data[0];
226 s->state |= (data[0]&data[1]);
227 if((data[0]>>0)&0xff)
228 outb((s->state>>0)&0xff, dev->iobase + 0);
229 if((data[0]>>8)&0xff)
230 outb((s->state>>8)&0xff, dev->iobase + 1);
231 if((data[0]>>16)&0xff)
232 outb((s->state>>16)&0xff, dev->iobase + 2);
233 if((data[0]>>24)&0xff)
234 outb((s->state>>24)&0xff, dev->iobase + 3);
241 COMEDI_INITCLEANUP(driver_poc);