From 33fe5e437da4233f6a716c6eab2f44620efef1d7 Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Wed, 27 Jan 2016 11:43:05 -0800 Subject: charger/Kunimitsu: Fix for boot from cut-off battery Battery in cut-off mode wakes when voltage is applied to the PACK and takes approximately 2 to 3 seconds to initialize before capable of providing the power. Hence made the battery present status to BP_NO in case of cut-off mode. Once the battery is ready new status is updated as BP_YES. When the battery status changes from BP_NO to BP_YES, charger input current is set to board specific charger input current which is not sufficient to boot the AP hence the system reboots. To avoid this issue, added code to write charger manager negotiated current to charger input current when the battery status changes from BP_NO to BP_YES. BRANCH=none BUG=chrome-os-partner:49224 TEST=Manually tested on Kunimitsu. Used console command 'cutoff' to put the battery in cut-off mode. Inserted the adopter to wake the system, system doesn't reboot & the battery charges. Change-Id: Ia5a1457506b4bef0b3dd27993e4b60ae64c8f746 Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/322430 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Shawn N --- board/kunimitsu/battery.c | 39 +++++++++++++++++++++++++++++++++++++++ board/kunimitsu/board.c | 20 -------------------- common/charge_manager.c | 9 +++++++++ common/charge_state_v2.c | 9 +++++++-- include/charge_manager.h | 3 +++ 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/board/kunimitsu/battery.c b/board/kunimitsu/battery.c index e03d687daf..3a10e0761b 100644 --- a/board/kunimitsu/battery.c +++ b/board/kunimitsu/battery.c @@ -5,6 +5,7 @@ * Battery pack vendor provided charging profile */ +#include "adc.h" #include "battery.h" #include "battery_smart.h" #include "util.h" @@ -42,3 +43,41 @@ int board_cut_off_battery(void) return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); } + +#ifdef CONFIG_BATTERY_PRESENT_CUSTOM +/* + * Physical detection of battery via ADC. + * + * Upper limit of valid voltage level (mV), when battery is attached to ADC + * port, is across the internal thermistor with external pullup resistor. + */ +#define BATT_PRESENT_MV 1500 +enum battery_present battery_is_present(void) +{ + enum battery_present batt_pres; + int batt_status; + + /* + * if voltage is below certain level (dependent on ratio of + * internal thermistor and external pullup resister), + * battery is attached. + */ + batt_pres = (adc_read_channel(ADC_BATT_PRESENT) > BATT_PRESENT_MV) ? + BP_NO : BP_YES; + + /* + * Make sure battery status is implemented, I2C transactions are + * success & the battery status is Initialized to find out if it + * is a working battery and it is not in the cut-off mode. + * + * FETs are turned off after Power Shutdown time. + * The device will wake up when a voltage is applied to PACK. + * Battery status will be inactive until it is initialized. + */ + if (batt_pres == BP_YES && !battery_status(&batt_status)) + if (!(batt_status & STATUS_INITIALIZED)) + batt_pres = BP_NO; + + return batt_pres; +} +#endif diff --git a/board/kunimitsu/board.c b/board/kunimitsu/board.c index 027208dd12..97ec137fa4 100644 --- a/board/kunimitsu/board.c +++ b/board/kunimitsu/board.c @@ -631,23 +631,3 @@ static void board_handle_reboot(void) ; /* wait here */ } DECLARE_HOOK(HOOK_INIT, board_handle_reboot, HOOK_PRIO_FIRST); - -#ifdef CONFIG_BATTERY_PRESENT_CUSTOM -/* - * Physical detection of battery via ADC. - * - * Uppper limit of valid voltage level(mV), when battery is attached to ADC port, - * is across the internal thermistor with external pullup resistor. - */ -#define BATT_PRESENT_MV 1500 -enum battery_present battery_is_present(void) -{ - /* - * if voltage is below certain level(dependant on ratio of - * internal thermistor and external pullup resister), - * battery is attached. - */ - return (adc_read_channel(ADC_BATT_PRESENT) > BATT_PRESENT_MV) ? - BP_NO : BP_YES; -} -#endif diff --git a/common/charge_manager.c b/common/charge_manager.c index 392cd74040..6a17d9ee4a 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -809,6 +809,15 @@ int charge_manager_get_active_charge_port(void) return charge_port; } +/** + * Return the charger current (mA) value. + */ +int charge_manager_get_charger_current(void) +{ + return (charge_current != CHARGE_CURRENT_UNINITIALIZED) ? + charge_current : 0; +} + /** * Return the power limit (uW) set by charge manager. */ diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 4401aa54bb..93e817d359 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -564,9 +564,14 @@ DECLARE_HOOK(HOOK_INIT, charger_init, HOOK_PRIO_DEFAULT); int get_desired_input_current(enum battery_present batt_present, const struct charger_info * const info) { - if (batt_present == BP_YES || system_is_locked()) + if (batt_present == BP_YES || system_is_locked()) { +#ifdef CONFIG_CHARGE_MANAGER + return MAX(CONFIG_CHARGER_INPUT_CURRENT, + charge_manager_get_charger_current()); +#else return CONFIG_CHARGER_INPUT_CURRENT; - else +#endif + } else return info->input_current_max; } diff --git a/include/charge_manager.h b/include/charge_manager.h index d3f14117b5..a47bf3a4d7 100644 --- a/include/charge_manager.h +++ b/include/charge_manager.h @@ -77,6 +77,9 @@ int charge_manager_get_active_charge_port(void); /* Return the power limit (uW) set by charge manager. */ int charge_manager_get_power_limit_uw(void); +/* Return the charger current (mA) value. */ +int charge_manager_get_charger_current(void); + #ifdef CONFIG_USB_PD_LOGGING /* Save power state log entry for the given port */ void charge_manager_save_log(int port); -- cgit v1.2.1