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

Commit 683d9f4e authored by Harry Yang's avatar Harry Yang
Browse files

qcom: smb138x: supsend USBIN and disable OTG before shutdown



SMB138X does not get reset when device restarts, so USBIN and OTG settings
will not be cleared. Reset them on PMIC shutdown, and restore in probe.

Disable OTG in early driver probe, because device may restart from WDOG
bite with OTG enabled.

CRs-Fixed: 2083638
Change-Id: I451d3e861ea28f89029fe8759599ac0e133baf11
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 379c6aea
Loading
Loading
Loading
Loading
+42 −2
Original line number Diff line number Diff line
@@ -871,6 +871,13 @@ static int smb138x_init_slave_hw(struct smb138x *chip)
		return rc;
	}

	/* Disable OTG */
	rc = smblib_masked_write(chg, CMD_OTG_REG, OTG_EN_BIT, 0);
	if (rc < 0) {
		pr_err("Couldn't disable OTG rc=%d\n", rc);
		return rc;
	}

	/* suspend parallel charging */
	rc = smb138x_set_parallel_suspend(chip, true);
	if (rc < 0) {
@@ -976,6 +983,20 @@ static int smb138x_init_hw(struct smb138x *chip)

	chg->dcp_icl_ua = chip->dt.usb_icl_ua;

	/* Disable OTG */
	rc = smblib_masked_write(chg, CMD_OTG_REG, OTG_EN_BIT, 0);
	if (rc < 0) {
		pr_err("Couldn't disable OTG rc=%d\n", rc);
		return rc;
	}

	/* Unsuspend USB input */
	rc = smblib_masked_write(chg, USBIN_CMD_IL_REG, USBIN_SUSPEND_BIT, 0);
	if (rc < 0) {
		pr_err("Couldn't unsuspend USB, rc=%d\n", rc);
		return rc;
	}

	/* configure to a fixed 700khz freq to avoid tdie errors */
	rc = smblib_set_charge_param(chg, &chg->param.freq_buck, 700);
	if (rc < 0) {
@@ -1616,6 +1637,24 @@ static int smb138x_remove(struct platform_device *pdev)
	return 0;
}

static void smb138x_shutdown(struct platform_device *pdev)
{
	struct smb138x *chip = platform_get_drvdata(pdev);
	struct smb_charger *chg = &chip->chg;
	int rc;

	/* Suspend charging */
	rc = smb138x_set_parallel_suspend(chip, true);
	if (rc < 0)
		pr_err("Couldn't suspend charging rc=%d\n", rc);

	/* Disable OTG */
	rc = smblib_masked_write(chg, CMD_OTG_REG, OTG_EN_BIT, 0);
	if (rc < 0)
		pr_err("Couldn't disable OTG rc=%d\n", rc);

}

static struct platform_driver smb138x_driver = {
	.driver	= {
		.name		= "qcom,smb138x-charger",
@@ -1624,6 +1663,7 @@ static struct platform_driver smb138x_driver = {
	},
	.probe		= smb138x_probe,
	.remove		= smb138x_remove,
	.shutdown	= smb138x_shutdown,
};
module_platform_driver(smb138x_driver);