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 */ 27struct fl512_private { 28 29 short ao_readback[2]; 30}; 31 32#define devpriv ((struct fl512_private *) dev->private) 33 34static const struct comedi_lrange range_fl512 = { 4, { 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 } 43}; 44 45static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it); 46static int fl512_detach(struct comedi_device *dev); 47 48static struct comedi_driver driver_fl512 = { 49 .driver_name = "fl512", 50 .module = THIS_MODULE, 51 .attach = fl512_attach, 52 .detach = fl512_detach, 53}; 54 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); 67 68static int fl512_ai_insn(struct comedi_device *dev, 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); 73static int fl512_ao_insn_readback(struct comedi_device *dev, 74 struct comedi_subdevice *s, 75 struct comedi_insn *insn, unsigned int *data); 76 77/* 78 * fl512_ai_insn : this is the analog input function 79 */ 80static int fl512_ai_insn(struct comedi_device *dev, 81 struct comedi_subdevice *s, struct comedi_insn *insn, 82 unsigned int *data) 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 */ 90 outb(chan, iobase + 2); /* select chan */ 91 outb(0, iobase + 3); /* start conversion */ 92 udelay(30); /* sleep 30 usec */ 93 lo_byte = inb(iobase + 2); /* low 8 byte */ 94 hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */ 95 data[n] = lo_byte + (hi_byte << 8); 96 } 97 return n; 98} 99 100/* 101 * fl512_ao_insn : used to write to a DA port n times 102 */ 103static int fl512_ao_insn(struct comedi_device *dev, 104 struct comedi_subdevice *s, struct comedi_insn *insn, 105 unsigned int *data) 106{ 107 int n; 108 int chan = CR_CHAN(insn->chanspec); /* get chan to write */ 109 unsigned long iobase = dev->iobase; /* get base address */ 110 111 for (n = 0; n < insn->n; n++) { /* write n data set */ 112 /* write low byte */ 113 outb(data[n] & 0x0ff, iobase + 4 + 2 * chan); 114 /* write high byte */ 115 outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan); 116 inb(iobase + 4 + 2 * chan); /* trig */ 117 118 devpriv->ao_readback[chan] = data[n]; 119 } 120 return n; 121} 122 123/* 124 * fl512_ao_insn_readback : used to read previous values written to 125 * DA port 126 */ 127static int fl512_ao_insn_readback(struct comedi_device *dev, 128 struct comedi_subdevice *s, 129 struct comedi_insn *insn, unsigned int *data) 130{ 131 int n; 132 int chan = CR_CHAN(insn->chanspec); 133 134 for (n = 0; n < insn->n; n++) 135 data[n] = devpriv->ao_readback[chan]; 136 137 return n; 138} 139 140/* 141 * start attach 142 */ 143static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it) 144{ 145 unsigned long iobase; 146 147 /* pointer to the subdevice: Analog in, Analog out, 148 (not made ->and Digital IO) */ 149 struct comedi_subdevice *s; 150 151 iobase = it->options[0]; 152 printk(KERN_INFO "comedi:%d fl512: 0x%04lx", dev->minor, iobase); 153 if (!request_region(iobase, FL512_SIZE, "fl512")) { 154 printk(KERN_WARNING " I/O port conflict\n"); 155 return -EIO; 156 } 157 dev->iobase = iobase; 158 dev->board_name = "fl512"; 159 if (alloc_private(dev, sizeof(struct fl512_private)) < 0) 160 return -ENOMEM; 161 162#if DEBUG 163 printk(KERN_DEBUG "malloc ok\n"); 164#endif 165 166 if (alloc_subdevices(dev, 2) < 0) 167 return -ENOMEM; 168 169 /* 170 * this if the definitions of the supdevices, 2 have been defined 171 */ 172 /* Analog indput */ 173 s = dev->subdevices + 0; 174 /* define subdevice as Analog In */ 175 s->type = COMEDI_SUBD_AI; 176 /* you can read it from userspace */ 177 s->subdev_flags = SDF_READABLE | SDF_GROUND; 178 /* Number of Analog input channels */ 179 s->n_chan = 16; 180 /* accept only 12 bits of data */ 181 s->maxdata = 0x0fff; 182 /* device use one of the ranges */ 183 s->range_table = &range_fl512; 184 /* function to call when read AD */ 185 s->insn_read = fl512_ai_insn; 186 printk(KERN_INFO "comedi: fl512: subdevice 0 initialized\n"); 187 188 /* Analog output */ 189 s = dev->subdevices + 1; 190 /* define subdevice as Analog OUT */ 191 s->type = COMEDI_SUBD_AO; 192 /* you can write it from userspace */ 193 s->subdev_flags = SDF_WRITABLE; 194 /* Number of Analog output channels */ 195 s->n_chan = 2; 196 /* accept only 12 bits of data */ 197 s->maxdata = 0x0fff; 198 /* device use one of the ranges */ 199 s->range_table = &range_fl512; 200 /* function to call when write DA */ 201 s->insn_write = fl512_ao_insn; 202 /* function to call when reading DA */ 203 s->insn_read = fl512_ao_insn_readback; 204 printk(KERN_INFO "comedi: fl512: subdevice 1 initialized\n"); 205 206 return 1; 207} 208 209static int fl512_detach(struct comedi_device *dev) 210{ 211 if (dev->iobase) 212 release_region(dev->iobase, FL512_SIZE); 213 printk(KERN_INFO "comedi%d: fl512: dummy i detach\n", dev->minor); 214 return 0; 215} 216 217MODULE_AUTHOR("Comedi http://www.comedi.org"); 218MODULE_DESCRIPTION("Comedi low-level driver"); 219MODULE_LICENSE("GPL"); 220