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

Commit 6899c6bf authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar
Browse files

smb-lib: improve handling of usbin plugin interrupt



Currently the code disables the dpdm regulator if VBUS is present and
regulator is enabled.

It could happen that the charger oscillates its VBUS as it settles and
based on the delay's in responding to an interrupt, the software could
read vbus_present while the regulator was enabled earlier causing an
incorrect disable of the dpdm regulator.

It is required to ignore the interrupt in such cases.

Change-Id: I882780c1bcbc7713973eda5383291d891787f144
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent bc356bec
Loading
Loading
Loading
Loading
+24 −21
Original line number Diff line number Diff line
@@ -1280,15 +1280,6 @@ irqreturn_t smblib_handle_usb_plugin(int irq, void *data)
	int rc;
	u8 stat;

	rc = smblib_read(chg, USBIN_BASE + INT_RT_STS_OFFSET, &stat);
	if (rc < 0) {
		dev_err(chg->dev, "Couldn't read USB_INT_RT_STS rc=%d\n",
			rc);
		return IRQ_HANDLED;
	}

	chg->vbus_present = (bool)(stat & USBIN_PLUGIN_RT_STS_BIT);

	/* fetch the DPDM regulator */
	if (!chg->dpdm_reg && of_get_property(chg->dev->of_node,
					      "dpdm-supply", NULL)) {
@@ -1303,19 +1294,31 @@ irqreturn_t smblib_handle_usb_plugin(int irq, void *data)
	if (!chg->dpdm_reg)
		goto skip_dpdm_float;

	if (chg->vbus_present && !regulator_is_enabled(chg->dpdm_reg)) {
	rc = smblib_read(chg, USBIN_BASE + INT_RT_STS_OFFSET, &stat);
	if (rc < 0) {
		dev_err(chg->dev, "Couldn't read USB_INT_RT_STS rc=%d\n", rc);
		return IRQ_HANDLED;
	}

	chg->vbus_present = (bool)(stat & USBIN_PLUGIN_RT_STS_BIT);

	if (chg->vbus_present) {
		if (!regulator_is_enabled(chg->dpdm_reg)) {
			smblib_dbg(chg, PR_MISC, "enabling DPDM regulator\n");
			rc = regulator_enable(chg->dpdm_reg);
			if (rc < 0)
				dev_err(chg->dev, "Couldn't enable dpdm regulator rc=%d\n",
					rc);
	} else if (regulator_is_enabled(chg->dpdm_reg)) {
		}
	} else {
		if (regulator_is_enabled(chg->dpdm_reg)) {
			smblib_dbg(chg, PR_MISC, "disabling DPDM regulator\n");
			rc = regulator_disable(chg->dpdm_reg);
			if (rc < 0)
				dev_err(chg->dev, "Couldn't disable dpdm regulator rc=%d\n",
					rc);
		}
	}

skip_dpdm_float:
	smblib_dbg(chg, PR_INTERRUPT, "IRQ: %s %s\n",