Commit | Line | Data |
---|---|---|
56af390d ZW |
1 | /* |
2 | ||
3 | comedi/drivers/aio_iiro_16.c | |
4 | ||
6cd5a9a3 | 5 | Driver for Access I/O Products PC-104 AIO-IIRO-16 Digital I/O board |
56af390d ZW |
6 | Copyright (C) 2006 C&C Technologies, Inc. |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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. | |
21 | */ | |
22 | ||
23 | /* | |
24 | ||
25 | Driver: aio_iiro_16 | |
6cd5a9a3 | 26 | Description: Access I/O Products PC-104 IIRO16 Relay And Isolated Input Board |
56af390d ZW |
27 | Author: Zachary Ware <zach.ware@cctechnol.com> |
28 | Devices: | |
6cd5a9a3 | 29 | [Access I/O] PC-104 AIO12-8 |
56af390d ZW |
30 | Status: experimental |
31 | ||
32 | Configuration Options: | |
33 | [0] - I/O port base address | |
34 | ||
35 | */ | |
36 | ||
37 | #include "../comedidev.h" | |
38 | #include <linux/ioport.h> | |
39 | ||
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 | |
46 | ||
28fa7754 | 47 | struct aio_iiro_16_board { |
56af390d ZW |
48 | const char *name; |
49 | int do_; | |
50 | int di; | |
28fa7754 | 51 | }; |
56af390d | 52 | |
28fa7754 | 53 | static const struct aio_iiro_16_board aio_iiro_16_boards[] = { |
56af390d | 54 | { |
0a85b6f0 MT |
55 | .name = "aio_iiro_16", |
56 | .di = 16, | |
57 | .do_ = 16}, | |
56af390d ZW |
58 | }; |
59 | ||
55d99639 | 60 | struct aio_iiro_16_private { |
56af390d ZW |
61 | int data; |
62 | struct pci_dev *pci_dev; | |
790c5541 | 63 | unsigned int ao_readback[2]; |
55d99639 | 64 | }; |
56af390d | 65 | |
55d99639 | 66 | #define devpriv ((struct aio_iiro_16_private *) dev->private) |
56af390d | 67 | |
6f97a28d HS |
68 | static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev, |
69 | struct comedi_subdevice *s, | |
70 | struct comedi_insn *insn, | |
71 | unsigned int *data) | |
72 | { | |
73 | if (insn->n != 2) | |
74 | return -EINVAL; | |
56af390d | 75 | |
6f97a28d HS |
76 | if (data[0]) { |
77 | s->state &= ~data[0]; | |
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); | |
82 | } | |
56af390d | 83 | |
6f97a28d HS |
84 | data[1] = s->state; |
85 | ||
86 | return 2; | |
87 | } | |
56af390d | 88 | |
da91b269 | 89 | static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev, |
0a85b6f0 MT |
90 | struct comedi_subdevice *s, |
91 | struct comedi_insn *insn, | |
6f97a28d HS |
92 | unsigned int *data) |
93 | { | |
94 | if (insn->n != 2) | |
95 | return -EINVAL; | |
56af390d | 96 | |
6f97a28d HS |
97 | data[1] = 0; |
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; | |
100 | ||
101 | return 2; | |
102 | } | |
56af390d | 103 | |
0a85b6f0 MT |
104 | static int aio_iiro_16_attach(struct comedi_device *dev, |
105 | struct comedi_devconfig *it) | |
56af390d | 106 | { |
b7405546 | 107 | const struct aio_iiro_16_board *board = comedi_board(dev); |
56af390d | 108 | int iobase; |
34c43922 | 109 | struct comedi_subdevice *s; |
8b6c5694 | 110 | int ret; |
56af390d | 111 | |
e20ad20d | 112 | printk(KERN_INFO "comedi%d: aio_iiro_16: ", dev->minor); |
56af390d | 113 | |
b7405546 | 114 | dev->board_name = board->name; |
56af390d ZW |
115 | |
116 | iobase = it->options[0]; | |
117 | ||
118 | if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) { | |
119 | printk("I/O port conflict"); | |
120 | return -EIO; | |
121 | } | |
122 | ||
123 | dev->iobase = iobase; | |
124 | ||
55d99639 | 125 | if (alloc_private(dev, sizeof(struct aio_iiro_16_private)) < 0) |
56af390d ZW |
126 | return -ENOMEM; |
127 | ||
8b6c5694 HS |
128 | ret = comedi_alloc_subdevices(dev, 2); |
129 | if (ret) | |
130 | return ret; | |
56af390d ZW |
131 | |
132 | s = dev->subdevices + 0; | |
133 | s->type = COMEDI_SUBD_DIO; | |
134 | s->subdev_flags = SDF_WRITABLE; | |
135 | s->n_chan = 16; | |
136 | s->maxdata = 1; | |
137 | s->range_table = &range_digital; | |
138 | s->insn_bits = aio_iiro_16_dio_insn_bits_write; | |
139 | ||
140 | s = dev->subdevices + 1; | |
141 | s->type = COMEDI_SUBD_DIO; | |
142 | s->subdev_flags = SDF_READABLE; | |
143 | s->n_chan = 16; | |
144 | s->maxdata = 1; | |
145 | s->range_table = &range_digital; | |
146 | s->insn_bits = aio_iiro_16_dio_insn_bits_read; | |
147 | ||
148 | printk("attached\n"); | |
149 | ||
150 | return 1; | |
151 | } | |
152 | ||
484ecc95 | 153 | static void aio_iiro_16_detach(struct comedi_device *dev) |
56af390d | 154 | { |
56af390d ZW |
155 | if (dev->iobase) |
156 | release_region(dev->iobase, AIO_IIRO_16_SIZE); | |
56af390d ZW |
157 | } |
158 | ||
294f930d | 159 | static struct comedi_driver aio_iiro_16_driver = { |
6f97a28d HS |
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), | |
167 | }; | |
294f930d | 168 | module_comedi_driver(aio_iiro_16_driver); |
90f703d3 AT |
169 | |
170 | MODULE_AUTHOR("Comedi http://www.comedi.org"); | |
171 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
172 | MODULE_LICENSE("GPL"); |