summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-04 15:15:44 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-05 22:33:14 +0000
commitb154d86174237feaa82aaa9da0cf1561c4f7a406 (patch)
tree0d09ff3b25f1a614169b6669d49d43653480272e
parent84f610eec742b9f84a0b11052377847679cf9276 (diff)
downloadchrome-ec-b154d86174237feaa82aaa9da0cf1561c4f7a406.tar.gz
charger: Move v/i setup code to decide_charge_state()
This code relates to deciding on the charge state, so move it into the same function. This makes no functional change. BUG=b:218332694 TEST=zmake build dev-posix Change-Id: I2d8fb744047f9d986b47b7460bbfa471233f9689 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4508345 Reviewed-by: Al Semjonovs <asemjonovs@google.com> Tested-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
-rw-r--r--common/charge_state_v2.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index f29ccd0322..2c92a90378 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1780,6 +1780,27 @@ static void process_battery_present_change(const struct charger_info *info,
/* Decide on the charge state we are in */
static void decide_charge_state(int *need_staticp, int *battery_criticalp)
{
+ /* battery current stable now, so save the current. */
+ if (IS_ENABLED(CONFIG_USB_PD_PREFER_MV) &&
+ get_time().val > stable_ts.val && curr.batt.current >= 0)
+ stable_current = curr.batt.current;
+
+ /*
+ * Now decide what we want to do about it. We'll normally just pass
+ * along whatever the battery wants to the charger. Note that if
+ * battery_get_params() can't get valid values from the battery it uses
+ * (0, 0), which is probably safer than blindly applying power to a
+ * battery we can't talk to.
+ */
+ if (curr.batt.flags &
+ (BATT_FLAG_BAD_DESIRED_VOLTAGE | BATT_FLAG_BAD_DESIRED_CURRENT)) {
+ curr.requested_voltage = 0;
+ curr.requested_current = 0;
+ } else {
+ curr.requested_voltage = curr.batt.desired_voltage;
+ curr.requested_current = curr.batt.desired_current;
+ }
+
/* If we *know* there's no battery, wait for one to appear. */
if (curr.batt.is_present == BP_NO) {
if (!curr.ac)
@@ -2061,27 +2082,6 @@ void charger_task(void *u)
notify_host_of_over_current(&curr.batt);
- /* battery current stable now, saves the current. */
- if (IS_ENABLED(CONFIG_USB_PD_PREFER_MV) &&
- get_time().val > stable_ts.val && curr.batt.current >= 0)
- stable_current = curr.batt.current;
-
- /*
- * Now decide what we want to do about it. We'll normally just
- * pass along whatever the battery wants to the charger. Note
- * that if battery_get_params() can't get valid values from the
- * battery it uses (0, 0), which is probably safer than blindly
- * applying power to a battery we can't talk to.
- */
- if (curr.batt.flags & (BATT_FLAG_BAD_DESIRED_VOLTAGE |
- BATT_FLAG_BAD_DESIRED_CURRENT)) {
- curr.requested_voltage = 0;
- curr.requested_current = 0;
- } else {
- curr.requested_voltage = curr.batt.desired_voltage;
- curr.requested_current = curr.batt.desired_current;
- }
-
decide_charge_state(&need_static, &battery_critical);
if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&