Merge branch 'vhost-net' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / comedi / drivers / fl512.c
CommitLineData
9e27db79
AG
1/*
2 comedi/drivers/fl512.c
3 Anders Gnistrup <ex18@kalman.iau.dtu.dk>
4*/
5
6/*
7Driver: fl512
8Description: unknown
9Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk>
10Devices: [unknown] FL512 (fl512)
11Status: unknown
12
13Digital I/O is not supported.
14
15Configuration options:
16 [0] - I/O port base address
17*/
18
19#define DEBUG 0
20
21#include "../comedidev.h"
22
23#include <linux/delay.h>
24#include <linux/ioport.h>
25
26#define FL512_SIZE 16 /* the size of the used memory */
fa11f7a9
BP
27struct fl512_private {
28
790c5541 29 short ao_readback[2];
fa11f7a9
BP
30};
31
32#define devpriv ((struct fl512_private *) dev->private)
9e27db79 33
9ced1de6 34static const struct comedi_lrange range_fl512 = { 4, {
0a85b6f0
MT
35 BIP_RANGE(0.5),
36 BIP_RANGE(1),
37 BIP_RANGE(5),
38 BIP_RANGE(10),
39 UNI_RANGE(1),
40 UNI_RANGE(5),
41 UNI_RANGE(10),
42 }
9e27db79
AG
43};
44
da91b269
BP
45static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it);
46static int fl512_detach(struct comedi_device *dev);
9e27db79 47
139dfbdf 48static struct comedi_driver driver_fl512 = {
68c3dbff
BP
49 .driver_name = "fl512",
50 .module = THIS_MODULE,
51 .attach = fl512_attach,
52 .detach = fl512_detach,
9e27db79
AG
53};
54
7114a280
AT
55static int __init driver_fl512_init_module(void)
56{
57 return comedi_driver_register(&driver_fl512);
58}
59
60static void __exit driver_fl512_cleanup_module(void)
61{
62 comedi_driver_unregister(&driver_fl512);
63}
64
65module_init(driver_fl512_init_module);
66module_exit(driver_fl512_cleanup_module);
9e27db79 67
da91b269 68static int fl512_ai_insn(struct comedi_device *dev,
0a85b6f0
MT
69 struct comedi_subdevice *s, struct comedi_insn *insn,
70 unsigned int *data);
71static int fl512_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
72 struct comedi_insn *insn, unsigned int *data);
da91b269 73static int fl512_ao_insn_readback(struct comedi_device *dev,
0a85b6f0
MT
74 struct comedi_subdevice *s,
75 struct comedi_insn *insn, unsigned int *data);
9e27db79
AG
76
77/*
78 * fl512_ai_insn : this is the analog input function
79 */
da91b269 80static int fl512_ai_insn(struct comedi_device *dev,
0a85b6f0
MT
81 struct comedi_subdevice *s, struct comedi_insn *insn,
82 unsigned int *data)
9e27db79
AG
83{
84 int n;
85 unsigned int lo_byte, hi_byte;
86 char chan = CR_CHAN(insn->chanspec);
87 unsigned long iobase = dev->iobase;
88
89 for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
27aa7320
BA
90 /* XXX probably can move next step out of for() loop -- will
91 * make AI a little bit faster. */
9e27db79
AG
92 outb(chan, iobase + 2); /* select chan */
93 outb(0, iobase + 3); /* start conversion */
94 /* XXX should test "done" flag instead of delay */
5f74ea14 95 udelay(30); /* sleep 30 usec */
9e27db79 96 lo_byte = inb(iobase + 2); /* low 8 byte */
27aa7320 97 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
9e27db79
AG
98 data[n] = lo_byte + (hi_byte << 8);
99 }
100 return n;
101}
102
103/*
104 * fl512_ao_insn : used to write to a DA port n times
105 */
da91b269 106static int fl512_ao_insn(struct comedi_device *dev,
0a85b6f0
MT
107 struct comedi_subdevice *s, struct comedi_insn *insn,
108 unsigned int *data)
9e27db79
AG
109{
110 int n;
111 int chan = CR_CHAN(insn->chanspec); /* get chan to write */
112 unsigned long iobase = dev->iobase; /* get base address */
113
114 for (n = 0; n < insn->n; n++) { /* write n data set */
27aa7320
BA
115 /* write low byte */
116 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
117 /* write high byte */
118 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
9e27db79
AG
119 inb(iobase + 4 + 2 * chan); /* trig */
120
121 devpriv->ao_readback[chan] = data[n];
122 }
123 return n;
124}
125
126/*
127 * fl512_ao_insn_readback : used to read previous values written to
128 * DA port
129 */
da91b269 130static int fl512_ao_insn_readback(struct comedi_device *dev,
0a85b6f0
MT
131 struct comedi_subdevice *s,
132 struct comedi_insn *insn, unsigned int *data)
9e27db79
AG
133{
134 int n;
135 int chan = CR_CHAN(insn->chanspec);
136
27aa7320 137 for (n = 0; n < insn->n; n++)
9e27db79 138 data[n] = devpriv->ao_readback[chan];
9e27db79
AG
139
140 return n;
141}
142
143/*
144 * start attach
145 */
da91b269 146static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
9e27db79
AG
147{
148 unsigned long iobase;
27aa7320
BA
149
150 /* pointer to the subdevice: Analog in, Analog out,
151 (not made ->and Digital IO) */
152 struct comedi_subdevice *s;
9e27db79
AG
153
154 iobase = it->options[0];
27aa7320 155 printk(KERN_INFO "comedi:%d fl512: 0x%04lx", dev->minor, iobase);
9e27db79 156 if (!request_region(iobase, FL512_SIZE, "fl512")) {
27aa7320 157 printk(KERN_WARNING " I/O port conflict\n");
9e27db79
AG
158 return -EIO;
159 }
160 dev->iobase = iobase;
161 dev->board_name = "fl512";
fa11f7a9 162 if (alloc_private(dev, sizeof(struct fl512_private)) < 0)
9e27db79
AG
163 return -ENOMEM;
164
165#if DEBUG
27aa7320 166 printk(KERN_DEBUG "malloc ok\n");
9e27db79
AG
167#endif
168
169 if (alloc_subdevices(dev, 2) < 0)
170 return -ENOMEM;
171
172 /*
173 * this if the definitions of the supdevices, 2 have been defined
174 */
175 /* Analog indput */
176 s = dev->subdevices + 0;
27aa7320
BA
177 /* define subdevice as Analog In */
178 s->type = COMEDI_SUBD_AI;
179 /* you can read it from userspace */
180 s->subdev_flags = SDF_READABLE | SDF_GROUND;
181 /* Number of Analog input channels */
182 s->n_chan = 16;
183 /* accept only 12 bits of data */
184 s->maxdata = 0x0fff;
185 /* device use one of the ranges */
186 s->range_table = &range_fl512;
187 /* function to call when read AD */
188 s->insn_read = fl512_ai_insn;
189 printk(KERN_INFO "comedi: fl512: subdevice 0 initialized\n");
9e27db79
AG
190
191 /* Analog output */
192 s = dev->subdevices + 1;
27aa7320
BA
193 /* define subdevice as Analog OUT */
194 s->type = COMEDI_SUBD_AO;
195 /* you can write it from userspace */
196 s->subdev_flags = SDF_WRITABLE;
197 /* Number of Analog output channels */
198 s->n_chan = 2;
199 /* accept only 12 bits of data */
200 s->maxdata = 0x0fff;
201 /* device use one of the ranges */
202 s->range_table = &range_fl512;
203 /* function to call when write DA */
204 s->insn_write = fl512_ao_insn;
205 /* function to call when reading DA */
206 s->insn_read = fl512_ao_insn_readback;
207 printk(KERN_INFO "comedi: fl512: subdevice 1 initialized\n");
9e27db79
AG
208
209 return 1;
210}
211
da91b269 212static int fl512_detach(struct comedi_device *dev)
9e27db79
AG
213{
214 if (dev->iobase)
215 release_region(dev->iobase, FL512_SIZE);
27aa7320 216 printk(KERN_INFO "comedi%d: fl512: dummy i detach\n", dev->minor);
9e27db79
AG
217 return 0;
218}
90f703d3
AT
219
220MODULE_AUTHOR("Comedi http://www.comedi.org");
221MODULE_DESCRIPTION("Comedi low-level driver");
222MODULE_LICENSE("GPL");