From 623e2be92c57d9fc3a73c936f1a875ec6f938399 Mon Sep 17 00:00:00 2001 From: wdc Date: Wed, 14 May 2014 18:01:58 +0800 Subject: [PATCH] saradc: fix sometimes adc print log frequently --- drivers/iio/adc/rockchip_adc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/rockchip_adc.c b/drivers/iio/adc/rockchip_adc.c index 7a66c7b25f18..c25aa5937f22 100755 --- a/drivers/iio/adc/rockchip_adc.c +++ b/drivers/iio/adc/rockchip_adc.c @@ -73,7 +73,7 @@ enum host_chn_mask{ #define SAMPLE_RATE (20/ADC_CLK_RATE) //20 CLK #define MAX_RK_ADC_CHANNELS 3 -#define RK_ADC_TIMEOUT (msecs_to_jiffies(100)) +#define RK_ADC_TIMEOUT HZ struct rk_adc { void __iomem *regs; @@ -109,6 +109,7 @@ static int rk_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { + int ret = IIO_VAL_INT; struct rk_adc *info = iio_priv(indio_dev); unsigned long timeout; @@ -117,6 +118,8 @@ static int rk_read_raw(struct iio_dev *indio_dev, mutex_lock(&indio_dev->mlock); + INIT_COMPLETION(info->completion); + /* Select the channel to be used and Trigger conversion */ writel_relaxed(0x08, info->regs + ADC_DELAY_PU_SOC); writel_relaxed(ADC_CTRL_POWER_UP|ADC_CTRL_CH(chan->channel)|ADC_CTRL_IRQ_ENABLE, info->regs + ADC_CTRL); @@ -125,17 +128,18 @@ static int rk_read_raw(struct iio_dev *indio_dev, (&info->completion, RK_ADC_TIMEOUT); *val = info->value; - mutex_unlock(&indio_dev->mlock); RK_ADC_DBG("read adc value: %d form channel: %d\n", *val, chan->channel); if (timeout == 0) { - rk_adc_dump(indio_dev); - writel_relaxed(0, info->regs + ADC_CTRL); - writel_relaxed(0, info->regs + ADC_DELAY_PU_SOC); - return -ETIMEDOUT; + rk_adc_dump(indio_dev); + writel_relaxed(0, info->regs + ADC_CTRL); + writel_relaxed(0, info->regs + ADC_DELAY_PU_SOC); + ret = -ETIMEDOUT; } - return IIO_VAL_INT; + mutex_unlock(&indio_dev->mlock); + + return ret; } static irqreturn_t rk_adc_isr(int irq, void *dev_id) -- 2.34.1