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

Commit 210b17b0 authored by Zhenhua Huang's avatar Zhenhua Huang Committed by Abhijeet Dharmapurikar
Browse files

power: smb1351-charger: add support for recovering from USB over voltage



The current driver indicates usb removal on a USB OV event.
There is also a need to notify usb insertion when charger
voltage back to normal.

In the meantime, fix a bug for the conflict between USB OV
interrupt and source detect interrupt by adding a USB OV check
in source detect interrupt handler.

CRs-Fixed: 841380
Change-Id: I3ef881552cfe610cace1ed438a7b85f06cacc11f
Signed-off-by: default avatarZhenhua Huang <zhenhuah@codeaurora.org>
parent 5b273681
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -447,6 +447,7 @@ struct smb1351_charger {
	bool			parallel_charger_present;
	bool			bms_controlled_charging;
	bool			apsd_rerun;
	bool			usbin_ov;
	bool			chg_remove_work_scheduled;
	bool			force_hvdcp_2p0;

@@ -1803,9 +1804,10 @@ static int smb1351_apsd_complete_handler(struct smb1351_charger *chip,
	 * If apsd is disabled, charger detection is done by
	 * USB phy driver.
	 */
	if (chip->disable_apsd) {
	if (chip->disable_apsd || chip->usbin_ov) {
		pr_debug("APSD %s, status = %d\n",
			chip->disable_apsd ? "disabled" : "enabled", !!status);
		pr_debug("USBIN ov, status = %d\n", chip->usbin_ov);
		return 0;
	}

@@ -1977,13 +1979,27 @@ static int smb1351_usbin_uv_handler(struct smb1351_charger *chip, u8 status)
static int smb1351_usbin_ov_handler(struct smb1351_charger *chip, u8 status)
{
	int health;
	int rc;
	u8 reg;

	rc = smb1351_read_reg(chip, IRQ_E_REG, &reg);
	if (rc)
		pr_err("Couldn't read IRQ_E rc = %d\n", rc);

	if (status != 0) {
		chip->chg_present = false;
		chip->usbin_ov = true;
		power_supply_set_supply_type(chip->usb_psy,
						POWER_SUPPLY_TYPE_UNKNOWN);
		power_supply_set_present(chip->usb_psy, chip->chg_present);
	} else {
		chip->usbin_ov = false;
		if (reg & IRQ_USBIN_UV_BIT)
			pr_debug("Charger unplugged from OV\n");
		else
			smb1351_apsd_complete_handler(chip, 1);
	}

	if (chip->usb_psy) {
		health = status ? POWER_SUPPLY_HEALTH_OVERVOLTAGE
					: POWER_SUPPLY_HEALTH_GOOD;