Introduce a helper function for the common code used to clear any pending interrupts. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/quatech_daqp_cs.c | 52 ++++++++++++------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c index 899340a..fb12665 100644 --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c @@ -151,6 +151,23 @@ static const struct comedi_lrange range_daqp_ai = { } }; +static int daqp_clear_events(struct comedi_device *dev, int loops) +{ + unsigned int status; + + /* + * Reset any pending interrupts (my card has a tendency to require + * require multiple reads on the status register to achieve this). + */ + while (--loops) { + status = inb(dev->iobase + DAQP_STATUS); + if ((status & DAQP_STATUS_EVENTS) == 0) + return 0; + } + dev_err(dev->class_dev, "couldn't clear events in status register\n"); + return -EBUSY; +} + static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) { @@ -277,9 +294,8 @@ static int daqp_ai_insn_read(struct comedi_device *dev, unsigned int *data) { struct daqp_private *devpriv = dev->private; - int ret = 0; + int ret; int i; - int counter = 10000; if (devpriv->stop) return -EIO; @@ -296,18 +312,9 @@ static int daqp_ai_insn_read(struct comedi_device *dev, /* one-shot internal trigger, no pacer, no interrupts */ outb(0, dev->iobase + DAQP_CONTROL); - /* Reset any pending interrupts (my card has a tendency to require - * require multiple reads on the status register to achieve this) - */ - - while (--counter - && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)) - ; - if (!counter) { - dev_err(dev->class_dev, - "couldn't clear interrupts in status register\n"); - return -1; - } + ret = daqp_clear_events(dev, 10000); + if (ret) + return ret; for (i = 0; i < insn->n; i++) { /* Start conversion */ @@ -433,8 +440,8 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) { struct daqp_private *devpriv = dev->private; struct comedi_cmd *cmd = &s->async->cmd; - int counter; int threshold; + int ret; if (devpriv->stop) return -EIO; @@ -552,18 +559,9 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) DAQP_CONTROL_TRIGGER_CONTINUOUS | DAQP_CONTROL_TRIGGER_INTERNAL, dev->iobase + DAQP_CONTROL); - /* Reset any pending interrupts (my card has a tendency to require - * require multiple reads on the status register to achieve this) - */ - counter = 100; - while (--counter - && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS)) - ; - if (!counter) { - dev_err(dev->class_dev, - "couldn't clear interrupts in status register\n"); - return -1; - } + ret = daqp_clear_events(dev, 100); + if (ret) + return ret; /* Start conversion */ outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA | devpriv->scanrate, -- 2.5.1 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel