3 comedi/drivers/aio_iiro_16.c
5 Driver for Access 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: Access I/O Products PC-104 IIRO16 Relay And Isolated Input Board
27 Author: Zachary Ware <zach.ware@cctechnol.com>
29 [Access 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 struct aio_iiro_16_board
{
53 static const struct aio_iiro_16_board aio_iiro_16_boards
[] = {
55 .name
= "aio_iiro_16",
60 struct aio_iiro_16_private
{
62 struct pci_dev
*pci_dev
;
63 unsigned int ao_readback
[2];
66 #define devpriv ((struct aio_iiro_16_private *) dev->private)
68 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device
*dev
,
69 struct comedi_subdevice
*s
,
70 struct comedi_insn
*insn
,
78 s
->state
|= data
[0] & data
[1];
79 outb(s
->state
& 0xff, dev
->iobase
+ AIO_IIRO_16_RELAY_0_7
);
80 outb((s
->state
>> 8) & 0xff,
81 dev
->iobase
+ AIO_IIRO_16_RELAY_8_15
);
89 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device
*dev
,
90 struct comedi_subdevice
*s
,
91 struct comedi_insn
*insn
,
98 data
[1] |= inb(dev
->iobase
+ AIO_IIRO_16_INPUT_0_7
);
99 data
[1] |= inb(dev
->iobase
+ AIO_IIRO_16_INPUT_8_15
) << 8;
104 static int aio_iiro_16_attach(struct comedi_device
*dev
,
105 struct comedi_devconfig
*it
)
107 const struct aio_iiro_16_board
*board
= comedi_board(dev
);
109 struct comedi_subdevice
*s
;
112 printk(KERN_INFO
"comedi%d: aio_iiro_16: ", dev
->minor
);
114 dev
->board_name
= board
->name
;
116 iobase
= it
->options
[0];
118 if (!request_region(iobase
, AIO_IIRO_16_SIZE
, dev
->board_name
)) {
119 printk("I/O port conflict");
123 dev
->iobase
= iobase
;
125 if (alloc_private(dev
, sizeof(struct aio_iiro_16_private
)) < 0)
128 ret
= comedi_alloc_subdevices(dev
, 2);
132 s
= dev
->subdevices
+ 0;
133 s
->type
= COMEDI_SUBD_DIO
;
134 s
->subdev_flags
= SDF_WRITABLE
;
137 s
->range_table
= &range_digital
;
138 s
->insn_bits
= aio_iiro_16_dio_insn_bits_write
;
140 s
= dev
->subdevices
+ 1;
141 s
->type
= COMEDI_SUBD_DIO
;
142 s
->subdev_flags
= SDF_READABLE
;
145 s
->range_table
= &range_digital
;
146 s
->insn_bits
= aio_iiro_16_dio_insn_bits_read
;
148 printk("attached\n");
153 static void aio_iiro_16_detach(struct comedi_device
*dev
)
156 release_region(dev
->iobase
, AIO_IIRO_16_SIZE
);
159 static struct comedi_driver aio_iiro_16_driver
= {
160 .driver_name
= "aio_iiro_16",
161 .module
= THIS_MODULE
,
162 .attach
= aio_iiro_16_attach
,
163 .detach
= aio_iiro_16_detach
,
164 .board_name
= &aio_iiro_16_boards
[0].name
,
165 .offset
= sizeof(struct aio_iiro_16_board
),
166 .num_names
= ARRAY_SIZE(aio_iiro_16_boards
),
168 module_comedi_driver(aio_iiro_16_driver
);
170 MODULE_AUTHOR("Comedi http://www.comedi.org");
171 MODULE_DESCRIPTION("Comedi low-level driver");
172 MODULE_LICENSE("GPL");