aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorFreeman Liu <freeman.liu@unisoc.com>2018-11-08 22:25:31 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2018-11-16 13:32:32 -0500
commit750ac07eb2c85617b5522402a99b4b408cd0b1b3 (patch)
tree645dbd93370a8dcd6e3f17164316ad96d4d05379 /drivers/iio
parentbefa9f6a3e1f00df0cff9d991650dc8d541fb730 (diff)
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: Freeman Liu <freeman.liu@unisoc.com> Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/sc27xx_adc.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index 7940b23dcad9..f7f7a18904b4 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -52,6 +52,9 @@
52/* Timeout (ms) for the trylock of hardware spinlocks */ 52/* Timeout (ms) for the trylock of hardware spinlocks */
53#define SC27XX_ADC_HWLOCK_TIMEOUT 5000 53#define SC27XX_ADC_HWLOCK_TIMEOUT 5000
54 54
55/* Timeout (ms) for ADC data conversion according to ADC datasheet */
56#define SC27XX_ADC_RDY_TIMEOUT 100
57
55/* Maximum ADC channel number */ 58/* Maximum ADC channel number */
56#define SC27XX_ADC_CHANNEL_MAX 32 59#define SC27XX_ADC_CHANNEL_MAX 32
57 60
@@ -223,7 +226,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
223 if (ret) 226 if (ret)
224 goto disable_adc; 227 goto disable_adc;
225 228
226 wait_for_completion(&data->completion); 229 ret = wait_for_completion_timeout(&data->completion,
230 msecs_to_jiffies(SC27XX_ADC_RDY_TIMEOUT));
231 if (!ret) {
232 dev_err(data->dev, "read ADC data timeout\n");
233 ret = -ETIMEDOUT;
234 } else {
235 ret = 0;
236 }
227 237
228disable_adc: 238disable_adc:
229 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL, 239 regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL,