From 7bf1696711c37d829b4663fa4dfce5e35b4d237e Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Wed, 1 Nov 2017 09:59:08 -0700 Subject: [PATCH] chg_ramp: Add charge_is_consuming_full_input_current(). Most boards had an identical implementation for this function, previously known as board_is_consuming_full_charge(). To reduce copy paste, let's just move it to common code. Boards that charge ramp without a battery will have to define their own implementation, but there probably won't be any boards like that in the near future. BUG=None BRANCH=None TEST=make -j buildall Change-Id: Ic99a378ac26dfd35d7d718bf9376eacfa8609166 Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/748919 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Shawn N --- board/coral/board.c | 10 ---------- board/eve/board.c | 10 ---------- board/grunt/board.c | 10 ---------- board/kahlee/board.c | 10 ---------- board/kevin/charge_ramp.c | 10 ---------- board/nautilus/board.c | 11 ----------- board/poppy/board.c | 11 ----------- board/reef/board.c | 10 ---------- board/reef_it8320/board.c | 10 ---------- board/samus_pd/board.c | 2 +- common/charge_ramp_sw.c | 5 +++-- common/charge_state_v2.c | 7 +++++++ include/charge_ramp.h | 7 ------- include/charge_state.h | 10 ++++++++++ test/charge_ramp.c | 2 +- 15 files changed, 22 insertions(+), 103 deletions(-) diff --git a/board/coral/board.c b/board/coral/board.c index 9fe3aaae78..650b89d317 100644 --- a/board/coral/board.c +++ b/board/coral/board.c @@ -662,16 +662,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - /** * Return if VBUS is sagging too low */ diff --git a/board/eve/board.c b/board/eve/board.c index e0f168fca4..ca5b43d63c 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -541,16 +541,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - /** * Return if VBUS is sagging too low */ diff --git a/board/grunt/board.c b/board/grunt/board.c index d08843dfb6..cd2ebcd215 100644 --- a/board/grunt/board.c +++ b/board/grunt/board.c @@ -416,16 +416,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - /** * Return if VBUS is sagging too low */ diff --git a/board/kahlee/board.c b/board/kahlee/board.c index dd57f8edcd..3826d4a181 100644 --- a/board/kahlee/board.c +++ b/board/kahlee/board.c @@ -416,16 +416,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - /** * Return if VBUS is sagging too low */ diff --git a/board/kevin/charge_ramp.c b/board/kevin/charge_ramp.c index 350c58924b..134f2e62de 100644 --- a/board/kevin/charge_ramp.c +++ b/board/kevin/charge_ramp.c @@ -20,13 +20,3 @@ int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) { return charger_get_vbus_voltage(port) < BD9995X_BC12_MIN_VOLTAGE; } - -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_pct = charge_get_percent(); - - return chg_pct > 2 && chg_pct < 95; -} diff --git a/board/nautilus/board.c b/board/nautilus/board.c index 84f5684739..a8e1a7d630 100644 --- a/board/nautilus/board.c +++ b/board/nautilus/board.c @@ -795,17 +795,6 @@ int board_get_ramp_current_limit(int supplier, int sup_curr) } } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - - void board_hibernate(void) { CPRINTS("Triggering PMIC shutdown."); diff --git a/board/poppy/board.c b/board/poppy/board.c index d13361c108..b80be0b7dd 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -802,17 +802,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - - void board_hibernate(void) { CPRINTS("Triggering PMIC shutdown."); diff --git a/board/reef/board.c b/board/reef/board.c index f4696b8ce2..cff56b7657 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -654,16 +654,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - /** * Return if VBUS is sagging too low */ diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c index 1c33c2ec65..a7f275a9f4 100644 --- a/board/reef_it8320/board.c +++ b/board/reef_it8320/board.c @@ -439,16 +439,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - /** * Return if VBUS is sagging too low */ diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index fc4c22d207..4a617ede97 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -363,7 +363,7 @@ int pd_is_max_request_allowed(void) /** * Return if board is consuming full amount of input current */ -int board_is_consuming_full_charge(void) +int charge_is_consuming_full_input_current(void) { return batt_soc >= 1 && batt_soc < HIGH_BATT_THRESHOLD; } diff --git a/common/charge_ramp_sw.c b/common/charge_ramp_sw.c index cfdfa50c21..d572115043 100644 --- a/common/charge_ramp_sw.c +++ b/common/charge_ramp_sw.c @@ -7,6 +7,7 @@ #include "charge_manager.h" #include "charge_ramp.h" +#include "charge_state.h" #include "common.h" #include "console.h" #include "ec_commands.h" @@ -224,7 +225,7 @@ void chg_ramp_task(void *u) * If we are not drawing full charge, then don't ramp, * just wait in this state, until we are. */ - if (!board_is_consuming_full_charge()) { + if (!charge_is_consuming_full_input_current()) { task_wait_time = CURRENT_DRAW_DELAY; break; } @@ -258,7 +259,7 @@ void chg_ramp_task(void *u) task_wait_time = RAMP_CURR_DELAY; /* Pause ramping if we are not drawing full current */ - if (!board_is_consuming_full_charge()) { + if (!charge_is_consuming_full_input_current()) { task_wait_time = CURRENT_DRAW_DELAY; break; } diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index ae039c61d2..df87184813 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1101,6 +1101,13 @@ int charge_get_battery_temp(int idx, int *temp_ptr) return EC_SUCCESS; } +int charge_is_consuming_full_input_current(void) +{ + int chg_pct = charge_get_percent(); + + return chg_pct > 2 && chg_pct < 95; +} + int charge_set_input_current_limit(int ma, int mv) { /* diff --git a/include/charge_ramp.h b/include/charge_ramp.h index 51ad777aa1..c4082fdbf2 100644 --- a/include/charge_ramp.h +++ b/include/charge_ramp.h @@ -16,13 +16,6 @@ enum chg_ramp_vbus_state { CHG_RAMP_VBUS_STABLE }; -/** - * Check if board is consuming full input current - * - * @return Board is consuming full input current - */ -int board_is_consuming_full_charge(void); - /** * Check if VBUS is too low * diff --git a/include/charge_state.h b/include/charge_state.h index 0cf70c22de..fb1a41527a 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -91,6 +91,16 @@ uint32_t charge_get_flags(void); */ int charge_get_percent(void); +/** + * Check if board is consuming full input current + * + * This returns true if the battery charge percentage is between 2% and 95% + * exclusive. + * + * @return Board is consuming full input current + */ +int charge_is_consuming_full_input_current(void); + /** * Return non-zero if discharging and battery so low we should shut down. */ diff --git a/test/charge_ramp.c b/test/charge_ramp.c index e3dce7a860..f6f8bd542e 100644 --- a/test/charge_ramp.c +++ b/test/charge_ramp.c @@ -64,7 +64,7 @@ int usb_charger_ramp_max(int supplier, int sup_curr) return 0; } -int board_is_consuming_full_charge(void) +int charge_is_consuming_full_input_current(void) { return charge_limit_ma <= system_load_current_ma; }