]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/rti802.c
arm: imx6: defconfig: update tx6 defconfigs
[karo-tx-linux.git] / drivers / staging / comedi / drivers / rti802.c
1 /*
2    comedi/drivers/rti802.c
3    Hardware driver for Analog Devices RTI-802 board
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.
17  */
18 /*
19 Driver: rti802
20 Description: Analog Devices RTI-802
21 Author: Anders Blomdell <anders.blomdell@control.lth.se>
22 Devices: [Analog Devices] RTI-802 (rti802)
23 Status: works
24
25 Configuration Options:
26     [0] - i/o base
27     [1] - unused
28     [2] - dac#0  0=two's comp, 1=straight
29     [3] - dac#0  0=bipolar, 1=unipolar
30     [4] - dac#1 ...
31     ...
32     [17] - dac#7 ...
33 */
34
35 #include <linux/module.h>
36 #include "../comedidev.h"
37
38 #define RTI802_SIZE 4
39
40 #define RTI802_SELECT 0
41 #define RTI802_DATALOW 1
42 #define RTI802_DATAHIGH 2
43
44 struct rti802_private {
45         enum {
46                 dac_2comp, dac_straight
47         } dac_coding[8];
48         const struct comedi_lrange *range_type_list[8];
49         unsigned int ao_readback[8];
50 };
51
52 static int rti802_ao_insn_read(struct comedi_device *dev,
53                                struct comedi_subdevice *s,
54                                struct comedi_insn *insn, unsigned int *data)
55 {
56         struct rti802_private *devpriv = dev->private;
57         int i;
58
59         for (i = 0; i < insn->n; i++)
60                 data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)];
61
62         return i;
63 }
64
65 static int rti802_ao_insn_write(struct comedi_device *dev,
66                                 struct comedi_subdevice *s,
67                                 struct comedi_insn *insn, unsigned int *data)
68 {
69         struct rti802_private *devpriv = dev->private;
70         int i, d;
71         int chan = CR_CHAN(insn->chanspec);
72
73         for (i = 0; i < insn->n; i++) {
74                 d = devpriv->ao_readback[chan] = data[i];
75                 if (devpriv->dac_coding[chan] == dac_2comp)
76                         d ^= 0x800;
77                 outb(chan, dev->iobase + RTI802_SELECT);
78                 outb(d & 0xff, dev->iobase + RTI802_DATALOW);
79                 outb(d >> 8, dev->iobase + RTI802_DATAHIGH);
80         }
81         return i;
82 }
83
84 static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it)
85 {
86         struct rti802_private *devpriv;
87         struct comedi_subdevice *s;
88         int i;
89         int ret;
90
91         ret = comedi_request_region(dev, it->options[0], RTI802_SIZE);
92         if (ret)
93                 return ret;
94
95         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
96         if (!devpriv)
97                 return -ENOMEM;
98
99         ret = comedi_alloc_subdevices(dev, 1);
100         if (ret)
101                 return ret;
102
103         s = &dev->subdevices[0];
104         /* ao subdevice */
105         s->type = COMEDI_SUBD_AO;
106         s->subdev_flags = SDF_WRITABLE;
107         s->maxdata = 0xfff;
108         s->n_chan = 8;
109         s->insn_read = rti802_ao_insn_read;
110         s->insn_write = rti802_ao_insn_write;
111         s->range_table_list = devpriv->range_type_list;
112
113         for (i = 0; i < 8; i++) {
114                 devpriv->dac_coding[i] = (it->options[3 + 2 * i])
115                     ? (dac_straight)
116                     : (dac_2comp);
117                 devpriv->range_type_list[i] = (it->options[2 + 2 * i])
118                     ? &range_unipolar10 : &range_bipolar10;
119         }
120
121         return 0;
122 }
123
124 static struct comedi_driver rti802_driver = {
125         .driver_name    = "rti802",
126         .module         = THIS_MODULE,
127         .attach         = rti802_attach,
128         .detach         = comedi_legacy_detach,
129 };
130 module_comedi_driver(rti802_driver);
131
132 MODULE_AUTHOR("Comedi http://www.comedi.org");
133 MODULE_DESCRIPTION("Comedi low-level driver");
134 MODULE_LICENSE("GPL");