From e353ab03638d4a58540cc8d933a6fa8a8f52dd21 Mon Sep 17 00:00:00 2001 From: Divya Sasidharan Date: Tue, 29 Mar 2016 16:46:38 -0700 Subject: [PATCH] pd: Fix multiple reboot for battery cut-off In case of boot after battery is cut-off without this change the battery is assumed to be present even though it is not initialized and ready to provide power in try source enable function. With this assumption charger is disconnected momentarily which causes reboot. Also make sure that try source enable is updated after battery is ready by notifying hook call HOOK_BATTERY_SOC_CHANGE. BUG=chrome-os-partner:51753 BRANCH=firmware-glados-7820.B TEST=Enter battery cutoff command from EC console to enter into ship mode and plug-in AC, verified no reboots happen. Change-Id: I6f7656125717f85851f5ad4e37dfd953a52799c6 Signed-off-by: Divya Sasidharan Reviewed-on: https://chromium-review.googlesource.com/335913 Reviewed-by: Shawn N (cherry picked from commit 10040ac6284efe88b74193bdbb0c05ec92b563b4) Reviewed-on: https://chromium-review.googlesource.com/336697 Commit-Ready: Divya S Sasidharan Tested-by: Divya Jyothi --- common/charge_state_v2.c | 1 + common/usb_pd_protocol.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 1fc4f7ff02..37ebb38032 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -657,6 +657,7 @@ void charger_task(void) curr.desired_input_current = get_desired_input_current(prev_bp, info); charger_set_input_current(curr.desired_input_current); + hook_notify(HOOK_BATTERY_SOC_CHANGE); } /* diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 2e34367459..358660d5d4 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1214,6 +1214,15 @@ static void pd_update_try_source(void) */ pd_try_src_enable = drp_state == PD_DRP_TOGGLE_ON && batt_soc >= CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC; +#if defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \ + defined(CONFIG_BATTERY_PRESENT_GPIO) + /* + * When battery is cutoff in ship mode it may not be reliable to + * check if battery is present with its state of charge. + * Also check if battery is initialized and ready to provide power. + */ + pd_try_src_enable &= (battery_is_present() == BP_YES); +#endif /* * Clear this flag to cover case where a TrySrc