This source file includes following definitions.
- aio_iiro_16_read_inputs
- aio_iiro_16_cos
- aio_iiro_enable_irq
- aio_iiro_16_cos_cancel
- aio_iiro_16_cos_cmd
- aio_iiro_16_cos_cmdtest
- aio_iiro_16_do_insn_bits
- aio_iiro_16_di_insn_bits
- aio_iiro_16_attach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <linux/module.h>
32 #include <linux/interrupt.h>
33
34 #include "../comedidev.h"
35
36 #define AIO_IIRO_16_RELAY_0_7 0x00
37 #define AIO_IIRO_16_INPUT_0_7 0x01
38 #define AIO_IIRO_16_IRQ 0x02
39 #define AIO_IIRO_16_RELAY_8_15 0x04
40 #define AIO_IIRO_16_INPUT_8_15 0x05
41 #define AIO_IIRO_16_STATUS 0x07
42 #define AIO_IIRO_16_STATUS_IRQE BIT(7)
43 #define AIO_IIRO_16_STATUS_INPUT_8_15 BIT(1)
44 #define AIO_IIRO_16_STATUS_INPUT_0_7 BIT(0)
45
46 static unsigned int aio_iiro_16_read_inputs(struct comedi_device *dev)
47 {
48 unsigned int val;
49
50 val = inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
51 val |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
52
53 return val;
54 }
55
56 static irqreturn_t aio_iiro_16_cos(int irq, void *d)
57 {
58 struct comedi_device *dev = d;
59 struct comedi_subdevice *s = dev->read_subdev;
60 unsigned int status;
61 unsigned int val;
62
63 status = inb(dev->iobase + AIO_IIRO_16_STATUS);
64 if (!(status & AIO_IIRO_16_STATUS_IRQE))
65 return IRQ_NONE;
66
67 val = aio_iiro_16_read_inputs(dev);
68 val |= (status << 16);
69
70 comedi_buf_write_samples(s, &val, 1);
71 comedi_handle_events(dev, s);
72
73 return IRQ_HANDLED;
74 }
75
76 static void aio_iiro_enable_irq(struct comedi_device *dev, bool enable)
77 {
78 if (enable)
79 inb(dev->iobase + AIO_IIRO_16_IRQ);
80 else
81 outb(0, dev->iobase + AIO_IIRO_16_IRQ);
82 }
83
84 static int aio_iiro_16_cos_cancel(struct comedi_device *dev,
85 struct comedi_subdevice *s)
86 {
87 aio_iiro_enable_irq(dev, false);
88
89 return 0;
90 }
91
92 static int aio_iiro_16_cos_cmd(struct comedi_device *dev,
93 struct comedi_subdevice *s)
94 {
95 aio_iiro_enable_irq(dev, true);
96
97 return 0;
98 }
99
100 static int aio_iiro_16_cos_cmdtest(struct comedi_device *dev,
101 struct comedi_subdevice *s,
102 struct comedi_cmd *cmd)
103 {
104 int err = 0;
105
106
107
108 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW);
109 err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
110 err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
111 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
112 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_NONE);
113
114 if (err)
115 return 1;
116
117
118
119
120
121
122 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
123 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
124 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
125 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
126 cmd->chanlist_len);
127 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
128
129 if (err)
130 return 3;
131
132
133
134
135
136 return 0;
137 }
138
139 static int aio_iiro_16_do_insn_bits(struct comedi_device *dev,
140 struct comedi_subdevice *s,
141 struct comedi_insn *insn,
142 unsigned int *data)
143 {
144 if (comedi_dio_update_state(s, data)) {
145 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
146 outb((s->state >> 8) & 0xff,
147 dev->iobase + AIO_IIRO_16_RELAY_8_15);
148 }
149
150 data[1] = s->state;
151
152 return insn->n;
153 }
154
155 static int aio_iiro_16_di_insn_bits(struct comedi_device *dev,
156 struct comedi_subdevice *s,
157 struct comedi_insn *insn,
158 unsigned int *data)
159 {
160 data[1] = aio_iiro_16_read_inputs(dev);
161
162 return insn->n;
163 }
164
165 static int aio_iiro_16_attach(struct comedi_device *dev,
166 struct comedi_devconfig *it)
167 {
168 struct comedi_subdevice *s;
169 int ret;
170
171 ret = comedi_request_region(dev, it->options[0], 0x8);
172 if (ret)
173 return ret;
174
175 aio_iiro_enable_irq(dev, false);
176
177
178
179
180
181 if ((1 << it->options[1]) & 0xdcfc) {
182 ret = request_irq(it->options[1], aio_iiro_16_cos, 0,
183 dev->board_name, dev);
184 if (ret == 0)
185 dev->irq = it->options[1];
186 }
187
188 ret = comedi_alloc_subdevices(dev, 2);
189 if (ret)
190 return ret;
191
192
193 s = &dev->subdevices[0];
194 s->type = COMEDI_SUBD_DO;
195 s->subdev_flags = SDF_WRITABLE;
196 s->n_chan = 16;
197 s->maxdata = 1;
198 s->range_table = &range_digital;
199 s->insn_bits = aio_iiro_16_do_insn_bits;
200
201
202 s->state = inb(dev->iobase + AIO_IIRO_16_RELAY_0_7) |
203 (inb(dev->iobase + AIO_IIRO_16_RELAY_8_15) << 8);
204
205
206 s = &dev->subdevices[1];
207 s->type = COMEDI_SUBD_DI;
208 s->subdev_flags = SDF_READABLE;
209 s->n_chan = 16;
210 s->maxdata = 1;
211 s->range_table = &range_digital;
212 s->insn_bits = aio_iiro_16_di_insn_bits;
213 if (dev->irq) {
214 dev->read_subdev = s;
215 s->subdev_flags |= SDF_CMD_READ | SDF_LSAMPL;
216 s->len_chanlist = 1;
217 s->do_cmdtest = aio_iiro_16_cos_cmdtest;
218 s->do_cmd = aio_iiro_16_cos_cmd;
219 s->cancel = aio_iiro_16_cos_cancel;
220 }
221
222 return 0;
223 }
224
225 static struct comedi_driver aio_iiro_16_driver = {
226 .driver_name = "aio_iiro_16",
227 .module = THIS_MODULE,
228 .attach = aio_iiro_16_attach,
229 .detach = comedi_legacy_detach,
230 };
231 module_comedi_driver(aio_iiro_16_driver);
232
233 MODULE_AUTHOR("Comedi http://www.comedi.org");
234 MODULE_DESCRIPTION("Comedi driver for Access I/O Products 104-IIRO-16 board");
235 MODULE_LICENSE("GPL");