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

staging: comedi: rtd520: use comedi_timeout()

Use comedi_timeout() to wait for the analog input and output end-of-
conversions.
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 a9f9d831
...@@ -237,20 +237,6 @@ ...@@ -237,20 +237,6 @@
/* The board support a channel list up to the FIFO length (1K or 8K) */ /* The board support a channel list up to the FIFO length (1K or 8K) */
#define RTD_MAX_CHANLIST 128 /* max channel list that we allow */ #define RTD_MAX_CHANLIST 128 /* max channel list that we allow */
/* tuning for ai/ao instruction done polling */
#ifdef FAST_SPIN
#define WAIT_QUIETLY /* as nothing, spin on done bit */
#define RTD_ADC_TIMEOUT 66000 /* 2 msec at 33mhz bus rate */
#define RTD_DAC_TIMEOUT 66000
#define RTD_DMA_TIMEOUT 33000 /* 1 msec */
#else
/* by delaying, power and electrical noise are reduced somewhat */
#define WAIT_QUIETLY udelay(1)
#define RTD_ADC_TIMEOUT 2000 /* in usec */
#define RTD_DAC_TIMEOUT 2000 /* in usec */
#define RTD_DMA_TIMEOUT 1000 /* in usec */
#endif
/*====================================================================== /*======================================================================
Board specific stuff Board specific stuff
======================================================================*/ ======================================================================*/
...@@ -562,21 +548,27 @@ static int rtd520_probe_fifo_depth(struct comedi_device *dev) ...@@ -562,21 +548,27 @@ static int rtd520_probe_fifo_depth(struct comedi_device *dev)
return fifo_size; return fifo_size;
} }
/* static int rtd_ai_eoc(struct comedi_device *dev,
"instructions" read/write data in "one-shot" or "software-triggered" struct comedi_subdevice *s,
mode (simplest case). struct comedi_insn *insn,
This doesn't use interrupts. unsigned long context)
{
struct rtd_private *devpriv = dev->private;
unsigned int status;
status = readl(devpriv->las0 + LAS0_ADC);
if (status & FS_ADC_NOT_EMPTY)
return 0;
return -EBUSY;
}
Note, we don't do any settling delays. Use a instruction list to
select, delay, then read.
*/
static int rtd_ai_rinsn(struct comedi_device *dev, static int rtd_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_insn *insn, struct comedi_subdevice *s, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
{ {
struct rtd_private *devpriv = dev->private; struct rtd_private *devpriv = dev->private;
int n, ii; int ret;
int stat; int n;
/* clear any old fifo data */ /* clear any old fifo data */
writel(0, devpriv->las0 + LAS0_ADC_FIFO_CLEAR); writel(0, devpriv->las0 + LAS0_ADC_FIFO_CLEAR);
...@@ -593,14 +585,9 @@ static int rtd_ai_rinsn(struct comedi_device *dev, ...@@ -593,14 +585,9 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
/* trigger conversion */ /* trigger conversion */
writew(0, devpriv->las0 + LAS0_ADC); writew(0, devpriv->las0 + LAS0_ADC);
for (ii = 0; ii < RTD_ADC_TIMEOUT; ++ii) { ret = comedi_timeout(dev, s, insn, rtd_ai_eoc, 0);
stat = readl(devpriv->las0 + LAS0_ADC); if (ret)
if (stat & FS_ADC_NOT_EMPTY) /* 1 -> not empty */ return ret;
break;
WAIT_QUIETLY;
}
if (ii >= RTD_ADC_TIMEOUT)
return -ETIMEDOUT;
/* read data */ /* read data */
d = readw(devpriv->las1 + LAS1_ADC_FIFO); d = readw(devpriv->las1 + LAS1_ADC_FIFO);
...@@ -1116,9 +1103,22 @@ static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -1116,9 +1103,22 @@ static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
return 0; return 0;
} }
/* static int rtd_ao_eoc(struct comedi_device *dev,
Output one (or more) analog values to a single port as fast as possible. struct comedi_subdevice *s,
*/ struct comedi_insn *insn,
unsigned long context)
{
struct rtd_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int bit = (chan == 0) ? FS_DAC1_NOT_EMPTY : FS_DAC2_NOT_EMPTY;
unsigned int status;
status = readl(devpriv->las0 + LAS0_ADC);
if (status & bit)
return 0;
return -EBUSY;
}
static int rtd_ao_winsn(struct comedi_device *dev, static int rtd_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_insn *insn, struct comedi_subdevice *s, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
...@@ -1127,6 +1127,7 @@ static int rtd_ao_winsn(struct comedi_device *dev, ...@@ -1127,6 +1127,7 @@ static int rtd_ao_winsn(struct comedi_device *dev,
int i; int i;
int chan = CR_CHAN(insn->chanspec); int chan = CR_CHAN(insn->chanspec);
int range = CR_RANGE(insn->chanspec); int range = CR_RANGE(insn->chanspec);
int ret;
/* Configure the output range (table index matches the range values) */ /* Configure the output range (table index matches the range values) */
writew(range & 7, devpriv->las0 + writew(range & 7, devpriv->las0 +
...@@ -1136,8 +1137,6 @@ static int rtd_ao_winsn(struct comedi_device *dev, ...@@ -1136,8 +1137,6 @@ static int rtd_ao_winsn(struct comedi_device *dev,
* very useful, but that's how the interface is defined. */ * very useful, but that's how the interface is defined. */
for (i = 0; i < insn->n; ++i) { for (i = 0; i < insn->n; ++i) {
int val = data[i] << 3; int val = data[i] << 3;
int stat = 0; /* initialize to avoid bogus warning */
int ii;
/* VERIFY: comedi range and offset conversions */ /* VERIFY: comedi range and offset conversions */
...@@ -1157,16 +1156,9 @@ static int rtd_ao_winsn(struct comedi_device *dev, ...@@ -1157,16 +1156,9 @@ static int rtd_ao_winsn(struct comedi_device *dev,
devpriv->ao_readback[chan] = data[i]; devpriv->ao_readback[chan] = data[i];
for (ii = 0; ii < RTD_DAC_TIMEOUT; ++ii) { ret = comedi_timeout(dev, s, insn, rtd_ao_eoc, 0);
stat = readl(devpriv->las0 + LAS0_ADC); if (ret)
/* 1 -> not empty */ return ret;
if (stat & ((0 == chan) ? FS_DAC1_NOT_EMPTY :
FS_DAC2_NOT_EMPTY))
break;
WAIT_QUIETLY;
}
if (ii >= RTD_DAC_TIMEOUT)
return -ETIMEDOUT;
} }
/* return the number of samples read/written */ /* return the number of samples read/written */
......
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