From 9ce71b3cca0b59fdc262d89dafc8f75efbc167a6 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Fri, 12 Jul 2013 14:43:11 +0200 Subject: ec/kontron/it8516e: Add PWM limits option Add an option to set minimal and maximal PWM percentages when the fan is in temperature controlled mode. Also fix a non-ascii flaw. Change-Id: I85ae244bee2145bf17d6c29e93dd4871540985c8 Signed-off-by: Nico Huber Reviewed-on: http://review.coreboot.org/3774 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Ronald G. Minnich --- src/ec/kontron/it8516e/chip.h | 7 +++++-- src/ec/kontron/it8516e/ec.c | 45 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 8 deletions(-) (limited to 'src/ec') diff --git a/src/ec/kontron/it8516e/chip.h b/src/ec/kontron/it8516e/chip.h index 5638efd696..a0e6dd7553 100644 --- a/src/ec/kontron/it8516e/chip.h +++ b/src/ec/kontron/it8516e/chip.h @@ -30,12 +30,15 @@ struct ec_kontron_it8516e_config { * Can be overwritten by * systemp_type, * fan1_mode, fan2_mode, - * fan1_target, and fan2_target + * fan1_target, fan2_target, + * fan1_min, fan2_min, fan1_max, and fan2_max * nvram options. */ enum it8516e_systemp_types default_systemp; enum it8516e_fan_modes default_fan_mode[2]; - u16 default_fan_target[2]; /* PWM: % / Speed: RPM / Thermal: °C */ + u16 default_fan_target[2]; /* PWM: % / Speed: RPM / Thermal: degree C */ + u8 default_fan_min[2]; /* min PWM in % */ + u8 default_fan_max[2]; /* max PWM in % */ }; #endif /* EC_KONTRON_IT8516E_CHIP_H */ diff --git a/src/ec/kontron/it8516e/ec.c b/src/ec/kontron/it8516e/ec.c index 2cf4f90fa2..d4e6019fd5 100644 --- a/src/ec/kontron/it8516e/ec.c +++ b/src/ec/kontron/it8516e/ec.c @@ -40,6 +40,7 @@ enum { /* EC commands */ IT8516E_CMD_SET_FAN_SPEED = 0x15, IT8516E_CMD_GET_FAN_TEMP = 0x16, IT8516E_CMD_SET_FAN_TEMP = 0x17, + IT8516E_CMD_SET_FAN_LIMITS = 0x1a, }; static void it8516e_set_systemp_type(const u8 type) @@ -89,14 +90,29 @@ static void it8516e_set_fan_temperature(const u8 idx, const u8 temp) send_ec_data(((temp << 6) >> 8) & 0xff); } +static void it8516e_set_fan_limits(const u8 idx, const u8 min, const u8 max) +{ + if (send_ec_command(IT8516E_CMD_SET_FAN_LIMITS)) + return; + if (send_ec_data(idx)) + return; + if (send_ec_data(min)) + return; + send_ec_data(max); +} + static void it8516e_set_fan_from_options(const config_t *const config, const u8 fan_idx) { static char fanX_mode[] = "fanX_mode"; static char fanX_target[] = "fanX_target"; + static char fanX_min[] = "fanX_min"; + static char fanX_max[] = "fanX_max"; - u8 fan_mode = config->default_fan_mode[fan_idx]; - u16 fan_target = config->default_fan_target[fan_idx]; + u8 fan_mode = config->default_fan_mode[fan_idx]; + u16 fan_target = config->default_fan_target[fan_idx]; + u8 fan_min = config->default_fan_min[fan_idx]; + u8 fan_max = config->default_fan_max[fan_idx]; fanX_mode[3] = '1' + fan_idx; get_option(&fan_mode, fanX_mode); @@ -129,11 +145,28 @@ static void it8516e_set_fan_from_options(const config_t *const config, break; case IT8516E_MODE_THERMAL: printk(BIOS_DEBUG, - "Setting it8516e fan%d " - "control to %d°C.\n", + "Setting it8516e fan%d control to %d C.\n", fan_idx + 1, fan_target); - it8516e_set_fan_temperature( - fan_idx, fan_target); + it8516e_set_fan_temperature(fan_idx, fan_target); + + fanX_min[3] = '1' + fan_idx; + fanX_max[3] = '1' + fan_idx; + get_option(&fan_min, fanX_min); + get_option(&fan_max, fanX_max); + + if (!fan_max || fan_max > 100) /* Constrain fan_max to 100% */ + fan_max = 100; + if (fan_min >= 100) /* Constrain fan_min to 99% */ + fan_min = 99; + if (fan_max <= fan_min) /* If fan_min is the higher of the two, + it's safer for the hardware to keep + its value. Therefore, update fan_max. */ + fan_max = fan_min + 1; + + printk(BIOS_DEBUG, + "Setting it8516e fan%d limits to %d%% - %d%% PWM.\n", + fan_idx + 1, fan_min, fan_max); + it8516e_set_fan_limits(fan_idx, fan_min, fan_max); break; } } -- cgit v1.2.3