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