Commit | Line | Data |
---|---|---|
d6a929b7 DS |
1 | /* |
2 | comedi/drivers/dt2815.c | |
3 | Hardware driver for Data Translation DT2815 | |
4 | ||
5 | COMEDI - Linux Control and Measurement Device Interface | |
6 | Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
d6a929b7 DS |
17 | */ |
18 | /* | |
19 | Driver: dt2815 | |
20 | Description: Data Translation DT2815 | |
21 | Author: ds | |
22 | Status: mostly complete, untested | |
23 | Devices: [Data Translation] DT2815 (dt2815) | |
24 | ||
25 | I'm not sure anyone has ever tested this board. If you have information | |
26 | contrary, please update. | |
27 | ||
28 | Configuration options: | |
29 | [0] - I/O port base base address | |
30 | [1] - IRQ (unused) | |
31 | [2] - Voltage unipolar/bipolar configuration | |
0acc516a BA |
32 | 0 == unipolar 5V (0V -- +5V) |
33 | 1 == bipolar 5V (-5V -- +5V) | |
d6a929b7 | 34 | [3] - Current offset configuration |
0acc516a BA |
35 | 0 == disabled (0mA -- +32mAV) |
36 | 1 == enabled (+4mA -- +20mAV) | |
d6a929b7 | 37 | [4] - Firmware program configuration |
0acc516a BA |
38 | 0 == program 1 (see manual table 5-4) |
39 | 1 == program 2 (see manual table 5-4) | |
40 | 2 == program 3 (see manual table 5-4) | |
41 | 3 == program 4 (see manual table 5-4) | |
d6a929b7 | 42 | [5] - Analog output 0 range configuration |
0acc516a BA |
43 | 0 == voltage |
44 | 1 == current | |
d6a929b7 DS |
45 | [6] - Analog output 1 range configuration (same options) |
46 | [7] - Analog output 2 range configuration (same options) | |
47 | [8] - Analog output 3 range configuration (same options) | |
48 | [9] - Analog output 4 range configuration (same options) | |
49 | [10] - Analog output 5 range configuration (same options) | |
50 | [11] - Analog output 6 range configuration (same options) | |
51 | [12] - Analog output 7 range configuration (same options) | |
52 | */ | |
53 | ||
ce157f80 | 54 | #include <linux/module.h> |
d6a929b7 DS |
55 | #include "../comedidev.h" |
56 | ||
d6a929b7 DS |
57 | #include <linux/delay.h> |
58 | ||
d6a929b7 DS |
59 | #define DT2815_DATA 0 |
60 | #define DT2815_STATUS 1 | |
61 | ||
0b011a6f | 62 | struct dt2815_private { |
9ced1de6 | 63 | const struct comedi_lrange *range_type_list[8]; |
790c5541 | 64 | unsigned int ao_readback[8]; |
0b011a6f BP |
65 | }; |
66 | ||
8a62fcbd HS |
67 | static int dt2815_ao_status(struct comedi_device *dev, |
68 | struct comedi_subdevice *s, | |
69 | struct comedi_insn *insn, | |
70 | unsigned long context) | |
d6a929b7 | 71 | { |
8a62fcbd | 72 | unsigned int status; |
d6a929b7 | 73 | |
8a62fcbd HS |
74 | status = inb(dev->iobase + DT2815_STATUS); |
75 | if (status == context) | |
76 | return 0; | |
77 | return -EBUSY; | |
d6a929b7 DS |
78 | } |
79 | ||
0a85b6f0 MT |
80 | static int dt2815_ao_insn_read(struct comedi_device *dev, |
81 | struct comedi_subdevice *s, | |
82 | struct comedi_insn *insn, unsigned int *data) | |
d6a929b7 | 83 | { |
9a1a6cf8 | 84 | struct dt2815_private *devpriv = dev->private; |
d6a929b7 DS |
85 | int i; |
86 | int chan = CR_CHAN(insn->chanspec); | |
87 | ||
0acc516a | 88 | for (i = 0; i < insn->n; i++) |
d6a929b7 | 89 | data[i] = devpriv->ao_readback[chan]; |
d6a929b7 DS |
90 | |
91 | return i; | |
92 | } | |
93 | ||
da91b269 | 94 | static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s, |
0a85b6f0 | 95 | struct comedi_insn *insn, unsigned int *data) |
d6a929b7 | 96 | { |
9a1a6cf8 | 97 | struct dt2815_private *devpriv = dev->private; |
d6a929b7 DS |
98 | int i; |
99 | int chan = CR_CHAN(insn->chanspec); | |
d6a929b7 | 100 | unsigned int lo, hi; |
8a62fcbd | 101 | int ret; |
d6a929b7 DS |
102 | |
103 | for (i = 0; i < insn->n; i++) { | |
104 | lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01; | |
105 | hi = (data[i] & 0xff0) >> 4; | |
106 | ||
8a62fcbd | 107 | ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x00); |
22ca19d9 | 108 | if (ret) |
8a62fcbd | 109 | return ret; |
d6a929b7 DS |
110 | |
111 | outb(lo, dev->iobase + DT2815_DATA); | |
112 | ||
8a62fcbd | 113 | ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x10); |
22ca19d9 | 114 | if (ret) |
8a62fcbd | 115 | return ret; |
8a62fcbd | 116 | |
d6a929b7 DS |
117 | devpriv->ao_readback[chan] = data[i]; |
118 | } | |
119 | return i; | |
120 | } | |
121 | ||
122 | /* | |
123 | options[0] Board base address | |
124 | options[1] IRQ (not applicable) | |
125 | options[2] Voltage unipolar/bipolar configuration | |
0acc516a BA |
126 | 0 == unipolar 5V (0V -- +5V) |
127 | 1 == bipolar 5V (-5V -- +5V) | |
d6a929b7 | 128 | options[3] Current offset configuration |
0acc516a BA |
129 | 0 == disabled (0mA -- +32mAV) |
130 | 1 == enabled (+4mA -- +20mAV) | |
d6a929b7 | 131 | options[4] Firmware program configuration |
0acc516a BA |
132 | 0 == program 1 (see manual table 5-4) |
133 | 1 == program 2 (see manual table 5-4) | |
134 | 2 == program 3 (see manual table 5-4) | |
135 | 3 == program 4 (see manual table 5-4) | |
d6a929b7 | 136 | options[5] Analog output 0 range configuration |
0acc516a BA |
137 | 0 == voltage |
138 | 1 == current | |
d6a929b7 DS |
139 | options[6] Analog output 1 range configuration |
140 | ... | |
141 | options[12] Analog output 7 range configuration | |
0acc516a BA |
142 | 0 == voltage |
143 | 1 == current | |
d6a929b7 DS |
144 | */ |
145 | ||
da91b269 | 146 | static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
d6a929b7 | 147 | { |
9a1a6cf8 | 148 | struct dt2815_private *devpriv; |
34c43922 | 149 | struct comedi_subdevice *s; |
d6a929b7 | 150 | int i; |
9ced1de6 | 151 | const struct comedi_lrange *current_range_type, *voltage_range_type; |
8b6c5694 | 152 | int ret; |
d6a929b7 | 153 | |
862755ec | 154 | ret = comedi_request_region(dev, it->options[0], 0x2); |
19b3da3e HS |
155 | if (ret) |
156 | return ret; | |
d6a929b7 | 157 | |
8b6c5694 HS |
158 | ret = comedi_alloc_subdevices(dev, 1); |
159 | if (ret) | |
160 | return ret; | |
161 | ||
0bdab509 | 162 | devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); |
c34fa261 HS |
163 | if (!devpriv) |
164 | return -ENOMEM; | |
d6a929b7 | 165 | |
76c40c47 | 166 | s = &dev->subdevices[0]; |
d6a929b7 DS |
167 | /* ao subdevice */ |
168 | s->type = COMEDI_SUBD_AO; | |
169 | s->subdev_flags = SDF_WRITABLE; | |
170 | s->maxdata = 0xfff; | |
171 | s->n_chan = 8; | |
172 | s->insn_write = dt2815_ao_insn; | |
173 | s->insn_read = dt2815_ao_insn_read; | |
174 | s->range_table_list = devpriv->range_type_list; | |
175 | ||
176 | current_range_type = (it->options[3]) | |
2c71c4ff | 177 | ? &range_4_20mA : &range_0_32mA; |
d6a929b7 | 178 | voltage_range_type = (it->options[2]) |
0a85b6f0 | 179 | ? &range_bipolar5 : &range_unipolar5; |
d6a929b7 DS |
180 | for (i = 0; i < 8; i++) { |
181 | devpriv->range_type_list[i] = (it->options[5 + i]) | |
0a85b6f0 | 182 | ? current_range_type : voltage_range_type; |
d6a929b7 DS |
183 | } |
184 | ||
185 | /* Init the 2815 */ | |
186 | outb(0x00, dev->iobase + DT2815_STATUS); | |
187 | for (i = 0; i < 100; i++) { | |
188 | /* This is incredibly slow (approx 20 ms) */ | |
189 | unsigned int status; | |
190 | ||
5f74ea14 | 191 | udelay(1000); |
d6a929b7 DS |
192 | status = inb(dev->iobase + DT2815_STATUS); |
193 | if (status == 4) { | |
194 | unsigned int program; | |
f61b57a4 | 195 | |
d6a929b7 DS |
196 | program = (it->options[4] & 0x3) << 3 | 0x7; |
197 | outb(program, dev->iobase + DT2815_DATA); | |
5b7b0eb2 HS |
198 | dev_dbg(dev->class_dev, "program: 0x%x (@t=%d)\n", |
199 | program, i); | |
d6a929b7 DS |
200 | break; |
201 | } else if (status != 0x00) { | |
5b7b0eb2 HS |
202 | dev_dbg(dev->class_dev, |
203 | "unexpected status 0x%x (@t=%d)\n", | |
204 | status, i); | |
0acc516a | 205 | if (status & 0x60) |
d6a929b7 | 206 | outb(0x00, dev->iobase + DT2815_STATUS); |
d6a929b7 DS |
207 | } |
208 | } | |
209 | ||
d6a929b7 DS |
210 | return 0; |
211 | } | |
212 | ||
294f930d | 213 | static struct comedi_driver dt2815_driver = { |
b85eec95 HS |
214 | .driver_name = "dt2815", |
215 | .module = THIS_MODULE, | |
216 | .attach = dt2815_attach, | |
21208519 | 217 | .detach = comedi_legacy_detach, |
b85eec95 | 218 | }; |
294f930d | 219 | module_comedi_driver(dt2815_driver); |
b85eec95 | 220 | |
90f703d3 AT |
221 | MODULE_AUTHOR("Comedi http://www.comedi.org"); |
222 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
223 | MODULE_LICENSE("GPL"); |