summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/build.mk2
-rw-r--r--common/pwm_commands.c4
-rw-r--r--common/thermal.c49
-rw-r--r--common/thermal_commands.c52
4 files changed, 100 insertions, 7 deletions
diff --git a/common/build.mk b/common/build.mk
index 649fe9b6d9..00386b15b3 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -16,7 +16,7 @@ common-$(CONFIG_TASK_GAIAPOWER)+=gaia_power.o
common-$(CONFIG_FLASH)+=flash_commands.o
common-$(CONFIG_PSTORE)+=pstore_commands.o
common-$(CONFIG_PWM)+=pwm_commands.o
-common-$(CONFIG_TASK_THERMAL)+=thermal.o
+common-$(CONFIG_TASK_THERMAL)+=thermal.o thermal_commands.o
common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
common-$(CONFIG_TMP006)+=tmp006.o
common-$(CONFIG_LIGHTBAR)+=leds.o
diff --git a/common/pwm_commands.c b/common/pwm_commands.c
index 3e6a9ee52b..d40314459f 100644
--- a/common/pwm_commands.c
+++ b/common/pwm_commands.c
@@ -7,6 +7,7 @@
#include "host_command.h"
#include "pwm.h"
+#include "thermal.h"
enum lpc_status pwm_command_get_fan_rpm(uint8_t *data)
@@ -25,6 +26,9 @@ enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data)
struct lpc_params_pwm_set_fan_target_rpm *p =
(struct lpc_params_pwm_set_fan_target_rpm *)data;
+#ifdef CONFIG_TASK_THERMAL
+ thermal_toggle_auto_fan_ctrl(0);
+#endif
pwm_set_fan_target_rpm(p->rpm);
return EC_LPC_STATUS_SUCCESS;
}
diff --git a/common/thermal.c b/common/thermal.c
index ffcd0986fd..4b7341444a 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -28,6 +28,41 @@ static int8_t ot_count[TEMP_SENSOR_COUNT][THRESHOLD_COUNT];
* are reached (since we can disable any threshold.) */
static int8_t overheated[THRESHOLD_COUNT];
+static int fan_ctrl_on = 1;
+
+
+int thermal_set_threshold(int sensor_id, int threshold_id, int value)
+{
+ if (sensor_id < 0 || sensor_id >= TEMP_SENSOR_COUNT)
+ return EC_ERROR_INVAL;
+ if (threshold_id < 0 || threshold_id >= THRESHOLD_COUNT)
+ return EC_ERROR_INVAL;
+ if (value < 0)
+ return EC_ERROR_INVAL;
+
+ thermal_config[sensor_id].thresholds[threshold_id] = value;
+
+ return EC_SUCCESS;
+}
+
+
+int thermal_get_threshold(int sensor_id, int threshold_id)
+{
+ if (sensor_id < 0 || sensor_id >= TEMP_SENSOR_COUNT)
+ return EC_ERROR_INVAL;
+ if (threshold_id < 0 || threshold_id >= THRESHOLD_COUNT)
+ return EC_ERROR_INVAL;
+
+ return thermal_config[sensor_id].thresholds[threshold_id];
+}
+
+
+int thermal_toggle_auto_fan_ctrl(int auto_fan_on)
+{
+ fan_ctrl_on = auto_fan_on;
+ return EC_SUCCESS;
+}
+
static void smi_overheated_warning(void)
{
@@ -56,12 +91,14 @@ static void overheated_action(void)
smi_overheated_warning();
}
- if (overheated[THRESHOLD_FAN_HI])
- pwm_set_fan_target_rpm(-1); /* Max RPM. */
- else if (overheated[THRESHOLD_FAN_LO])
- pwm_set_fan_target_rpm(6000);
- else
- pwm_set_fan_target_rpm(0);
+ if (fan_ctrl_on) {
+ if (overheated[THRESHOLD_FAN_HI])
+ pwm_set_fan_target_rpm(-1); /* Max RPM. */
+ else if (overheated[THRESHOLD_FAN_LO])
+ pwm_set_fan_target_rpm(6000);
+ else
+ pwm_set_fan_target_rpm(0);
+ }
}
diff --git a/common/thermal_commands.c b/common/thermal_commands.c
new file mode 100644
index 0000000000..6c590ca840
--- /dev/null
+++ b/common/thermal_commands.c
@@ -0,0 +1,52 @@
+/* Copyright (c) 2012 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.
+ */
+
+/* Thermal engine host commands for Chrome EC */
+
+#include "thermal.h"
+#include "host_command.h"
+
+
+/*****************************************************************************/
+/* Host commands */
+
+enum lpc_status thermal_command_set_threshold(uint8_t *data)
+{
+ struct lpc_params_thermal_set_threshold *p =
+ (struct lpc_params_thermal_set_threshold *)data;
+
+ if (thermal_set_threshold(p->sensor_id, p->threshold_id, p->value))
+ return EC_LPC_STATUS_ERROR;
+ return EC_LPC_STATUS_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_THERMAL_SET_THRESHOLD,
+ thermal_command_set_threshold);
+
+
+enum lpc_status thermal_command_get_threshold(uint8_t *data)
+{
+ struct lpc_params_thermal_get_threshold *p =
+ (struct lpc_params_thermal_get_threshold *)data;
+ struct lpc_response_thermal_get_threshold *r =
+ (struct lpc_response_thermal_get_threshold *)data;
+
+ r->value = thermal_get_threshold(p->sensor_id, p->threshold_id);
+ if (r->value == -1)
+ return EC_LPC_STATUS_ERROR;
+
+ return EC_LPC_STATUS_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_THERMAL_GET_THRESHOLD,
+ thermal_command_get_threshold);
+
+
+enum lpc_status thermal_command_auto_fan_ctrl(uint8_t *data)
+{
+ if (thermal_toggle_auto_fan_ctrl(1))
+ return EC_LPC_STATUS_ERROR;
+ return EC_LPC_STATUS_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_THERMAL_AUTO_FAN_CTRL,
+ thermal_command_auto_fan_ctrl);