summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/lm4/pwm.c4
-rw-r--r--common/pwm_commands.c2
-rw-r--r--common/thermal.c35
-rw-r--r--common/thermal_commands.c2
-rw-r--r--include/thermal.h33
5 files changed, 49 insertions, 27 deletions
diff --git a/chip/lm4/pwm.c b/chip/lm4/pwm.c
index 043a8b556c..431f04036f 100644
--- a/chip/lm4/pwm.c
+++ b/chip/lm4/pwm.c
@@ -205,7 +205,7 @@ static int command_fan_set(int argc, char **argv)
#ifdef CONFIG_TASK_THERMAL
/* Disable thermal engine automatic fan control. */
- thermal_toggle_auto_fan_ctrl(0);
+ thermal_control_fan(0);
#endif
return pwm_set_fan_target_rpm(rpm);
@@ -236,7 +236,7 @@ int pwm_set_fan_duty(int percent)
#ifdef CONFIG_TASK_THERMAL
/* Disable thermal engine automatic fan control. */
- thermal_toggle_auto_fan_ctrl(0);
+ thermal_control_fan(0);
#endif
/* Set the duty cycle */
diff --git a/common/pwm_commands.c b/common/pwm_commands.c
index 8cc4d8dc2d..b23f2d82d2 100644
--- a/common/pwm_commands.c
+++ b/common/pwm_commands.c
@@ -28,7 +28,7 @@ int pwm_command_set_fan_target_rpm(struct host_cmd_handler_args *args)
const struct ec_params_pwm_set_fan_target_rpm *p = args->params;
#ifdef CONFIG_TASK_THERMAL
- thermal_toggle_auto_fan_ctrl(0);
+ thermal_control_fan(0);
#endif
pwm_set_fan_target_rpm(p->rpm);
diff --git a/common/thermal.c b/common/thermal.c
index a300497bde..b189075af1 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -9,6 +9,7 @@
#include "common.h"
#include "console.h"
#include "gpio.h"
+#include "hooks.h"
#include "host_command.h"
#include "pwm.h"
#include "task.h"
@@ -55,23 +56,22 @@ static int8_t *fan_threshold_reached = overheated + THRESHOLD_COUNT;
static int fan_ctrl_on = 1;
-
-int thermal_set_threshold(enum temp_sensor_type type, int threshold_id, int value)
+int thermal_set_threshold(enum temp_sensor_type type, int threshold_id,
+ int value)
{
if (type < 0 || type >= TEMP_SENSOR_TYPE_COUNT)
- return -1;
+ return EC_ERROR_INVAL;
if (threshold_id < 0 ||
threshold_id >= THRESHOLD_COUNT + THERMAL_FAN_STEPS)
- return -1;
+ return EC_ERROR_INVAL;
if (value < 0)
- return -1;
+ return EC_ERROR_INVAL;
thermal_config[type].thresholds[threshold_id] = value;
return EC_SUCCESS;
}
-
int thermal_get_threshold(enum temp_sensor_type type, int threshold_id)
{
if (type < 0 || type >= TEMP_SENSOR_TYPE_COUNT)
@@ -83,10 +83,9 @@ int thermal_get_threshold(enum temp_sensor_type type, int threshold_id)
return thermal_config[type].thresholds[threshold_id];
}
-
-int thermal_toggle_auto_fan_ctrl(int auto_fan_on)
+int thermal_control_fan(int enable)
{
- fan_ctrl_on = auto_fan_on;
+ fan_ctrl_on = enable;
return EC_SUCCESS;
}
@@ -100,7 +99,6 @@ static void smi_sensor_failure_warning(void)
host_set_single_event(EC_HOST_EVENT_THERMAL);
}
-
/* TODO: When we need different overheated action for different boards,
* move these action to board-specific file. (e.g. board_thermal.c)
*/
@@ -135,7 +133,6 @@ static void overheated_action(void)
}
}
-
/* Update counter and check if the counter has reached delay limit.
* Note that we have various delay period to prevent one error value triggering
* overheated action. */
@@ -167,7 +164,6 @@ static inline void update_and_check_stat(int temp,
ot_count[sensor_id][threshold_id] = 0;
}
-
static void thermal_process(void)
{
int i, j;
@@ -204,7 +200,6 @@ static void thermal_process(void)
overheated_action();
}
-
void thermal_task(void)
{
while (1) {
@@ -213,6 +208,14 @@ void thermal_task(void)
}
}
+static int thermal_shutdown(void)
+{
+ /* Take back fan control when the processor shuts down */
+ thermal_control_fan(1);
+ return EC_SUCCESS;
+}
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, thermal_shutdown, HOOK_PRIO_DEFAULT);
+
/*****************************************************************************/
/* Console commands */
@@ -228,7 +231,6 @@ static void print_thermal_config(enum temp_sensor_type type)
config->thresholds[THRESHOLD_POWER_DOWN]);
}
-
static void print_fan_stepping(enum temp_sensor_type type)
{
const struct thermal_config_t *config = thermal_config + type;
@@ -242,7 +244,6 @@ static void print_fan_stepping(enum temp_sensor_type type)
fan_speed[i+1]);
}
-
static int command_thermal_config(int argc, char **argv)
{
char *e;
@@ -279,7 +280,6 @@ DECLARE_CONSOLE_COMMAND(thermalconf, command_thermal_config,
"Get/set thermal threshold temp",
NULL);
-
static int command_fan_config(int argc, char **argv)
{
char *e;
@@ -318,10 +318,9 @@ DECLARE_CONSOLE_COMMAND(thermalfan, command_fan_config,
"Get/set thermal threshold fan rpm",
NULL);
-
static int command_thermal_auto_fan_ctrl(int argc, char **argv)
{
- return thermal_toggle_auto_fan_ctrl(1);
+ return thermal_control_fan(1);
}
DECLARE_CONSOLE_COMMAND(autofan, command_thermal_auto_fan_ctrl,
NULL,
diff --git a/common/thermal_commands.c b/common/thermal_commands.c
index 4638b60ac3..07261ce5fb 100644
--- a/common/thermal_commands.c
+++ b/common/thermal_commands.c
@@ -42,7 +42,7 @@ DECLARE_HOST_COMMAND(EC_CMD_THERMAL_GET_THRESHOLD,
int thermal_command_auto_fan_ctrl(struct host_cmd_handler_args *args)
{
- if (thermal_toggle_auto_fan_ctrl(1))
+ if (thermal_control_fan(1))
return EC_RES_ERROR;
return EC_RES_SUCCESS;
}
diff --git a/include/thermal.h b/include/thermal.h
index 6259504c01..8b32bf9773 100644
--- a/include/thermal.h
+++ b/include/thermal.h
@@ -46,13 +46,36 @@ struct thermal_config_t {
int16_t thresholds[THRESHOLD_COUNT + THERMAL_FAN_STEPS];
};
-/* Set the threshold temperature value. Return -1 on error. */
-int thermal_set_threshold(enum temp_sensor_type type, int threshold_id, int value);
+/**
+ * Set a threshold temperature.
+ *
+ * @param type Sensor type to set threshold for
+ * @param threshold_id Threshold ID to set
+ * @param value New threshold temperature in K, or
+ * THERMAL_THRESHOLD_DISABLE to disable this threshold.
+ *
+ * @return EC_SUCCESS if success, non-zero if error.
+ */
+int thermal_set_threshold(enum temp_sensor_type type, int threshold_id,
+ int value);
-/* Get the threshold temperature value. Return -1 on error. */
+/**
+ * Read a threshold temperature.
+ *
+ * @param type Sensor type to get threshold for
+ * @param threshold_id Threshold ID
+ *
+ * @return The threshold temperature in K, THERMAL_THRESHOLD_DISABLE if
+ * disabled, -1 if error.
+ */
int thermal_get_threshold(enum temp_sensor_type type, int threshold_id);
-/* Toggle automatic fan speed control. Return -1 on error. */
-int thermal_toggle_auto_fan_ctrl(int auto_fan_on);
+/**
+ * Enable/disable automatic fan speed control
+ *
+ * @param enable Enable (!=0) or disable (0) auto fan control
+ *
+ * @return EC_SUCCESS if successful, non-zero if error. */
+int thermal_control_fan(int enable);
#endif /* __CROS_EC_THERMAL_H */