staging: comedi: adq12b: use comedi_timeout()
Use comedi_timeout() to wait for the analog input end-of-conversion. This also fixes a possible bug where invalid data is returned if the conversion did not complete. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
fa3fa1dea6
commit
5cc0387c19
@ -94,8 +94,6 @@ If you do not specify any options, they will default to
|
|||||||
/* mask of the bit at STINR to check end of conversion */
|
/* mask of the bit at STINR to check end of conversion */
|
||||||
#define ADQ12B_EOC 0x20
|
#define ADQ12B_EOC 0x20
|
||||||
|
|
||||||
#define TIMEOUT 20
|
|
||||||
|
|
||||||
/* available ranges through the PGA gains */
|
/* available ranges through the PGA gains */
|
||||||
static const struct comedi_lrange range_adq12b_ai_bipolar = {
|
static const struct comedi_lrange range_adq12b_ai_bipolar = {
|
||||||
4, {
|
4, {
|
||||||
@ -122,19 +120,28 @@ struct adq12b_private {
|
|||||||
int last_range;
|
int last_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
static int adq12b_ai_eoc(struct comedi_device *dev,
|
||||||
* "instructions" read/write data in "one-shot" or "software-triggered"
|
struct comedi_subdevice *s,
|
||||||
* mode.
|
struct comedi_insn *insn,
|
||||||
*/
|
unsigned long context)
|
||||||
|
{
|
||||||
|
unsigned char status;
|
||||||
|
|
||||||
|
status = inb(dev->iobase + ADQ12B_STINR);
|
||||||
|
if (status & ADQ12B_EOC)
|
||||||
|
return 0;
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
static int adq12b_ai_rinsn(struct comedi_device *dev,
|
static int adq12b_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 adq12b_private *devpriv = dev->private;
|
struct adq12b_private *devpriv = dev->private;
|
||||||
int n, i;
|
int n;
|
||||||
int range, channel;
|
int range, channel;
|
||||||
unsigned char hi, lo, status;
|
unsigned char hi, lo, status;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* change channel and range only if it is different from the previous */
|
/* change channel and range only if it is different from the previous */
|
||||||
range = CR_RANGE(insn->chanspec);
|
range = CR_RANGE(insn->chanspec);
|
||||||
@ -151,13 +158,9 @@ static int adq12b_ai_rinsn(struct comedi_device *dev,
|
|||||||
for (n = 0; n < insn->n; n++) {
|
for (n = 0; n < insn->n; n++) {
|
||||||
|
|
||||||
/* wait for end of conversion */
|
/* wait for end of conversion */
|
||||||
i = 0;
|
ret = comedi_timeout(dev, s, insn, adq12b_ai_eoc, 0);
|
||||||
do {
|
if (ret)
|
||||||
/* udelay(1); */
|
return ret;
|
||||||
status = inb(dev->iobase + ADQ12B_STINR);
|
|
||||||
status = status & ADQ12B_EOC;
|
|
||||||
} while (status == 0 && ++i < TIMEOUT);
|
|
||||||
/* } while (++i < 10); */
|
|
||||||
|
|
||||||
/* read data */
|
/* read data */
|
||||||
hi = inb(dev->iobase + ADQ12B_ADHIG);
|
hi = inb(dev->iobase + ADQ12B_ADHIG);
|
||||||
|
Loading…
Reference in New Issue
Block a user