diff options
author | Raymond Chung <raymondchung@ami.corp-partner.google.com> | 2022-11-01 14:45:42 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-10 09:28:51 +0000 |
commit | a7ac3c24ef9ea655be4f8fb1a59bcd9b2c460f29 (patch) | |
tree | 43b9068763950b5e8d02919644982a7cf7d5d2a3 /board/gaelin | |
parent | 871f6b34054a07cd68c7cfec459db272d000b434 (diff) | |
download | chrome-ec-a7ac3c24ef9ea655be4f8fb1a59bcd9b2c460f29.tar.gz |
gaelin: Enable the fan controlrelease-R109-15237.B-main
Fan control with custom fan table.
BUG=b:249000573
BRANCH=None
TEST=Thermal team verified thermal policy is expected.
Change-Id: Ifbd3d8ffbc8035e5b3075bf840beccd158e28e18
Signed-off-by: Raymond Chung <raymondchung@ami.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3995727
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Derek Huang <derekhuang@google.com>
Diffstat (limited to 'board/gaelin')
-rw-r--r-- | board/gaelin/board.h | 7 | ||||
-rw-r--r-- | board/gaelin/build.mk | 1 | ||||
-rw-r--r-- | board/gaelin/fans.c | 12 | ||||
-rw-r--r-- | board/gaelin/pwm.c | 4 | ||||
-rw-r--r-- | board/gaelin/thermal.c | 140 |
5 files changed, 149 insertions, 15 deletions
diff --git a/board/gaelin/board.h b/board/gaelin/board.h index f113c6cffd..8323c99599 100644 --- a/board/gaelin/board.h +++ b/board/gaelin/board.h @@ -136,11 +136,10 @@ /* ADC */ #define CONFIG_ADC -/* - * TODO(b/197478860): Enable the fan control. We need - * to check the sensor value and adjust the fan speed. - */ +/* Fan */ #define CONFIG_FANS FAN_CH_COUNT +#define RPM_DEVIATION 1 +#define CONFIG_CUSTOM_FAN_CONTROL /* Include math_util for bitmask_uint64 used in pd_timers */ #define CONFIG_MATH_UTIL diff --git a/board/gaelin/build.mk b/board/gaelin/build.mk index 3de758d1bd..6961fb3f60 100644 --- a/board/gaelin/build.mk +++ b/board/gaelin/build.mk @@ -19,4 +19,5 @@ board-y+=i2c.o board-y+=led.o board-y+=pwm.o board-y+=sensors.o +board-y+=thermal.o board-y+=usbc_config.o diff --git a/board/gaelin/fans.c b/board/gaelin/fans.c index 6828438a10..5f54e6e63c 100644 --- a/board/gaelin/fans.c +++ b/board/gaelin/fans.c @@ -30,16 +30,10 @@ static const struct fan_conf fan_conf_0 = { .enable_gpio = GPIO_EN_PP5000_FAN, }; -/* - * TOOD(b/197478860): need to update for real fan - * - * Prototype fan spins at about 7200 RPM at 100% PWM. - * Set minimum at around 30% PWM. - */ static const struct fan_rpm fan_rpm_0 = { - .rpm_min = 2200, - .rpm_start = 2200, - .rpm_max = 7200, + .rpm_min = 2350, + .rpm_start = 2350, + .rpm_max = 4100, }; const struct fan_t fans[FAN_CH_COUNT] = { diff --git a/board/gaelin/pwm.c b/board/gaelin/pwm.c index 3d4335f453..fe7e82894a 100644 --- a/board/gaelin/pwm.c +++ b/board/gaelin/pwm.c @@ -16,8 +16,8 @@ const struct pwm_t pwm_channels[] = { PWM_CONFIG_DSLEEP, .freq = 2000 }, [PWM_CH_FAN] = { .channel = 5, - .flags = PWM_CONFIG_OPEN_DRAIN | PWM_CONFIG_DSLEEP, - .freq = 1000 }, + .flags = PWM_CONFIG_OPEN_DRAIN, + .freq = 25000 }, [PWM_CH_LED_RED] = { .channel = 2, .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, .freq = 2000 }, diff --git a/board/gaelin/thermal.c b/board/gaelin/thermal.c new file mode 100644 index 0000000000..e15e0043e1 --- /dev/null +++ b/board/gaelin/thermal.c @@ -0,0 +1,140 @@ +/* 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 "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 */ + int16_t rpm[FAN_CH_COUNT]; +}; + +static const struct fan_step fan_table[] = { + { + /* level 0 */ + .on = { 65, -1, -1, -1 }, + .off = { 0, -1, -1, -1 }, + .rpm = { 2350 }, + }, + { + /* level 1 */ + .on = { 80, -1, -1, -1 }, + .off = { 60, -1, -1, -1 }, + .rpm = { 2350 }, + }, + { + /* level 2 */ + .on = { 87, -1, -1, -1 }, + .off = { 75, -1, -1, -1 }, + .rpm = { 3250 }, + }, + { + /* level 3 */ + .on = { 91, -1, -1, -1 }, + .off = { 82, -1, -1, -1 }, + .rpm = { 3750 }, + }, + { + /* level 4 */ + .on = { 100, -1, -1, -1 }, + .off = { 86, -1, -1, -1 }, + .rpm = { 4100 }, + }, +}; +const int num_fan_levels = ARRAY_SIZE(fan_table); + +int fan_table_to_rpm(int fan, int *temp, enum temp_sensor_id temp_sensor) +{ + /* current fan level */ + static int current_level; + /* previous fan level */ + static int prev_current_level; + /* previous sensor temperature */ + static int prev_temp[TEMP_SENSOR_COUNT]; + 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) + */ + if (temp[temp_sensor] < prev_temp[temp_sensor]) { + for (i = current_level; i > 0; i--) { + if (temp[temp_sensor] < fan_table[i].off[temp_sensor]) + current_level = i - 1; + else + break; + } + } else if (temp[temp_sensor] > prev_temp[temp_sensor]) { + for (i = current_level; i < num_fan_levels; i++) { + if (temp[temp_sensor] > fan_table[i].on[temp_sensor]) + current_level = i + 1; + else + break; + } + } + + if (current_level < 0) + current_level = 0; + if (current_level >= num_fan_levels) + current_level = num_fan_levels - 1; + + if (current_level != prev_current_level) { + CPRINTS("temp: %d, prev_temp: %d", temp[temp_sensor], + prev_temp[temp_sensor]); + CPRINTS("current_level: %d", current_level); + } + + prev_temp[temp_sensor] = temp[temp_sensor]; + prev_current_level = 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_CH(fan), temp, + TEMP_SENSOR_1_CPU)); + } 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); + } +} |