From 4e6b3d37f5aea2bb5389392236f8a926e110c4cf Mon Sep 17 00:00:00 2001 From: Harry Yang Date: Thu, 27 Jul 2017 12:38:29 -0700 Subject: [PATCH] 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: Harry Yang --- drivers/power/supply/qcom/smb138x-charger.c | 44 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/qcom/smb138x-charger.c b/drivers/power/supply/qcom/smb138x-charger.c index ec74e3825dd5..6e4a3b8a4bdf 100644 --- a/drivers/power/supply/qcom/smb138x-charger.c +++ b/drivers/power/supply/qcom/smb138x-charger.c @@ -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) { @@ -968,6 +975,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) { @@ -1608,14 +1629,33 @@ 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", .owner = THIS_MODULE, .of_match_table = match_table, }, - .probe = smb138x_probe, - .remove = smb138x_remove, + .probe = smb138x_probe, + .remove = smb138x_remove, + .shutdown = smb138x_shutdown, }; module_platform_driver(smb138x_driver);