staging: comedi: pcl818: 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. 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@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9350557325
commit
8916f5bcdf
1 changed files with 36 additions and 37 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue