diff options
author | Vic Yang <victoryang@google.com> | 2012-03-15 14:55:28 +0800 |
---|---|---|
committer | Vic Yang <victoryang@google.com> | 2012-03-16 10:40:52 +0800 |
commit | 9f8e8dc6a3461cf0e8e3758db876c7b98c35a92a (patch) | |
tree | 02e5ca561dab349f9e74db3a4ecae807a1420888 | |
parent | 7d1884ee06793b776a8b8af3508e6cb6b7027b3f (diff) | |
download | chrome-ec-9f8e8dc6a3461cf0e8e3758db876c7b98c35a92a.tar.gz |
Temperature sensor grouping.
Group temperature sensors into different types so we only have to set
temperature threshold for each type instead of each sensor.
Signed-off-by: Vic Yang <victoryang@google.com>
BUG=chrome-os-partner:8466
TEST=Fan control still works.
Change-Id: I7acc714c32f282cec490b9e02d402ab91a53becf
-rw-r--r-- | board/bds/board_temp_sensor.c | 9 | ||||
-rw-r--r-- | board/link/board_temp_sensor.c | 30 | ||||
-rw-r--r-- | board/link/board_thermal.c | 37 | ||||
-rw-r--r-- | board/link/build.mk | 1 | ||||
-rw-r--r-- | common/thermal.c | 62 | ||||
-rw-r--r-- | common/thermal_commands.c | 4 | ||||
-rw-r--r-- | include/lpc_commands.h | 4 | ||||
-rw-r--r-- | include/temp_sensor.h | 14 | ||||
-rw-r--r-- | include/thermal.h | 5 | ||||
-rw-r--r-- | util/ectool.c | 20 |
10 files changed, 94 insertions, 92 deletions
diff --git a/board/bds/board_temp_sensor.c b/board/bds/board_temp_sensor.c index 0a10178e8e..d519f8cc61 100644 --- a/board/bds/board_temp_sensor.c +++ b/board/bds/board_temp_sensor.c @@ -20,9 +20,12 @@ * temp_sensor_id. */ const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = { - {"ECInternal", TEMP_SENSOR_POWER_NONE, chip_temp_sensor_get_val, 0}, - {"CaseDie", TEMP_SENSOR_POWER_VS, tmp006_get_val, 0}, - {"Object", TEMP_SENSOR_POWER_VS, tmp006_get_val, 0}, + {"ECInternal", TEMP_SENSOR_POWER_NONE, TEMP_SENSOR_TYPE_BOARD, + chip_temp_sensor_get_val, 0}, + {"CaseDie", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_BOARD, + tmp006_get_val, 0}, + {"Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE, + tmp006_get_val, 1}, }; const struct tmp006_t tmp006_sensors[TMP006_COUNT] = { diff --git a/board/link/board_temp_sensor.c b/board/link/board_temp_sensor.c index 29a61bfcaa..35a5d3b4bb 100644 --- a/board/link/board_temp_sensor.c +++ b/board/link/board_temp_sensor.c @@ -27,16 +27,26 @@ * temp_sensor_id. */ const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = { - {"I2C_CPU-Die", TEMP_SENSOR_POWER_VS, tmp006_get_val, 0}, - {"I2C_CPU-Object", TEMP_SENSOR_POWER_VS, tmp006_get_val, 1}, - {"I2C_PCH-Die", TEMP_SENSOR_POWER_VS, tmp006_get_val, 2}, - {"I2C_PCH-Object", TEMP_SENSOR_POWER_VS, tmp006_get_val, 3}, - {"I2C_DDR-Die", TEMP_SENSOR_POWER_VS, tmp006_get_val, 4}, - {"I2C_DDR-Object", TEMP_SENSOR_POWER_VS, tmp006_get_val, 5}, - {"I2C_Charger-Die", TEMP_SENSOR_POWER_VS, tmp006_get_val, 6}, - {"I2C_Charger-Object", TEMP_SENSOR_POWER_VS, tmp006_get_val, 7}, - {"ECInternal", TEMP_SENSOR_POWER_NONE, chip_temp_sensor_get_val, 0}, - {"PECI", TEMP_SENSOR_POWER_CPU, peci_temp_sensor_get_val, 0}, + {"I2C_CPU-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CPU, + tmp006_get_val, 0}, + {"I2C_CPU-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE, + tmp006_get_val, 1}, + {"I2C_PCH-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_BOARD, + tmp006_get_val, 2}, + {"I2C_PCH-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE, + tmp006_get_val, 3}, + {"I2C_DDR-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_BOARD, + tmp006_get_val, 4}, + {"I2C_DDR-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE, + tmp006_get_val, 5}, + {"I2C_Charger-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_BOARD, + tmp006_get_val, 6}, + {"I2C_Charger-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE, + tmp006_get_val, 7}, + {"ECInternal", TEMP_SENSOR_POWER_NONE, TEMP_SENSOR_TYPE_BOARD, + chip_temp_sensor_get_val, 0}, + {"PECI", TEMP_SENSOR_POWER_CPU, TEMP_SENSOR_TYPE_CPU, + peci_temp_sensor_get_val, 0}, }; const struct tmp006_t tmp006_sensors[TMP006_COUNT] = { diff --git a/board/link/board_thermal.c b/board/link/board_thermal.c deleted file mode 100644 index f8a024c84a..0000000000 --- a/board/link/board_thermal.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. - */ - -/* Link-specific thermal configuration module for Chrome EC */ - -#include "thermal.h" -#include "board.h" - -struct thermal_config_t thermal_config[TEMP_SENSOR_COUNT] = { - /* I2C_CPU-Die */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE_ALL}}, - /* I2C_CPU-Object */ - {THERMAL_CONFIG_NO_FLAG, {313, 323, 343, 353, 358}}, - /* I2C_PCH-Die */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE_ALL}}, - /* I2C_PCH-Object */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE, - THERMAL_THRESHOLD_DISABLE, 343, THERMAL_THRESHOLD_DISABLE, 358}}, - /* I2C_DDR-Die */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE_ALL}}, - /* I2C_DDR-Object */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE, - THERMAL_THRESHOLD_DISABLE, 343, THERMAL_THRESHOLD_DISABLE, 358}}, - /* I2C_Charger-Die */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE_ALL}}, - /* I2C_Charger-Object */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE, - THERMAL_THRESHOLD_DISABLE, 343, THERMAL_THRESHOLD_DISABLE, 358}}, - /* ECInternal */ - {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE, - THERMAL_THRESHOLD_DISABLE, 343, THERMAL_THRESHOLD_DISABLE, 373}}, - /* PECI */ - {THERMAL_CONFIG_WARNING_ON_FAIL, - {328, 338, 343, 348, 353}}, -}; diff --git a/board/link/build.mk b/board/link/build.mk index 97595996d9..b600d69d13 100644 --- a/board/link/build.mk +++ b/board/link/build.mk @@ -10,4 +10,3 @@ CHIP:=lm4 board-y=board.o board-$(CONFIG_TEMP_SENSOR)+=board_temp_sensor.o -board-$(CONFIG_TASK_THERMAL)+=board_thermal.o diff --git a/common/thermal.c b/common/thermal.c index 1bdeaadaec..d7fbcc76f8 100644 --- a/common/thermal.c +++ b/common/thermal.c @@ -19,9 +19,22 @@ #include "util.h" #include "x86_power.h" -/* Defined in board_thermal.c. Must be in the same order - * as in enum temp_sensor_id. */ -extern struct thermal_config_t thermal_config[TEMP_SENSOR_COUNT]; +/* 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 temp_sensor_type. */ +struct thermal_config_t thermal_config[TEMP_SENSOR_TYPE_COUNT] = { + /* TEMP_SENSOR_TYPE_CPU */ + {THERMAL_CONFIG_WARNING_ON_FAIL, {328, 338, 343, 348, 353}}, + /* TEMP_SENSOR_TYPE_BOARD */ + {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE_ALL}}, + /* TEMP_SENSOR_TYPE_CASE */ + {THERMAL_CONFIG_NO_FLAG, {THERMAL_THRESHOLD_DISABLE, + THERMAL_THRESHOLD_DISABLE, 343, THERMAL_THRESHOLD_DISABLE, 358}}, +}; /* Number of consecutive overheated events for each temperature sensor. */ static int8_t ot_count[TEMP_SENSOR_COUNT][THRESHOLD_COUNT]; @@ -34,29 +47,25 @@ static int8_t overheated[THRESHOLD_COUNT]; static int fan_ctrl_on = 1; -int thermal_set_threshold(int sensor_id, int threshold_id, int value) +int thermal_set_threshold(enum temp_sensor_type type, 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; + thermal_config[type].thresholds[threshold_id] = value; return EC_SUCCESS; } -int thermal_get_threshold(int sensor_id, int threshold_id) +int thermal_get_threshold(enum temp_sensor_type type, 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]; + return thermal_config[type].thresholds[threshold_id]; } @@ -120,7 +129,8 @@ static inline void update_and_check_stat(int temp, int sensor_id, int threshold_id) { - const struct thermal_config_t *config = thermal_config + sensor_id; + enum temp_sensor_type type = temp_sensors[sensor_id].type; + const struct thermal_config_t *config = thermal_config + type; const int16_t threshold = config->thresholds[threshold_id]; if (threshold > 0 && temp >= threshold) { @@ -152,7 +162,8 @@ static void thermal_process(void) overheated[i] = 0; for (i = 0; i < TEMP_SENSOR_COUNT; ++i) { - int flag = thermal_config[i].config_flags; + enum temp_sensor_type type = temp_sensors[i].type; + int flag = thermal_config[type].config_flags; if (!temp_sensor_powered(i)) continue; @@ -185,10 +196,10 @@ void thermal_task(void) /*****************************************************************************/ /* Console commands */ -static void print_thermal_config(int sensor_id) +static void print_thermal_config(enum temp_sensor_type type) { - const struct thermal_config_t *config = thermal_config + sensor_id; - uart_printf("Sensor %d:\n", sensor_id); + const struct thermal_config_t *config = thermal_config + type; + uart_printf("Sensor Type %d:\n", type); uart_printf("\tFan Low: %d K \n", config->thresholds[THRESHOLD_FAN_LO]); uart_printf("\tFan High: %d K \n", @@ -205,21 +216,22 @@ static void print_thermal_config(int sensor_id) static int command_thermal_config(int argc, char **argv) { char *e; - int sensor_id, threshold_id, value; + int sensor_type, threshold_id, value; if (argc != 2 && argc != 4) { - uart_puts("Usage: thermal <sensor> [<threshold_id> <value>]\n"); + uart_puts("Usage: thermal <sensor_type> [<threshold_id> <value>]\n"); return EC_ERROR_UNKNOWN; } - sensor_id = strtoi(argv[1], &e, 0); - if ((e && *e) || sensor_id < 0 || sensor_id >= TEMP_SENSOR_COUNT) { - uart_puts("Bad sensor ID.\n"); + sensor_type = strtoi(argv[1], &e, 0); + if ((e && *e) || sensor_type < 0 || + sensor_type >= TEMP_SENSOR_TYPE_COUNT) { + uart_puts("Bad sensor type ID.\n"); return EC_ERROR_UNKNOWN; } if (argc == 2) { - print_thermal_config(sensor_id); + print_thermal_config(sensor_type); return EC_SUCCESS; } @@ -235,9 +247,9 @@ static int command_thermal_config(int argc, char **argv) return EC_ERROR_UNKNOWN; } - thermal_config[sensor_id].thresholds[threshold_id] = value; - uart_printf("Setting threshold %d of sensor %d to %d\n", - threshold_id, sensor_id, value); + thermal_config[sensor_type].thresholds[threshold_id] = value; + uart_printf("Setting threshold %d of sensor type %d to %d\n", + threshold_id, sensor_type, value); return EC_SUCCESS; } diff --git a/common/thermal_commands.c b/common/thermal_commands.c index 2fac1606f9..e3be7429ab 100644 --- a/common/thermal_commands.c +++ b/common/thermal_commands.c @@ -14,7 +14,7 @@ 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)) + if (thermal_set_threshold(p->sensor_type, p->threshold_id, p->value)) return EC_LPC_RESULT_ERROR; return EC_LPC_RESULT_SUCCESS; } @@ -29,7 +29,7 @@ enum lpc_status thermal_command_get_threshold(uint8_t *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); + r->value = thermal_get_threshold(p->sensor_type, p->threshold_id); if (r->value == -1) return EC_LPC_RESULT_ERROR; diff --git a/include/lpc_commands.h b/include/lpc_commands.h index 61e35f009e..9aa22c8603 100644 --- a/include/lpc_commands.h +++ b/include/lpc_commands.h @@ -366,7 +366,7 @@ struct lpc_params_pstore_write { /* Set thershold value */ #define EC_LPC_COMMAND_THERMAL_SET_THRESHOLD 0x50 struct lpc_params_thermal_set_threshold { - uint8_t sensor_id; + uint8_t sensor_type; uint8_t threshold_id; uint16_t value; } __attribute__ ((packed)); @@ -374,7 +374,7 @@ struct lpc_params_thermal_set_threshold { /* Get threshold value */ #define EC_LPC_COMMAND_THERMAL_GET_THRESHOLD 0x51 struct lpc_params_thermal_get_threshold { - uint8_t sensor_id; + uint8_t sensor_type; uint8_t threshold_id; } __attribute__ ((packed)); struct lpc_response_thermal_get_threshold { diff --git a/include/temp_sensor.h b/include/temp_sensor.h index f6051824ee..d3ce646a19 100644 --- a/include/temp_sensor.h +++ b/include/temp_sensor.h @@ -18,10 +18,24 @@ /* "enum temp_sensor_id" must be defined for each board in board.h. */ enum temp_sensor_id; +/* Type of temperature sensors. */ +enum temp_sensor_type { + /* CPU temperature sensors. */ + TEMP_SENSOR_TYPE_CPU = 0, + /* Other on-board temperature sensors. */ + TEMP_SENSOR_TYPE_BOARD, + /* Case temperature sensors. */ + TEMP_SENSOR_TYPE_CASE, + + TEMP_SENSOR_TYPE_COUNT +}; + struct temp_sensor_t { const char* name; /* Flags indicating power needed by temp sensor. */ int8_t power_flags; + /* Temperature sensor type. */ + enum temp_sensor_type type; /* Read sensor value and return temperature in K. */ int (*read)(int idx); /* Index among the same kind of sensors. */ diff --git a/include/thermal.h b/include/thermal.h index a2c26d9d4d..ab606baaa8 100644 --- a/include/thermal.h +++ b/include/thermal.h @@ -8,6 +8,7 @@ #ifndef __CROS_EC_THERMAL_H #define __CROS_EC_THERMAL_H +#include "temp_sensor.h" #include "util.h" #define THERMAL_CONFIG_NO_FLAG 0x0 @@ -46,10 +47,10 @@ struct thermal_config_t { }; /* Set the threshold temperature value. Return -1 on error. */ -int thermal_set_threshold(int sensor_id, int threshold_id, int value); +int thermal_set_threshold(enum temp_sensor_type type, int threshold_id, int value); /* Get the threshold temperature value. Return -1 on error. */ -int thermal_get_threshold(int sensor_id, int threshold_id); +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); diff --git a/util/ectool.c b/util/ectool.c index e3d24b1abd..ed63c1668b 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -657,13 +657,13 @@ int cmd_thermal_get_threshold(int argc, char *argv[]) int rv; if (argc != 2) { - fprintf(stderr, "Usage: thermalget <sensorid> <thresholdid>\n"); + fprintf(stderr, "Usage: thermalget <sensortypeid> <thresholdid>\n"); return -1; } - p.sensor_id = strtol(argv[0], &e, 0); + p.sensor_type = strtol(argv[0], &e, 0); if (e && *e) { - fprintf(stderr, "Bad sensor ID.\n"); + fprintf(stderr, "Bad sensor type ID.\n"); return -1; } @@ -681,8 +681,8 @@ int cmd_thermal_get_threshold(int argc, char *argv[]) if (r.value < 0) return -1; - printf("Threshold %d for sensor %d is %d K.\n", - p.threshold_id, p.sensor_id, r.value); + printf("Threshold %d for sensor type %d is %d K.\n", + p.threshold_id, p.sensor_type, r.value); return 0; } @@ -696,13 +696,13 @@ int cmd_thermal_set_threshold(int argc, char *argv[]) if (argc != 3) { fprintf(stderr, - "Usage: thermalset <sensorid> <thresholdid> <value>\n"); + "Usage: thermalset <sensortypeid> <thresholdid> <value>\n"); return -1; } - p.sensor_id = strtol(argv[0], &e, 0); + p.sensor_type = strtol(argv[0], &e, 0); if (e && *e) { - fprintf(stderr, "Bad sensor ID.\n"); + fprintf(stderr, "Bad sensor type ID.\n"); return -1; } @@ -723,8 +723,8 @@ int cmd_thermal_set_threshold(int argc, char *argv[]) if (rv) return rv; - printf("Threshold %d for sensor %d set to %d.\n", - p.threshold_id, p.sensor_id, p.value); + printf("Threshold %d for sensor type %d set to %d.\n", + p.threshold_id, p.sensor_type, p.value); return 0; } |