summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorZick Wei <zick.wei@quanta.corp-partner.google.com>2022-11-02 09:55:37 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-08 07:04:48 +0000
commitb33d0923d0965cc478ef43ec1c2e4eac6f20e4b4 (patch)
treea7405d26c987dbb15ed47de259fcf115a818584b /zephyr
parent54e6e96e64196737aa491b1d647cb765d5170b84 (diff)
downloadchrome-ec-b33d0923d0965cc478ef43ec1c2e4eac6f20e4b4.tar.gz
yaviks: update fan table to v1-1
Implement fan steps table V1-1_20221015, and enable config CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL, set fan rpm deviation to 1. BUG=b:253557900 BRANCH=none TEST=make sure fan follow fan steps. Signed-off-by: Zick Wei <zick.wei@quanta.corp-partner.google.com> Change-Id: Ie9876af7a0cb85b9bd8dfa85a9b3b4950c24c50f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3997773 Code-Coverage: Andrew McRae <amcrae@google.com> Reviewed-by: Andrew McRae <amcrae@google.com> Commit-Queue: Andrew McRae <amcrae@google.com> Tested-by: Andrew McRae <amcrae@google.com>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/program/nissa/CMakeLists.txt1
-rw-r--r--zephyr/program/nissa/yaviks/fan.dtsi71
-rw-r--r--zephyr/program/nissa/yaviks/overlay.dtsi46
-rw-r--r--zephyr/program/nissa/yaviks/project.conf1
-rw-r--r--zephyr/program/nissa/yaviks/project.overlay1
-rw-r--r--zephyr/program/nissa/yaviks/src/thermal.c107
6 files changed, 190 insertions, 37 deletions
diff --git a/zephyr/program/nissa/CMakeLists.txt b/zephyr/program/nissa/CMakeLists.txt
index 8769af58ba..7088092ae6 100644
--- a/zephyr/program/nissa/CMakeLists.txt
+++ b/zephyr/program/nissa/CMakeLists.txt
@@ -77,6 +77,7 @@ if(DEFINED CONFIG_BOARD_YAVIKS)
zephyr_library_sources(
"yaviks/src/led.c"
"yaviks/src/keyboard.c"
+ "yaviks/src/thermal.c"
)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "yaviks/src/usbc.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGER "yaviks/src/charger.c")
diff --git a/zephyr/program/nissa/yaviks/fan.dtsi b/zephyr/program/nissa/yaviks/fan.dtsi
new file mode 100644
index 0000000000..229530b57a
--- /dev/null
+++ b/zephyr/program/nissa/yaviks/fan.dtsi
@@ -0,0 +1,71 @@
+/* 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.
+ */
+/ {
+ fans {
+ compatible = "cros-ec,fans";
+ fan_0 {
+ pwms = <&pwm2 PWM_CHANNEL_2 PWM_KHZ(25) PWM_POLARITY_NORMAL>;
+ tach = <&tach1>;
+ rpm_min = <2500>;
+ rpm_start = <2500>;
+ rpm_max = <4100>;
+ rpm_deviation = <1>;
+ enable_gpio = <&gpio_fan_enable>;
+ };
+ };
+ fan_steps {
+ compatible = "cros-ec,fan-steps";
+ level_0 {
+ temp_on = <44 47 0>;
+ temp_off = <99 99 99>;
+ rpm_target = <0>;
+ };
+ level_1 {
+ temp_on = <48 48 0>;
+ temp_off = <43 45 99>;
+ rpm_target = <2600>;
+ };
+ level_2 {
+ temp_on = <50 49 0>;
+ temp_off = <47 46 99>;
+ rpm_target = <2800>;
+ };
+ level_3 {
+ temp_on = <52 50 54>;
+ temp_off = <49 47 51>;
+ rpm_target = <3000>;
+ };
+ level_4 {
+ temp_on = <54 56 60>;
+ temp_off = <51 48 52>;
+ rpm_target = <3300>;
+ };
+ level_5 {
+ temp_on = <60 60 64>;
+ temp_off = <53 52 56>;
+ rpm_target = <3600>;
+ };
+ level_6 {
+ temp_on = <100 100 100>;
+ temp_off = <59 54 58>;
+ rpm_target = <4100>;
+ };
+ };
+};
+/* pwm for fan */
+&pwm2 {
+ status = "okay";
+ prescaler-cx = <PWM_PRESCALER_C6>;
+ pinctrl-0 = <&pwm2_gpa2_default>;
+ pinctrl-names = "default";
+};
+/* fan tachometer sensor */
+&tach1 {
+ status = "okay";
+ channel = <IT8XXX2_TACH_CHANNEL_A>;
+ pulses-per-round = <2>;
+ pinctrl-0 = <&tach1a_gpd7_default>;
+ pinctrl-names = "default";
+};
diff --git a/zephyr/program/nissa/yaviks/overlay.dtsi b/zephyr/program/nissa/yaviks/overlay.dtsi
index d768116444..2a5a8561a0 100644
--- a/zephyr/program/nissa/yaviks/overlay.dtsi
+++ b/zephyr/program/nissa/yaviks/overlay.dtsi
@@ -130,17 +130,17 @@
};
};
- temp_cpu: cpu {
+ temp_cpu_thermistor: cpu {
compatible = "cros-ec,temp-sensor-thermistor";
thermistor = <&thermistor_3V3_51K1_47K_4050B>;
adc = <&adc_temp_sensor_1>;
};
- temp_5v_regulator: 5v_regulator {
+ temp_5v_regulator_thermistor: 5v-regulator {
compatible = "cros-ec,temp-sensor-thermistor";
thermistor = <&thermistor_3V3_51K1_47K_4050B>;
adc = <&adc_temp_sensor_2>;
};
- temp_charger: charger {
+ temp_charger_thermistor: charger {
compatible = "cros-ec,temp-sensor-thermistor";
thermistor = <&thermistor_3V3_51K1_47K_4050B>;
adc = <&adc_temp_sensor_3>;
@@ -148,32 +148,32 @@
named-temp-sensors {
compatible = "cros-ec,temp-sensors";
- cpu {
+ temp_cpu: cpu {
temp_fan_off = <45>;
temp_fan_max = <60>;
temp_host_high = <75>;
temp_host_halt = <85>;
temp_host_release_high = <65>;
power-good-pin = <&gpio_ec_soc_dsw_pwrok>;
- sensor = <&temp_cpu>;
+ sensor = <&temp_cpu_thermistor>;
};
- 5v_regulator {
+ temp_5v_regulator: 5v-regulator {
temp_fan_off = <50>;
temp_fan_max = <65>;
temp_host_high = <75>;
temp_host_halt = <85>;
temp_host_release_high = <65>;
power-good-pin = <&gpio_ec_soc_dsw_pwrok>;
- sensor = <&temp_5v_regulator>;
+ sensor = <&temp_5v_regulator_thermistor>;
};
- charger {
+ temp_charger: charger {
temp_fan_off = <50>;
temp_fan_max = <65>;
temp_host_high = <80>;
temp_host_halt = <85>;
temp_host_release_high = <75>;
power-good-pin = <&gpio_ec_soc_dsw_pwrok>;
- sensor = <&temp_charger>;
+ sensor = <&temp_charger_thermistor>;
};
};
@@ -235,18 +235,6 @@
};
};
};
-
- fans {
- compatible = "cros-ec,fans";
- fan_0 {
- pwms = <&pwm2 PWM_CHANNEL_2 PWM_KHZ(25) PWM_POLARITY_NORMAL>;
- tach = <&tach1>;
- rpm_min = <2600>;
- rpm_start = <2600>;
- rpm_max = <4100>;
- enable_gpio = <&gpio_fan_enable>;
- };
- };
};
&thermistor_3V3_51K1_47K_4050B {
@@ -384,19 +372,3 @@
&usbpd0 {
status = "okay";
};
-
-/* pwm for fan */
-&pwm2 {
- status = "okay";
- prescaler-cx = <PWM_PRESCALER_C6>;
- pinctrl-0 = <&pwm2_gpa2_default>;
- pinctrl-names = "default";
-};
-/* fan tachometer sensor */
-&tach1 {
- status = "okay";
- channel = <IT8XXX2_TACH_CHANNEL_A>;
- pulses-per-round = <2>;
- pinctrl-0 = <&tach1a_gpd7_default>;
- pinctrl-names = "default";
-};
diff --git a/zephyr/program/nissa/yaviks/project.conf b/zephyr/program/nissa/yaviks/project.conf
index 0e385b843e..80a9e9ea97 100644
--- a/zephyr/program/nissa/yaviks/project.conf
+++ b/zephyr/program/nissa/yaviks/project.conf
@@ -28,6 +28,7 @@ CONFIG_PLATFORM_EC_KBLIGHT_ENABLE_PIN=n
# Fan
CONFIG_PLATFORM_EC_FAN=y
+CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL=y
# LED
CONFIG_PLATFORM_EC_LED_PWM=n
diff --git a/zephyr/program/nissa/yaviks/project.overlay b/zephyr/program/nissa/yaviks/project.overlay
index a7ce97a8b3..fecd1c98c8 100644
--- a/zephyr/program/nissa/yaviks/project.overlay
+++ b/zephyr/program/nissa/yaviks/project.overlay
@@ -6,6 +6,7 @@
#include "../cbi.dtsi"
#include "cbi.dtsi"
+#include "fan.dtsi"
#include "gpio.dtsi"
#include "keyboard.dtsi"
#include "overlay.dtsi"
diff --git a/zephyr/program/nissa/yaviks/src/thermal.c b/zephyr/program/nissa/yaviks/src/thermal.c
new file mode 100644
index 0000000000..43b30f0497
--- /dev/null
+++ b/zephyr/program/nissa/yaviks/src/thermal.c
@@ -0,0 +1,107 @@
+/* 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 <ap_power/ap_power_interface.h>
+#include "common.h"
+#include "fan.h"
+#include "temp_sensor/temp_sensor.h"
+#include "thermal.h"
+#include "util.h"
+
+#define TEMP_CPU TEMP_SENSOR_ID(DT_NODELABEL(temp_cpu))
+#define TEMP_5V TEMP_SENSOR_ID(DT_NODELABEL(temp_5v_regulator))
+#define TEMP_CHARGER TEMP_SENSOR_ID(DT_NODELABEL(temp_charger))
+
+struct fan_step {
+ /*
+ * Sensor 1~3 trigger point, set -1 if we're not using this
+ * sensor to determine fan speed.
+ */
+ int8_t on[TEMP_SENSOR_COUNT];
+ /*
+ * Sensor 1~3 trigger point, set -1 if we're not using this
+ * sensor to determine fan speed.
+ */
+ int8_t 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_step_table[] = { DT_FOREACH_CHILD(
+ DT_INST(0, cros_ec_fan_steps), FAN_TABLE_ENTRY) };
+
+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)
+ *
+ * Yaviks thermal table V1-1
+ * Increase path judgment: CPU || (5V && Charger)
+ * Decrease path judgment: CPU && 5V && Charger
+ */
+ if (temp[TEMP_CPU] < prev_tmp[TEMP_CPU] ||
+ temp[TEMP_5V] < prev_tmp[TEMP_5V] ||
+ temp[TEMP_CHARGER] < prev_tmp[TEMP_CHARGER]) {
+ for (i = current_level; i > 0; i--) {
+ if (temp[TEMP_CPU] < fan_step_table[i].off[TEMP_CPU] &&
+ temp[TEMP_5V] < fan_step_table[i].off[TEMP_5V] &&
+ temp[TEMP_CHARGER] <
+ fan_step_table[i].off[TEMP_CHARGER]) {
+ current_level = i - 1;
+ } else
+ break;
+ }
+ } else if (temp[TEMP_CPU] > prev_tmp[TEMP_CPU] ||
+ temp[TEMP_5V] > prev_tmp[TEMP_5V] ||
+ temp[TEMP_CHARGER] > prev_tmp[TEMP_CHARGER]) {
+ for (i = current_level; i < ARRAY_SIZE(fan_step_table); i++) {
+ if (temp[TEMP_CPU] > fan_step_table[i].on[TEMP_CPU] ||
+ (temp[TEMP_5V] > fan_step_table[i].on[TEMP_5V] &&
+ temp[TEMP_CHARGER] >
+ fan_step_table[i].on[TEMP_CHARGER])) {
+ current_level = i + 1;
+ } else
+ break;
+ }
+ }
+ if (current_level < 0)
+ current_level = 0;
+
+ if (current_level >= ARRAY_SIZE(fan_step_table))
+ current_level = ARRAY_SIZE(fan_step_table) - 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 (ap_power_in_state(AP_POWER_STATE_ON)) {
+ fan_set_rpm_mode(fan, 1);
+ fan_set_rpm_target(fan, fan_table_to_rpm(fan, temp));
+ }
+}