summaryrefslogtreecommitdiff
path: root/driver/charger/sm5803.c
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-09-23 21:55:54 -0600
committerCommit Bot <commit-bot@chromium.org>2020-09-25 18:42:06 +0000
commitb4d2fbb10cbc508ed1193d1339f11b9fafb94692 (patch)
tree957650b78ddc972399dd66a7320507bd3a669fa9 /driver/charger/sm5803.c
parent87ec8e1ea0189a5d1bd1c9e1397b9753d92bd8a3 (diff)
downloadchrome-ec-b4d2fbb10cbc508ed1193d1339f11b9fafb94692.tar.gz
SM5803: Prevent brown out on source disable
The PD tasks will disable sourcing on initial boot up. This can cause the SM driver to clear sinking mode, while attempting to clear the sourcing related bits. This change skips disabling source mode if sink mode is currently present. Additionally, it skips the Vbus ramp up wait which enable requires. BRANCH=None BUG=b:168931726 TEST=on waddledee, confirm booting with a battery doesn't brown out with either port. Confirm that FLOW1 is set to zero when sinking dongle is unplugged. Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I3c57d543f012bd0648cf20e0421a58d460ccd475 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2429926 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r--driver/charger/sm5803.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index c39e601ac4..dfbb6a5136 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -1208,7 +1208,6 @@ static enum ec_error_list sm5803_enable_otg_power(int chgnum, int enabled)
{
enum ec_error_list rv;
int reg;
- int selected_current;
if (enabled) {
rv = chg_read8(chgnum, SM5803_REG_ANA_EN1, &reg);
@@ -1252,37 +1251,50 @@ static enum ec_error_list sm5803_enable_otg_power(int chgnum, int enabled)
}
- /*
- * In order to ensure the Vbus output doesn't overshoot too much, turn
- * the starting voltage down to 4.8 V and ramp up after 4 ms
- */
- rv = chg_read8(chgnum, SM5803_REG_DISCH_CONF5, &reg);
- if (rv)
- return rv;
+ if (enabled) {
+ int selected_current;
- selected_current = (reg & SM5803_DISCH_CONF5_CLS_LIMIT) *
- SM5803_CLS_CURRENT_STEP;
- sm5803_set_otg_current_voltage(chgnum, selected_current, 4800);
+ /*
+ * In order to ensure the Vbus output doesn't overshoot too
+ * much, turn the starting voltage down to 4.8 V and ramp up
+ * after 4 ms
+ */
+ rv = chg_read8(chgnum, SM5803_REG_DISCH_CONF5, &reg);
+ if (rv)
+ return rv;
- /*
- * Enable: SOURCE_MODE - enable sourcing out
- * DIRECTCHG_SOURCE_EN - enable current loop (for designs with
- * no external Vbus FET)
- *
- * Disable: disable bits above
- */
- if (enabled)
+ selected_current = (reg & SM5803_DISCH_CONF5_CLS_LIMIT) *
+ SM5803_CLS_CURRENT_STEP;
+ sm5803_set_otg_current_voltage(chgnum, selected_current, 4800);
+
+ /*
+ * Enable: SOURCE_MODE - enable sourcing out
+ * DIRECTCHG_SOURCE_EN - enable current loop
+ * (for designs with no external Vbus FET)
+ */
rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE |
SM5803_FLOW1_DIRECTCHG_SRC_EN,
MASK_SET);
- else
- rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE |
- SM5803_FLOW1_DIRECTCHG_SRC_EN,
- MASK_CLR);
+ usleep(4000);
- usleep(4000);
+ sm5803_set_otg_current_voltage(chgnum, selected_current, 5000);
+ } else {
+ /*
+ * PD tasks will always turn off previous sourcing on init.
+ * Protect ourselves from brown out on init by checking if we're
+ * sinking right now. The init process should only leave sink
+ * mode enabled if a charger is plugged in; otherwise it's
+ * expected to be 0.
+ */
+ rv = chg_read8(chgnum, SM5803_REG_FLOW1, &reg);
+ if (rv)
+ return rv;
- sm5803_set_otg_current_voltage(chgnum, selected_current, 5000);
+ if ((reg & SM5803_FLOW1_MODE) != CHARGER_MODE_SINK)
+ rv = sm5803_flow1_update(chgnum, CHARGER_MODE_SOURCE |
+ SM5803_FLOW1_DIRECTCHG_SRC_EN,
+ MASK_CLR);
+ }
return rv;
}