From c78b5ae472e69452d5fe44c261d57c8083c59f74 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Tue, 3 Feb 2015 15:15:08 +0530 Subject: iio: adc: vf610: use sample period of minimum 6 ADC clocks The patch changes the sample period to 6 ADC clocks instead of the earlier 2 ADC clocks. This is required as reading multiple channels simultaneously at short time intervals (< 10ms) leads to fluctuations in the internal temperature sensor readouts. Internal temperature sensor seems to require atleast 4 ADC clocks for a stable reading. Also change the formula for calculating available sampling frequencies accordingly. Signed-off-by: Sanchayan Maity Signed-off-by: Stefan Agner --- drivers/iio/adc/vf610_adc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c index deffcc6658a4..4dc55f849dc3 100644 --- a/drivers/iio/adc/vf610_adc.c +++ b/drivers/iio/adc/vf610_adc.c @@ -68,6 +68,9 @@ #define VF610_ADC_CLK_DIV8 0x60 #define VF610_ADC_CLK_MASK 0x60 #define VF610_ADC_ADLSMP_LONG 0x10 +#define VF610_ADC_ADSTS_SHORT 0x100 +#define VF610_ADC_ADSTS_NORMAL 0x200 +#define VF610_ADC_ADSTS_LONG 0x300 #define VF610_ADC_ADSTS_MASK 0x300 #define VF610_ADC_ADLPC_EN 0x80 #define VF610_ADC_ADHSC_EN 0x400 @@ -239,7 +242,7 @@ static inline void vf610_adc_cfg_init(struct vf610_adc *info, adck_rate = ipg_rate / info->adc_feature.clk_div; for (i = 0; i < VF610_SAMPLE_FREQ_CNT; i++) info->sample_freq_avail[i] = - adck_rate / (6 + vf610_hw_avgs[i] * (25 + 3)); + adck_rate / (6 + vf610_hw_avgs[i] * (25 + 7)); } static void vf610_adc_cfg_post_set(struct vf610_adc *info) @@ -384,7 +387,13 @@ static void vf610_adc_sample_set(struct vf610_adc *info) } /* Use the short sample mode */ - cfg_data &= ~(VF610_ADC_ADLSMP_LONG | VF610_ADC_ADSTS_MASK); + cfg_data &= ~VF610_ADC_ADLSMP_LONG; + /* + * Keep sample period to atleast 6 ADC clocks. This is required + * for correct readings of temperature sensor when multiple channels + * are sampled continuously in very short intervals. + */ + cfg_data |= VF610_ADC_ADSTS_NORMAL; /* update hardware average selection */ cfg_data &= ~VF610_ADC_AVGS_MASK; -- cgit v1.2.3