Commit 8a62fcbd authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: dt2815: use comedi_timeout()

Use comedi_timeout() to wait for the analog output end-of-conversion.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6fd13f76
...@@ -67,15 +67,17 @@ struct dt2815_private { ...@@ -67,15 +67,17 @@ struct dt2815_private {
unsigned int ao_readback[8]; unsigned int ao_readback[8];
}; };
static int dt2815_wait_for_status(struct comedi_device *dev, int status) static int dt2815_ao_status(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{ {
int i; unsigned int status;
for (i = 0; i < 100; i++) { status = inb(dev->iobase + DT2815_STATUS);
if (inb(dev->iobase + DT2815_STATUS) == status) if (status == context)
break; return 0;
} return -EBUSY;
return status;
} }
static int dt2815_ao_insn_read(struct comedi_device *dev, static int dt2815_ao_insn_read(struct comedi_device *dev,
...@@ -98,30 +100,31 @@ static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -98,30 +100,31 @@ static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
struct dt2815_private *devpriv = dev->private; struct dt2815_private *devpriv = dev->private;
int i; int i;
int chan = CR_CHAN(insn->chanspec); int chan = CR_CHAN(insn->chanspec);
unsigned int status;
unsigned int lo, hi; unsigned int lo, hi;
int ret;
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01; lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01;
hi = (data[i] & 0xff0) >> 4; hi = (data[i] & 0xff0) >> 4;
status = dt2815_wait_for_status(dev, 0x00); ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x00);
if (status != 0) { if (ret) {
dev_dbg(dev->class_dev, dev_dbg(dev->class_dev,
"failed to write low byte on %d reason %x\n", "failed to write low byte on %d\n",
chan, status); chan);
return -EBUSY; return ret;
} }
outb(lo, dev->iobase + DT2815_DATA); outb(lo, dev->iobase + DT2815_DATA);
status = dt2815_wait_for_status(dev, 0x10); ret = comedi_timeout(dev, s, insn, dt2815_ao_status, 0x10);
if (status != 0x10) { if (ret) {
dev_dbg(dev->class_dev, dev_dbg(dev->class_dev,
"failed to write high byte on %d reason %x\n", "failed to write high byte on %d\n",
chan, status); chan);
return -EBUSY; return ret;
} }
devpriv->ao_readback[chan] = data[i]; devpriv->ao_readback[chan] = data[i];
} }
return i; return i;
......
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