summaryrefslogtreecommitdiff
path: root/zephyr/projects/herobrine/src/herobrine/alt_dev_replacement.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/projects/herobrine/src/herobrine/alt_dev_replacement.c')
-rw-r--r--zephyr/projects/herobrine/src/herobrine/alt_dev_replacement.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/zephyr/projects/herobrine/src/herobrine/alt_dev_replacement.c b/zephyr/projects/herobrine/src/herobrine/alt_dev_replacement.c
new file mode 100644
index 0000000000..00acd509f4
--- /dev/null
+++ b/zephyr/projects/herobrine/src/herobrine/alt_dev_replacement.c
@@ -0,0 +1,36 @@
+/* Copyright 2021 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <zephyr/logging/log.h>
+#include "usbc/ppc.h"
+#include "hooks.h"
+#include "cros_board_info.h"
+
+LOG_MODULE_REGISTER(alt_dev_replacement);
+
+#define BOARD_VERSION_UNKNOWN 0xffffffff
+
+/* Check board version to decide which ppc is used. */
+static bool board_has_alt_ppc(void)
+{
+ static uint32_t board_version = BOARD_VERSION_UNKNOWN;
+
+ if (board_version == BOARD_VERSION_UNKNOWN) {
+ if (cbi_get_board_version(&board_version) != EC_SUCCESS) {
+ LOG_ERR("Failed to get board version.");
+ board_version = 0;
+ }
+ }
+
+ return (board_version >= 1);
+}
+
+static void check_alternate_devices(void)
+{
+ /* Configure the PPC driver */
+ if (board_has_alt_ppc())
+ /* Arg is the USB port number */
+ PPC_ENABLE_ALTERNATE(0);
+}
+DECLARE_HOOK(HOOK_INIT, check_alternate_devices, HOOK_PRIO_DEFAULT);