summaryrefslogtreecommitdiff
path: root/zephyr/program/skyrim/markarth/src/thermal.c
diff options
context:
space:
mode:
authormatt_wang <matt_wang@compal.corp-partner.google.com>2023-03-16 15:07:29 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-28 13:27:45 +0000
commit406479236a4848beed8d07fd75c98ea89e78d38f (patch)
tree0eb1ac2245b881cc152519eab91d7f82345ebeac /zephyr/program/skyrim/markarth/src/thermal.c
parent60ec9acc47cf55ff3be3d16d53b50374c450837c (diff)
downloadchrome-ec-406479236a4848beed8d07fd75c98ea89e78d38f.tar.gz
markarth: moidfy fan table
According to the thermal team's request to modify the fan table. BUG=b:273636132 BRANCH=none TEST=thermal team member test pass LOW_COVERAGE_REASON=markarth not implement fan test yet. b/275133976 Change-Id: I6742b5008b536a760b3f0ddcc3f3d883ba5c7080 Signed-off-by: matt_wang <matt_wang@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4344829 Reviewed-by: Chao Gui <chaogui@google.com> Commit-Queue: Chao Gui <chaogui@google.com> Reviewed-by: Josh Tsai <josh_tsai@compal.corp-partner.google.com> (cherry picked from commit 272b7f98b0538d5a0013617a568cd345a5fc1ced) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4374559
Diffstat (limited to 'zephyr/program/skyrim/markarth/src/thermal.c')
-rw-r--r--zephyr/program/skyrim/markarth/src/thermal.c99
1 files changed, 99 insertions, 0 deletions
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));
+ }
+}