summaryrefslogtreecommitdiff
path: root/board/eldrid
diff options
context:
space:
mode:
authorScott Chao <scott_chao@wistron.corp-partner.google.com>2020-09-04 18:05:35 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-15 18:24:06 +0000
commit06d1dbc4bb5337a3782936b7895dd571f7b57732 (patch)
treed7306443347b0b8adf62a3270d844c3ffea92def /board/eldrid
parent50a60938781de636dd29bc29c18a7a512f4b8e33 (diff)
downloadchrome-ec-06d1dbc4bb5337a3782936b7895dd571f7b57732.tar.gz
eldrid: add custom fan control
This is an initial version. Also disable fan when enter S0ix. BUG=b:167931578 BRANCH=none TEST=make -j BOARD=volteer TEST=make buildall TEST=verify by thermal team Change-Id: I146caf056486709763d2793e9c43b6e713bf87e0 Signed-off-by: Scott Chao <scott_chao@wistron.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2393408 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Diffstat (limited to 'board/eldrid')
-rw-r--r--board/eldrid/board.h1
-rw-r--r--board/eldrid/build.mk1
-rw-r--r--board/eldrid/thermal.c161
3 files changed, 163 insertions, 0 deletions
diff --git a/board/eldrid/board.h b/board/eldrid/board.h
index 8e59d5e0c6..0e8d754182 100644
--- a/board/eldrid/board.h
+++ b/board/eldrid/board.h
@@ -114,6 +114,7 @@
/* Volume Button feature */
/* Fan features */
+#define CONFIG_CUSTOM_FAN_CONTROL
/* charger defines */
#define CONFIG_CHARGER_SENSE_RESISTOR 10
diff --git a/board/eldrid/build.mk b/board/eldrid/build.mk
index b78172d3cf..8a5f8f68cd 100644
--- a/board/eldrid/build.mk
+++ b/board/eldrid/build.mk
@@ -15,3 +15,4 @@ board-y=board.o
board-y+=battery.o
board-y+=led.o
board-y+=sensors.o
+board-y+=thermal.o
diff --git a/board/eldrid/thermal.c b/board/eldrid/thermal.c
new file mode 100644
index 0000000000..ce36ce3860
--- /dev/null
+++ b/board/eldrid/thermal.c
@@ -0,0 +1,161 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * 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 "hooks.h"
+#include "host_command.h"
+#include "temp_sensor.h"
+#include "thermal.h"
+#include "util.h"
+
+/* Console output macros */
+#define CPUTS(outstr) cputs(CC_THERMAL, outstr)
+#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
+
+struct fan_step {
+ /*
+ * Sensor 1~4 trigger point, set -1 if we're not using this
+ * sensor to determine fan speed.
+ */
+ int8_t on[TEMP_SENSOR_COUNT];
+
+ /*
+ * Sensor 1~4 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];
+};
+
+/*
+ * TODO(b/167931578) Only monitor sensor3 for now.
+ * Will add more sensors support if needed.
+ */
+static const struct fan_step fan_table[] = {
+ {
+ /* level 0 */
+ .on = {-1, -1, 36, -1},
+ .off = {-1, -1, 0, -1},
+ .rpm = {0},
+ },
+ {
+ /* level 1 */
+ .on = {-1, -1, 38, -1},
+ .off = {-1, -1, 36, -1},
+ .rpm = {2000},
+ },
+ {
+ /* level 2 */
+ .on = {-1, -1, 41, -1},
+ .off = {-1, -1, 39, -1},
+ .rpm = {2600},
+ },
+ {
+ /* level 3 */
+ .on = {-1, -1, 44, -1},
+ .off = {-1, -1, 42, -1},
+ .rpm = {3000},
+ },
+ {
+ /* level 4 */
+ .on = {-1, -1, 46, -1},
+ .off = {-1, -1, 44, -1},
+ .rpm = {3300},
+ },
+ {
+ /* level 5 */
+ .on = {-1, -1, 49, -1},
+ .off = {-1, -1, 47, -1},
+ .rpm = {3600},
+ },
+ {
+ /* level 6 */
+ .on = {-1, -1, 51, -1},
+ .off = {-1, -1, 49, -1},
+ .rpm = {4200},
+ },
+ {
+ /* level 7 */
+ .on = {-1, -1, 55, -1},
+ .off = {-1, -1, 52, -1},
+ .rpm = {4700},
+ },
+};
+
+int fan_table_to_rpm(int fan, int *temp)
+{
+ /* current fan level */
+ static int current_level;
+ /* previous sensor temperature */
+ static int prev_temp[TEMP_SENSOR_COUNT];
+ const int num_fan_levels = ARRAY_SIZE(fan_table);
+ int i;
+ int new_rpm = 0;
+
+ /*
+ * 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)
+ */
+
+ CPRINTS("temp: %d, prev_temp: %d", temp[TEMP_SENSOR_3_DDR_SOC],
+ prev_temp[TEMP_SENSOR_3_DDR_SOC]);
+ if (temp[TEMP_SENSOR_3_DDR_SOC] < prev_temp[TEMP_SENSOR_3_DDR_SOC]) {
+ for (i = current_level; i > 0; i--) {
+ if (temp[TEMP_SENSOR_3_DDR_SOC] <
+ fan_table[i].off[TEMP_SENSOR_3_DDR_SOC])
+ current_level = i - 1;
+ else
+ break;
+ }
+ } else if (temp[TEMP_SENSOR_3_DDR_SOC] >
+ prev_temp[TEMP_SENSOR_3_DDR_SOC]) {
+ for (i = current_level; i < num_fan_levels; i++) {
+ if (temp[TEMP_SENSOR_3_DDR_SOC] >
+ fan_table[i].on[TEMP_SENSOR_3_DDR_SOC])
+ current_level = i + 1;
+ else
+ break;
+ }
+ }
+
+ if (current_level < 0)
+ current_level = 0;
+
+ for (i = 0; i < TEMP_SENSOR_COUNT; ++i)
+ prev_temp[i] = temp[i];
+
+ CPRINTS("current_level: %d", current_level);
+
+ switch (fan) {
+ case FAN_CH_0:
+ new_rpm = fan_table[current_level].rpm[FAN_CH_0];
+ break;
+ default:
+ break;
+ }
+
+ return new_rpm;
+}
+
+void board_override_fan_control(int fan, int *temp)
+{
+ if (chipset_in_state(CHIPSET_STATE_ON)) {
+ fan_set_rpm_mode(FAN_CH(fan), 1);
+ fan_set_rpm_target(FAN_CH(fan),
+ fan_table_to_rpm(fan, temp));
+ } else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) {
+ /* Stop fan when enter S0ix */
+ fan_set_rpm_mode(FAN_CH(fan), 1);
+ fan_set_rpm_target(FAN_CH(fan), 0);
+ }
+}