3 Anders Gnistrup <ex18@kalman.iau.dtu.dk>
9 Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk>
10 Devices: [unknown] FL512 (fl512)
13 Digital I/O is not supported.
15 Configuration options:
16 [0] - I/O port base address
21 #include "../comedidev.h"
23 #include <linux/delay.h>
24 #include <linux/ioport.h>
26 #define FL512_SIZE 16 /* the size of the used memory */
27 struct fl512_private
{
32 #define devpriv ((struct fl512_private *) dev->private)
34 static const struct comedi_lrange range_fl512
= { 4, {
45 static int fl512_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
);
46 static int fl512_detach(struct comedi_device
*dev
);
48 static struct comedi_driver driver_fl512
= {
49 .driver_name
= "fl512",
50 .module
= THIS_MODULE
,
51 .attach
= fl512_attach
,
52 .detach
= fl512_detach
,
55 static int __init
driver_fl512_init_module(void)
57 return comedi_driver_register(&driver_fl512
);
60 static void __exit
driver_fl512_cleanup_module(void)
62 comedi_driver_unregister(&driver_fl512
);
65 module_init(driver_fl512_init_module
);
66 module_exit(driver_fl512_cleanup_module
);
68 static int fl512_ai_insn(struct comedi_device
*dev
,
69 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
71 static int fl512_ao_insn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
72 struct comedi_insn
*insn
, unsigned int *data
);
73 static int fl512_ao_insn_readback(struct comedi_device
*dev
,
74 struct comedi_subdevice
*s
,
75 struct comedi_insn
*insn
, unsigned int *data
);
78 * fl512_ai_insn : this is the analog input function
80 static int fl512_ai_insn(struct comedi_device
*dev
,
81 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
85 unsigned int lo_byte
, hi_byte
;
86 char chan
= CR_CHAN(insn
->chanspec
);
87 unsigned long iobase
= dev
->iobase
;
89 for (n
= 0; n
< insn
->n
; n
++) { /* sample n times on selected channel */
90 /* XXX probably can move next step out of for() loop -- will
91 * make AI a little bit faster. */
92 outb(chan
, iobase
+ 2); /* select chan */
93 outb(0, iobase
+ 3); /* start conversion */
94 /* XXX should test "done" flag instead of delay */
95 udelay(30); /* sleep 30 usec */
96 lo_byte
= inb(iobase
+ 2); /* low 8 byte */
97 hi_byte
= inb(iobase
+ 3) & 0xf; /* high 4 bit and mask */
98 data
[n
] = lo_byte
+ (hi_byte
<< 8);
104 * fl512_ao_insn : used to write to a DA port n times
106 static int fl512_ao_insn(struct comedi_device
*dev
,
107 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
111 int chan
= CR_CHAN(insn
->chanspec
); /* get chan to write */
112 unsigned long iobase
= dev
->iobase
; /* get base address */
114 for (n
= 0; n
< insn
->n
; n
++) { /* write n data set */
116 outb(data
[n
] & 0x0ff, iobase
+ 4 + 2 * chan
);
117 /* write high byte */
118 outb((data
[n
] & 0xf00) >> 8, iobase
+ 4 + 2 * chan
);
119 inb(iobase
+ 4 + 2 * chan
); /* trig */
121 devpriv
->ao_readback
[chan
] = data
[n
];
127 * fl512_ao_insn_readback : used to read previous values written to
130 static int fl512_ao_insn_readback(struct comedi_device
*dev
,
131 struct comedi_subdevice
*s
,
132 struct comedi_insn
*insn
, unsigned int *data
)
135 int chan
= CR_CHAN(insn
->chanspec
);
137 for (n
= 0; n
< insn
->n
; n
++)
138 data
[n
] = devpriv
->ao_readback
[chan
];
146 static int fl512_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
148 unsigned long iobase
;
150 /* pointer to the subdevice: Analog in, Analog out,
151 (not made ->and Digital IO) */
152 struct comedi_subdevice
*s
;
154 iobase
= it
->options
[0];
155 printk(KERN_INFO
"comedi:%d fl512: 0x%04lx", dev
->minor
, iobase
);
156 if (!request_region(iobase
, FL512_SIZE
, "fl512")) {
157 printk(KERN_WARNING
" I/O port conflict\n");
160 dev
->iobase
= iobase
;
161 dev
->board_name
= "fl512";
162 if (alloc_private(dev
, sizeof(struct fl512_private
)) < 0)
166 printk(KERN_DEBUG
"malloc ok\n");
169 if (alloc_subdevices(dev
, 2) < 0)
173 * this if the definitions of the supdevices, 2 have been defined
176 s
= dev
->subdevices
+ 0;
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 */
183 /* accept only 12 bits of data */
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");
192 s
= dev
->subdevices
+ 1;
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 */
199 /* accept only 12 bits of data */
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");
212 static int fl512_detach(struct comedi_device
*dev
)
215 release_region(dev
->iobase
, FL512_SIZE
);
216 printk(KERN_INFO
"comedi%d: fl512: dummy i detach\n", dev
->minor
);
220 MODULE_AUTHOR("Comedi http://www.comedi.org");
221 MODULE_DESCRIPTION("Comedi low-level driver");
222 MODULE_LICENSE("GPL");