From 6e0dd622e2f4d83432f0b518b58cf99645097ab4 Mon Sep 17 00:00:00 2001 From: Michael5 Chen Date: Tue, 27 Aug 2019 10:27:58 +0800 Subject: rammus: Set input voltage to 9V when batt full To reduce our power consumption in our lowest power state, we should reduce the charger's input voltage down to 9V when the battery is full and we are no longer charging it. This commit will trigger a PD negotiation to select a 9V source cap. BUG=b:139429471 BRANCH=firmware-rammus-11275.B TEST=Manual Power team check power consumption under S5. Change-Id: I88517255b196ca56660441270fe01143f97f4f4d Signed-off-by: Michael5 Chen Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1772576 Reviewed-by: Zhuohao Lee Commit-Queue: Zhuohao Lee --- board/rammus/battery.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/board/rammus/battery.c b/board/rammus/battery.c index 916aac5fd3..d0cc2f13d2 100644 --- a/board/rammus/battery.c +++ b/board/rammus/battery.c @@ -7,11 +7,15 @@ #include "battery.h" #include "battery_smart.h" +#include "charge_manager.h" #include "charge_state.h" +#include "chipset.h" #include "console.h" #include "ec_commands.h" #include "extpower.h" +#include "hooks.h" #include "gpio.h" +#include "usb_pd.h" #include "util.h" static enum battery_present batt_pres_prev = BP_NOT_SURE; @@ -128,3 +132,28 @@ enum battery_present battery_is_present(void) return batt_pres; } +static void reduce_input_voltage_when_full(void) +{ + struct batt_params batt; + int max_pd_voltage_mv; + int active_chg_port; + + active_chg_port = charge_manager_get_active_charge_port(); + if (active_chg_port == CHARGE_PORT_NONE) + return; + + battery_get_params(&batt); + if (!(batt.flags & BATT_FLAG_BAD_STATUS)) { + /* Lower our input voltage to 9V when battery is full. */ + if ((batt.status & STATUS_FULLY_CHARGED) && + chipset_in_state(CHIPSET_STATE_ANY_OFF)) + max_pd_voltage_mv = 9000; + else + max_pd_voltage_mv = PD_MAX_VOLTAGE_MV; + + if (pd_get_max_voltage() != max_pd_voltage_mv) + pd_set_external_voltage_limit(active_chg_port, + max_pd_voltage_mv); + } +} +DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full, HOOK_PRIO_DEFAULT); -- cgit v1.2.1