summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zephyr/projects/skyrim/CMakeLists.txt2
-rw-r--r--zephyr/projects/skyrim/fan.c46
-rw-r--r--zephyr/projects/skyrim/skyrim.dts25
3 files changed, 73 insertions, 0 deletions
diff --git a/zephyr/projects/skyrim/CMakeLists.txt b/zephyr/projects/skyrim/CMakeLists.txt
index b1573a81ab..79a1c72c94 100644
--- a/zephyr/projects/skyrim/CMakeLists.txt
+++ b/zephyr/projects/skyrim/CMakeLists.txt
@@ -21,3 +21,5 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_AMD_STT
"stt.c")
+
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_FAN "fan.c")
diff --git a/zephyr/projects/skyrim/fan.c b/zephyr/projects/skyrim/fan.c
new file mode 100644
index 0000000000..71896420da
--- /dev/null
+++ b/zephyr/projects/skyrim/fan.c
@@ -0,0 +1,46 @@
+/* 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 <zephyr/devicetree.h>
+#include <zephyr/drivers/gpio.h>
+#include <zephyr/logging/log.h>
+
+#include "cros_board_info.h"
+#include "cros_cbi.h"
+#include "fan.h"
+#include "gpio/gpio.h"
+#include "hooks.h"
+
+LOG_MODULE_DECLARE(skyrim, CONFIG_SKYRIM_LOG_LEVEL);
+
+/*
+ * Skyrim fan support
+ */
+static void fan_init(void)
+{
+ int ret;
+ uint32_t val;
+ uint32_t board_version;
+ /*
+ * Retrieve the fan config.
+ */
+ ret = cros_cbi_get_fw_config(FW_FAN, &val);
+ if (ret != 0) {
+ LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_FAN);
+ return;
+ }
+
+ ret = cbi_get_board_version(&board_version);
+ if (ret != EC_SUCCESS) {
+ LOG_ERR("Error retrieving CBI board version");
+ return;
+ }
+
+ if ((board_version >= 3) && (val != FW_FAN_PRESENT)) {
+ /* Disable the fan */
+ fan_set_count(0);
+ }
+}
+DECLARE_HOOK(HOOK_INIT, fan_init, HOOK_PRIO_POST_FIRST);
diff --git a/zephyr/projects/skyrim/skyrim.dts b/zephyr/projects/skyrim/skyrim.dts
index 51aebe8d1d..494b33b4eb 100644
--- a/zephyr/projects/skyrim/skyrim.dts
+++ b/zephyr/projects/skyrim/skyrim.dts
@@ -187,6 +187,31 @@
default;
};
};
+
+ /*
+ * FW_CONFIG field to enable fan or not.
+ */
+ fan {
+ enum-name = "FW_FAN";
+ start = <10>;
+ size = <1>;
+
+ no-fan {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "FW_FAN_NOT_PRESENT";
+ value = <0>;
+ };
+ fan-present {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "FW_FAN_PRESENT";
+ value = <1>;
+ /*
+ * Set as default so that unprovisioned
+ * configs will run the fan regardless.
+ */
+ default;
+ };
+ };
};
/* Rotation matrices for motion sensors. */