From af4e33377e481762a117e39fd29eda913808d45c Mon Sep 17 00:00:00 2001 From: Rakesh Kota Date: Wed, 6 Sep 2023 12:35:14 +0530 Subject: [PATCH] iio: spmi-adc5: Add DT based option to specify scale-fn-type Based on the board designs, same ADC channel for a PMIC may be required to use with a different scale function. eg - PM7250B PMIC's VADC channel for reading slave charger temperature will require different scaling function to calculate the voltage to temperature based on the slave charger used on that board(SMB1390/SMB1398). Add DT based option to specify scale-fn-type to handle such kind of requirements. Change-Id: I52d7b8afb5b6b6ef0419740bdb67ed3f48108cde Signed-off-by: Rakesh Kota --- drivers/iio/adc/qcom-spmi-adc5.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index 9d37c9bada5e..1bfa247c8b18 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -1104,6 +1104,11 @@ static int adc5_get_fw_channel_data(struct adc5_chip *adc, prop->avg_samples = VADC_DEF_AVG_SAMPLES; } + prop->scale_fn_type = -EINVAL; + ret = fwnode_property_read_u32(fwnode, "qcom,scale-fn-type", &value); + if (!ret && value < SCALE_HW_CALIB_INVALID) + prop->scale_fn_type = value; + if (fwnode_property_read_bool(fwnode, "qcom,ratiometric")) prop->cal_method = ADC5_RATIOMETRIC_CAL; else if (fwnode_property_read_bool(fwnode, "qcom,no-cal")) @@ -1239,8 +1244,10 @@ static int adc5_get_fw_data(struct adc5_chip *adc) return ret; } - prop.scale_fn_type = - adc->data->adc_chans[prop.channel].scale_fn_type; + if (prop.scale_fn_type == -EINVAL) + prop.scale_fn_type = + adc->data->adc_chans[prop.channel].scale_fn_type; + *chan_props = prop; adc_chan = &adc->data->adc_chans[prop.channel];