summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-05-03 15:33:50 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-05 17:38:39 +0000
commitedcc544a2e8329e93d871e68af6e8f7913d02e21 (patch)
tree24d34a1a13dde0b0218b14aca50639dabad40862
parent51a5aaaeabfdb7d97242dc1f9ed25c250540b2e8 (diff)
downloadchrome-ec-edcc544a2e8329e93d871e68af6e8f7913d02e21.tar.gz
charger: Move handling of requested voltage/current to func
Move this related code into a separate function. BUG=b:218332694 TEST=zmake build dev-posix make BOARD=brya -j50 |grep "brya " |sed 's/still.*on //' *** 33464 bytes in flash and 23136 bytes in RAM brya RO **** *** 33424 bytes in flash and 23136 bytes in RAM brya RW **** (RO flash space decreased from 33488 = 24 bytes) Change-Id: I24655906c1865e0fc7d3c83a1a74aa708854fbbc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4500690 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Yuval Peress <peress@google.com> Commit-Queue: Simon Glass <sjg@chromium.org>
-rw-r--r--common/charge_state_v2.c120
1 files changed, 62 insertions, 58 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index b2435febb8..699daeddeb 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1865,6 +1865,67 @@ static void decide_charge_state(int *need_staticp, int *battery_criticalp)
set_charge_state(ST_CHARGE);
}
+/* Determine voltage/current to request and make it so */
+static void adjust_requested_vi(const struct charger_info *info)
+{
+ /* Turn charger off if it's not needed */
+ if (!IS_ENABLED(CONFIG_CHARGER_MAINTAIN_VBAT) &&
+ (curr.state == ST_IDLE || curr.state == ST_DISCHARGE)) {
+ curr.requested_voltage = 0;
+ curr.requested_current = 0;
+ }
+
+ /* Apply external limits */
+ if (curr.requested_current > user_current_limit)
+ curr.requested_current = user_current_limit;
+
+ /* Round to valid values */
+ curr.requested_voltage =
+ charger_closest_voltage(curr.requested_voltage);
+ curr.requested_current =
+ charger_closest_current(curr.requested_current);
+
+ /* Charger only accepts request when AC is on. */
+ if (curr.ac) {
+ /*
+ * Some batteries would wake up after cut-off if we keep
+ * charging it. Thus, we only charge when AC is on and battery
+ * is not cut off yet.
+ */
+ if (battery_is_cut_off()) {
+ curr.requested_voltage = 0;
+ curr.requested_current = 0;
+ }
+ /*
+ * As a safety feature, some chargers will stop charging if we
+ * don't communicate with it frequently enough. In manual mode,
+ * we'll just tell it what it knows.
+ */
+ else {
+ if (manual_voltage != -1)
+ curr.requested_voltage = manual_voltage;
+ if (manual_current != -1)
+ curr.requested_current = manual_current;
+ }
+ } else if (!IS_ENABLED(CONFIG_CHARGER_MAINTAIN_VBAT)) {
+ curr.requested_voltage = charger_closest_voltage(
+ curr.batt.voltage + info->voltage_step);
+ curr.requested_current = -1;
+ /*
+ * On EC-EC server, do not charge if curr.ac is 0: there might
+ * still be some external power available but we do not want to
+ * use it for charging.
+ */
+ if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_SERVER))
+ curr.requested_current = 0;
+ }
+
+ if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT))
+ base_charge_allocate_input_current_limit();
+ else
+ charge_request(curr.requested_voltage, curr.requested_current);
+}
+
/* Main loop */
void charger_task(void *u)
{
@@ -1977,64 +2038,7 @@ void charger_task(void *u)
prev_full = is_full;
- /* Turn charger off if it's not needed */
- if (!IS_ENABLED(CONFIG_CHARGER_MAINTAIN_VBAT) &&
- (curr.state == ST_IDLE || curr.state == ST_DISCHARGE)) {
- curr.requested_voltage = 0;
- curr.requested_current = 0;
- }
-
- /* Apply external limits */
- if (curr.requested_current > user_current_limit)
- curr.requested_current = user_current_limit;
-
- /* Round to valid values */
- curr.requested_voltage =
- charger_closest_voltage(curr.requested_voltage);
- curr.requested_current =
- charger_closest_current(curr.requested_current);
-
- /* Charger only accpets request when AC is on. */
- if (curr.ac) {
- /*
- * Some batteries would wake up after cut-off if we keep
- * charging it. Thus, we only charge when AC is on and
- * battery is not cut off yet.
- */
- if (battery_is_cut_off()) {
- curr.requested_voltage = 0;
- curr.requested_current = 0;
- }
- /*
- * As a safety feature, some chargers will stop
- * charging if we don't communicate with it frequently
- * enough. In manual mode, we'll just tell it what it
- * knows.
- */
- else {
- if (manual_voltage != -1)
- curr.requested_voltage = manual_voltage;
- if (manual_current != -1)
- curr.requested_current = manual_current;
- }
- } else if (!IS_ENABLED(CONFIG_CHARGER_MAINTAIN_VBAT)) {
- curr.requested_voltage = charger_closest_voltage(
- curr.batt.voltage + info->voltage_step);
- curr.requested_current = -1;
- /*
- * On EC-EC server, do not charge if curr.ac is 0: there
- * might still be some external power available but we
- * do not want to use it for charging.
- */
- if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_SERVER))
- curr.requested_current = 0;
- }
-
- if (IS_ENABLED(CONFIG_EC_EC_COMM_BATTERY_CLIENT))
- base_charge_allocate_input_current_limit();
- else
- charge_request(curr.requested_voltage,
- curr.requested_current);
+ adjust_requested_vi(info);
/* How long to sleep? */
if (problems_exist)