Commit 73ef2b53 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: das16: tidy up das16_ai_insn_read()

Factor out the loop that waits for the ai conversion to complete.

Tidy up the function a bit.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b53ceaf7
...@@ -253,8 +253,6 @@ struct das16_board { ...@@ -253,8 +253,6 @@ struct das16_board {
unsigned int id; unsigned int id;
}; };
#define DAS16_TIMEOUT 1000
/* Period for timer interrupt in jiffies. It's a function /* Period for timer interrupt in jiffies. It's a function
* to deal with possibility of dynamic HZ patches */ * to deal with possibility of dynamic HZ patches */
static inline int timer_period(void) static inline int timer_period(void)
...@@ -564,55 +562,61 @@ static void das16_reset(struct comedi_device *dev) ...@@ -564,55 +562,61 @@ static void das16_reset(struct comedi_device *dev)
outb(0, dev->iobase + DAS16_CNTR_CONTROL); outb(0, dev->iobase + DAS16_CNTR_CONTROL);
} }
static int das16_ai_wait_for_conv(struct comedi_device *dev,
unsigned int timeout)
{
unsigned int status;
int i;
for (i = 0; i < timeout; i++) {
status = inb(dev->iobase + DAS16_STATUS);
if (!(status & BUSY))
return 0;
}
return -ETIME;
}
static int das16_ai_insn_read(struct comedi_device *dev, static int das16_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
{ {
const struct das16_board *board = comedi_board(dev); const struct das16_board *board = comedi_board(dev);
int i, n; unsigned int chan = CR_CHAN(insn->chanspec);
int range; unsigned int range = CR_RANGE(insn->chanspec);
int chan; unsigned int val;
int ret;
int i;
das16_ai_disable(dev); das16_ai_disable(dev);
/* set multiplexer */ /* set multiplexer */
chan = CR_CHAN(insn->chanspec); outb(chan | (chan << 4), dev->iobase + DAS16_MUX);
chan |= CR_CHAN(insn->chanspec) << 4;
outb(chan, dev->iobase + DAS16_MUX);
/* set gain */ /* set gain */
if (board->ai_pg != das16_pg_none) { if (board->ai_pg != das16_pg_none) {
range = CR_RANGE(insn->chanspec);
outb((das16_gainlists[board->ai_pg])[range], outb((das16_gainlists[board->ai_pg])[range],
dev->iobase + DAS16_GAIN); dev->iobase + DAS16_GAIN);
} }
for (n = 0; n < insn->n; n++) { for (i = 0; i < insn->n; i++) {
unsigned int val;
/* trigger conversion */ /* trigger conversion */
outb_p(0, dev->iobase + DAS16_TRIG); outb_p(0, dev->iobase + DAS16_TRIG);
for (i = 0; i < DAS16_TIMEOUT; i++) { ret = das16_ai_wait_for_conv(dev, 1000);
if (!(inb(dev->iobase + DAS16_STATUS) & BUSY)) if (ret)
break; return ret;
}
if (i == DAS16_TIMEOUT) {
printk("das16: timeout\n");
return -ETIME;
}
val = inb(dev->iobase + DAS16_AI_MSB) << 8; val = inb(dev->iobase + DAS16_AI_MSB) << 8;
val |= inb(dev->iobase + DAS16_AI_LSB); val |= inb(dev->iobase + DAS16_AI_LSB);
if (s->maxdata == 0x0fff) if (s->maxdata == 0x0fff)
data[n] >>= 4; val >>= 4;
val &= s->maxdata; val &= s->maxdata;
data[n] = val; data[i] = val;
} }
return n; return insn->n;
} }
static int das16_di_insn_bits(struct comedi_device *dev, static int das16_di_insn_bits(struct comedi_device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment