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 | |
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>
-rw-r--r-- | driver/charger/sm5803.c | 54 | ||||
-rw-r--r-- | driver/charger/sm5803.h | 16 |
2 files changed, 66 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) { diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h index 79dbd55129..e1a3e10560 100644 --- a/driver/charger/sm5803.h +++ b/driver/charger/sm5803.h @@ -8,6 +8,8 @@ #ifndef __CROS_EC_SM5803_H #define __CROS_EC_SM5803_H +#include "common.h" + /* Note: configure charger struct with CHARGER_FLAGS */ #define SM5803_ADDR_MAIN_FLAGS 0x30 #define SM5803_ADDR_MEAS_FLAGS 0x31 @@ -132,6 +134,8 @@ enum sm5803_gpio0_modes { /* Note: Threshold registers all assume lower 2 bits are 0 */ #define SM5803_REG_VBUS_LOW_TH 0x1A #define SM5803_REG_VBUS_HIGH_TH 0x2A +#define SM5803_REG_VCHG_PWR_LOW_TH 0x1B +#define SM5803_REG_VCHG_PWR_HIGH_TH 0x2B #define SM5803_REG_TINT_LOW_TH 0x1D #define SM5803_REG_TINT_HIGH_TH 0x2D @@ -172,6 +176,9 @@ enum sm5803_gpio0_modes { #define SM5803_VBUS_MEAS_OV_TEMP BIT(5) #define SM5803_VBUS_MEAS_CHG_DET BIT(6) +/* VCHGPWR levels - The VCHGPWR levels increment in 23.4mV steps. */ +#define SM5803_REG_VCHG_PWR_MSB 0x4A + #define SM5803_REG_TINT_MEAS_MSB 0x4E /* VSYS levels - The VSYS levels increment in 23.4mV steps. */ @@ -382,6 +389,15 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable); void sm5803_hibernate(int chgnum); void sm5803_interrupt(int chgnum); +/** + * Return whether ACOK is high or low. + * + * @param chgnum index into chg_chips table. + * @param acok will be set to true if ACOK is asserted, otherwise false. + * @return EC_SUCCESS, error otherwise. + */ +enum ec_error_list sm5803_is_acok(int chgnum, bool *acok); + /* Expose low power mode functions */ void sm5803_disable_low_power_mode(int chgnum); void sm5803_enable_low_power_mode(int chgnum); |