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

Commit 4915375b authored by Umang Agrawal's avatar Umang Agrawal Committed by Guru Das Srinagesh
Browse files

power: smb1390-psy: Allow taper exit if increase in float voltage



Due to reduction of float voltage in JEITA condition, taper charging
can be initiated at a lower float voltage value. On removal of JEITA
condition, float voltage scales back to its default value, but as per
current SW design, once taper charging is initiated, charge pump holds
its reduction vote on FCC until disabled. Due to this, FCC does not
scale back to its default value, restricting charge current further
down the charge cycle.

Add support to exit taper charging on increase in float voltage if it
was initiated on reduced float voltage.

Change-Id: Ib072df1ec2d96593ba4bb67b37012c0f245a3f4a
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent 223d73fb
Loading
Loading
Loading
Loading
+48 −8
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@
#define CP_VOTER		"CP_VOTER"
#define USER_VOTER		"USER_VOTER"
#define ILIM_VOTER		"ILIM_VOTER"
#define TAPER_END_VOTER		"TAPER_END_VOTER"
#define FCC_VOTER		"FCC_VOTER"
#define ICL_VOTER		"ICL_VOTER"
#define WIRELESS_VOTER		"WIRELESS_VOTER"
@@ -122,6 +123,7 @@ struct smb1390 {
	struct votable		*disable_votable;
	struct votable		*ilim_votable;
	struct votable		*fcc_votable;
	struct votable		*fv_votable;
	struct votable		*cp_awake_votable;

	/* power supplies */
@@ -135,6 +137,7 @@ struct smb1390 {
	bool			taper_work_running;
	struct smb1390_iio	iio;
	int			irq_status;
	int			taper_entry_fv;
};

struct smb_irq {
@@ -204,6 +207,19 @@ static bool is_psy_voter_available(struct smb1390 *chip)
		}
	}

	if (!chip->fv_votable) {
		chip->fv_votable = find_votable("FV");
		if (!chip->fv_votable) {
			pr_debug("Couldn't find FV votable\n");
			return false;
		}
	}

	if (!chip->disable_votable) {
		pr_debug("Couldn't find CP DISABLE votable\n");
		return false;
	}

	return true;
}

@@ -546,6 +562,14 @@ static void smb1390_status_change_work(struct work_struct *work)
								pval.intval);
		}

		/*
		 * Remove SMB1390 Taper condition disable vote if float voltage
		 * increased in comparison to voltage at which it entered taper.
		 */
		if (chip->taper_entry_fv <
				get_effective_result(chip->fv_votable))
			vote(chip->disable_votable, TAPER_END_VOTER, false, 0);

		/*
		 * all votes that would result in disabling the charge pump have
		 * been cast; ensure the charhe pump is still enabled before
@@ -572,6 +596,7 @@ static void smb1390_status_change_work(struct work_struct *work)
		}
	} else {
		vote(chip->disable_votable, SRC_VOTER, true, 0);
		vote(chip->disable_votable, TAPER_END_VOTER, false, 0);
		vote(chip->fcc_votable, CP_VOTER, false, 0);
	}

@@ -589,11 +614,8 @@ static void smb1390_taper_work(struct work_struct *work)
	if (!is_psy_voter_available(chip))
		goto out;

	do {
		fcc_uA = get_effective_result(chip->fcc_votable) - 100000;
		pr_debug("taper work reducing FCC to %duA\n", fcc_uA);
		vote(chip->fcc_votable, CP_VOTER, true, fcc_uA);

	chip->taper_entry_fv = get_effective_result(chip->fv_votable);
	while (true) {
		rc = power_supply_get_property(chip->batt_psy,
					POWER_SUPPLY_PROP_CHARGE_TYPE, &pval);
		if (rc < 0) {
@@ -601,12 +623,30 @@ static void smb1390_taper_work(struct work_struct *work)
			goto out;
		}

		msleep(500);
	} while (fcc_uA >= 2000000
		 && pval.intval == POWER_SUPPLY_CHARGE_TYPE_TAPER);
		if (pval.intval == POWER_SUPPLY_CHARGE_TYPE_TAPER) {
			fcc_uA = get_effective_result(chip->fcc_votable)
								- 100000;
			pr_debug("taper work reducing FCC to %duA\n", fcc_uA);
			vote(chip->fcc_votable, CP_VOTER, true, fcc_uA);

			if (fcc_uA < 2000000) {
				vote(chip->disable_votable, TAPER_END_VOTER,
								true, 0);
				goto out;
			}
		} else if (get_effective_result(chip->fv_votable) >
						chip->taper_entry_fv) {
			pr_debug("Float voltage increased. Exiting taper\n");
			goto out;
		} else {
			pr_debug("In fast charging. Wait for next taper\n");
		}

		msleep(500);
	}
out:
	pr_debug("taper work exit\n");
	vote(chip->fcc_votable, CP_VOTER, false, 0);
	chip->taper_work_running = false;
}