From fe7d188ad17f6e07ff7f2bcac063e88d8a9bad3c Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Fri, 28 Feb 2020 09:28:21 -0800 Subject: [PATCH] driver: thermal: bcl_pmic5: Register vbat only when enabled Vbat in BCL peripheral can be disabled by default depending on the PMIC configuration. In those cases, registering vbat sensor will read 0 Volt always. Before registering the vbat sensor, check if the vbat ADC measurement is enabled in the hardware. If not, skip the registration of vbat sensor. Change-Id: Ic937201349a505825615a412bdbbfb7348b30689 Signed-off-by: Ram Chandrasekar --- drivers/thermal/qcom/bcl_pmic5.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qcom/bcl_pmic5.c b/drivers/thermal/qcom/bcl_pmic5.c index 7c6d27167782..f44dad55b7f1 100644 --- a/drivers/thermal/qcom/bcl_pmic5.c +++ b/drivers/thermal/qcom/bcl_pmic5.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "%s:%s " fmt, KBUILD_MODNAME, __func__ @@ -34,6 +34,7 @@ #define BCL_VBAT_ADC_LOW 0x48 #define BCL_VBAT_COMP_LOW 0x49 #define BCL_VBAT_COMP_TLOW 0x4A +#define BCL_VBAT_CONV_REQ 0x72 #define BCL_IRQ_L0 0x1 #define BCL_IRQ_L1 0x2 @@ -503,11 +504,17 @@ static void bcl_vbat_init(struct platform_device *pdev, enum bcl_dev_type type, struct bcl_device *bcl_perph) { struct bcl_peripheral_data *vbat = &bcl_perph->param[type]; + unsigned int val = 0; + int ret; mutex_init(&vbat->state_trans_lock); vbat->dev = bcl_perph; vbat->irq_num = 0; vbat->irq_enabled = false; + vbat->tz_dev = NULL; + ret = bcl_read_register(bcl_perph, BCL_VBAT_CONV_REQ, &val); + if (ret || !val) + return; vbat->tz_dev = thermal_zone_device_register("vbat", 3, 0, vbat, &vbat_tzd_ops, &vbat_tzp, 0, 0); if (IS_ERR(vbat->tz_dev)) {