summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-25 16:41:00 -0700
committerGerrit <chrome-bot@google.com>2012-10-26 13:10:57 -0700
commitbff5a49e6d06c13e67b1a72470dc1d9a2326eb16 (patch)
tree20fe2704ed432ff31df9acca23a5bebbb81609a2
parentd5dec77a950e67b387cf84e61ad85ec84e4f97d9 (diff)
downloadchrome-ec-bff5a49e6d06c13e67b1a72470dc1d9a2326eb16.tar.gz
Clean up thermal modules
No functional changes. BUG=chrome-os-partner:15579 BRANCH=none TEST='temps' should print good temperatures Change-Id: I20bd2376b86f1e9d2f9a91016ed90bb933235021 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/36611
-rw-r--r--common/build.mk4
-rw-r--r--common/temp_sensor.c42
-rw-r--r--common/temp_sensor_commands.c37
-rw-r--r--common/thermal.c110
-rw-r--r--common/thermal_commands.c52
-rw-r--r--common/tmp006.c4
-rw-r--r--include/temp_sensor.h6
-rw-r--r--include/thermal.h34
8 files changed, 136 insertions, 153 deletions
diff --git a/common/build.mk b/common/build.mk
index 62891da7ec..9788e54847 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -27,8 +27,8 @@ common-$(CONFIG_TASK_HOSTCMD)+=host_command.o host_event_commands.o
common-$(CONFIG_TASK_I8042CMD)+=i8042.o keyboard.o
common-$(CONFIG_TASK_LIGHTBAR)+=lightbar.o
common-$(CONFIG_TASK_POWERSTATE)+=charge_state.o battery_precharge.o
-common-$(CONFIG_TASK_TEMPSENSOR)+=temp_sensor.o temp_sensor_commands.o
-common-$(CONFIG_TASK_THERMAL)+=thermal.o thermal_commands.o
+common-$(CONFIG_TASK_TEMPSENSOR)+=temp_sensor.o
+common-$(CONFIG_TASK_THERMAL)+=thermal.o
common-$(CONFIG_TASK_VBOOTHASH)+=sha256.o vboot_hash.o
common-$(CONFIG_TASK_X86POWER)+=x86_power.o
common-$(CONFIG_TMP006)+=tmp006.o
diff --git a/common/temp_sensor.c b/common/temp_sensor.c
index 7f5a5e7a53..ecbe6c0825 100644
--- a/common/temp_sensor.c
+++ b/common/temp_sensor.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+/* 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.
*/
@@ -20,10 +20,8 @@
#include "tmp006.h"
#include "util.h"
-/* Defined in board_temp_sensor.c. Must be in the same order as
- * in enum temp_sensor_id.
- */
-extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
+/* Default temperature to report in mapped memory */
+#define MAPPED_TEMP_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr)
{
@@ -93,17 +91,18 @@ void temp_sensor_task(void)
uint8_t *base, *base_b;
/*
- * Initialize memory-mapped data. We initialize valid sensors to 23 C
- * so that if a temperature value is read before we actually poll the
- * sensors, we don't end up with an insane value.
+ * Initialize memory-mapped data so that if a temperature value is read
+ * before we actually poll the sensors, we don't end up with an insane
+ * value.
*/
base = host_get_memmap(EC_MEMMAP_TEMP_SENSOR);
base_b = host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B);
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
if (i < EC_TEMP_SENSOR_ENTRIES)
- base[i] = 0x60; /* 23 C */
+ base[i] = MAPPED_TEMP_DEFAULT;
else
- base_b[i - EC_TEMP_SENSOR_ENTRIES] = 0x60; /* 23 C */
+ base_b[i - EC_TEMP_SENSOR_ENTRIES] =
+ MAPPED_TEMP_DEFAULT;
}
/* Set the rest of memory region to SENSOR_NOT_PRESENT */
@@ -163,3 +162,26 @@ DECLARE_CONSOLE_COMMAND(temps, command_temps,
NULL,
"Print temp sensors",
NULL);
+
+/*****************************************************************************/
+/* Host commands */
+
+int temp_sensor_command_get_info(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_temp_sensor_get_info *p = args->params;
+ struct ec_response_temp_sensor_get_info *r = args->response;
+ int id = p->id;
+
+ if (id >= TEMP_SENSOR_COUNT)
+ return EC_RES_ERROR;
+
+ strzcpy(r->sensor_name, temp_sensors[id].name, sizeof(r->sensor_name));
+ r->sensor_type = temp_sensors[id].type;
+
+ args->response_size = sizeof(*r);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO,
+ temp_sensor_command_get_info,
+ EC_VER_MASK(0));
diff --git a/common/temp_sensor_commands.c b/common/temp_sensor_commands.c
deleted file mode 100644
index 987efa8505..0000000000
--- a/common/temp_sensor_commands.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* 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.
- */
-
-/* Temp sensor host commands for Chrome EC */
-
-#include "common.h"
-#include "host_command.h"
-#include "temp_sensor.h"
-#include "util.h"
-
-/*
- * Defined in board_temp_sensor.c. Must be in the same order as in enum
- * temp_sensor_id.
- */
-extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
-
-int temp_sensor_command_get_info(struct host_cmd_handler_args *args)
-{
- const struct ec_params_temp_sensor_get_info *p = args->params;
- struct ec_response_temp_sensor_get_info *r = args->response;
- int id = p->id;
-
- if (id >= TEMP_SENSOR_COUNT)
- return EC_RES_ERROR;
-
- strzcpy(r->sensor_name, temp_sensors[id].name, sizeof(r->sensor_name));
- r->sensor_type = temp_sensors[id].type;
-
- args->response_size = sizeof(*r);
-
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO,
- temp_sensor_command_get_info,
- EC_VER_MASK(0));
diff --git a/common/thermal.c b/common/thermal.c
index 780b9c2042..d280c4614c 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -19,14 +19,11 @@
#include "util.h"
#include "x86_power.h"
-/* Defined in board_temp_sensor.c. Must be in the same order as
- * in enum temp_sensor_id.
- */
-extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
-
-/* Temperature threshold configuration. Must be in the same order as in enum
+/*
+ * Temperature threshold configuration. Must be in the same order as in enum
* temp_sensor_type. Threshold values for overheated action first (warning,
- * prochot, power-down), followed by fan speed stepping thresholds. */
+ * prochot, power-down), followed by fan speed stepping thresholds.
+ */
static struct thermal_config_t thermal_config[TEMP_SENSOR_TYPE_COUNT] = {
/* TEMP_SENSOR_TYPE_CPU */
{THERMAL_CONFIG_WARNING_ON_FAIL,
@@ -37,17 +34,18 @@ static struct thermal_config_t thermal_config[TEMP_SENSOR_TYPE_COUNT] = {
{THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE_ALL} },
};
-/* Fan speed settings. */
-/* Real max RPM is about 9300. */
+/* Fan speed settings. Real max RPM is about 9300. */
static const int fan_speed[THERMAL_FAN_STEPS + 1] = {0, 3000, 4575, 6150,
7725, -1};
/* Number of consecutive overheated events for each temperature sensor. */
static int8_t ot_count[TEMP_SENSOR_COUNT][THRESHOLD_COUNT + THERMAL_FAN_STEPS];
-/* Flag that indicate if each threshold is reached.
- * Note that higher threshold reached does not necessarily mean lower thresholds
- * are reached (since we can disable any threshold.) */
+/*
+ * Flag that indicate if each threshold is reached. Note that higher threshold
+ * reached does not necessarily mean lower thresholds are reached (since we can
+ * disable any threshold.)
+ */
static int8_t overheated[THRESHOLD_COUNT + THERMAL_FAN_STEPS];
static int8_t *fan_threshold_reached = overheated + THRESHOLD_COUNT;
@@ -80,15 +78,13 @@ int thermal_get_threshold(enum temp_sensor_type type, int threshold_id)
return thermal_config[type].thresholds[threshold_id];
}
-int thermal_control_fan(int enable)
+void thermal_control_fan(int enable)
{
fan_ctrl_on = enable;
/* If controlling the fan, need it in RPM-control mode */
if (enable)
pwm_set_rpm_mode(1);
-
- return EC_SUCCESS;
}
static void smi_overheated_warning(void)
@@ -101,8 +97,9 @@ 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)
+/*
+ * TODO: When we need different overheated action for different boards, move
+ * these actiona to a board-specific file. (e.g. board_thermal.c)
*/
static void overheated_action(void)
{
@@ -122,12 +119,13 @@ static void overheated_action(void)
if (overheated[THRESHOLD_WARNING]) {
smi_overheated_warning();
chipset_throttle_cpu(1);
- }
- else
+ } else {
chipset_throttle_cpu(0);
+ }
if (fan_ctrl_on) {
int i;
+
for (i = THERMAL_FAN_STEPS - 1; i >= 0; --i)
if (fan_threshold_reached[i])
break;
@@ -135,9 +133,12 @@ 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. */
+/**
+ * Update counter and check if the counter has reached delay limit.
+ *
+ * Note that we have various delay periods to prevent one error value
+ * triggering an overheated action.
+ */
static inline void update_and_check_stat(int temp,
int sensor_id,
int threshold_id)
@@ -153,17 +154,18 @@ static inline void update_and_check_stat(int temp,
ot_count[sensor_id][threshold_id] = delay;
overheated[threshold_id] = 1;
}
- }
- else if (ot_count[sensor_id][threshold_id] >= delay &&
- temp >= threshold - 3) {
- /* Once the threshold is reached, only if the temperature
- * drops to 3 degrees below threshold do we deassert
- * overheated signal. This is to prevent temperature
- * oscillating around the threshold causing threshold
- * keep being triggered. */
+ } else if (ot_count[sensor_id][threshold_id] >= delay &&
+ temp >= threshold - 3) {
+ /*
+ * Once the threshold is reached, only deassert overheated if
+ * the temperature drops to 3 degrees below threshold. This
+ * hysteresis prevents a temperature oscillating around the
+ * threshold causing overheated actions to trigger repeatedly.
+ */
overheated[threshold_id] = 1;
- } else
+ } else {
ot_count[sensor_id][threshold_id] = 0;
+ }
}
static void thermal_process(void)
@@ -321,9 +323,53 @@ DECLARE_CONSOLE_COMMAND(thermalfan, command_fan_config,
static int command_thermal_auto_fan_ctrl(int argc, char **argv)
{
- return thermal_control_fan(1);
+ thermal_control_fan(1);
+ return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(autofan, command_thermal_auto_fan_ctrl,
NULL,
"Enable thermal fan control",
NULL);
+
+/*****************************************************************************/
+/* Host commands */
+
+static int thermal_command_set_threshold(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_thermal_set_threshold *p = args->params;
+
+ if (thermal_set_threshold(p->sensor_type, p->threshold_id, p->value))
+ return EC_RES_ERROR;
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_THERMAL_SET_THRESHOLD,
+ thermal_command_set_threshold,
+ EC_VER_MASK(0));
+
+static int thermal_command_get_threshold(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_thermal_get_threshold *p = args->params;
+ struct ec_response_thermal_get_threshold *r = args->response;
+ int value = thermal_get_threshold(p->sensor_type, p->threshold_id);
+
+ if (value == -1)
+ return EC_RES_ERROR;
+ r->value = value;
+
+ args->response_size = sizeof(*r);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_THERMAL_GET_THRESHOLD,
+ thermal_command_get_threshold,
+ EC_VER_MASK(0));
+
+static int thermal_command_auto_fan_ctrl(struct host_cmd_handler_args *args)
+{
+ thermal_control_fan(1);
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_THERMAL_AUTO_FAN_CTRL,
+ thermal_command_auto_fan_ctrl,
+ EC_VER_MASK(0));
diff --git a/common/thermal_commands.c b/common/thermal_commands.c
deleted file mode 100644
index 07261ce5fb..0000000000
--- a/common/thermal_commands.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* 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 "common.h"
-#include "host_command.h"
-#include "thermal.h"
-
-int thermal_command_set_threshold(struct host_cmd_handler_args *args)
-{
- const struct ec_params_thermal_set_threshold *p = args->params;
-
- if (thermal_set_threshold(p->sensor_type, p->threshold_id, p->value))
- return EC_RES_ERROR;
-
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_THERMAL_SET_THRESHOLD,
- thermal_command_set_threshold,
- EC_VER_MASK(0));
-
-int thermal_command_get_threshold(struct host_cmd_handler_args *args)
-{
- const struct ec_params_thermal_get_threshold *p = args->params;
- struct ec_response_thermal_get_threshold *r = args->response;
- int value = thermal_get_threshold(p->sensor_type, p->threshold_id);
-
- if (value == -1)
- return EC_RES_ERROR;
- r->value = value;
-
- args->response_size = sizeof(*r);
-
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_THERMAL_GET_THRESHOLD,
- thermal_command_get_threshold,
- EC_VER_MASK(0));
-
-int thermal_command_auto_fan_ctrl(struct host_cmd_handler_args *args)
-{
- if (thermal_control_fan(1))
- return EC_RES_ERROR;
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_THERMAL_AUTO_FAN_CTRL,
- thermal_command_auto_fan_ctrl,
- EC_VER_MASK(0));
-
diff --git a/common/tmp006.c b/common/tmp006.c
index cd1bdb0c10..67d9d41af3 100644
--- a/common/tmp006.c
+++ b/common/tmp006.c
@@ -319,7 +319,9 @@ DECLARE_HOST_COMMAND(EC_CMD_TMP006_SET_CALIBRATION,
/*****************************************************************************/
/* Console commands */
-/* Print temperature info for a sensor; used by console command. */
+/**
+ * Print temperature info for a sensor; used by console command.
+ */
static int tmp006_print(int idx)
{
int vraw, v;
diff --git a/include/temp_sensor.h b/include/temp_sensor.h
index 04b7e868ff..687618fa63 100644
--- a/include/temp_sensor.h
+++ b/include/temp_sensor.h
@@ -41,6 +41,12 @@ struct temp_sensor_t {
int action_delay_sec;
};
+/*
+ * Defined in board_temp_sensor.c. Must be in the same order as
+ * in enum temp_sensor_id.
+ */
+extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
+
/**
* Get the most recently measured temperature for the sensor.
*
diff --git a/include/thermal.h b/include/thermal.h
index 8b32bf9773..3e43dfcd1a 100644
--- a/include/thermal.h
+++ b/include/thermal.h
@@ -9,40 +9,37 @@
#define __CROS_EC_THERMAL_H
#include "temp_sensor.h"
-#include "util.h"
#define THERMAL_CONFIG_NO_FLAG 0x0
#define THERMAL_CONFIG_WARNING_ON_FAIL 0x1
-/* Number of steps for fan speed control. Speed of each step defined
- * in thermal.c */
+/*
+ * Number of steps for fan speed control. Speed of each step is defined
+ * in thermal.c.
+ */
#define THERMAL_FAN_STEPS 5
/* Set a threshold temperature to this value to disable the threshold limit. */
#define THERMAL_THRESHOLD_DISABLE 0
-/* This macro is used to disable all threshold for a sensor.
- * The value 0 expands to all field in the array 'thresholds'. Change this
- * if THERMAL_THRESHOLD_DISABLE is no longer 0.
+/* This macro is used to disable all threshold for a sensor. The value 0
+ * expands to all field in the array 'thresholds'. Change this if
+ * THERMAL_THRESHOLD_DISABLE is no longer 0.
*/
#define THERMAL_THRESHOLD_DISABLE_ALL 0
enum thermal_threshold {
- /* Issue overheating warning */
- THRESHOLD_WARNING = 0,
- /* Shut down CPU */
- THRESHOLD_CPU_DOWN,
- /* Shut down everything we can */
- THRESHOLD_POWER_DOWN,
-
+ THRESHOLD_WARNING = 0, /* Issue overheating warning */
+ THRESHOLD_CPU_DOWN, /* Shut down CPU */
+ THRESHOLD_POWER_DOWN, /* Shut down everything we can */
THRESHOLD_COUNT
};
-/* Configuration for temperature sensor. Temperature value in degree K. */
+/* Configuration for temperature sensor */
struct thermal_config_t {
- /* Configuration flags. */
+ /* Configuration flags */
int8_t config_flags;
- /* Threshold temperatures. */
+ /* Threshold temperatures in K */
int16_t thresholds[THRESHOLD_COUNT + THERMAL_FAN_STEPS];
};
@@ -74,8 +71,7 @@ int thermal_get_threshold(enum temp_sensor_type type, int threshold_id);
* 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);
+ */
+void thermal_control_fan(int enable);
#endif /* __CROS_EC_THERMAL_H */