From: David Schleef Date: Mon, 19 Feb 2001 21:18:28 +0000 (+0000) Subject: fixups for driver X-Git-Tag: r0_7_57~22 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cefb2459e22dd8094a1fb381180501cc0b083c5c;p=comedi.git fixups for driver --- diff --git a/comedi/drivers/fl512.c b/comedi/drivers/fl512.c index 5e2e1f0b..b70764bf 100644 --- a/comedi/drivers/fl512.c +++ b/comedi/drivers/fl512.c @@ -1,5 +1,5 @@ /* - module/FL512.c + module/fl512.c */ /* Option for this board * [0] IO base addres @@ -21,14 +21,11 @@ #define FL512_SIZE 16 /* the size of the used memory */ typedef struct { - char l_byte; - char h_byte; - int chan_ai; - int chan_ao; -} FL512_private; -#define devpriv ((FL512_private *) dev->private) - -static comedi_lrange range_FL512 = + sampl_t ao_readback[2]; +} fl512_private; +#define devpriv ((fl512_private *) dev->private) + +static comedi_lrange range_fl512 = { 4, { BIP_RANGE(0.5), BIP_RANGE(1), @@ -39,30 +36,33 @@ static comedi_lrange range_FL512 = UNI_RANGE(10), }}; -static int FL512_attach(comedi_device *dev,comedi_devconfig *it); -static int FL512_detach(comedi_device *dev); -static int FL512_recognize(char *name); +static int fl512_attach(comedi_device *dev,comedi_devconfig *it); +static int fl512_detach(comedi_device *dev); -comedi_driver driver_FL512 = { - driver_name: "FL512", +comedi_driver driver_fl512 = { + driver_name: "fl512", module: THIS_MODULE, - attach: FL512_attach, - detach: FL512_detach, - recognize: FL512_recognize, + attach: fl512_attach, + detach: fl512_detach, }; -static int FL512_ai(comedi_device *dev, +static int fl512_ai_insn(comedi_device *dev, + comedi_subdevice *s, + comedi_insn *insn, + lsampl_t *data); +static int fl512_ao_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); -static int FL512_ao(comedi_device *dev, +static int fl512_ao_insn_readback(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data); + /* - * FL512_ai : this is the analog input funkton + * fl512_ai_insn : this is the analog input function */ -static int FL512_ai(comedi_device *dev, +static int fl512_ai_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) @@ -71,70 +71,80 @@ static int FL512_ai(comedi_device *dev, unsigned int lo_byte, hi_byte; char chan = CR_CHAN(insn->chanspec); int iobase = dev->iobase; - if ( chan < 0 || chan >=16 ) return -1; - for(n=0; nn; n++) { /* sample n times on selected -channel */ + for(n=0; nn; n++) { /* sample n times on selected channel */ + /* XXX probably can move next step out of for() loop -- will make + * AI a little bit faster. */ outb(chan,iobase+2); /* select chan */ outb(0,iobase+3); /* start conversion */ + /* XXX should test "done" flag instead of delay */ udelay(30); /* sleep 30 usec */ lo_byte = inb(iobase+2); /* low 8 byte */ - hi_byte = inb(iobase+3) & 0x8; /* high 4 bit and mask */ + hi_byte = inb(iobase+3) & 0xf; /* high 4 bit and mask */ data[n] = lo_byte + (hi_byte << 8); } - return 1; /*should be changed when interupt is test as timeout */ + return n; } /* - * FL512_ao : used to write to a DA port n times + * fl512_ao_insn : used to write to a DA port n times */ -static int FL512_ao(comedi_device *dev, +static int fl512_ao_insn(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) { int n; - char chan = CR_CHAN(insn->chanspec); /* get chan to -write */ - int iobase = dev->iobase; /* get base -addres */ - - if (chan!=0 && chan!=1) return -1; - for (n=0; nn; n++) { /* write n data -set */ - outb_p(data[n] & 0x0ff, iobase+4+2*chan); /* write low -byte */ - outb_p((data[n] & 0x800) >> 8, iobase+4+2*chan); /* write high -byte */ - inb_p(iobase+4+2*chan); /* trig */ + int chan = CR_CHAN(insn->chanspec); /* get chan to write */ + int iobase = dev->iobase; /* get base address */ + + for (n=0; nn; n++) { /* write n data set */ + outb(data[n] & 0x0ff, iobase+4+2*chan); /* write low byte */ + outb((data[n] & 0xf00) >> 8, iobase+4+2*chan); /* write high byte */ + inb(iobase+4+2*chan); /* trig */ + + devpriv->ao_readback[chan]=data[n]; } - return 1; /*should be changed when interupt is test as timeout */ + return n; } /* - * start to recognize + * fl512_ao_insn_readback : used to read previous values written to + * DA port */ -static int FL512_recognize(char *name) { - if (!strcmp("FL512",name)) return 0; - return -1; +static int fl512_ao_insn_readback(comedi_device *dev, + comedi_subdevice *s, + comedi_insn *insn, + lsampl_t *data) +{ + int n; + int chan = CR_CHAN(insn->chanspec); + + for (n=0; nn; n++) { + data[n] = devpriv->ao_readback[chan]; + } + + return n; } + /* * start attach */ -static int FL512_attach(comedi_device *dev,comedi_devconfig *it) +static int fl512_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; /* pointer to the subdevice: Analog in, Analog out, ( not made ->and Digital IO) */ + dev->iobase = it->options[0]; - printk("comedi:%d FL512: 0x%04x",dev->minor,dev->iobase); + printk("comedi:%d fl512: 0x%04x",dev->minor,dev->iobase); if (check_region(dev->iobase, FL512_SIZE) < 0) { - printk("I/O port conflikt\n"); + printk(" I/O port conflict\n"); return -EIO; } - request_region(dev->iobase, FL512_SIZE, "FL512"); - dev->board_name = "FL512"; + request_region(dev->iobase, FL512_SIZE, "fl512"); + dev->board_name = "fl512"; dev->n_subdevices = 2; /* Analog in/out */ - if(alloc_private(dev,sizeof(FL512_private)) < 0) + if(alloc_private(dev,sizeof(fl512_private)) < 0) return -ENOMEM; #if DEBUG @@ -149,50 +159,34 @@ static int FL512_attach(comedi_device *dev,comedi_devconfig *it) */ /* Analog indput */ s = dev->subdevices+0; - s->type = COMEDI_SUBD_AI; /* define subdevice as -Analog In */ - s->subdev_flags = SDF_READABLE; /* you can read it from -userspace */ - s->n_chan = 16; /* Number of Analog input -channels */ - s->maxdata = 0x0fff; /* accept only 12 bits of -data */ - s->range_table = &range_FL512; /* device use one of the -ranges */ - s->insn_read = FL512_ai; /* funktion to call when -read AD */ - printk("comedi: subdevice 1 i FL512 lavet\n"); + s->type = COMEDI_SUBD_AI; /* define subdevice as Analog In */ + s->subdev_flags = SDF_READABLE; /* you can read it from userspace */ + s->n_chan = 16; /* Number of Analog input channels */ + s->maxdata = 0x0fff; /* accept only 12 bits of data */ + s->range_table = &range_fl512; /* device use one of the ranges */ + s->insn_read = fl512_ai_insn; /* function to call when read AD */ + printk("comedi: fl512: subdevice 0 initialized\n"); /* Analog output */ s = dev->subdevices+1; - s->type = COMEDI_SUBD_AO; /* define subdevice as -Analog OUT */ - s->subdev_flags = SDF_WRITEABLE; /* you can write it from -userspace */ - s->n_chan = 2; /* Number of Analog output -channels */ - s->maxdata = 0x0fff; /* accept only 12 bits of -data */ - s->range_table = &range_FL512; /* device use one of the -ranges */ - s->insn_write = FL512_ao; /* funktion to call when -write DA */ - printk("comedi: subdevice 2 i FL512 lavet\n"); + s->type = COMEDI_SUBD_AO; /* define subdevice as Analog OUT */ + s->subdev_flags = SDF_WRITEABLE; /* you can write it from userspace */ + s->n_chan = 2; /* Number of Analog output channels */ + s->maxdata = 0x0fff; /* accept only 12 bits of data */ + s->range_table = &range_fl512; /* device use one of the ranges */ + s->insn_write = fl512_ao_insn; /* function to call when write DA */ + s->insn_read = fl512_ao_insn_readback; /* function to call when reading DA */ + printk("comedi: fl512: subdevice 1 initialized\n"); + return 1; } -static int FL512_detach(comedi_device *dev) { +static int fl512_detach(comedi_device *dev) +{ release_region(dev->iobase,FL512_SIZE); - printk("comedi%d:FL512: dummy i detach\n",dev->minor); + printk("comedi%d: fl512: dummy i detach\n",dev->minor); return 0; } -int init_module(void) { - comedi_driver_register(&driver_FL512); - return 0; -} - -void cleanup_module(void) { - comedi_driver_unregister(&driver_FL512); -} +COMEDI_INITCLEANUP(driver_fl512);