From: H Hartley Sweeten Date: Tue, 4 Mar 2014 18:30:02 +0000 (-0700) Subject: staging: comedi: pcl812: tidy up the analog input (*insn_read) X-Git-Tag: firefly_0821_release~176^2~4193^2~641 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=30bcb039d573356170ba26e829eba9a4b1ce3048;p=firefly-linux-kernel-4.4.55.git staging: comedi: pcl812: tidy up the analog input (*insn_read) 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. The driver currently does not do this. Refactor the function a bit so it's more like the pcl818 and pcl816 drivers and use common code to clear the flag for a timeout and after the last sample. Do a bit of other tidying up during the move. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/pcl812.c b/drivers/staging/comedi/drivers/pcl812.c index 734226eabaf1..cf183c86fb5b 100644 --- a/drivers/staging/comedi/drivers/pcl812.c +++ b/drivers/staging/comedi/drivers/pcl812.c @@ -667,34 +667,6 @@ static int pcl812_ai_eoc(struct comedi_device *dev, return -EBUSY; } -static int pcl812_ai_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - struct pcl812_private *devpriv = dev->private; - int ret = 0; - int n; - - /* select software trigger */ - outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE); - /* select channel and renge */ - setup_range_channel(dev, s, insn->chanspec, 1); - for (n = 0; n < insn->n; n++) { - /* start conversion */ - outb(255, dev->iobase + PCL812_SOFTTRIG); - udelay(5); - - ret = comedi_timeout(dev, s, insn, pcl812_ai_eoc, 0); - if (ret) - break; - - data[n] = pcl812_ai_get_sample(dev, s); - } - outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); - - return ret ? ret : n; -} - static int pcl812_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { @@ -1033,6 +1005,40 @@ static int pcl812_ai_cancel(struct comedi_device *dev, return 0; } +static int pcl812_ai_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct pcl812_private *devpriv = dev->private; + int ret = 0; + int i; + + /* select software trigger */ + outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE); + + /* select channel and renge */ + setup_range_channel(dev, s, insn->chanspec, 1); + + for (i = 0; i < insn->n; i++) { + /* clear INT request */ + outb(0, dev->iobase + PCL812_CLRINT); + /* start conversion */ + outb(255, dev->iobase + PCL812_SOFTTRIG); + + ret = comedi_timeout(dev, s, insn, pcl812_ai_eoc, 0); + if (ret) + break; + + data[i] = pcl812_ai_get_sample(dev, s); + } + /* clear INT request */ + outb(0, dev->iobase + PCL812_CLRINT); + outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); + + return ret ? ret : insn->n; +} + static int pcl812_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn,