From a51524b9ff16588c30d5b16716a2b8f8cc4f5592 Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Thu, 20 Sep 2018 11:58:36 -0700 Subject: CHERRY-PICK: nocturne: 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:116125689 BRANCH=firmware-nocturne-10984.B TEST=Let battery discharge that it will accept current, plug in blackcat, verify that it chooses a 15V contract. Wait until battery gets full and stops accepting current, verify that the new explicit contract is for 9V. TEST=While battery is full, turn on AP, verify that contract changes to 15V/3A. Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/1239550 Reviewed-by: Furquan Shaikh Commit-Queue: Aseda Aboagye Tested-by: Aseda Aboagye Change-Id: I8a1ad7b289d4d2a74661658d707c5f9bd44444a9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2157059 Tested-by: Patryk Duda Commit-Queue: Patryk Duda Reviewed-by: Aseda Aboagye --- board/nocturne/battery.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'board/nocturne') diff --git a/board/nocturne/battery.c b/board/nocturne/battery.c index 73feb6ecc3..3db5fede33 100644 --- a/board/nocturne/battery.c +++ b/board/nocturne/battery.c @@ -7,9 +7,14 @@ #include "battery.h" #include "battery_smart.h" +#include "charge_manager.h" +#include "chipset.h" #include "common.h" +#include "console.h" #include "ec_commands.h" #include "extpower.h" +#include "hooks.h" +#include "usb_pd.h" /* Shutdown mode parameter to write to manufacturer access register */ #define SB_SHUTDOWN_DATA 0x0010 @@ -84,3 +89,29 @@ enum battery_disconnect_state battery_get_disconnect_state(void) /* No safety fault, battery is disconnected */ return BATTERY_DISCONNECTED; } + +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