This source file includes following definitions.
- dac02_ao_insn_write
- dac02_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 #include <linux/module.h>
28
29 #include "../comedidev.h"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 static const struct comedi_lrange das02_ao_ranges = {
52 6, {
53 UNI_RANGE(5),
54 UNI_RANGE(10),
55 BIP_RANGE(5),
56 BIP_RANGE(10),
57 RANGE_mA(4, 20),
58 RANGE_ext(0, 1)
59 }
60 };
61
62
63
64
65 #define DAC02_AO_LSB(x) (0x00 + ((x) * 2))
66 #define DAC02_AO_MSB(x) (0x01 + ((x) * 2))
67
68 static int dac02_ao_insn_write(struct comedi_device *dev,
69 struct comedi_subdevice *s,
70 struct comedi_insn *insn,
71 unsigned int *data)
72 {
73 unsigned int chan = CR_CHAN(insn->chanspec);
74 unsigned int range = CR_RANGE(insn->chanspec);
75 unsigned int val;
76 int i;
77
78 for (i = 0; i < insn->n; i++) {
79 val = data[i];
80
81 s->readback[chan] = val;
82
83
84
85
86
87
88 if (comedi_range_is_bipolar(s, range))
89 val = s->maxdata - val;
90
91
92
93
94
95 outb((val << 4) & 0xf0, dev->iobase + DAC02_AO_LSB(chan));
96 outb((val >> 4) & 0xff, dev->iobase + DAC02_AO_MSB(chan));
97 }
98
99 return insn->n;
100 }
101
102 static int dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
103 {
104 struct comedi_subdevice *s;
105 int ret;
106
107 ret = comedi_request_region(dev, it->options[0], 0x08);
108 if (ret)
109 return ret;
110
111 ret = comedi_alloc_subdevices(dev, 1);
112 if (ret)
113 return ret;
114
115
116 s = &dev->subdevices[0];
117 s->type = COMEDI_SUBD_AO;
118 s->subdev_flags = SDF_WRITABLE;
119 s->n_chan = 2;
120 s->maxdata = 0x0fff;
121 s->range_table = &das02_ao_ranges;
122 s->insn_write = dac02_ao_insn_write;
123
124 return comedi_alloc_subdev_readback(s);
125 }
126
127 static struct comedi_driver dac02_driver = {
128 .driver_name = "dac02",
129 .module = THIS_MODULE,
130 .attach = dac02_attach,
131 .detach = comedi_legacy_detach,
132 };
133 module_comedi_driver(dac02_driver);
134
135 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
136 MODULE_DESCRIPTION("Comedi driver for DAC02 compatible boards");
137 MODULE_LICENSE("GPL");