diff options
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/program/skyrim/markarth/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/program/skyrim/markarth/project.conf | 3 | ||||
-rw-r--r-- | zephyr/program/skyrim/markarth/project.overlay | 74 | ||||
-rw-r--r-- | zephyr/program/skyrim/markarth/src/thermal.c | 99 |
4 files changed, 172 insertions, 7 deletions
diff --git a/zephyr/program/skyrim/markarth/CMakeLists.txt b/zephyr/program/skyrim/markarth/CMakeLists.txt index 7075b650cc..65740f572a 100644 --- a/zephyr/program/skyrim/markarth/CMakeLists.txt +++ b/zephyr/program/skyrim/markarth/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2022 The ChromiumOS Authors +# Copyright 2023 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -9,6 +9,7 @@ zephyr_library_sources( "src/form_factor.c" "src/keyboard.c" "src/kb_backlight.c" + "src/thermal.c" ) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD_CUSTOMIZATION "src/keyboard.c" diff --git a/zephyr/program/skyrim/markarth/project.conf b/zephyr/program/skyrim/markarth/project.conf index 8c2c204f2b..4f00aa256c 100644 --- a/zephyr/program/skyrim/markarth/project.conf +++ b/zephyr/program/skyrim/markarth/project.conf @@ -24,3 +24,6 @@ CONFIG_PLATFORM_EC_KEYBOARD_CUSTOMIZATION=y # Sensors CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=y + +# Fan +CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL=y diff --git a/zephyr/program/skyrim/markarth/project.overlay b/zephyr/program/skyrim/markarth/project.overlay index 0678eae9a5..794a8e5151 100644 --- a/zephyr/program/skyrim/markarth/project.overlay +++ b/zephyr/program/skyrim/markarth/project.overlay @@ -50,12 +50,6 @@ named-temp-sensors { compatible = "cros-ec,temp-sensors"; f75303-local { - 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>; power-good-pin = <&gpio_pg_pwr_s5>; sensor = <&f75303_local>; }; @@ -69,6 +63,40 @@ }; }; + fan_steps: fan-step { + compatible = "cros-ec,fan-steps"; + level_0 { + temp_on = <(-1) (-1) 40 (-1) (-1) (-1)>; + temp_off = <(-1) (-1) 99 (-1) (-1) (-1)>; + rpm_target = <0>; + }; + level_1 { + temp_on = <(-1) (-1) 45 (-1) (-1) (-1)>; + temp_off = <(-1) (-1) 39 (-1) (-1) (-1)>; + rpm_target = <2400>; + }; + level_2 { + temp_on = <(-1) (-1) 50 (-1) (-1) (-1)>; + temp_off = <(-1) (-1) 44 (-1) (-1) (-1)>; + rpm_target = <2800>; + }; + level_3 { + temp_on = <(-1) (-1) 55 (-1) (-1) (-1)>; + temp_off = <(-1) (-1) 49 (-1) (-1) (-1)>; + rpm_target = <3000>; + }; + level_4 { + temp_on = <(-1) (-1) 60 (-1) (-1) (-1)>; + temp_off = <(-1) (-1) 54 (-1) (-1) (-1)>; + rpm_target = <3450>; + }; + level_5 { + temp_on = <(-1) (-1) 65 (-1) (-1) (-1)>; + temp_off = <(-1) (-1) 59 (-1) (-1) (-1)>; + rpm_target = <3800>; + }; + }; + /* * Note this is expected to vary per-board, so we keep it in the overlay * files. @@ -226,3 +254,37 @@ &kso12_gp05 >; }; + +&temp_sensor_cpu { + temp_host_warn = <92>; + temp_host_high = <95>; + temp_host_halt = <100>; + temp_host_release_warn = <91>; + temp_host_release_high = <80>; + temp_host_release_halt = <90>; + temp_fan_off = <40>; + temp_fan_max = <95>; +}; + +&temp_sensor_charger { + /delete-property/ temp_host_high; + /delete-property/ temp_host_halt; + /delete-property/ temp_host_release_high; + /delete-property/ temp_host_release_halt; +}; + +&temp_sensor_memory { + /delete-property/ temp_host_high; + /delete-property/ temp_host_halt; + /delete-property/ temp_host_release_high; + /delete-property/ temp_host_release_halt; +}; + +/* fan overrides */ +&fan0 { + pwms = <&pwm0 0 PWM_KHZ(25) PWM_POLARITY_NORMAL>; + rpm_min = <2100>; + rpm_start = <2400>; + rpm_max = <4464>; + rpm_deviation = <2>; +}; diff --git a/zephyr/program/skyrim/markarth/src/thermal.c b/zephyr/program/skyrim/markarth/src/thermal.c new file mode 100644 index 0000000000..dab74883be --- /dev/null +++ b/zephyr/program/skyrim/markarth/src/thermal.c @@ -0,0 +1,99 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "chipset.h" +#include "common.h" +#include "console.h" +#include "fan.h" +#include "tablet_mode.h" +#include "temp_sensor/temp_sensor.h" +#include "thermal.h" +#include "util.h" + +#define TEMP_CPU TEMP_SENSOR_ID(DT_NODELABEL(temp_sensor_cpu)) + +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[] = { DT_FOREACH_CHILD( + DT_NODELABEL(fan_steps), FAN_TABLE_ENTRY) }; + +static const struct fan_step *fan_step_table = fan_table; +#define NUM_FAN_LEVELS ARRAY_SIZE(fan_table) + +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; + + /* + * 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_CPU] < prev_tmp[TEMP_CPU]) { + for (i = current_level; i > 0; i--) { + if (temp[TEMP_CPU] <= fan_step_table[i].off[TEMP_CPU]) + current_level = i - 1; + else + break; + } + } else if (temp[TEMP_CPU] > prev_tmp[TEMP_CPU]) { + for (i = current_level; i < NUM_FAN_LEVELS; i++) { + if (temp[TEMP_CPU] >= fan_step_table[i].on[TEMP_CPU]) + current_level = i; + 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)); + } +} |