Commit | Line | Data |
---|---|---|
9e27db79 | 1 | /* |
884c015f HS |
2 | * fl512.c |
3 | * Anders Gnistrup <ex18@kalman.iau.dtu.dk> | |
4 | * | |
5 | * COMEDI - Linux Control and Measurement Device Interface | |
6 | * Copyright (C) 2000 David A. Schleef <ds@schleef.org> | |
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. | |
17 | */ | |
9e27db79 AG |
18 | |
19 | /* | |
884c015f HS |
20 | * Driver: fl512 |
21 | * Description: unknown | |
22 | * Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk> | |
23 | * Devices: [unknown] FL512 (fl512) | |
24 | * Status: unknown | |
25 | * | |
26 | * Digital I/O is not supported. | |
27 | * | |
28 | * Configuration options: | |
29 | * [0] - I/O port base address | |
30 | */ | |
9e27db79 | 31 | |
ce157f80 | 32 | #include <linux/module.h> |
9e27db79 AG |
33 | #include "../comedidev.h" |
34 | ||
35 | #include <linux/delay.h> | |
9e27db79 | 36 | |
96653ed6 HS |
37 | /* |
38 | * Register I/O map | |
39 | */ | |
40 | #define FL512_AI_LSB_REG 0x02 | |
41 | #define FL512_AI_MSB_REG 0x03 | |
42 | #define FL512_AI_MUX_REG 0x02 | |
43 | #define FL512_AI_START_CONV_REG 0x03 | |
44 | #define FL512_AO_DATA_REG(x) (0x04 + ((x) * 2)) | |
45 | #define FL512_AO_TRIG_REG(x) (0x04 + ((x) * 2)) | |
46 | ||
170341e4 HS |
47 | static const struct comedi_lrange range_fl512 = { |
48 | 4, { | |
49 | BIP_RANGE(0.5), | |
50 | BIP_RANGE(1), | |
51 | BIP_RANGE(5), | |
52 | BIP_RANGE(10), | |
53 | UNI_RANGE(1), | |
54 | UNI_RANGE(5), | |
55 | UNI_RANGE(10) | |
56 | } | |
9e27db79 AG |
57 | }; |
58 | ||
6a083a68 HS |
59 | static int fl512_ai_insn_read(struct comedi_device *dev, |
60 | struct comedi_subdevice *s, | |
61 | struct comedi_insn *insn, | |
62 | unsigned int *data) | |
9e27db79 | 63 | { |
6632d65e HS |
64 | unsigned int chan = CR_CHAN(insn->chanspec); |
65 | unsigned int val; | |
66 | int i; | |
67 | ||
68 | outb(chan, dev->iobase + FL512_AI_MUX_REG); | |
69 | ||
70 | for (i = 0; i < insn->n; i++) { | |
96653ed6 | 71 | outb(0, dev->iobase + FL512_AI_START_CONV_REG); |
6632d65e | 72 | |
9e27db79 | 73 | /* XXX should test "done" flag instead of delay */ |
71c01379 | 74 | usleep_range(30, 100); |
6632d65e HS |
75 | |
76 | val = inb(dev->iobase + FL512_AI_LSB_REG); | |
77 | val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8); | |
78 | val &= s->maxdata; | |
79 | ||
80 | data[i] = val; | |
9e27db79 | 81 | } |
6632d65e HS |
82 | |
83 | return insn->n; | |
9e27db79 AG |
84 | } |
85 | ||
6a083a68 HS |
86 | static int fl512_ao_insn_write(struct comedi_device *dev, |
87 | struct comedi_subdevice *s, | |
88 | struct comedi_insn *insn, | |
89 | unsigned int *data) | |
9e27db79 | 90 | { |
3ecbbb56 | 91 | unsigned int chan = CR_CHAN(insn->chanspec); |
ec00fdc8 | 92 | unsigned int val = s->readback[chan]; |
3ecbbb56 HS |
93 | int i; |
94 | ||
95 | for (i = 0; i < insn->n; i++) { | |
96 | val = data[i]; | |
9e27db79 | 97 | |
3ecbbb56 HS |
98 | /* write LSB, MSB then trigger conversion */ |
99 | outb(val & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan)); | |
100 | outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan)); | |
101 | inb(dev->iobase + FL512_AO_TRIG_REG(chan)); | |
9e27db79 | 102 | } |
ec00fdc8 | 103 | s->readback[chan] = val; |
9e27db79 | 104 | |
18c4110e | 105 | return insn->n; |
9e27db79 AG |
106 | } |
107 | ||
da91b269 | 108 | static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
9e27db79 | 109 | { |
27aa7320 | 110 | struct comedi_subdevice *s; |
efe4567c | 111 | int ret; |
9e27db79 | 112 | |
8f28c9d9 | 113 | ret = comedi_request_region(dev, it->options[0], 0x10); |
efe4567c HS |
114 | if (ret) |
115 | return ret; | |
9a1a6cf8 | 116 | |
8b6c5694 HS |
117 | ret = comedi_alloc_subdevices(dev, 2); |
118 | if (ret) | |
119 | return ret; | |
9e27db79 | 120 | |
638622a2 | 121 | /* Analog Input subdevice */ |
6fc01d32 | 122 | s = &dev->subdevices[0]; |
638622a2 HS |
123 | s->type = COMEDI_SUBD_AI; |
124 | s->subdev_flags = SDF_READABLE | SDF_GROUND; | |
125 | s->n_chan = 16; | |
126 | s->maxdata = 0x0fff; | |
127 | s->range_table = &range_fl512; | |
6a083a68 | 128 | s->insn_read = fl512_ai_insn_read; |
638622a2 HS |
129 | |
130 | /* Analog Output subdevice */ | |
6fc01d32 | 131 | s = &dev->subdevices[1]; |
638622a2 HS |
132 | s->type = COMEDI_SUBD_AO; |
133 | s->subdev_flags = SDF_WRITABLE; | |
134 | s->n_chan = 2; | |
135 | s->maxdata = 0x0fff; | |
136 | s->range_table = &range_fl512; | |
6a083a68 | 137 | s->insn_write = fl512_ao_insn_write; |
ec00fdc8 | 138 | |
11b22e14 | 139 | return comedi_alloc_subdev_readback(s); |
9e27db79 AG |
140 | } |
141 | ||
294f930d | 142 | static struct comedi_driver fl512_driver = { |
a39eb906 HS |
143 | .driver_name = "fl512", |
144 | .module = THIS_MODULE, | |
145 | .attach = fl512_attach, | |
21208519 | 146 | .detach = comedi_legacy_detach, |
a39eb906 | 147 | }; |
294f930d | 148 | module_comedi_driver(fl512_driver); |
a39eb906 | 149 | |
90f703d3 AT |
150 | MODULE_AUTHOR("Comedi http://www.comedi.org"); |
151 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
152 | MODULE_LICENSE("GPL"); |