From 1ecbc6d7ead288248e46defc5759e96ddf6d16ef Mon Sep 17 00:00:00 2001 From: Ashay Jaiswal Date: Thu, 16 Nov 2017 14:02:20 +0530 Subject: battery: fix ordering of ICL/FCC configuration Current parallel design has fixed order of configuring ICL/FCC between main and parallel charger, this could lead to a situation where total(main + parallel) ICL/FCC goes beyond maximum configured value. Fix this by dynamic ordering of ICL/FCC between main and parallel based on AICL change. CRs-Fixed: 2148379 Change-Id: Ia1ff7093d1de9205ce8072760c80ba0a58638462 Signed-off-by: Ashay Jaiswal --- drivers/power/supply/qcom/battery.c | 114 ++++++++++++++++++++++++++++-------- 1 file changed, 88 insertions(+), 26 deletions(-) diff --git a/drivers/power/supply/qcom/battery.c b/drivers/power/supply/qcom/battery.c index cb26658e564e..68640e349765 100644 --- a/drivers/power/supply/qcom/battery.c +++ b/drivers/power/supply/qcom/battery.c @@ -145,22 +145,52 @@ static void split_settled(struct pl_data *chip) total_current_ua = pval.intval; } - pval.intval = total_current_ua - slave_ua; - /* Set ICL on main charger */ - rc = power_supply_set_property(chip->main_psy, + /* + * If there is an increase in slave share + * (Also handles parallel enable case) + * Set Main ICL then slave ICL + * else + * (Also handles parallel disable case) + * Set slave ICL then main ICL. + */ + if (slave_ua > chip->pl_settled_ua) { + pval.intval = total_current_ua - slave_ua; + /* Set ICL on main charger */ + rc = power_supply_set_property(chip->main_psy, POWER_SUPPLY_PROP_CURRENT_MAX, &pval); - if (rc < 0) { - pr_err("Couldn't change slave suspend state rc=%d\n", rc); - return; - } + if (rc < 0) { + pr_err("Couldn't change slave suspend state rc=%d\n", + rc); + return; + } - /* set parallel's ICL could be 0mA when pl is disabled */ - pval.intval = slave_ua; - rc = power_supply_set_property(chip->pl_psy, - POWER_SUPPLY_PROP_CURRENT_MAX, &pval); - if (rc < 0) { - pr_err("Couldn't set parallel icl, rc=%d\n", rc); - return; + /* set parallel's ICL could be 0mA when pl is disabled */ + pval.intval = slave_ua; + rc = power_supply_set_property(chip->pl_psy, + POWER_SUPPLY_PROP_CURRENT_MAX, &pval); + if (rc < 0) { + pr_err("Couldn't set parallel icl, rc=%d\n", rc); + return; + } + } else { + /* set parallel's ICL could be 0mA when pl is disabled */ + pval.intval = slave_ua; + rc = power_supply_set_property(chip->pl_psy, + POWER_SUPPLY_PROP_CURRENT_MAX, &pval); + if (rc < 0) { + pr_err("Couldn't set parallel icl, rc=%d\n", rc); + return; + } + + pval.intval = total_current_ua - slave_ua; + /* Set ICL on main charger */ + rc = power_supply_set_property(chip->main_psy, + POWER_SUPPLY_PROP_CURRENT_MAX, &pval); + if (rc < 0) { + pr_err("Couldn't change slave suspend state rc=%d\n", + rc); + return; + } } chip->total_settled_ua = total_settled_ua; @@ -429,24 +459,56 @@ static int pl_fcc_vote_callback(struct votable *votable, void *data, get_fcc_split(chip, total_fcc_ua, &master_fcc_ua, &slave_fcc_ua); - pval.intval = slave_fcc_ua; - rc = power_supply_set_property(chip->pl_psy, + /* + * If there is an increase in slave share + * (Also handles parallel enable case) + * Set Main ICL then slave FCC + * else + * (Also handles parallel disable case) + * Set slave ICL then main FCC. + */ + if (slave_fcc_ua > chip->slave_fcc_ua) { + pval.intval = master_fcc_ua; + rc = power_supply_set_property(chip->main_psy, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, &pval); - if (rc < 0) { - pr_err("Couldn't set parallel fcc, rc=%d\n", rc); - return rc; - } + if (rc < 0) { + pr_err("Could not set main fcc, rc=%d\n", rc); + return rc; + } + + pval.intval = slave_fcc_ua; + rc = power_supply_set_property(chip->pl_psy, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, + &pval); + if (rc < 0) { + pr_err("Couldn't set parallel fcc, rc=%d\n", + rc); + return rc; + } + + chip->slave_fcc_ua = slave_fcc_ua; + } else { + pval.intval = slave_fcc_ua; + rc = power_supply_set_property(chip->pl_psy, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, + &pval); + if (rc < 0) { + pr_err("Couldn't set parallel fcc, rc=%d\n", + rc); + return rc; + } - chip->slave_fcc_ua = slave_fcc_ua; + chip->slave_fcc_ua = slave_fcc_ua; - pval.intval = master_fcc_ua; - rc = power_supply_set_property(chip->main_psy, + pval.intval = master_fcc_ua; + rc = power_supply_set_property(chip->main_psy, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, &pval); - if (rc < 0) { - pr_err("Could not set main fcc, rc=%d\n", rc); - return rc; + if (rc < 0) { + pr_err("Could not set main fcc, rc=%d\n", rc); + return rc; + } } } -- cgit v1.2.3