From f177d3261298d72e36ac328dcd163af6e7a01c28 Mon Sep 17 00:00:00 2001 From: Jishnu Prakash Date: Tue, 1 Nov 2022 22:01:33 +0530 Subject: [PATCH] iio: qcom-spmi-adc5-gen3: Update immediate read handling Update logic used in immediate reading path to ensure that immediate reads performed on channels monitored in ADC_TM on all SDAMs work correctly. Fixes: 2b91fcd524b0 ("iio: qcom-spmi-adc5-gen3: update API for immediate conversions") Change-Id: I4a5b44c493058eed5d43ebed4d7a91cdf0fef29b Signed-off-by: Jishnu Prakash --- drivers/iio/adc/qcom-spmi-adc5-gen3.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c index 49bda46b7f59..6808a138b092 100644 --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c @@ -313,12 +313,12 @@ static int adc5_decimation_from_dt(u32 value, } static int adc5_gen3_read_voltage_data(struct adc5_chip *adc, u16 *data, - struct adc5_channel_prop *prop) + u8 sdam_index) { int ret; u8 rslt[2]; - ret = adc5_read(adc, prop->sdam_index, ADC5_GEN3_CH0_DATA0, rslt, 2); + ret = adc5_read(adc, sdam_index, ADC5_GEN3_CH0_DATA0, rslt, 2); if (ret < 0) return ret; @@ -444,7 +444,11 @@ static int adc5_gen3_do_conversion(struct adc5_chip *adc, int ret; unsigned long rc; unsigned int time_pending_ms; - u8 val; + u8 val, sdam_index = prop->sdam_index; + + /* Reserve channel 0 of first SDAM for immediate conversions */ + if (prop->adc_tm) + sdam_index = 0; mutex_lock(&adc->lock); ret = adc5_gen3_poll_wait_hs(adc, 0); @@ -471,23 +475,23 @@ static int adc5_gen3_do_conversion(struct adc5_chip *adc, pr_debug("ADC channel %s EOC took %u ms\n", prop->datasheet_name, ADC5_GEN3_CONV_TIMEOUT_MS - time_pending_ms); - ret = adc5_gen3_read_voltage_data(adc, data_volt, prop); + ret = adc5_gen3_read_voltage_data(adc, data_volt, sdam_index); if (ret < 0) goto unlock; val = BIT(0); - ret = adc5_write(adc, prop->sdam_index, ADC5_GEN3_EOC_CLR, &val, 1); + ret = adc5_write(adc, sdam_index, ADC5_GEN3_EOC_CLR, &val, 1); if (ret < 0) goto unlock; /* To indicate conversion request is only to clear a status */ val = 0; - ret = adc5_write(adc, prop->sdam_index, ADC5_GEN3_PERPH_CH, &val, 1); + ret = adc5_write(adc, sdam_index, ADC5_GEN3_PERPH_CH, &val, 1); if (ret < 0) goto unlock; val = ADC5_GEN3_CONV_REQ_REQ; - ret = adc5_write(adc, prop->sdam_index, ADC5_GEN3_CONV_REQ, &val, 1); + ret = adc5_write(adc, sdam_index, ADC5_GEN3_CONV_REQ, &val, 1); unlock: mutex_unlock(&adc->lock);