Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 330bd099 authored by Ashay Jaiswal's avatar Ashay Jaiswal Committed by Umang Agrawal
Browse files

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: default avatarAshay Jaiswal <ashayj@codeaurora.org>
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent 9bc8edeb
Loading
Loading
Loading
Loading
+89 −27
Original line number Diff line number Diff line
/* Copyright (c) 2017 The Linux Foundation. All rights reserved.
/* Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -155,12 +155,22 @@ static void split_settled(struct pl_data *chip)
		total_current_ua = pval.intval;
	}

	/*
	 * 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);
			pr_err("Couldn't change slave suspend state rc=%d\n",
					rc);
			return;
		}

@@ -172,6 +182,26 @@ static void split_settled(struct pl_data *chip)
			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;
	chip->pl_settled_ua = slave_ua;
@@ -634,8 +664,15 @@ static int pl_disable_vote_callback(struct votable *votable,
		get_fcc_split(chip, total_fcc_ua, &master_fcc_ua,
				&slave_fcc_ua);

		chip->slave_fcc_ua = slave_fcc_ua;

		/*
		 * 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,
@@ -650,10 +687,35 @@ static int pl_disable_vote_callback(struct votable *votable,
				POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
				&pval);
			if (rc < 0) {
			pr_err("Couldn't set parallel fcc, rc=%d\n", rc);
				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;

			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;
			}
		}

		/*
		 * Enable will be called with a valid pl_psy always. The
		 * PARALLEL_PSY_VOTER keeps it disabled unless a pl_psy