diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-04-18 10:02:51 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-05-21 14:20:39 -0700 |
commit | 1df7f1fb8b60d3a9314f354eae23db1674704a94 (patch) | |
tree | e41e34f6ffb6a3485feb983acc3eeb2c0efef3af | |
parent | 9a21e92fbc0af22ddc86a29b51d8ecf0ab5e2f76 (diff) | |
download | chrome-ec-1df7f1fb8b60d3a9314f354eae23db1674704a94.tar.gz |
Flapjack: Limit VBUS when charge current is < 1A
Currently, when soc is above 85%, the input voltage is limited to 5V.
With this patch, the VBUS limitation is applied when soc > 85% and the
battery input current is below 1A. When discharging, VBUS can be kept
high.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BRANCH=None
BUG=b/124370341
TEST=Verify Flapjack can charge with a PD charger above 85%.
TEST=Verify VBUS is reduced to 5V when charged through USB-C.
TEST=Verify VBUS is reduced to 5V when charged through WPC.
Change-Id: Ib47d4881e04c68e5e93a2a2292b37c1471b5e79b
Reviewed-on: https://chromium-review.googlesource.com/1573208
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Yilun Lin <yllin@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | board/flapjack/battery.c | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/board/flapjack/battery.c b/board/flapjack/battery.c index 506ea593c3..582b2d2e98 100644 --- a/board/flapjack/battery.c +++ b/board/flapjack/battery.c @@ -16,12 +16,14 @@ #include "extpower.h" #include "gpio.h" #include "hooks.h" +#include "i2c.h" #include "usb_pd.h" #include "util.h" #include "board.h" #include "adc.h" #include "adc_chip.h" #include "math_util.h" +#include "p9221.h" #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) #define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) @@ -346,10 +348,43 @@ int charger_profile_override(struct charge_state_data *curr) /* battery temp in 0.1 deg C */ int temp = curr->batt.temperature - 2731; enum temp_zone zone; + int usb_mv, wpc_mv; + static int previous_usb_mv; + int val; if (curr->state != ST_CHARGE) return 0; + /* Limit input (=VBUS) to 5V when soc > 85% and charge current < 1A. */ + if (!(curr->batt.flags & BATT_FLAG_BAD_CURRENT) && + charge_get_percent() > BAT_LEVEL_PD_LIMIT && + curr->batt.current < 1000 && + curr->batt.current > 0) { + usb_mv = 5500; + wpc_mv = 5500; + } else { + usb_mv = PD_MAX_VOLTAGE_MV; + wpc_mv = P9221_DC_IVL_EPP_MV; + } + + if (usb_mv != previous_usb_mv) + CPRINTS("VBUS limited to %dmV", usb_mv); + previous_usb_mv = usb_mv; + + /* Pull down USB VBUS */ + if (pd_get_max_voltage() != usb_mv) + pd_set_external_voltage_limit(0, usb_mv); + + /* + * Pull down WPC VBUS. Need to use raw i2c APIs because RO + * doesn't have p9221 driver. If WPC is off, this is a no-op. + */ + if (i2c_read_offset16(I2C_PORT_WPC, P9221_R7_ADDR, + P9221R7_VOUT_SET_REG, &val, 1) == EC_SUCCESS + && val * 100 != wpc_mv) + i2c_write_offset16(I2C_PORT_WPC, P9221_R7_ADDR, + P9221R7_VOUT_SET_REG, wpc_mv / 100, 1); + if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) || (temp < temp_zones[batt_type][TEMP_ZONE_0].temp_min)) { zone = TEMP_OUT_OF_RANGE; @@ -398,23 +433,6 @@ DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, board_charge_termination, HOOK_PRIO_DEFAULT); -static void pd_limit_5v(uint8_t en) -{ - int wanted_pd_voltage; - - wanted_pd_voltage = en ? 5500 : PD_MAX_VOLTAGE_MV; - - if (pd_get_max_voltage() != wanted_pd_voltage) - pd_set_external_voltage_limit(0, wanted_pd_voltage); -} - -/* When battery level > BAT_LEVEL_PD_LIMIT, we limit PD voltage to 5V. */ -static void board_pd_voltage(void) -{ - pd_limit_5v(charge_get_percent() > BAT_LEVEL_PD_LIMIT); -} -DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, board_pd_voltage, HOOK_PRIO_DEFAULT); - /* Customs options controllable by host command. */ #define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0) |