Commit 750ac07e authored by Freeman Liu's avatar Freeman Liu Committed by Jonathan Cameron

iio: adc: sc27xx: Add ADC data conversion timeout

Sometimes the ADC controller met some problems, and it will not complete
the data conversion, that will can not wake up the read process any more
to block users. So we should add one maximum conversion time to avoid
this issue.
Signed-off-by: default avatarFreeman Liu <freeman.liu@unisoc.com>
Signed-off-by: default avatarBaolin Wang <baolin.wang@linaro.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent befa9f6a
...@@ -52,6 +52,9 @@ ...@@ -52,6 +52,9 @@
/* Timeout (ms) for the trylock of hardware spinlocks */ /* Timeout (ms) for the trylock of hardware spinlocks */
#define SC27XX_ADC_HWLOCK_TIMEOUT 5000 #define SC27XX_ADC_HWLOCK_TIMEOUT 5000
/* Timeout (ms) for ADC data conversion according to ADC datasheet */
#define SC27XX_ADC_RDY_TIMEOUT 100
/* Maximum ADC channel number */ /* Maximum ADC channel number */
#define SC27XX_ADC_CHANNEL_MAX 32 #define SC27XX_ADC_CHANNEL_MAX 32
...@@ -223,7 +226,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel, ...@@ -223,7 +226,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
if (ret) if (ret)
goto disable_adc; goto disable_adc;
wait_for_completion(&data->completion); ret = wait_for_completion_timeout(&data->completion,
msecs_to_jiffies(SC27XX_ADC_RDY_TIMEOUT));
if (!ret) {
dev_err(data->dev, "read ADC data timeout\n");
ret = -ETIMEDOUT;
} else {
ret = 0;
}
disable_adc: disable_adc:
regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL, regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment