summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-04-18 10:02:51 -0700
committerYH Lin <yueherngl@chromium.org>2019-05-10 22:09:09 +0000
commit8299be183a457a4c0b008a9b574a810ada3f0816 (patch)
treedf2ef2b217898ce3a4dbe6ad1a9cf7121c107f43
parent4fe989a87a4703c0a7891e4142f42feeca7e1d9f (diff)
downloadchrome-ec-8299be183a457a4c0b008a9b574a810ada3f0816.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. 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/c/chromiumos/platform/ec/+/1606740 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/flapjack/battery.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/board/flapjack/battery.c b/board/flapjack/battery.c
index 506ea593c3..0e2f25a464 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,42 @@ 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) {
+ 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 VBUS from USB */
+ if (pd_get_max_voltage() != usb_mv)
+ pd_set_external_voltage_limit(0, usb_mv);
+
+ /*
+ * Pull down VBUS from WPC. Need to use 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 +432,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)