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

Commit 055b00b7 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: supply: qti_battery_charger: Fix FCC configuration



With adding support to restricted charging through properties
restricted_chg and restricted_cur under /sys/class/qcom-battery,
configuring fast charging current (FCC) via "charge_control"
property in battery power supply is not working as expected.
Especially, when the restricted charging is disabled, FCC
configured (i.e. after setting it in ascending order first and
in descending order) is based on the previous request instead of
the current request. Fix it.

Fixes: 9c3f7e47 ("power: supply: qti_battery_charger: add some more properties")
Change-Id: I6c591a0e1e914b37764350fb7389824410800868
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 1f8ff78e
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -939,10 +939,10 @@ static int __battery_psy_set_charge_current(struct battery_chg_dev *bcdev,
{
	int rc;

	if (bcdev->restrict_chg_en)
	if (bcdev->restrict_chg_en) {
		fcc_ua = min_t(u32, fcc_ua, bcdev->restrict_fcc_ua);
		fcc_ua = min_t(u32, fcc_ua, bcdev->thermal_fcc_ua);
	else
		fcc_ua = bcdev->thermal_fcc_ua;
	}

	rc = write_property_id(bcdev, &bcdev->psy_list[PSY_TYPE_BATTERY],
				BATT_CHG_CTRL_LIM, fcc_ua);
@@ -958,7 +958,7 @@ static int battery_psy_set_charge_current(struct battery_chg_dev *bcdev,
					int val)
{
	int rc;
	u32 fcc_ua;
	u32 fcc_ua, prev_fcc_ua;

	if (!bcdev->num_thermal_levels)
		return 0;
@@ -972,12 +972,14 @@ static int battery_psy_set_charge_current(struct battery_chg_dev *bcdev,
		return -EINVAL;

	fcc_ua = bcdev->thermal_levels[val];
	prev_fcc_ua = bcdev->thermal_fcc_ua;
	bcdev->thermal_fcc_ua = fcc_ua;

	rc = __battery_psy_set_charge_current(bcdev, fcc_ua);
	if (!rc) {
	if (!rc)
		bcdev->curr_thermal_level = val;
		bcdev->thermal_fcc_ua = fcc_ua;
	}
	else
		bcdev->thermal_fcc_ua = prev_fcc_ua;

	return rc;
}
@@ -1392,18 +1394,20 @@ static ssize_t restrict_cur_store(struct class *c, struct class_attribute *attr,
	struct battery_chg_dev *bcdev = container_of(c, struct battery_chg_dev,
						battery_class);
	int rc;
	u32 val;
	u32 fcc_ua, prev_fcc_ua;

	if (kstrtou32(buf, 0, &val) || val > bcdev->thermal_fcc_ua)
	if (kstrtou32(buf, 0, &fcc_ua) || fcc_ua > bcdev->thermal_fcc_ua)
		return -EINVAL;

	prev_fcc_ua = bcdev->restrict_fcc_ua;
	bcdev->restrict_fcc_ua = fcc_ua;
	if (bcdev->restrict_chg_en) {
		rc = __battery_psy_set_charge_current(bcdev, val);
		if (rc < 0)
		rc = __battery_psy_set_charge_current(bcdev, fcc_ua);
		if (rc < 0) {
			bcdev->restrict_fcc_ua = prev_fcc_ua;
			return rc;
		}

	bcdev->restrict_fcc_ua = val;
	}

	return count;
}
@@ -1430,8 +1434,8 @@ static ssize_t restrict_chg_store(struct class *c, struct class_attribute *attr,
		return -EINVAL;

	bcdev->restrict_chg_en = val;

	rc = __battery_psy_set_charge_current(bcdev, bcdev->restrict_fcc_ua);
	rc = __battery_psy_set_charge_current(bcdev, bcdev->restrict_chg_en ?
			bcdev->restrict_fcc_ua : bcdev->thermal_fcc_ua);
	if (rc < 0)
		return rc;