summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu-An Chen <yu-an.chen@quanta.corp-partner.google.com>2022-12-12 14:43:19 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-12-17 17:53:46 +0000
commita6fdc7885a8465065e5c8bd6316181026045bb6c (patch)
treeb38f112cab42fe2c3392828632acef0699768445
parent5e2e4a52a1b2d5231285a7ff5081f291b8adad1a (diff)
downloadchrome-ec-a6fdc7885a8465065e5c8bd6316181026045bb6c.tar.gz
evoker: Dynamic changing charge current
Support dynamic changing charge current BUG=b:259508078 BRANCH=none TEST=check current limit setting is correct via console command LOW_COVERAGE_REASON=test function is prepare on another CL Change-Id: I7a21a8e13c48d957413d5367a79700f359a17a9a Signed-off-by: Yu-An Chen <yu-an.chen@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4095162 Reviewed-by: Wai-Hong Tam <waihong@google.com> Commit-Queue: Sam Hurst <shurst@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Sam Hurst <shurst@google.com>
-rw-r--r--zephyr/program/herobrine/CMakeLists.txt3
-rw-r--r--zephyr/program/herobrine/evoker/src/charger_override.c105
2 files changed, 108 insertions, 0 deletions
diff --git a/zephyr/program/herobrine/CMakeLists.txt b/zephyr/program/herobrine/CMakeLists.txt
index 0fbb8a366f..53f642d7e6 100644
--- a/zephyr/program/herobrine/CMakeLists.txt
+++ b/zephyr/program/herobrine/CMakeLists.txt
@@ -22,6 +22,9 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C
if(DEFINED CONFIG_BOARD_EVOKER)
project(evoker)
+ zephyr_library_sources(
+ "evoker/src/charger_override.c"
+ )
elseif(DEFINED CONFIG_BOARD_HEROBRINE)
project(herobrine)
add_subdirectory(herobrine)
diff --git a/zephyr/program/herobrine/evoker/src/charger_override.c b/zephyr/program/herobrine/evoker/src/charger_override.c
new file mode 100644
index 0000000000..daefa240a9
--- /dev/null
+++ b/zephyr/program/herobrine/evoker/src/charger_override.c
@@ -0,0 +1,105 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "battery.h"
+#include "charge_state.h"
+#include "charger.h"
+#include "console.h"
+#include "extpower.h"
+#include "temp_sensor/temp_sensor.h"
+#include "util.h"
+
+#include <zephyr/logging/log.h>
+
+LOG_MODULE_REGISTER(smart_battery);
+
+/*
+ * Dynamic changing charge current.
+ */
+
+struct temp_chg_step {
+ int low; /* temp thershold ('C) to lower level*/
+ int high; /* temp thershold ('C) to higher level */
+ int current; /* charging limitation (mA) */
+};
+
+static const struct temp_chg_step temp_chg_table[] = {
+ { .low = 0, .high = 56, .current = __INT32_MAX__ },
+ { .low = 50, .high = 100, .current = 2000 },
+};
+#define NUM_TEMP_CHG_LEVELS ARRAY_SIZE(temp_chg_table)
+
+#undef BOARD_TEMP_TEST
+
+#ifdef BOARD_TEMP_TEST
+static int manual_temp = -1;
+#endif
+
+__override int board_charger_profile_override(struct charge_state_data *curr)
+{
+ static int current_level;
+ int charger_temp, charger_temp_c;
+
+ if (curr->state != ST_CHARGE)
+ return 0;
+
+ temp_sensor_read(TEMP_SENSOR_ID_BY_DEV(DT_NODELABEL(temp_charger)),
+ &charger_temp);
+
+ charger_temp_c = K_TO_C(charger_temp);
+
+#ifdef BOARD_TEMP_TEST
+ if (manual_temp != -1)
+ charger_temp_c = manual_temp;
+ LOG_WRN("chg_temp_c: %d", charger_temp_c);
+#endif
+
+ if (charger_temp_c <= temp_chg_table[current_level].low)
+ current_level--;
+ else if (charger_temp_c >= temp_chg_table[current_level].high)
+ current_level++;
+
+ if (current_level < 0)
+ current_level = 0;
+
+ if (current_level >= NUM_TEMP_CHG_LEVELS)
+ current_level = NUM_TEMP_CHG_LEVELS - 1;
+
+ curr->requested_current = MIN(curr->requested_current,
+ temp_chg_table[current_level].current);
+
+#ifdef BOARD_TEMP_TEST
+ LOG_WRN("level: %d, batt_current: %d, limit_current: %d", current_level,
+ curr->requested_current, temp_chg_table[current_level].current);
+#endif
+
+ return EC_SUCCESS;
+}
+
+#ifdef BOARD_TEMP_TEST
+static int command_temp_test(int argc, const char **argv)
+{
+ char *e;
+ int t;
+
+ if (argc > 1) {
+ t = strtoi(argv[1], &e, 0);
+ if (*e) {
+ LOG_WRN("Invalid test temp");
+ return EC_ERROR_INVAL;
+ }
+ manual_temp = t;
+ LOG_WRN("manual temp is %d", manual_temp);
+ return EC_SUCCESS;
+ }
+
+ manual_temp = -1;
+ LOG_WRN("manual temp reset");
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(tt, command_temp_test, "[temperature]",
+ "set manual temperature for test");
+#endif