diff options
author | Aseda Aboagye <aaboagye@google.com> | 2021-05-17 20:23:14 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-19 20:26:19 +0000 |
commit | 48c2e894a960a186a1b19b21ad270d7a2f62ed00 (patch) | |
tree | 718aa2e88b057b0eb9e9d86e5a91e10bd6ccb3f9 /driver/charger/sm5803.c | |
parent | 477dda563e0ee3bb831ebb8883cb72903bbb8141 (diff) | |
download | chrome-ec-48c2e894a960a186a1b19b21ad270d7a2f62ed00.tar.gz |
sm5803: Add sm5803_is_acok()
This commit adds a function to return whether the voltage before the
switching FETs is greater than ~4V. This would generally be the
criteria for other buck-boost chargers which have an "ACOK" signal.
BUG=b:187965740
BRANCH=dedede
TEST=With other changes, build and flash drawcia, verify that "AC on"
prints are only printed when we decide to charge from a port and not
just when VBUS is present
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: If3a5398197fb0a251b5290d107daf88e56ca12b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2901253
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r-- | driver/charger/sm5803.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 81108e7506..d4a20826a7 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -9,6 +9,7 @@ #include "battery_smart.h" #include "charge_state_v2.h" #include "charger.h" +#include "extpower.h" #include "gpio.h" #include "hooks.h" #include "i2c.h" @@ -624,6 +625,12 @@ static void sm5803_init(int chgnum) rv = chg_write8(chgnum, SM5803_REG_DPM_VL_SET_MSB, (reg >> 3)); rv |= chg_write8(chgnum, SM5803_REG_DPM_VL_SET_LSB, (reg & 0x7)); + /* Set the VCHGPWR thresholds to mirror those for VBUS. */ + rv |= meas_write8(chgnum, SM5803_REG_VCHG_PWR_HIGH_TH, + SM5803_VBUS_HIGH_LEVEL); + rv |= meas_write8(chgnum, SM5803_REG_VCHG_PWR_LOW_TH, + SM5803_VBUS_LOW_LEVEL); + /* Set default input current */ reg = SM5803_CURRENT_TO_REG(CONFIG_CHARGER_INPUT_CURRENT) & SM5803_CHG_ILIM_RAW; @@ -647,8 +654,11 @@ static void sm5803_init(int chgnum) SM5803_TINT_MIN_LEVEL); - /* Configure TINT interrupts to fire after thresholds are set */ - rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT); + /* + * Configure TINT & VCHGPWR interrupts to fire after thresholds are set + */ + rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT | + SM5803_INT2_VCHGPWR); /* * Configure CHG_ENABLE to only be set through I2C by setting @@ -1020,12 +1030,10 @@ void sm5803_handle_interrupt(int chgnum) charger_vbus[chgnum] = 0; if (IS_ENABLED(CONFIG_USB_CHARGER)) usb_charger_vbus_change(chgnum, 0); - board_vbus_present_change(); } else { charger_vbus[chgnum] = 1; if (IS_ENABLED(CONFIG_USB_CHARGER)) usb_charger_vbus_change(chgnum, 1); - board_vbus_present_change(); } } @@ -1070,6 +1078,10 @@ void sm5803_handle_interrupt(int chgnum) */ } + /* Update extpower if VCHGPWR changes. */ + if (int_reg & SM5803_INT2_VCHGPWR) + board_vbus_present_change(); + /* TODO(b/159376384): Take action on fatal BFET power alert. */ rv = main_read8(chgnum, SM5803_REG_INT3_REQ, &int_reg); if (rv) { @@ -1474,6 +1486,40 @@ static enum ec_error_list sm5803_get_option(int chgnum, int *option) return rv; } +enum ec_error_list sm5803_is_acok(int chgnum, bool *acok) +{ + int rv; + enum sm5803_charger_modes mode; + int reg; + + rv = chg_read8(chgnum, SM5803_REG_FLOW1, ®); + if (rv) + return rv; + + /* The charger mode is contained in the last 2 bits. */ + reg &= SM5803_FLOW1_MODE; + mode = (enum sm5803_charger_modes)reg; + + /* If we're not sinking, then AC can't be OK. */ + if (mode != CHARGER_MODE_SINK) { + *acok = false; + return EC_SUCCESS; + } + + /* + * Okay, we're sinking. Check that VCHGPWR has some voltage. This + * should indicate that the path is good. + */ + rv = meas_read8(chgnum, SM5803_REG_VCHG_PWR_MSB, ®); + if (rv) + return rv; + + /* Assume that ACOK would be asserted if VCHGPWR is higher than ~4V. */ + *acok = reg >= SM5803_VBUS_HIGH_LEVEL; + + return EC_SUCCESS; +} + static enum ec_error_list sm5803_is_input_current_limit_reached(int chgnum, bool *reached) { |