From 9835eac11c89f7d91925097814ce64b02bdfc66e Mon Sep 17 00:00:00 2001 From: Anirudh Ghayal Date: Wed, 27 Jan 2021 11:07:00 +0530 Subject: [PATCH 1/2] power: qpnp-smb5: Add DT option to enable JEITA-ARB handling Add a DT option "qcom,jeita-arb-enable" to allow suspending the input when VBAT > VJEITA to prevent ARB (reverse boost). Change-Id: I5bf91367b633abf79cbc60ef5bdf93cca9559023 Signed-off-by: Anirudh Ghayal --- drivers/power/supply/qcom/qpnp-smb5.c | 5 ++++- drivers/power/supply/qcom/smb5-lib.c | 5 +++-- drivers/power/supply/qcom/smb5-lib.h | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/qcom/qpnp-smb5.c b/drivers/power/supply/qcom/qpnp-smb5.c index ac8e0e7b7435..597f5f4ed0aa 100644 --- a/drivers/power/supply/qcom/qpnp-smb5.c +++ b/drivers/power/supply/qcom/qpnp-smb5.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. */ #include @@ -446,6 +446,9 @@ static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node) chg->sw_jeita_enabled = of_property_read_bool(node, "qcom,sw-jeita-enable"); + chg->jeita_arb_enable = of_property_read_bool(node, + "qcom,jeita-arb-enable"); + chg->pd_not_supported = chg->pd_not_supported || of_property_read_bool(node, "qcom,usb-pd-disable"); diff --git a/drivers/power/supply/qcom/smb5-lib.c b/drivers/power/supply/qcom/smb5-lib.c index 82f95d244a58..3819b366f914 100644 --- a/drivers/power/supply/qcom/smb5-lib.c +++ b/drivers/power/supply/qcom/smb5-lib.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. */ #include @@ -8283,7 +8283,8 @@ int smblib_init(struct smb_charger *chg) } rc = qcom_step_chg_init(chg->dev, chg->step_chg_enabled, - chg->sw_jeita_enabled, false, chg->iio_chans); + chg->sw_jeita_enabled, chg->jeita_arb_enable, + chg->iio_chans); if (rc < 0) { smblib_err(chg, "Couldn't init qcom_step_chg_init rc=%d\n", rc); diff --git a/drivers/power/supply/qcom/smb5-lib.h b/drivers/power/supply/qcom/smb5-lib.h index 1ef50504258b..14ca5c5227d5 100644 --- a/drivers/power/supply/qcom/smb5-lib.h +++ b/drivers/power/supply/qcom/smb5-lib.h @@ -519,6 +519,7 @@ struct smb_charger { int fake_batt_status; bool step_chg_enabled; bool sw_jeita_enabled; + bool jeita_arb_enable; bool typec_legacy_use_rp_icl; bool is_hdc; bool chg_done; From d457c7353f465fd6ff4491431f4fa5834a746c82 Mon Sep 17 00:00:00 2001 From: Anirudh Ghayal Date: Wed, 27 Jan 2021 11:13:50 +0530 Subject: [PATCH 2/2] power: smb5-lib: Add additional check to exit charge-termination WA There is a possibility of the "real capacity" dropping post termination due to a OCV update causing the charger-termination WA to exit. Fix this by explicitly checking that we are not in termination before exiting from the WA. Change-Id: I5bf91367b633abf79cbc60ef5bdf93cca9559029 Signed-off-by: Anirudh Ghayal --- drivers/power/supply/qcom/smb5-lib.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/power/supply/qcom/smb5-lib.c b/drivers/power/supply/qcom/smb5-lib.c index 3819b366f914..ca2bb13e6280 100644 --- a/drivers/power/supply/qcom/smb5-lib.c +++ b/drivers/power/supply/qcom/smb5-lib.c @@ -7591,8 +7591,10 @@ static void smblib_chg_termination_work(struct work_struct *work) int val; struct smb_charger *chg = container_of(work, struct smb_charger, chg_termination_work); + union power_supply_propval pval = {0, }; int rc, input_present, delay = CHG_TERM_WA_ENTRY_DELAY_MS; int vbat_now_uv, max_fv_uv; + u8 stat = 0; /* * Hold awake votable to prevent pm_relax being called prior to @@ -7612,6 +7614,21 @@ static void smblib_chg_termination_work(struct work_struct *work) goto out; } + if ((rc < 0) || (pval.intval < 100)) { + rc = smblib_read(chg, BATTERY_CHARGER_STATUS_1_REG, &stat); + if (rc < 0) + goto out; + + /* check we are not in termination to exit the WA */ + if ((stat & BATTERY_CHARGER_STATUS_MASK) != TERMINATE_CHARGE) { + vote(chg->usb_icl_votable, CHG_TERMINATION_VOTER, + false, 0); + vote(chg->dc_suspend_votable, CHG_TERMINATION_VOTER, + false, 0); + goto out; + } + } + /* Get the battery float voltage */ rc = smblib_get_prop_from_bms(chg, SMB5_QG_VOLTAGE_MAX, &val); if (rc < 0) {