summaryrefslogtreecommitdiff
path: root/zephyr/program
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/program')
-rw-r--r--zephyr/program/skyrim/CMakeLists.txt1
-rw-r--r--zephyr/program/skyrim/frostflow.dts117
-rw-r--r--zephyr/program/skyrim/prj_frostflow.conf4
-rw-r--r--zephyr/program/skyrim/src/frostflow/thermal.c109
4 files changed, 223 insertions, 8 deletions
diff --git a/zephyr/program/skyrim/CMakeLists.txt b/zephyr/program/skyrim/CMakeLists.txt
index 7291ad93ce..375099717e 100644
--- a/zephyr/program/skyrim/CMakeLists.txt
+++ b/zephyr/program/skyrim/CMakeLists.txt
@@ -57,6 +57,7 @@ if(DEFINED CONFIG_BOARD_FROSTFLOW)
zephyr_library_sources(
"src/frostflow/usb_mux_config.c"
"src/frostflow/ppc_config.c"
+ "src/frostflow/thermal.c"
)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD_CUSTOMIZATION
"src/frostflow/keyboard.c"
diff --git a/zephyr/program/skyrim/frostflow.dts b/zephyr/program/skyrim/frostflow.dts
index ffc2fff237..5e4a21ae57 100644
--- a/zephyr/program/skyrim/frostflow.dts
+++ b/zephyr/program/skyrim/frostflow.dts
@@ -14,17 +14,21 @@
named-temp-sensors {
compatible = "cros-ec,temp-sensors";
- soc-pct2075 {
- temp_host_high = <100>;
- temp_host_halt = <105>;
- temp_host_release_high = <80>;
- temp_host_release_halt = <80>;
- temp_fan_off = <35>;
- temp_fan_max = <70>;
+ temp_soc: soc-pct2075 {
+ temp_host_high = <75>;
+ temp_host_halt = <80>;
+ temp_host_release_high = <65>;
+ temp_host_release_halt = <70>;
power-good-pin = <&gpio_pg_pwr_s5>;
sensor = <&soc_pct2075>;
};
- amb-pct2075 {
+ temp_amb: amb-pct2075 {
+ temp_host_high = <65>;
+ temp_host_halt = <70>;
+ temp_host_release_high = <55>;
+ temp_host_release_halt = <60>;
+ temp_fan_off = <32>;
+ temp_fan_max = <45>;
power-good-pin = <&gpio_pg_pwr_s5>;
sensor = <&amb_pct2075>;
};
@@ -50,6 +54,74 @@
compatible = "aoz,aoz1380";
status = "okay";
};
+
+ fan_steps_clamshell: fan-steps-clamshell {
+ compatible = "cros-ec,fan-steps";
+ level_0 {
+ temp_on = <(-1) (-1) (-1) (-1) 31>;
+ temp_off = <(-1) (-1) (-1) (-1) 99>;
+ rpm_target = <0>;
+ };
+ level_1 {
+ temp_on = <(-1) (-1) (-1) (-1) 32>;
+ temp_off = <(-1) (-1) (-1) (-1) 30>;
+ rpm_target = <2600>;
+ };
+ level_2 {
+ temp_on = <(-1) (-1) (-1) (-1) 34>;
+ temp_off = <(-1) (-1) (-1) (-1) 31>;
+ rpm_target = <2900>;
+ };
+ level_3 {
+ temp_on = <(-1) (-1) (-1) (-1) 36>;
+ temp_off = <(-1) (-1) (-1) (-1) 33>;
+ rpm_target = <3600>;
+ };
+ level_4 {
+ temp_on = <(-1) (-1) (-1) (-1) 38>;
+ temp_off = <(-1) (-1) (-1) (-1) 35>;
+ rpm_target = <4200>;
+ };
+ level_5 {
+ temp_on = <(-1) (-1) (-1) (-1) 45>;
+ temp_off = <(-1) (-1) (-1) (-1) 37>;
+ rpm_target = <4600>;
+ };
+ };
+
+ fan_steps_tablet: fan-steps-tablet {
+ compatible = "cros-ec,fan-steps";
+ level_0 {
+ temp_on = <(-1) (-1) (-1) (-1) 31>;
+ temp_off = <(-1) (-1) (-1) (-1) 99>;
+ rpm_target = <0>;
+ };
+ level_1 {
+ temp_on = <(-1) (-1) (-1) (-1) 32>;
+ temp_off = <(-1) (-1) (-1) (-1) 30>;
+ rpm_target = <2600>;
+ };
+ level_2 {
+ temp_on = <(-1) (-1) (-1) (-1) 34>;
+ temp_off = <(-1) (-1) (-1) (-1) 31>;
+ rpm_target = <2900>;
+ };
+ level_3 {
+ temp_on = <(-1) (-1) (-1) (-1) 36>;
+ temp_off = <(-1) (-1) (-1) (-1) 33>;
+ rpm_target = <3600>;
+ };
+ level_4 {
+ temp_on = <(-1) (-1) (-1) (-1) 38>;
+ temp_off = <(-1) (-1) (-1) (-1) 35>;
+ rpm_target = <4200>;
+ };
+ level_5 {
+ temp_on = <(-1) (-1) (-1) (-1) 45>;
+ temp_off = <(-1) (-1) (-1) (-1) 37>;
+ rpm_target = <4600>;
+ };
+ };
};
&i2c1_0 {
@@ -120,3 +192,32 @@
&kso14_gp82
>;
};
+
+&temp_sensor_charger {
+ temp_host_high = <75>;
+ temp_host_halt = <80>;
+ temp_host_release_high = <65>;
+ temp_host_release_halt = <70>;
+};
+
+&temp_sensor_memory {
+ temp_host_high = <75>;
+ temp_host_halt = <80>;
+ temp_host_release_high = <65>;
+ temp_host_release_halt = <70>;
+};
+
+&temp_sensor_cpu {
+ /delete-property/ temp_host_high;
+ /delete-property/ temp_host_halt;
+ /delete-property/ temp_host_release_high;
+ /delete-property/ temp_fan_off;
+ /delete-property/ temp_fan_max;
+};
+
+&fan0 {
+ pwms = <&pwm0 0 PWM_KHZ(25) PWM_POLARITY_NORMAL>;
+ rpm_min = <2400>;
+ rpm_start = <2600>;
+ rpm_max = <4600>;
+};
diff --git a/zephyr/program/skyrim/prj_frostflow.conf b/zephyr/program/skyrim/prj_frostflow.conf
index 675c387aae..02da02d35d 100644
--- a/zephyr/program/skyrim/prj_frostflow.conf
+++ b/zephyr/program/skyrim/prj_frostflow.conf
@@ -27,3 +27,7 @@ CONFIG_BOARD_USB_HUB_RESET=n
# Battery
CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y
+
+# Fan
+CONFIG_PLATFORM_EC_FAN=y
+CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL=y
diff --git a/zephyr/program/skyrim/src/frostflow/thermal.c b/zephyr/program/skyrim/src/frostflow/thermal.c
new file mode 100644
index 0000000000..eae8aac25d
--- /dev/null
+++ b/zephyr/program/skyrim/src/frostflow/thermal.c
@@ -0,0 +1,109 @@
+/* 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 "common.h"
+#include "chipset.h"
+#include "fan.h"
+#include "tablet_mode.h"
+#include "temp_sensor/temp_sensor.h"
+#include "thermal.h"
+#include "util.h"
+#include "console.h"
+
+#define TEMP_AMB TEMP_SENSOR_ID(DT_NODELABEL(temp_amb))
+
+struct fan_step {
+ /*
+ * Sensor 0~4 trigger point, set -1 if we're not using this
+ * sensor to determine fan speed.
+ */
+ int on[TEMP_SENSOR_COUNT];
+ /*
+ * Sensor 0~4 release point, set -1 if we're not using this
+ * sensor to determine fan speed.
+ */
+ int off[TEMP_SENSOR_COUNT];
+ /* Fan rpm */
+ uint16_t rpm[FAN_CH_COUNT];
+};
+
+#define FAN_TABLE_ENTRY(nd) \
+ { \
+ .on = DT_PROP(nd, temp_on), \
+ .off = DT_PROP(nd, temp_off), \
+ .rpm = DT_PROP(nd, rpm_target), \
+ },
+
+static const struct fan_step fan_table_clamshell[] = { DT_FOREACH_CHILD(
+ DT_NODELABEL(fan_steps_clamshell), FAN_TABLE_ENTRY) };
+
+static const struct fan_step fan_table_tablet[] = { DT_FOREACH_CHILD(
+ DT_NODELABEL(fan_steps_tablet), FAN_TABLE_ENTRY) };
+
+static const struct fan_step *fan_step_table;
+#define NUM_FAN_LEVELS ARRAY_SIZE(fan_table_clamshell)
+
+BUILD_ASSERT(ARRAY_SIZE(fan_table_clamshell) == ARRAY_SIZE(fan_table_tablet));
+
+int fan_table_to_rpm(int fan, int *temp)
+{
+ /* current fan level */
+ static int current_level;
+ /* previous sensor temperature */
+ static int prev_tmp[TEMP_SENSOR_COUNT];
+ int i;
+
+ if (tablet_get_mode())
+ fan_step_table = fan_table_tablet;
+ else
+ fan_step_table = fan_table_clamshell;
+
+ /*
+ * Compare the current and previous temperature, we have
+ * the three paths :
+ * 1. decreasing path. (check the release point)
+ * 2. increasing path. (check the trigger point)
+ * 3. invariant path. (return the current RPM)
+ */
+
+ if (temp[TEMP_AMB] < prev_tmp[TEMP_AMB]) {
+ for (i = current_level; i > 0; i--) {
+ if (temp[TEMP_AMB] < fan_step_table[i].off[TEMP_AMB])
+ current_level = i - 1;
+ else
+ break;
+ }
+ } else if (temp[TEMP_AMB] > prev_tmp[TEMP_AMB]) {
+ for (i = current_level; i < NUM_FAN_LEVELS; i++) {
+ if (temp[TEMP_AMB] > fan_step_table[i].on[TEMP_AMB])
+ current_level = i + 1;
+ else
+ break;
+ }
+ }
+
+ if (current_level < 0)
+ current_level = 0;
+
+ if (current_level >= NUM_FAN_LEVELS)
+ current_level = NUM_FAN_LEVELS - 1;
+
+ for (i = 0; i < TEMP_SENSOR_COUNT; ++i)
+ prev_tmp[i] = temp[i];
+
+ return fan_step_table[current_level].rpm[fan];
+}
+
+void board_override_fan_control(int fan, int *temp)
+{
+ /*
+ * In common/fan.c pwm_fan_stop() will turn off fan
+ * when chipset suspend or shutdown.
+ */
+ if (chipset_in_state(CHIPSET_STATE_ON)) {
+ fan_set_rpm_mode(fan, 1);
+ fan_set_rpm_target(fan, fan_table_to_rpm(fan, temp));
+ }
+}