3 comedi/drivers/aio_iiro_16.c
5 Driver for Acces I/O Products PC-104 AIO-IIRO-16 Digital I/O board
6 Copyright (C) 2006 C&C Technologies, Inc.
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.
26 Description: Acces I/O Products PC-104 IIRO16 Relay And Isolated Input Board
27 Author: Zachary Ware <zach.ware@cctechnol.com>
29 [Acces I/O] PC-104 AIO12-8
32 Configuration Options:
33 [0] - I/O port base address
37 #include "../comedidev.h"
38 #include <linux/ioport.h>
40 #define AIO_IIRO_16_SIZE 0x08
41 #define AIO_IIRO_16_RELAY_0_7 0x00
42 #define AIO_IIRO_16_INPUT_0_7 0x01
43 #define AIO_IIRO_16_IRQ 0x02
44 #define AIO_IIRO_16_RELAY_8_15 0x04
45 #define AIO_IIRO_16_INPUT_8_15 0x05
47 typedef struct aio_iiro_16_board_struct {
53 static const aio_iiro_16_board aio_iiro_16_boards[] = {
60 #define thisboard ((const aio_iiro_16_board *) dev->board_ptr)
64 struct pci_dev *pci_dev;
65 unsigned int ao_readback[2];
66 } aio_iiro_16_private;
68 #define devpriv ((aio_iiro_16_private *) dev->private)
70 static int aio_iiro_16_attach(struct comedi_device * dev, comedi_devconfig * it);
72 static int aio_iiro_16_detach(struct comedi_device * dev);
74 static comedi_driver driver_aio_iiro_16 = {
75 driver_name:"aio_iiro_16",
77 attach:aio_iiro_16_attach,
78 detach:aio_iiro_16_detach,
79 board_name:&aio_iiro_16_boards[0].name,
80 offset:sizeof(aio_iiro_16_board),
81 num_names:sizeof(aio_iiro_16_boards) / sizeof(aio_iiro_16_board),
84 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device * dev,
85 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data);
87 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device * dev,
88 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data);
90 static int aio_iiro_16_attach(struct comedi_device * dev, comedi_devconfig * it)
93 struct comedi_subdevice *s;
95 printk("comedi%d: aio_iiro_16: ", dev->minor);
97 dev->board_name = thisboard->name;
99 iobase = it->options[0];
101 if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) {
102 printk("I/O port conflict");
106 dev->iobase = iobase;
108 if (alloc_private(dev, sizeof(aio_iiro_16_private)) < 0)
111 if (alloc_subdevices(dev, 2) < 0)
114 s = dev->subdevices + 0;
115 s->type = COMEDI_SUBD_DIO;
116 s->subdev_flags = SDF_WRITABLE;
119 s->range_table = &range_digital;
120 s->insn_bits = aio_iiro_16_dio_insn_bits_write;
122 s = dev->subdevices + 1;
123 s->type = COMEDI_SUBD_DIO;
124 s->subdev_flags = SDF_READABLE;
127 s->range_table = &range_digital;
128 s->insn_bits = aio_iiro_16_dio_insn_bits_read;
130 printk("attached\n");
135 static int aio_iiro_16_detach(struct comedi_device * dev)
137 printk("comedi%d: aio_iiro_16: remove\n", dev->minor);
140 release_region(dev->iobase, AIO_IIRO_16_SIZE);
145 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device * dev,
146 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data)
152 s->state &= ~data[0];
153 s->state |= data[0] & data[1];
154 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
155 outb((s->state >> 8) & 0xff,
156 dev->iobase + AIO_IIRO_16_RELAY_8_15);
164 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device * dev,
165 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data)
171 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
172 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
177 COMEDI_INITCLEANUP(driver_aio_iiro_16);