summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu-An Chen <yu-an.chen@quanta.corp-partner.google.com>2022-07-14 14:01:24 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-20 00:32:50 +0000
commitfba0a2092ae80395754ebb2a310024ce2e2eaaf5 (patch)
treed12df1d7edeefd1441e7aa07b2d53d2448d05770
parent726707640938b7fe5d0bf7a538976543fa7aaf01 (diff)
downloadchrome-ec-fba0a2092ae80395754ebb2a310024ce2e2eaaf5.tar.gz
osiris: Update thermal policy
This CL updated fan control policy to step control. Each fan has its own control table, and the number of steps can be different between two fans. BUG=b:234545460 BRANCH=none TEST=Thermal team verified thermal policy is expected. Signed-off-by: Yu-An Chen <yu-an.chen@quanta.corp-partner.google.com> Change-Id: I2572868974947beade5e6f83610130d9110814ff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3760804 Commit-Queue: Boris Mittelberg <bmbm@google.com> Reviewed-by: Boris Mittelberg <bmbm@google.com>
-rw-r--r--board/osiris/board.h1
-rw-r--r--board/osiris/fans.c155
-rw-r--r--board/osiris/sensors.c12
3 files changed, 158 insertions, 10 deletions
diff --git a/board/osiris/board.h b/board/osiris/board.h
index d52f52878e..685e84a4fb 100644
--- a/board/osiris/board.h
+++ b/board/osiris/board.h
@@ -123,6 +123,7 @@
#define CONFIG_STEINHART_HART_3V3_30K9_47K_4050B
#define CONFIG_FANS FAN_CH_COUNT
+#define CONFIG_FAN_RPM_CUSTOM
/* Charger defines */
#define CONFIG_CHARGER_ISL9241
diff --git a/board/osiris/fans.c b/board/osiris/fans.c
index e5ea507099..746d4c85c6 100644
--- a/board/osiris/fans.c
+++ b/board/osiris/fans.c
@@ -12,6 +12,7 @@
#include "fan.h"
#include "hooks.h"
#include "pwm.h"
+#include "util.h"
/* MFT channels. These are logically separate from pwm_channels. */
const struct mft_t mft_channels[] = {
@@ -50,14 +51,14 @@ static const struct fan_conf fan_conf_1 = {
* boards as well.
*/
static const struct fan_rpm fan_rpm_0 = {
- .rpm_min = 3000,
- .rpm_start = 3000,
+ .rpm_min = 2500,
+ .rpm_start = 2500,
.rpm_max = 6000,
};
static const struct fan_rpm fan_rpm_1 = {
- .rpm_min = 3000,
- .rpm_start = 3000,
+ .rpm_min = 2500,
+ .rpm_start = 2500,
.rpm_max = 6000,
};
@@ -71,3 +72,149 @@ const struct fan_t fans[FAN_CH_COUNT] = {
.rpm = &fan_rpm_1,
},
};
+
+/* fan control */
+
+struct fan_step {
+ int on;
+ int off;
+ int rpm;
+};
+
+struct fan_table_config {
+ /* number of control_table */
+ uint8_t step;
+ /* fan control table */
+ const struct fan_step *control_table;
+};
+
+const struct fan_step fan_table0[] = {
+ { .on = 25, .off = 0, .rpm = 0 },
+ { .on = 37, .off = 34, .rpm = 2500 },
+ { .on = 42, .off = 39, .rpm = 2800 },
+ { .on = 46, .off = 43, .rpm = 3000 },
+ { .on = 51, .off = 48, .rpm = 3200 },
+ { .on = 55, .off = 52, .rpm = 3600 },
+ { .on = 59, .off = 56, .rpm = 4000 },
+ { .on = 66, .off = 63, .rpm = 4600 },
+ { .on = 72, .off = 69, .rpm = 5000 },
+ { .on = 74, .off = 71, .rpm = 5500 },
+};
+const int fan_table0_count = ARRAY_SIZE(fan_table0);
+
+const struct fan_step fan_table1[] = {
+ { .on = 25, .off = 0, .rpm = 0 },
+ { .on = 51, .off = 48, .rpm = 3200 },
+ { .on = 55, .off = 52, .rpm = 3600 },
+ { .on = 59, .off = 56, .rpm = 4000 },
+ { .on = 66, .off = 63, .rpm = 4600 },
+ { .on = 72, .off = 69, .rpm = 5000 },
+ { .on = 74, .off = 71, .rpm = 5500 },
+};
+const int fan_table1_count = ARRAY_SIZE(fan_table1);
+
+/* Fan control configuration */
+static struct fan_table_config fan_tables[] = {
+ [FAN_CH_0] = {
+ .step = fan_table0_count,
+ .control_table = (const struct fan_step *) &fan_table0,
+ },
+ [FAN_CH_1] = {
+ .step = fan_table1_count,
+ .control_table = (const struct fan_step *) &fan_table1,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(fan_tables) == FAN_CH_COUNT);
+
+static int current_level[] = { 0, 0 };
+BUILD_ASSERT(ARRAY_SIZE(current_level) == FAN_CH_COUNT);
+
+static int previous_level[] = { 0, 0 };
+BUILD_ASSERT(ARRAY_SIZE(previous_level) == FAN_CH_COUNT);
+
+#undef BOARD_FAN_TEST
+
+#ifdef BOARD_FAN_TEST
+static int manual_temp = -1;
+#endif
+
+int fan_percent_to_rpm(int fan, int pct)
+{
+ static struct fan_table_config *fan_table;
+ static int previous_pct;
+ int i;
+
+ fan_table = &fan_tables[fan];
+
+#ifdef BOARD_FAN_TEST
+ if (manual_temp != -1)
+ pct = manual_temp;
+#endif
+
+ /*
+ * Compare the pct and previous pct, we have the three paths :
+ * 1. decreasing path. (check the off point)
+ * 2. increasing path. (check the on point)
+ * 3. invariant path. (return the current RPM)
+ */
+ if (pct < previous_pct) {
+ for (i = current_level[fan]; i >= 0; i--) {
+ if (pct <= fan_table->control_table[i].off)
+ current_level[fan] = i - 1;
+ else
+ break;
+ }
+ } else if (pct > previous_pct) {
+ for (i = current_level[fan] + 1; i < fan_table->step; i++) {
+ if (pct >= fan_table->control_table[i].on)
+ current_level[fan] = i;
+ else
+ break;
+ }
+ }
+
+ if (current_level[fan] < 0)
+ current_level[fan] = 0;
+
+ if (current_level[fan] != previous_level[fan])
+ cprints(CC_THERMAL, "Fan %d: Set fan RPM to %d", fan,
+ fan_table->control_table[current_level[fan]].rpm);
+
+ if (fan == (FAN_CH_COUNT - 1))
+ previous_pct = pct;
+
+#ifdef BOARD_FAN_TEST
+ if (manual_temp != -1)
+ ccprints("Fan%d: temps:%d curr:%d prev:%d rpm:%d", fan, pct,
+ current_level[fan], previous_level[fan],
+ fan_table->control_table[current_level[fan]].rpm);
+#endif
+
+ previous_level[fan] = current_level[fan];
+
+ return fan_table->control_table[current_level[fan]].rpm;
+}
+
+#ifdef BOARD_FAN_TEST
+static int command_fan_test(int argc, char **argv)
+{
+ char *e;
+ int t;
+
+ if (argc > 1) {
+ t = strtoi(argv[1], &e, 0);
+ if (*e) {
+ ccprints("Invalid test temp");
+ return EC_ERROR_INVAL;
+ }
+ manual_temp = t;
+ ccprints("manual temp is %d", manual_temp);
+ return EC_SUCCESS;
+ }
+ manual_temp = -1;
+ ccprints("manual temp reset");
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(fan_test, command_fan_test, "[temperature]",
+ "set manual temperature for fan test");
+#endif
diff --git a/board/osiris/sensors.c b/board/osiris/sensors.c
index 8c50a9514c..65551e5198 100644
--- a/board/osiris/sensors.c
+++ b/board/osiris/sensors.c
@@ -63,9 +63,9 @@ const struct temp_sensor_t temp_sensors[] = {
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
/*
- * TODO(b/234545460): update for Alder Lake/brya
- *
- * temperature limit, See thermal table in b/234545460#comment2
+ * Temperature limit, See thermal table in b/234545460#comment16
+ * For real temperature in fan control table, set temp_fan_off
+ * and temp_fan_max to 0 and 99.
*/
/*
* TODO(b/202062363): Remove when clang is fixed.
@@ -74,13 +74,13 @@ BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
{ \
.temp_host = { \
[EC_TEMP_THRESH_HIGH] = C_TO_K(78), \
- [EC_TEMP_THRESH_HALT] = C_TO_K(90), \
+ [EC_TEMP_THRESH_HALT] = C_TO_K(80), \
}, \
.temp_host_release = { \
[EC_TEMP_THRESH_HIGH] = C_TO_K(75), \
}, \
- .temp_fan_off = C_TO_K(25), \
- .temp_fan_max = C_TO_K(89), \
+ .temp_fan_off = C_TO_K(0), \
+ .temp_fan_max = C_TO_K(99), \
}
__maybe_unused static const struct ec_thermal_config thermal_cpu = THERMAL_CPU;