]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/fl512.c
arm: imx6: defconfig: update tx6 defconfigs
[karo-tx-linux.git] / drivers / staging / comedi / drivers / fl512.c
1 /*
2     comedi/drivers/fl512.c
3     Anders Gnistrup <ex18@kalman.iau.dtu.dk>
4 */
5
6 /*
7 Driver: fl512
8 Description: unknown
9 Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk>
10 Devices: [unknown] FL512 (fl512)
11 Status: unknown
12
13 Digital I/O is not supported.
14
15 Configuration options:
16   [0] - I/O port base address
17 */
18
19 #define DEBUG 0
20
21 #include <linux/module.h>
22 #include "../comedidev.h"
23
24 #include <linux/delay.h>
25
26 #define FL512_SIZE 16           /* the size of the used memory */
27 struct fl512_private {
28         unsigned short ao_readback[2];
29 };
30
31 static const struct comedi_lrange range_fl512 = { 4, {
32                                                       BIP_RANGE(0.5),
33                                                       BIP_RANGE(1),
34                                                       BIP_RANGE(5),
35                                                       BIP_RANGE(10),
36                                                       UNI_RANGE(1),
37                                                       UNI_RANGE(5),
38                                                       UNI_RANGE(10),
39                                                       }
40 };
41
42 /*
43  * fl512_ai_insn : this is the analog input function
44  */
45 static int fl512_ai_insn(struct comedi_device *dev,
46                          struct comedi_subdevice *s, struct comedi_insn *insn,
47                          unsigned int *data)
48 {
49         int n;
50         unsigned int lo_byte, hi_byte;
51         char chan = CR_CHAN(insn->chanspec);
52         unsigned long iobase = dev->iobase;
53
54         for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
55                 /* XXX probably can move next step out of for() loop -- will
56                  * make AI a little bit faster. */
57                 outb(chan, iobase + 2); /* select chan */
58                 outb(0, iobase + 3);    /* start conversion */
59                 /* XXX should test "done" flag instead of delay */
60                 udelay(30);     /* sleep 30 usec */
61                 lo_byte = inb(iobase + 2);      /* low 8 byte */
62                 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
63                 data[n] = lo_byte + (hi_byte << 8);
64         }
65         return n;
66 }
67
68 /*
69  * fl512_ao_insn : used to write to a DA port n times
70  */
71 static int fl512_ao_insn(struct comedi_device *dev,
72                          struct comedi_subdevice *s, struct comedi_insn *insn,
73                          unsigned int *data)
74 {
75         struct fl512_private *devpriv = dev->private;
76         int n;
77         int chan = CR_CHAN(insn->chanspec);     /* get chan to write */
78         unsigned long iobase = dev->iobase;     /* get base address  */
79
80         for (n = 0; n < insn->n; n++) { /* write n data set */
81                 /* write low byte   */
82                 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
83                 /* write high byte  */
84                 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
85                 inb(iobase + 4 + 2 * chan);     /* trig */
86
87                 devpriv->ao_readback[chan] = data[n];
88         }
89         return n;
90 }
91
92 /*
93  * fl512_ao_insn_readback : used to read previous values written to
94  * DA port
95  */
96 static int fl512_ao_insn_readback(struct comedi_device *dev,
97                                   struct comedi_subdevice *s,
98                                   struct comedi_insn *insn, unsigned int *data)
99 {
100         struct fl512_private *devpriv = dev->private;
101         int n;
102         int chan = CR_CHAN(insn->chanspec);
103
104         for (n = 0; n < insn->n; n++)
105                 data[n] = devpriv->ao_readback[chan];
106
107         return n;
108 }
109
110 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
111 {
112         struct fl512_private *devpriv;
113         struct comedi_subdevice *s;
114         int ret;
115
116         ret = comedi_request_region(dev, it->options[0], FL512_SIZE);
117         if (ret)
118                 return ret;
119
120         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
121         if (!devpriv)
122                 return -ENOMEM;
123
124         ret = comedi_alloc_subdevices(dev, 2);
125         if (ret)
126                 return ret;
127
128         /*
129          * this if the definitions of the supdevices, 2 have been defined
130          */
131         /* Analog indput */
132         s = &dev->subdevices[0];
133         /* define subdevice as Analog In */
134         s->type = COMEDI_SUBD_AI;
135         /* you can read it from userspace */
136         s->subdev_flags = SDF_READABLE | SDF_GROUND;
137         /* Number of Analog input channels */
138         s->n_chan = 16;
139         /* accept only 12 bits of data */
140         s->maxdata = 0x0fff;
141         /* device use one of the ranges */
142         s->range_table = &range_fl512;
143         /* function to call when read AD */
144         s->insn_read = fl512_ai_insn;
145
146         /* Analog output */
147         s = &dev->subdevices[1];
148         /* define subdevice as Analog OUT */
149         s->type = COMEDI_SUBD_AO;
150         /* you can write it from userspace */
151         s->subdev_flags = SDF_WRITABLE;
152         /* Number of Analog output channels */
153         s->n_chan = 2;
154         /* accept only 12 bits of data */
155         s->maxdata = 0x0fff;
156         /* device use one of the ranges */
157         s->range_table = &range_fl512;
158         /* function to call when write DA */
159         s->insn_write = fl512_ao_insn;
160         /* function to call when reading DA */
161         s->insn_read = fl512_ao_insn_readback;
162
163         return 1;
164 }
165
166 static struct comedi_driver fl512_driver = {
167         .driver_name    = "fl512",
168         .module         = THIS_MODULE,
169         .attach         = fl512_attach,
170         .detach         = comedi_legacy_detach,
171 };
172 module_comedi_driver(fl512_driver);
173
174 MODULE_AUTHOR("Comedi http://www.comedi.org");
175 MODULE_DESCRIPTION("Comedi low-level driver");
176 MODULE_LICENSE("GPL");