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

staging: comedi: dmm32at: use comedi_timeout()

Use comedi_timeout() to wait for the analog input settle and end-of-
conversion. These tests use different registers but the same bit so
the register is passed as the 'context'. The same test is used in
dmm32at_ai_cmd() but the 'insn' is not available. This is ok since
the test function, and comedi_timeout() don't use it.

Use comedi_timout() 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 82c7e864
...@@ -164,16 +164,29 @@ struct dmm32at_private { ...@@ -164,16 +164,29 @@ struct dmm32at_private {
}; };
static int dmm32at_ai_status(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{
unsigned char status;
status = inb(dev->iobase + context);
if ((status & DMM32AT_STATUS) == 0)
return 0;
return -EBUSY;
}
static int dmm32at_ai_rinsn(struct comedi_device *dev, static int dmm32at_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
int n, i; int n;
unsigned int d; unsigned int d;
unsigned char status;
unsigned short msb, lsb; unsigned short msb, lsb;
unsigned char chan; unsigned char chan;
int range; int range;
int ret;
/* get the channel and range number */ /* get the channel and range number */
...@@ -190,26 +203,20 @@ static int dmm32at_ai_rinsn(struct comedi_device *dev, ...@@ -190,26 +203,20 @@ static int dmm32at_ai_rinsn(struct comedi_device *dev,
outb(dmm32at_rangebits[range], dev->iobase + DMM32AT_AICONF); outb(dmm32at_rangebits[range], dev->iobase + DMM32AT_AICONF);
/* wait for circuit to settle */ /* wait for circuit to settle */
for (i = 0; i < 40000; i++) { ret = comedi_timeout(dev, s, insn, dmm32at_ai_status, DMM32AT_AIRBACK);
status = inb(dev->iobase + DMM32AT_AIRBACK); if (ret)
if ((status & DMM32AT_STATUS) == 0) return ret;
break;
}
if (i == 40000)
return -ETIMEDOUT;
/* convert n samples */ /* convert n samples */
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
/* trigger conversion */ /* trigger conversion */
outb(0xff, dev->iobase + DMM32AT_CONV); outb(0xff, dev->iobase + DMM32AT_CONV);
/* wait for conversion to end */ /* wait for conversion to end */
for (i = 0; i < 40000; i++) { ret = comedi_timeout(dev, s, insn, dmm32at_ai_status,
status = inb(dev->iobase + DMM32AT_AISTAT); DMM32AT_AISTAT);
if ((status & DMM32AT_STATUS) == 0) if (ret)
break; return ret;
}
if (i == 40000)
return -ETIMEDOUT;
/* read data */ /* read data */
lsb = inb(dev->iobase + DMM32AT_AILSB); lsb = inb(dev->iobase + DMM32AT_AILSB);
...@@ -403,8 +410,9 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -403,8 +410,9 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{ {
struct dmm32at_private *devpriv = dev->private; struct dmm32at_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
int i, range; int range;
unsigned char chanlo, chanhi, status; unsigned char chanlo, chanhi;
int ret;
if (!cmd->chanlist) if (!cmd->chanlist)
return -EINVAL; return -EINVAL;
...@@ -439,14 +447,13 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -439,14 +447,13 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
* isr */ * isr */
} }
/* wait for circuit to settle */ /*
for (i = 0; i < 40000; i++) { * wait for circuit to settle
status = inb(dev->iobase + DMM32AT_AIRBACK); * we don't have the 'insn' here but it's not needed
if ((status & DMM32AT_STATUS) == 0) */
break; ret = comedi_timeout(dev, s, NULL, dmm32at_ai_status, DMM32AT_AIRBACK);
} if (ret)
if (i == 40000) return ret;
return -ETIMEDOUT;
if (devpriv->ai_scans_left > 1) { if (devpriv->ai_scans_left > 1) {
/* start the clock and enable the interrupts */ /* start the clock and enable the interrupts */
...@@ -525,6 +532,19 @@ static irqreturn_t dmm32at_isr(int irq, void *d) ...@@ -525,6 +532,19 @@ static irqreturn_t dmm32at_isr(int irq, void *d)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int dmm32at_ao_eoc(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{
unsigned char status;
status = inb(dev->iobase + DMM32AT_DACSTAT);
if ((status & DMM32AT_DACBUSY) == 0)
return 0;
return -EBUSY;
}
static int dmm32at_ao_winsn(struct comedi_device *dev, static int dmm32at_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
...@@ -533,6 +553,7 @@ static int dmm32at_ao_winsn(struct comedi_device *dev, ...@@ -533,6 +553,7 @@ static int dmm32at_ao_winsn(struct comedi_device *dev,
int i; int i;
int chan = CR_CHAN(insn->chanspec); int chan = CR_CHAN(insn->chanspec);
unsigned char hi, lo, status; unsigned char hi, lo, status;
int ret;
/* Writing a list of values to an AO channel is probably not /* Writing a list of values to an AO channel is probably not
* very useful, but that's how the interface is defined. */ * very useful, but that's how the interface is defined. */
...@@ -549,13 +570,9 @@ static int dmm32at_ao_winsn(struct comedi_device *dev, ...@@ -549,13 +570,9 @@ static int dmm32at_ao_winsn(struct comedi_device *dev,
outb(hi, dev->iobase + DMM32AT_DACMSB); outb(hi, dev->iobase + DMM32AT_DACMSB);
/* wait for circuit to settle */ /* wait for circuit to settle */
for (i = 0; i < 40000; i++) { ret = comedi_timeout(dev, s, insn, dmm32at_ao_eoc, 0);
status = inb(dev->iobase + DMM32AT_DACSTAT); if (ret)
if ((status & DMM32AT_DACBUSY) == 0) return ret;
break;
}
if (i == 40000)
return -ETIMEDOUT;
/* dummy read to update trigger the output */ /* dummy read to update trigger the output */
status = inb(dev->iobase + DMM32AT_DACMSB); status = inb(dev->iobase + DMM32AT_DACMSB);
......
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