From: H Hartley Sweeten Date: Wed, 5 Aug 2015 17:44:54 +0000 (-0700) Subject: staging: comedi: me4000: use comedi_timeout() to wait for ai (*insn_read) X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=023c129f0a90edf1a9cf2c7ba9086f029f56d488;p=openwrt%2Fstaging%2Fblogic.git staging: comedi: me4000: use comedi_timeout() to wait for ai (*insn_read) 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c index 39dbdafdc953..4231e393c577 100644 --- a/drivers/staging/comedi/drivers/me4000.c +++ b/drivers/staging/comedi/drivers/me4000.c @@ -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;