summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-05 10:55:43 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-09 22:29:33 +0000
commit58335c0c178bcd1ec3cd8e8e9cb9faea22225431 (patch)
tree7782da66d0c909b5f358ea8c876c6e68b9e21a69
parenta080c059920468be00f94325617f31b109750f4c (diff)
downloadchrome-ec-58335c0c178bcd1ec3cd8e8e9cb9faea22225431.tar.gz
charger: Simplify the arguments to charge_request()
This function is called in two modes, one where it deals with the currently requested voltage/current and one where it does not. The function has access to the necessary state so there is no need to pass it in. It is better to tell the function which approach to take explicitly, using a boolean, rather than using zero values for the first two arguments to indicate this. Replace the first two arguments with a boolean. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Check code on lux: *** 69552 bytes in flash and 1152 bytes in RAM lux RO **** *** 69416 bytes in flash and 1152 bytes in RAM lux RW **** Change-Id: I8389e35b0f61b2c4f03a7e7aac746eeab20ef0de Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4509872 Reviewed-by: Aaron Massey <aaronmassey@google.com> Commit-Queue: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/charge_state_v2.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index a209efb654..a82075730f 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -73,7 +73,7 @@
static timestamp_t uvp_throttle_start_time;
#endif /* CONFIG_THROTTLE_AP_ON_BAT_OLTAGE */
-static int charge_request(int voltage, int current, bool is_full);
+static int charge_request(bool use_curr, bool is_full);
static uint8_t battery_level_shutdown;
@@ -424,11 +424,7 @@ static void set_base_lid_current(int current_base, int allow_charge_base,
ret = charger_set_input_current_limit(chgnum, current_lid);
if (ret)
return;
- if (allow_charge_lid)
- ret = charge_request(curr.requested_voltage,
- curr.requested_current, is_full);
- else
- ret = charge_request(0, 0, is_full);
+ ret = charge_request(allow_charge_lid, is_full);
} else {
ret = charge_set_output_current_limit(
CHARGER_SOLO, -current_lid, otg_voltage);
@@ -997,13 +993,22 @@ __overridable int board_should_charger_bypass(void)
/*
* Ask the charger for some voltage and current. If either value is 0,
* charging is disabled; otherwise it's enabled. Negative values are ignored.
+ *
+ * @param use_curr Use values from requested voltage and current (otherwise use
+ * 0 for both)
+ * @param is_full Battery is full
*/
-static int charge_request(int voltage, int current, bool is_full)
+static int charge_request(bool use_curr, bool is_full)
{
int r1 = EC_SUCCESS, r2 = EC_SUCCESS, r3 = EC_SUCCESS, r4 = EC_SUCCESS;
static int prev_volt, prev_curr;
bool should_bypass;
+ int voltage = 0, current = 0;
+ if (use_curr) {
+ voltage = curr.requested_voltage;
+ current = curr.requested_current;
+ }
if (!voltage || !current) {
#ifdef CONFIG_CHARGER_NARROW_VDC
current = 0;
@@ -1978,8 +1983,7 @@ static void adjust_requested_vi(const struct charger_info *const info,
if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT))
base_charge_allocate_input_current_limit(is_full);
else
- charge_request(curr.requested_voltage, curr.requested_current,
- is_full);
+ charge_request(true, is_full);
}
/* Handle selection of the preferred voltage */