summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-05 12:50:48 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-09 22:29:41 +0000
commit0b76ed29fdbb81b0933993c455958883cea4056f (patch)
tree9350177724826db5f68897bf05e77c486f656cff
parent5be73aa62a6ce6ccb72624c128c3dd76b5ac828b (diff)
downloadchrome-ec-0b76ed29fdbb81b0933993c455958883cea4056f.tar.gz
charger: Make prev_charge_base static
Move use of this variable wholly within charger_base.c by adding two functions to deal with what charger_state_v2.c needs: - seeing if charge_base has changed since last time - committing that change I did toy with the idea of making these two functions static inlines, but that does tend to obfuscate the fact that they only exist when the base is present. So for now at least I have left two IS_ENABLED() calls in the code. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check size on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69448 bytes in flash and 1120 bytes in RAM lux RW **** Change-Id: Ib9bdbce62cefb99b12aeb235450eac5d29861d3b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4510246 Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/charge_state_v2.c10
-rw-r--r--common/charger_base.c12
-rw-r--r--include/charger_base.h10
3 files changed, 23 insertions, 9 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index bd52a682f5..aa7c54ddf1 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1147,17 +1147,15 @@ void check_battery_change_soc(bool is_full, bool prev_full)
{
if ((!(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
curr.batt.state_of_charge != prev_charge) ||
-#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
- (charge_base != prev_charge_base) ||
-#endif
+ (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT) &&
+ charger_base_charge_changed()) ||
is_full != prev_full || (curr.state != prev_state) ||
(charge_get_display_charge() != prev_disp_charge)) {
show_charging_progress(is_full);
prev_charge = curr.batt.state_of_charge;
prev_disp_charge = charge_get_display_charge();
-#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
- prev_charge_base = charge_base;
-#endif
+ if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT))
+ charger_base_charge_update();
hook_notify(HOOK_BATTERY_SOC_CHANGE);
}
}
diff --git a/common/charger_base.c b/common/charger_base.c
index 127229068c..9eaf11cc1e 100644
--- a/common/charger_base.c
+++ b/common/charger_base.c
@@ -23,7 +23,7 @@
/* Base has responded to one of our commands already. */
static int base_responsive;
int charge_base;
-int prev_charge_base;
+static int prev_charge_base;
static int prev_current_base;
static int prev_allow_charge_base;
static int prev_current_lid;
@@ -647,5 +647,15 @@ void charger_base_setup(void)
base_responsive = 0;
}
+bool charger_base_charge_changed(void)
+{
+ return charge_base != prev_charge_base;
+}
+
+void charger_base_charge_update(void)
+{
+ prev_charge_base = charge_base;
+}
+
/* Reset the base on S5->S0 transition. */
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_base_reset, HOOK_PRIO_DEFAULT);
diff --git a/include/charger_base.h b/include/charger_base.h
index 511ec2b4ab..8b7ae1421f 100644
--- a/include/charger_base.h
+++ b/include/charger_base.h
@@ -13,7 +13,6 @@
struct charge_state_data;
extern int charge_base;
-extern int prev_charge_base;
/* allocate power between the base and the lid */
void base_charge_allocate_input_current_limit(
@@ -34,8 +33,9 @@ void base_update_battery_info(void);
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
/* Check if there is a base and it is connected */
bool base_connected(void);
+
#else
-bool base_connected(void)
+static inline bool base_connected(void)
{
return false;
}
@@ -44,4 +44,10 @@ bool base_connected(void)
/* Set up the charger task for the base */
void charger_base_setup(void);
+/* Check if charge_base has changed since last time */
+bool charger_base_charge_changed(void);
+
+/* Update prev_charge_base with charge_base */
+void charger_base_charge_update(void);
+
#endif /* __CROS_EC_CHARGER_BASE_H */