This source file includes following definitions.
- pcmda12_ao_insn_write
- pcmda12_ao_insn_read
- pcmda12_ao_reset
- pcmda12_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
32
33
34
35
36
37
38
39
40
41
42 #include <linux/module.h>
43 #include "../comedidev.h"
44
45
46 static const struct comedi_lrange pcmda12_ranges = {
47 3, {
48 UNI_RANGE(5),
49 UNI_RANGE(10),
50 BIP_RANGE(5)
51 }
52 };
53
54 struct pcmda12_private {
55 int simultaneous_xfer_mode;
56 };
57
58 static int pcmda12_ao_insn_write(struct comedi_device *dev,
59 struct comedi_subdevice *s,
60 struct comedi_insn *insn,
61 unsigned int *data)
62 {
63 struct pcmda12_private *devpriv = dev->private;
64 unsigned int chan = CR_CHAN(insn->chanspec);
65 unsigned int val = s->readback[chan];
66 unsigned long ioreg = dev->iobase + (chan * 2);
67 int i;
68
69 for (i = 0; i < insn->n; ++i) {
70 val = data[i];
71 outb(val & 0xff, ioreg);
72 outb((val >> 8) & 0xff, ioreg + 1);
73
74
75
76
77
78 if (!devpriv->simultaneous_xfer_mode)
79 inb(ioreg);
80 }
81 s->readback[chan] = val;
82
83 return insn->n;
84 }
85
86 static int pcmda12_ao_insn_read(struct comedi_device *dev,
87 struct comedi_subdevice *s,
88 struct comedi_insn *insn,
89 unsigned int *data)
90 {
91 struct pcmda12_private *devpriv = dev->private;
92
93
94
95
96
97 if (devpriv->simultaneous_xfer_mode)
98 inb(dev->iobase);
99
100 return comedi_readback_insn_read(dev, s, insn, data);
101 }
102
103 static void pcmda12_ao_reset(struct comedi_device *dev,
104 struct comedi_subdevice *s)
105 {
106 int i;
107
108 for (i = 0; i < s->n_chan; ++i) {
109 outb(0, dev->iobase + (i * 2));
110 outb(0, dev->iobase + (i * 2) + 1);
111 }
112
113 inb(dev->iobase);
114 }
115
116 static int pcmda12_attach(struct comedi_device *dev,
117 struct comedi_devconfig *it)
118 {
119 struct pcmda12_private *devpriv;
120 struct comedi_subdevice *s;
121 int ret;
122
123 ret = comedi_request_region(dev, it->options[0], 0x10);
124 if (ret)
125 return ret;
126
127 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
128 if (!devpriv)
129 return -ENOMEM;
130
131 devpriv->simultaneous_xfer_mode = it->options[1];
132
133 ret = comedi_alloc_subdevices(dev, 1);
134 if (ret)
135 return ret;
136
137 s = &dev->subdevices[0];
138 s->type = COMEDI_SUBD_AO;
139 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
140 s->n_chan = 8;
141 s->maxdata = 0x0fff;
142 s->range_table = &pcmda12_ranges;
143 s->insn_write = pcmda12_ao_insn_write;
144 s->insn_read = pcmda12_ao_insn_read;
145
146 ret = comedi_alloc_subdev_readback(s);
147 if (ret)
148 return ret;
149
150 pcmda12_ao_reset(dev, s);
151
152 return 0;
153 }
154
155 static struct comedi_driver pcmda12_driver = {
156 .driver_name = "pcmda12",
157 .module = THIS_MODULE,
158 .attach = pcmda12_attach,
159 .detach = comedi_legacy_detach,
160 };
161 module_comedi_driver(pcmda12_driver);
162
163 MODULE_AUTHOR("Comedi http://www.comedi.org");
164 MODULE_DESCRIPTION("Comedi low-level driver");
165 MODULE_LICENSE("GPL");