From 6540ba7ec988ab05b96e2ba132df9ad1e3dd449f Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Fri, 26 Jun 2020 16:44:57 -0700 Subject: [PATCH] drivers: thermal: bcl: Update the threshold conversion Ibat and vbat threshold registers were bit shifted in earlier BCL peripheral and starting PMIC7, the bit shift is not there. So remove the ADC to ibat/vbat and vice versa conversion to accommodate this. Change-Id: I45c3b389925c9f6853d14cd8d7aaee3de5310bdf Signed-off-by: Ram Chandrasekar --- drivers/thermal/qcom/bcl_pmic5.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/qcom/bcl_pmic5.c b/drivers/thermal/qcom/bcl_pmic5.c index f44dad55b7f1..bead6a71ab11 100644 --- a/drivers/thermal/qcom/bcl_pmic5.c +++ b/drivers/thermal/qcom/bcl_pmic5.c @@ -40,6 +40,10 @@ #define BCL_IRQ_L1 0x2 #define BCL_IRQ_L2 0x4 +/* + * 49827 = 64.879uV (one bit value) * 3 (voltage divider) + * * 256 (8 bit shift for MSB) + */ #define BCL_VBAT_SCALING_UV 49827 #define BCL_VBAT_NO_READING 127 #define BCL_VBAT_BASE_MV 2000 @@ -97,6 +101,7 @@ struct bcl_device { static struct bcl_device *bcl_devices[MAX_PERPH_COUNT]; static int bcl_device_ct; static bool ibat_use_qg_adc; +static bool no_bit_shift; static int bcl_read_register(struct bcl_device *bcl_perph, int16_t reg_offset, unsigned int *data) @@ -147,10 +152,13 @@ static int bcl_write_register(struct bcl_device *bcl_perph, static void convert_adc_to_vbat_thresh_val(int *val) { /* - * Threshold register is bit shifted from ADC MSB. - * So the scaling factor is half. + * Threshold register can be bit shifted from ADC MSB. + * So the scaling factor is half in those cases. */ - *val = (*val * BCL_VBAT_SCALING_UV) / 2000; + if (no_bit_shift) + *val = (*val * BCL_VBAT_SCALING_UV) / 1000; + else + *val = (*val * BCL_VBAT_SCALING_UV) / 2000; } static void convert_adc_to_vbat_val(int *val) @@ -161,11 +169,13 @@ static void convert_adc_to_vbat_val(int *val) static void convert_ibat_to_adc_val(int *val) { /* - * Threshold register is bit shifted from ADC MSB. - * So the scaling factor is half. + * Threshold register can be bit shifted from ADC MSB. + * So the scaling factor is half in those cases. */ if (ibat_use_qg_adc) *val = (int)div_s64(*val * 2000 * 2, BCL_IBAT_SCALING_UA); + else if (no_bit_shift) + *val = (int)div_s64(*val * 1000, BCL_IBAT_SCALING_UA); else *val = (int)div_s64(*val * 2000, BCL_IBAT_SCALING_UA); @@ -464,6 +474,8 @@ static int bcl_get_devicetree_data(struct platform_device *pdev, ibat_use_qg_adc = of_property_read_bool(dev_node, "qcom,ibat-use-qg-adc-5a"); + no_bit_shift = of_property_read_bool(dev_node, + "qcom,pmic7-threshold"); return ret; }