diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-11 10:23:16 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-10-11 13:47:17 -0700 |
commit | 8f2e99da75152c428c6c92b20a13a62a5fcb40d1 (patch) | |
tree | c2d3dc52372a79a03c2d503c55ead568c066a7e1 | |
parent | d1bebbbe66f78d2dcfb9380456a80e7c2f26a662 (diff) | |
download | chrome-ec-8f2e99da75152c428c6c92b20a13a62a5fcb40d1.tar.gz |
link: Temp sensor read can return an error code
This will be used in a follow-up CL to return specific error codes
(not powered, not calibrated, etc.)
BUG=chrome-os-partner:15174
BRANCH=link
TEST=manual
Power on system.
'temps' should return all good temps.
Power off system (into S5)
Only ECInternal temp should work; others should return Error 1
'gpioset enable_vs 1' and wait a second
Now all the I2C temps should display good data, but PECI will still be error 1.
Change-Id: I925434e71653ad53ad76bad992a7a8fdeadb088c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/35286
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | chip/lm4/chip_temp_sensor.c | 12 | ||||
-rw-r--r-- | chip/lm4/peci.c | 11 | ||||
-rw-r--r-- | common/temp_sensor.c | 30 | ||||
-rw-r--r-- | common/thermal.c | 7 | ||||
-rw-r--r-- | common/tmp006.c | 26 | ||||
-rw-r--r-- | include/chip_temp_sensor.h | 11 | ||||
-rw-r--r-- | include/peci.h | 13 | ||||
-rw-r--r-- | include/temp_sensor.h | 16 | ||||
-rw-r--r-- | include/tmp006.h | 5 |
9 files changed, 76 insertions, 55 deletions
diff --git a/chip/lm4/chip_temp_sensor.c b/chip/lm4/chip_temp_sensor.c index fb9084e82e..54e8a3c6ea 100644 --- a/chip/lm4/chip_temp_sensor.c +++ b/chip/lm4/chip_temp_sensor.c @@ -6,8 +6,9 @@ /* Temperature sensor module for Chrome EC */ #include "adc.h" -#include "board.h" +#include "config.h" #include "hooks.h" +#include "lm4_adc.h" #include "temp_sensor.h" static int last_val; @@ -19,9 +20,14 @@ int chip_temp_sensor_poll(void) return EC_SUCCESS; } -int chip_temp_sensor_get_val(int idx) +int chip_temp_sensor_get_val(int idx, int *temp_ptr) { - return last_val; + if (last_val == ADC_READ_ERROR) + return EC_ERROR_UNKNOWN; + + *temp_ptr = last_val; + + return EC_SUCCESS; } static int chip_temp_sensor_init(void) diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c index 4091ee8640..210fb4e6c9 100644 --- a/chip/lm4/peci.c +++ b/chip/lm4/peci.c @@ -69,7 +69,7 @@ int peci_temp_sensor_poll(void) } -int peci_temp_sensor_get_val(int idx) +int peci_temp_sensor_get_val(int idx, int *temp_ptr) { int sum = 0; int success_cnt = 0; @@ -82,10 +82,11 @@ int peci_temp_sensor_get_val(int idx) } } - if (success_cnt) - return sum / success_cnt; - else - return -1; + if (!success_cnt) + return EC_ERROR_UNKNOWN; + + *temp_ptr = sum / success_cnt; + return EC_SUCCESS; } diff --git a/common/temp_sensor.c b/common/temp_sensor.c index cdad3ebd1f..333ed1d266 100644 --- a/common/temp_sensor.c +++ b/common/temp_sensor.c @@ -25,17 +25,16 @@ */ extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT]; - -int temp_sensor_read(enum temp_sensor_id id) +int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr) { const struct temp_sensor_t *sensor; if (id < 0 || id >= TEMP_SENSOR_COUNT) - return -1; + return EC_ERROR_INVAL; sensor = temp_sensors + id; - return sensor->read(sensor->idx); -} + return sensor->read(sensor->idx, temp_ptr); +} int temp_sensor_powered(enum temp_sensor_id id) { @@ -52,7 +51,6 @@ int temp_sensor_powered(enum temp_sensor_id id) return 1; } - void poll_slow_sensors(void) { /* Poll every second */ @@ -72,7 +70,6 @@ static void poll_fast_sensors(void) #endif } - static void update_mapped_memory(void) { int i, t; @@ -94,15 +91,13 @@ static void update_mapped_memory(void) continue; } - t = temp_sensor_read(i); - if (t == -1) + if (temp_sensor_read(i, &t)) *mptr = EC_TEMP_SENSOR_ERROR; else *mptr = t - EC_TEMP_SENSOR_OFFSET; } } - void temp_sensor_task(void) { int i; @@ -149,21 +144,20 @@ void temp_sensor_task(void) static int command_temps(int argc, char **argv) { - int i; - int rv = EC_SUCCESS; - int t; + int t, i; + int rv, rv1 = EC_SUCCESS; for (i = 0; i < TEMP_SENSOR_COUNT; ++i) { ccprintf(" %-20s: ", temp_sensors[i].name); - t = temp_sensor_read(i); - if (t < 0) { - ccprintf("Error\n"); - rv = EC_ERROR_UNKNOWN; + rv = temp_sensor_read(i, &t); + if (rv) { + ccprintf("Error %d\n", rv); + rv1 = rv; } else ccprintf("%d K = %d C\n", t, t - 273); } - return rv; + return rv1; } DECLARE_CONSOLE_COMMAND(temps, command_temps, NULL, diff --git a/common/thermal.c b/common/thermal.c index 3f570be058..6b4f3fa355 100644 --- a/common/thermal.c +++ b/common/thermal.c @@ -188,14 +188,13 @@ static void thermal_process(void) if (!temp_sensor_powered(i)) continue; - cur_temp = temp_sensor_read(i); - - /* Sensor failure. */ - if (cur_temp == -1) { + if (temp_sensor_read(i, &cur_temp)) { + /* Sensor failure. */ if (flag & THERMAL_CONFIG_WARNING_ON_FAIL) smi_sensor_failure_warning(); continue; } + for (j = 0; j < THRESHOLD_COUNT + THERMAL_FAN_STEPS; ++j) update_and_check_stat(cur_temp, i, j); } diff --git a/common/tmp006.c b/common/tmp006.c index 72e004de4d..edb20af586 100644 --- a/common/tmp006.c +++ b/common/tmp006.c @@ -63,13 +63,15 @@ static int tmp006_has_power(int idx) return gpio_get_level(GPIO_PGOOD_1_8VS); } -static int tmp006_read_die_temp(const struct tmp006_data_t *tdata) +static int tmp006_read_die_temp(const struct tmp006_data_t *tdata, + int *temp_ptr) { if (tdata->fail) - return -1; + return EC_ERROR_UNKNOWN; /* Return previous die temperature */ - return tdata->t[(tdata->tidx - 1) & 0x3] / 100; + *temp_ptr = tdata->t[(tdata->tidx - 1) & 0x3] / 100; + return EC_SUCCESS; } /** @@ -123,14 +125,15 @@ static int tmp006_correct_object_voltage(int T1, int T2, int T3, int T4, return Vobj + 296 * Tslope; } -static int tmp006_read_object_temp(const struct tmp006_data_t *tdata) +static int tmp006_read_object_temp(const struct tmp006_data_t *tdata, + int *temp_ptr) { int pidx = (tdata->tidx - 1) & 0x3; int t = tdata->t[pidx]; int v = tdata->v; if (tdata->fail) - return -1; + return EC_ERROR_UNKNOWN; v = tmp006_correct_object_voltage( t, @@ -139,7 +142,9 @@ static int tmp006_read_object_temp(const struct tmp006_data_t *tdata) tdata->t[(pidx + 1) & 3], v); - return tmp006_calculate_object_temp(t, v, tdata) / 100; + *temp_ptr = tmp006_calculate_object_temp(t, v, tdata) / 100; + + return EC_SUCCESS; } static int tmp006_poll_sensor(int sensor_id) @@ -206,7 +211,7 @@ static int tmp006_poll_sensor(int sensor_id) return EC_SUCCESS; } -int tmp006_get_val(int idx) +int tmp006_get_val(int idx, int *temp_ptr) { /* * Note: idx is a thermal sensor index, where the top N-1 bits are the @@ -216,9 +221,9 @@ int tmp006_get_val(int idx) /* Check the low bit to determine which temperature to read. */ if ((idx & 0x1) == 0) - return tmp006_read_die_temp(tdata); + return tmp006_read_die_temp(tdata, temp_ptr); else - return tmp006_read_object_temp(tdata); + return tmp006_read_object_temp(tdata, temp_ptr); } int tmp006_poll(void) @@ -287,9 +292,6 @@ DECLARE_HOST_COMMAND(EC_CMD_TMP006_GET_CALIBRATION, tmp006_get_calibration, EC_VER_MASK(0)); -/*****************************************************************************/ -/* Host commands */ - int tmp006_set_calibration(struct host_cmd_handler_args *args) { const struct ec_params_tmp006_set_calibration *p = args->params; diff --git a/include/chip_temp_sensor.h b/include/chip_temp_sensor.h index 867733d2db..c7ca1e1caf 100644 --- a/include/chip_temp_sensor.h +++ b/include/chip_temp_sensor.h @@ -13,7 +13,14 @@ struct temp_sensor_t; /* Temperature polling function. */ int chip_temp_sensor_poll(void); -/* Temperature reading function. Return temperature in K. */ -int chip_temp_sensor_get_val(int idx); +/** + * Get the last polled value of the sensor. + * + * @param idx Sensor index to read. + * @param temp_ptr Destination for temperature in K. + * + * @return EC_SUCCESS if successful, non-zero if error. + */ +int chip_temp_sensor_get_val(int idx, int *temp_ptr); #endif /* __CROS_EC_CHIP_TEMP_SENSOR_H */ diff --git a/include/peci.h b/include/peci.h index e24a3d0c15..4776002a42 100644 --- a/include/peci.h +++ b/include/peci.h @@ -16,10 +16,15 @@ * error, retry a bit later. */ int peci_get_cpu_temp(void); -/* Read the CPU temperature sensor via PECI. This interface is for the - * temperature sensor module. Returns the temperature in degrees K, or -1 if - * error. */ -int peci_temp_sensor_get_val(int idx); +/** + * Get the last polled value of the PECI temp sensor. + * + * @param idx Sensor index to read. + * @param temp_ptr Destination for temperature in K. + * + * @return EC_SUCCESS if successful, non-zero if error. + */ +int peci_temp_sensor_get_val(int idx, int *temp_ptr); /* Temperature polling of CPU temperature sensor via PECI. */ int peci_temp_sensor_poll(void); diff --git a/include/temp_sensor.h b/include/temp_sensor.h index db3a8536e9..9de57a0c71 100644 --- a/include/temp_sensor.h +++ b/include/temp_sensor.h @@ -38,8 +38,8 @@ struct temp_sensor_t { int8_t power_flags; /* Temperature sensor type. */ enum temp_sensor_type type; - /* Read sensor value and return temperature in K. */ - int (*read)(int idx); + /* Read sensor value in K into temp_ptr; return non-zero if error. */ + int (*read)(int idx, int *temp_ptr); /* Index among the same kind of sensors. */ int idx; /* Delay between reading temperature and taking action about it, @@ -47,9 +47,15 @@ struct temp_sensor_t { int action_delay_sec; }; -/* Return the most recently measured temperature for the sensor in K, - * or -1 if error. */ -int temp_sensor_read(enum temp_sensor_id id); +/** + * Get the most recently measured temperature for the sensor. + * + * @param id Sensor ID + * @param temp_ptr Destination for temperature + * + * @return EC_SUCCESS, or non-zero if error. + */ +int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr); /* Return non-zero if sensor is powered. */ int temp_sensor_powered(enum temp_sensor_id id); diff --git a/include/tmp006.h b/include/tmp006.h index c1c4b21c24..1ed9be03d8 100644 --- a/include/tmp006.h +++ b/include/tmp006.h @@ -30,9 +30,10 @@ int tmp006_poll(void); * @param idx Index to read. The low bit in idx indicates whether * to read die temperature or object temperature. The * other bits serve as internal index to tmp006 module. + * @param temp_ptr Destination for temperature in K. * - * @return Temperature in K. + * @return EC_SUCCESS if successful, non-zero if error. */ -int tmp006_get_val(int idx); +int tmp006_get_val(int idx, int *temp_ptr); #endif /* __CROS_EC_TMP006_H */ |