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#include <linux/module.h>
28#include "../comedidev.h"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102struct pcl730_board {
103 const char *name;
104 unsigned int io_range;
105 unsigned is_pcl725:1;
106 unsigned is_acl7225b:1;
107 unsigned is_ir104:1;
108 unsigned has_readback:1;
109 unsigned has_ttl_io:1;
110 int n_subdevs;
111 int n_iso_out_chan;
112 int n_iso_in_chan;
113 int n_ttl_chan;
114};
115
116static const struct pcl730_board pcl730_boards[] = {
117 {
118 .name = "pcl730",
119 .io_range = 0x04,
120 .has_ttl_io = 1,
121 .n_subdevs = 4,
122 .n_iso_out_chan = 16,
123 .n_iso_in_chan = 16,
124 .n_ttl_chan = 16,
125 }, {
126 .name = "iso730",
127 .io_range = 0x04,
128 .n_subdevs = 4,
129 .n_iso_out_chan = 16,
130 .n_iso_in_chan = 16,
131 .n_ttl_chan = 16,
132 }, {
133 .name = "acl7130",
134 .io_range = 0x08,
135 .has_ttl_io = 1,
136 .n_subdevs = 4,
137 .n_iso_out_chan = 16,
138 .n_iso_in_chan = 16,
139 .n_ttl_chan = 16,
140 }, {
141 .name = "pcm3730",
142 .io_range = 0x04,
143 .has_ttl_io = 1,
144 .n_subdevs = 4,
145 .n_iso_out_chan = 8,
146 .n_iso_in_chan = 8,
147 .n_ttl_chan = 16,
148 }, {
149 .name = "pcl725",
150 .io_range = 0x02,
151 .is_pcl725 = 1,
152 .n_subdevs = 2,
153 .n_iso_out_chan = 8,
154 .n_iso_in_chan = 8,
155 }, {
156 .name = "p8r8dio",
157 .io_range = 0x02,
158 .is_pcl725 = 1,
159 .has_readback = 1,
160 .n_subdevs = 2,
161 .n_iso_out_chan = 8,
162 .n_iso_in_chan = 8,
163 }, {
164 .name = "acl7225b",
165 .io_range = 0x08,
166 .is_acl7225b = 1,
167 .has_readback = 1,
168 .n_subdevs = 2,
169 .n_iso_out_chan = 16,
170 .n_iso_in_chan = 16,
171 }, {
172 .name = "p16r16dio",
173 .io_range = 0x04,
174 .is_acl7225b = 1,
175 .has_readback = 1,
176 .n_subdevs = 2,
177 .n_iso_out_chan = 16,
178 .n_iso_in_chan = 16,
179 }, {
180 .name = "pcl733",
181 .io_range = 0x04,
182 .n_subdevs = 1,
183 .n_iso_in_chan = 32,
184 }, {
185 .name = "pcl734",
186 .io_range = 0x04,
187 .n_subdevs = 1,
188 .n_iso_out_chan = 32,
189 }, {
190 .name = "opmm-1616-xt",
191 .io_range = 0x10,
192 .is_acl7225b = 1,
193 .has_readback = 1,
194 .n_subdevs = 2,
195 .n_iso_out_chan = 16,
196 .n_iso_in_chan = 16,
197 }, {
198 .name = "pearl-mm-p",
199 .io_range = 0x02,
200 .n_subdevs = 1,
201 .n_iso_out_chan = 16,
202 }, {
203 .name = "ir104-pbf",
204 .io_range = 0x08,
205 .is_ir104 = 1,
206 .has_readback = 1,
207 .n_iso_out_chan = 20,
208 .n_iso_in_chan = 20,
209 },
210};
211
212static int pcl730_do_insn_bits(struct comedi_device *dev,
213 struct comedi_subdevice *s,
214 struct comedi_insn *insn,
215 unsigned int *data)
216{
217 unsigned long reg = (unsigned long)s->private;
218 unsigned int mask;
219
220 mask = comedi_dio_update_state(s, data);
221 if (mask) {
222 if (mask & 0x00ff)
223 outb(s->state & 0xff, dev->iobase + reg);
224 if ((mask & 0xff00) && (s->n_chan > 8))
225 outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
226 if ((mask & 0xff0000) && (s->n_chan > 16))
227 outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
228 if ((mask & 0xff000000) && (s->n_chan > 24))
229 outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
230 }
231
232 data[1] = s->state;
233
234 return insn->n;
235}
236
237static unsigned int pcl730_get_bits(struct comedi_device *dev,
238 struct comedi_subdevice *s)
239{
240 unsigned long reg = (unsigned long)s->private;
241 unsigned int val;
242
243 val = inb(dev->iobase + reg);
244 if (s->n_chan > 8)
245 val |= (inb(dev->iobase + reg + 1) << 8);
246 if (s->n_chan > 16)
247 val |= (inb(dev->iobase + reg + 2) << 16);
248 if (s->n_chan > 24)
249 val |= (inb(dev->iobase + reg + 3) << 24);
250
251 return val;
252}
253
254static int pcl730_di_insn_bits(struct comedi_device *dev,
255 struct comedi_subdevice *s,
256 struct comedi_insn *insn,
257 unsigned int *data)
258{
259 data[1] = pcl730_get_bits(dev, s);
260
261 return insn->n;
262}
263
264static int pcl730_attach(struct comedi_device *dev,
265 struct comedi_devconfig *it)
266{
267 const struct pcl730_board *board = dev->board_ptr;
268 struct comedi_subdevice *s;
269 int subdev;
270 int ret;
271
272 ret = comedi_request_region(dev, it->options[0], board->io_range);
273 if (ret)
274 return ret;
275
276 ret = comedi_alloc_subdevices(dev, board->n_subdevs);
277 if (ret)
278 return ret;
279
280 subdev = 0;
281
282 if (board->n_iso_out_chan) {
283
284 s = &dev->subdevices[subdev++];
285 s->type = COMEDI_SUBD_DO;
286 s->subdev_flags = SDF_WRITABLE;
287 s->n_chan = board->n_iso_out_chan;
288 s->maxdata = 1;
289 s->range_table = &range_digital;
290 s->insn_bits = pcl730_do_insn_bits;
291 s->private = (void *)0;
292
293
294 if (board->has_readback)
295 s->state = pcl730_get_bits(dev, s);
296 }
297
298 if (board->n_iso_in_chan) {
299
300 s = &dev->subdevices[subdev++];
301 s->type = COMEDI_SUBD_DI;
302 s->subdev_flags = SDF_READABLE;
303 s->n_chan = board->n_iso_in_chan;
304 s->maxdata = 1;
305 s->range_table = &range_digital;
306 s->insn_bits = pcl730_di_insn_bits;
307 s->private = board->is_ir104 ? (void *)4 :
308 board->is_acl7225b ? (void *)2 :
309 board->is_pcl725 ? (void *)1 : (void *)0;
310 }
311
312 if (board->has_ttl_io) {
313
314 s = &dev->subdevices[subdev++];
315 s->type = COMEDI_SUBD_DO;
316 s->subdev_flags = SDF_WRITABLE;
317 s->n_chan = board->n_ttl_chan;
318 s->maxdata = 1;
319 s->range_table = &range_digital;
320 s->insn_bits = pcl730_do_insn_bits;
321 s->private = (void *)2;
322
323
324 s = &dev->subdevices[subdev++];
325 s->type = COMEDI_SUBD_DI;
326 s->subdev_flags = SDF_READABLE;
327 s->n_chan = board->n_ttl_chan;
328 s->maxdata = 1;
329 s->range_table = &range_digital;
330 s->insn_bits = pcl730_di_insn_bits;
331 s->private = (void *)2;
332 }
333
334 return 0;
335}
336
337static struct comedi_driver pcl730_driver = {
338 .driver_name = "pcl730",
339 .module = THIS_MODULE,
340 .attach = pcl730_attach,
341 .detach = comedi_legacy_detach,
342 .board_name = &pcl730_boards[0].name,
343 .num_names = ARRAY_SIZE(pcl730_boards),
344 .offset = sizeof(struct pcl730_board),
345};
346module_comedi_driver(pcl730_driver);
347
348MODULE_AUTHOR("Comedi https://www.comedi.org");
349MODULE_DESCRIPTION("Comedi low-level driver");
350MODULE_LICENSE("GPL");
351