For aesthetics, move this function out of the async command support code. For safety, the INT request (end-of-conversion flag) should be cleared before doing each conversion and after the final data sample is read. This driver already clears the flag before starting a conversion but it does not clear the flag after the final sample. Refactor the function a bit so that the flag is cleared for a conversion timeout and after the last sample. Do a bit of other tidying up during the move. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/pcl818.c | 73 ++++++++++++++++----------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c index db62447..c8fc961 100644 --- a/drivers/staging/comedi/drivers/pcl818.c +++ b/drivers/staging/comedi/drivers/pcl818.c @@ -443,43 +443,6 @@ static int pcl818_ai_eoc(struct comedi_device *dev, return -EBUSY; } -static int pcl818_ai_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - int ret; - int n; - - /* software trigger, DMA and INT off */ - outb(0, dev->iobase + PCL818_CONTROL); - - /* select channel */ - outb(muxonechan[CR_CHAN(insn->chanspec)], dev->iobase + PCL818_MUX); - - /* select gain */ - outb(CR_RANGE(insn->chanspec), dev->iobase + PCL818_RANGE); - - for (n = 0; n < insn->n; n++) { - - /* clear INT (conversion end) flag */ - outb(0, dev->iobase + PCL818_CLRINT); - - /* start conversion */ - outb(0, dev->iobase + PCL818_AD_LO); - - ret = comedi_timeout(dev, s, insn, pcl818_ai_eoc, 0); - if (ret) { - /* clear INT (conversion end) flag */ - outb(0, dev->iobase + PCL818_CLRINT); - return ret; - } - - data[n] = pcl818_ai_get_sample(dev, s, NULL); - } - - return n; -} - static bool pcl818_ai_dropout(struct comedi_device *dev, struct comedi_subdevice *s, unsigned int chan) @@ -963,6 +926,42 @@ static int pcl818_ai_cancel(struct comedi_device *dev, return 0; } +static int pcl818_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int range = CR_RANGE(insn->chanspec); + int ret = 0; + int i; + + /* software trigger, DMA and INT off */ + outb(0, dev->iobase + PCL818_CONTROL); + + /* select channel */ + outb(muxonechan[chan], dev->iobase + PCL818_MUX); + /* select gain */ + outb(range, dev->iobase + PCL818_RANGE); + + for (i = 0; i < insn->n; i++) { + /* clear INT (conversion end) flag */ + outb(0, dev->iobase + PCL818_CLRINT); + /* start conversion */ + outb(0, dev->iobase + PCL818_AD_LO); + + ret = comedi_timeout(dev, s, insn, pcl818_ai_eoc, 0); + if (ret) + break; + + data[i] = pcl818_ai_get_sample(dev, s, NULL); + } + /* clear INT (conversion end) flag */ + outb(0, dev->iobase + PCL818_CLRINT); + + return ret ? ret : insn->n; +} + static int pcl818_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, -- 1.8.5.2 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel