staging: comedi: me4000: use comedi_timeout() to wait for ai (*insn_read)
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 5 Aug 2015 17:44:54 +0000 (10:44 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Aug 2015 22:03:28 +0000 (15:03 -0700)
Use the comedi_timeout() helper to busy-wait for the analog input end-of-
conversion instead of the udelay().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/me4000.c

index 39dbdafdc953c1f6a689f1be56500bb57eba8513..4231e393c5778cf84c8003f7cc37de1ab1133fab 100644 (file)
@@ -433,9 +433,18 @@ static void me4000_reset(struct comedi_device *dev)
                outl(0x1, dev->iobase + ME4000_DIO_CTRL_REG);
 }
 
-/*=============================================================================
-  Analog input section
-  ===========================================================================*/
+static int me4000_ai_eoc(struct comedi_device *dev,
+                        struct comedi_subdevice *s,
+                        struct comedi_insn *insn,
+                        unsigned long context)
+{
+       unsigned int status;
+
+       status = inl(dev->iobase + ME4000_AI_STATUS_REG);
+       if (status & ME4000_AI_STATUS_BIT_EF_DATA)
+               return 0;
+       return -EBUSY;
+}
 
 static int me4000_ai_insn_read(struct comedi_device *dev,
                               struct comedi_subdevice *s,
@@ -445,10 +454,10 @@ static int me4000_ai_insn_read(struct comedi_device *dev,
        int chan = CR_CHAN(insn->chanspec);
        int rang = CR_RANGE(insn->chanspec);
        int aref = CR_AREF(insn->chanspec);
-
        unsigned int entry = 0;
        unsigned int tmp;
        unsigned int lval;
+       int ret;
 
        if (insn->n == 0) {
                return 0;
@@ -509,13 +518,9 @@ static int me4000_ai_insn_read(struct comedi_device *dev,
        /* Start conversion by dummy read */
        inl(dev->iobase + ME4000_AI_START_REG);
 
-       /* Wait until ready */
-       udelay(10);
-       if (!(inl(dev->iobase + ME4000_AI_STATUS_REG) &
-            ME4000_AI_STATUS_BIT_EF_DATA)) {
-               dev_err(dev->class_dev, "Value not available after wait\n");
-               return -EIO;
-       }
+       ret = comedi_timeout(dev, s, insn, me4000_ai_eoc, 0);
+       if (ret)
+               return ret;
 
        /* Read value from data fifo */
        lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;