summaryrefslogtreecommitdiff
path: root/zephyr/program/nissa/gothrax/src/charger.c
diff options
context:
space:
mode:
authorYunlong Jia <yunlong.jia@ecs.corp-partner.google.com>2023-05-16 14:24:02 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-17 03:58:45 +0000
commitb98a347e1b0711a565f94b65beb8a8850169e190 (patch)
tree2c206579a26b20266d0c2db45a079bd35ed8051e /zephyr/program/nissa/gothrax/src/charger.c
parent764c88f6b9a4f2363609a5f5bf0d4ce3dee7250d (diff)
downloadchrome-ec-b98a347e1b0711a565f94b65beb8a8850169e190.tar.gz
gothrax: Initial Zephyr EC image
Create the initial Zephyr EC image for the gothrax variant based on the nereid reference board. (Auto-Generated by create_zephyr_ec_image.sh version 1.0.0). BUG=b:279614675 BRANCH=None TEST=PASS Change-Id: I7a977ed3448101a400a01ae06b452dc8577ebf49 Signed-off-by: Yunlong Jia <yunlong.jia@ecs.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4537641 Reviewed-by: Henry Sun <henrysun@google.com> Commit-Queue: Henry Sun <henrysun@google.com>
Diffstat (limited to 'zephyr/program/nissa/gothrax/src/charger.c')
-rw-r--r--zephyr/program/nissa/gothrax/src/charger.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/zephyr/program/nissa/gothrax/src/charger.c b/zephyr/program/nissa/gothrax/src/charger.c
new file mode 100644
index 0000000000..c8b09bd82c
--- /dev/null
+++ b/zephyr/program/nissa/gothrax/src/charger.c
@@ -0,0 +1,55 @@
+/* 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 "charger.h"
+#include "console.h"
+#include "driver/charger/sm5803.h"
+#include "extpower.h"
+#include "usb_pd.h"
+
+#include <zephyr/logging/log.h>
+
+LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
+
+int extpower_is_present(void)
+{
+ int port;
+ int rv;
+ bool acok;
+
+ for (port = 0; port < board_get_usb_pd_port_count(); port++) {
+ rv = sm5803_is_acok(port, &acok);
+ if ((rv == EC_SUCCESS) && acok)
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Nereid does not have a GPIO indicating whether extpower is present,
+ * so detect using the charger(s).
+ */
+__override void board_check_extpower(void)
+{
+ static int last_extpower_present;
+ int extpower_present = extpower_is_present();
+
+ if (last_extpower_present ^ extpower_present)
+ extpower_handle_update(extpower_present);
+
+ last_extpower_present = extpower_present;
+}
+
+__override void board_hibernate(void)
+{
+ /* Shut down the chargers */
+ if (board_get_usb_pd_port_count() == 2)
+ sm5803_hibernate(CHARGER_SECONDARY);
+ sm5803_hibernate(CHARGER_PRIMARY);
+ LOG_INF("Charger(s) hibernated");
+ cflush();
+}