staging: comedi: ni_mio_common: remove devpriv macro
[deliverable/linux.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
9e27db79
AG
45/*
46 * fl512_ai_insn : this is the analog input function
47 */
da91b269 48static int fl512_ai_insn(struct comedi_device *dev,
0a85b6f0
MT
49 struct comedi_subdevice *s, struct comedi_insn *insn,
50 unsigned int *data)
9e27db79
AG
51{
52 int n;
53 unsigned int lo_byte, hi_byte;
54 char chan = CR_CHAN(insn->chanspec);
55 unsigned long iobase = dev->iobase;
56
57 for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
27aa7320
BA
58 /* XXX probably can move next step out of for() loop -- will
59 * make AI a little bit faster. */
9e27db79
AG
60 outb(chan, iobase + 2); /* select chan */
61 outb(0, iobase + 3); /* start conversion */
62 /* XXX should test "done" flag instead of delay */
5f74ea14 63 udelay(30); /* sleep 30 usec */
9e27db79 64 lo_byte = inb(iobase + 2); /* low 8 byte */
27aa7320 65 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
9e27db79
AG
66 data[n] = lo_byte + (hi_byte << 8);
67 }
68 return n;
69}
70
71/*
72 * fl512_ao_insn : used to write to a DA port n times
73 */
da91b269 74static int fl512_ao_insn(struct comedi_device *dev,
0a85b6f0
MT
75 struct comedi_subdevice *s, struct comedi_insn *insn,
76 unsigned int *data)
9e27db79
AG
77{
78 int n;
79 int chan = CR_CHAN(insn->chanspec); /* get chan to write */
80 unsigned long iobase = dev->iobase; /* get base address */
81
82 for (n = 0; n < insn->n; n++) { /* write n data set */
27aa7320
BA
83 /* write low byte */
84 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
85 /* write high byte */
86 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
9e27db79
AG
87 inb(iobase + 4 + 2 * chan); /* trig */
88
89 devpriv->ao_readback[chan] = data[n];
90 }
91 return n;
92}
93
94/*
95 * fl512_ao_insn_readback : used to read previous values written to
96 * DA port
97 */
da91b269 98static int fl512_ao_insn_readback(struct comedi_device *dev,
0a85b6f0
MT
99 struct comedi_subdevice *s,
100 struct comedi_insn *insn, unsigned int *data)
9e27db79
AG
101{
102 int n;
103 int chan = CR_CHAN(insn->chanspec);
104
27aa7320 105 for (n = 0; n < insn->n; n++)
9e27db79 106 data[n] = devpriv->ao_readback[chan];
9e27db79
AG
107
108 return n;
109}
110
da91b269 111static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
9e27db79
AG
112{
113 unsigned long iobase;
8b6c5694 114 int ret;
27aa7320
BA
115
116 /* pointer to the subdevice: Analog in, Analog out,
117 (not made ->and Digital IO) */
118 struct comedi_subdevice *s;
9e27db79
AG
119
120 iobase = it->options[0];
27aa7320 121 printk(KERN_INFO "comedi:%d fl512: 0x%04lx", dev->minor, iobase);
9e27db79 122 if (!request_region(iobase, FL512_SIZE, "fl512")) {
27aa7320 123 printk(KERN_WARNING " I/O port conflict\n");
9e27db79
AG
124 return -EIO;
125 }
126 dev->iobase = iobase;
127 dev->board_name = "fl512";
fa11f7a9 128 if (alloc_private(dev, sizeof(struct fl512_private)) < 0)
9e27db79
AG
129 return -ENOMEM;
130
131#if DEBUG
27aa7320 132 printk(KERN_DEBUG "malloc ok\n");
9e27db79
AG
133#endif
134
8b6c5694
HS
135 ret = comedi_alloc_subdevices(dev, 2);
136 if (ret)
137 return ret;
9e27db79
AG
138
139 /*
140 * this if the definitions of the supdevices, 2 have been defined
141 */
142 /* Analog indput */
6fc01d32 143 s = &dev->subdevices[0];
27aa7320
BA
144 /* define subdevice as Analog In */
145 s->type = COMEDI_SUBD_AI;
146 /* you can read it from userspace */
147 s->subdev_flags = SDF_READABLE | SDF_GROUND;
148 /* Number of Analog input channels */
149 s->n_chan = 16;
150 /* accept only 12 bits of data */
151 s->maxdata = 0x0fff;
152 /* device use one of the ranges */
153 s->range_table = &range_fl512;
154 /* function to call when read AD */
155 s->insn_read = fl512_ai_insn;
156 printk(KERN_INFO "comedi: fl512: subdevice 0 initialized\n");
9e27db79
AG
157
158 /* Analog output */
6fc01d32 159 s = &dev->subdevices[1];
27aa7320
BA
160 /* define subdevice as Analog OUT */
161 s->type = COMEDI_SUBD_AO;
162 /* you can write it from userspace */
163 s->subdev_flags = SDF_WRITABLE;
164 /* Number of Analog output channels */
165 s->n_chan = 2;
166 /* accept only 12 bits of data */
167 s->maxdata = 0x0fff;
168 /* device use one of the ranges */
169 s->range_table = &range_fl512;
170 /* function to call when write DA */
171 s->insn_write = fl512_ao_insn;
172 /* function to call when reading DA */
173 s->insn_read = fl512_ao_insn_readback;
174 printk(KERN_INFO "comedi: fl512: subdevice 1 initialized\n");
9e27db79
AG
175
176 return 1;
177}
178
484ecc95 179static void fl512_detach(struct comedi_device *dev)
9e27db79
AG
180{
181 if (dev->iobase)
182 release_region(dev->iobase, FL512_SIZE);
9e27db79 183}
90f703d3 184
294f930d 185static struct comedi_driver fl512_driver = {
a39eb906
HS
186 .driver_name = "fl512",
187 .module = THIS_MODULE,
188 .attach = fl512_attach,
189 .detach = fl512_detach,
190};
294f930d 191module_comedi_driver(fl512_driver);
a39eb906 192
90f703d3
AT
193MODULE_AUTHOR("Comedi http://www.comedi.org");
194MODULE_DESCRIPTION("Comedi low-level driver");
195MODULE_LICENSE("GPL");
This page took 3.573669 seconds and 5 git commands to generate.