1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/module.h>
24#include "../comedidev.h"
25
26#include <linux/delay.h>
27
28
29
30
31#define FL512_AI_LSB_REG 0x02
32#define FL512_AI_MSB_REG 0x03
33#define FL512_AI_MUX_REG 0x02
34#define FL512_AI_START_CONV_REG 0x03
35#define FL512_AO_DATA_REG(x) (0x04 + ((x) * 2))
36#define FL512_AO_TRIG_REG(x) (0x04 + ((x) * 2))
37
38static const struct comedi_lrange range_fl512 = {
39 4, {
40 BIP_RANGE(0.5),
41 BIP_RANGE(1),
42 BIP_RANGE(5),
43 BIP_RANGE(10),
44 UNI_RANGE(1),
45 UNI_RANGE(5),
46 UNI_RANGE(10)
47 }
48};
49
50static int fl512_ai_insn_read(struct comedi_device *dev,
51 struct comedi_subdevice *s,
52 struct comedi_insn *insn,
53 unsigned int *data)
54{
55 unsigned int chan = CR_CHAN(insn->chanspec);
56 unsigned int val;
57 int i;
58
59 outb(chan, dev->iobase + FL512_AI_MUX_REG);
60
61 for (i = 0; i < insn->n; i++) {
62 outb(0, dev->iobase + FL512_AI_START_CONV_REG);
63
64
65 usleep_range(30, 100);
66
67 val = inb(dev->iobase + FL512_AI_LSB_REG);
68 val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8);
69 val &= s->maxdata;
70
71 data[i] = val;
72 }
73
74 return insn->n;
75}
76
77static int fl512_ao_insn_write(struct comedi_device *dev,
78 struct comedi_subdevice *s,
79 struct comedi_insn *insn,
80 unsigned int *data)
81{
82 unsigned int chan = CR_CHAN(insn->chanspec);
83 unsigned int val = s->readback[chan];
84 int i;
85
86 for (i = 0; i < insn->n; i++) {
87 val = data[i];
88
89
90 outb(val & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan));
91 outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan));
92 inb(dev->iobase + FL512_AO_TRIG_REG(chan));
93 }
94 s->readback[chan] = val;
95
96 return insn->n;
97}
98
99static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
100{
101 struct comedi_subdevice *s;
102 int ret;
103
104 ret = comedi_request_region(dev, it->options[0], 0x10);
105 if (ret)
106 return ret;
107
108 ret = comedi_alloc_subdevices(dev, 2);
109 if (ret)
110 return ret;
111
112
113 s = &dev->subdevices[0];
114 s->type = COMEDI_SUBD_AI;
115 s->subdev_flags = SDF_READABLE | SDF_GROUND;
116 s->n_chan = 16;
117 s->maxdata = 0x0fff;
118 s->range_table = &range_fl512;
119 s->insn_read = fl512_ai_insn_read;
120
121
122 s = &dev->subdevices[1];
123 s->type = COMEDI_SUBD_AO;
124 s->subdev_flags = SDF_WRITABLE;
125 s->n_chan = 2;
126 s->maxdata = 0x0fff;
127 s->range_table = &range_fl512;
128 s->insn_write = fl512_ao_insn_write;
129
130 return comedi_alloc_subdev_readback(s);
131}
132
133static struct comedi_driver fl512_driver = {
134 .driver_name = "fl512",
135 .module = THIS_MODULE,
136 .attach = fl512_attach,
137 .detach = comedi_legacy_detach,
138};
139module_comedi_driver(fl512_driver);
140
141MODULE_AUTHOR("Comedi https://www.comedi.org");
142MODULE_DESCRIPTION("Comedi low-level driver");
143MODULE_LICENSE("GPL");
144