summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-11 11:06:29 -0700
committerRong Chang <rongchang@chromium.org>2012-10-16 01:00:03 -0700
commit2342c6fdb21b8d472201b12815d5bcf48026f203 (patch)
tree3733762e1355745d76d5675e88c2947b2e11f00d
parent54b8568680ffab2fc106f329847e707bb547b945 (diff)
downloadchrome-ec-2342c6fdb21b8d472201b12815d5bcf48026f203.tar.gz
link: Temp sensors can return not-powered error code
This removes the need for a separate method to check sensor power, and gets rid of temp_sensor.c knowledge of what powers each sensor. BUG=chrome-os-partner:15174 BRANCH=link TEST=manual - reboot - within a second, type 'temps'; I2C sensors should return error 1 - type 'temps' again; all sensors should return data - power off system - type 'temps' again; I2C sensors and PECI should return error 8 - 'gpioset enable_vs 1' - type 'temps' again; I2C sensors should return valid data; PECI should still return error 8. Original-Change-Id: I17c353b3c483bc320769307c7715008ec729089b Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35287 Reviewed-by: Bill Richardson <wfrichar@chromium.org> (cherry picked from commit 22e03a1de6d525e84e511f4b25531caf6f1a93fd) Change-Id: Iad6a0691beabfed6185d22e4ce89d49d8c90fd7e Reviewed-on: https://gerrit.chromium.org/gerrit/35670 Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
-rw-r--r--board/link/board_temp_sensor.c30
-rw-r--r--chip/lm4/peci.c6
-rw-r--r--common/temp_sensor.c30
-rw-r--r--common/thermal.c10
-rw-r--r--common/tmp006.c6
-rw-r--r--include/common.h6
-rw-r--r--include/temp_sensor.h9
7 files changed, 39 insertions, 58 deletions
diff --git a/board/link/board_temp_sensor.c b/board/link/board_temp_sensor.c
index c5b317b204..96ef9050d3 100644
--- a/board/link/board_temp_sensor.c
+++ b/board/link/board_temp_sensor.c
@@ -26,30 +26,20 @@
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
#ifdef CONFIG_TMP006
- {"I2C-USB C-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_IGNORED,
- tmp006_get_val, 0, 7},
- {"I2C-USB C-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_IGNORED,
- tmp006_get_val, 1, 7},
- {"I2C-PCH D-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_BOARD,
- tmp006_get_val, 2, 7},
- {"I2C-PCH D-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE,
- tmp006_get_val, 3, 7},
- {"I2C-Hinge C-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_IGNORED,
- tmp006_get_val, 4, 7},
- {"I2C-Hinge C-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_IGNORED,
- tmp006_get_val, 5, 7},
- {"I2C-Charger D-Die", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_BOARD,
- tmp006_get_val, 6, 7},
- {"I2C-Charger D-Object", TEMP_SENSOR_POWER_VS, TEMP_SENSOR_TYPE_CASE,
- tmp006_get_val, 7, 7},
+ {"I2C-USB C-Die", TEMP_SENSOR_TYPE_IGNORED, tmp006_get_val, 0, 7},
+ {"I2C-USB C-Object", TEMP_SENSOR_TYPE_IGNORED, tmp006_get_val, 1, 7},
+ {"I2C-PCH D-Die", TEMP_SENSOR_TYPE_BOARD, tmp006_get_val, 2, 7},
+ {"I2C-PCH D-Object", TEMP_SENSOR_TYPE_CASE, tmp006_get_val, 3, 7},
+ {"I2C-Hinge C-Die", TEMP_SENSOR_TYPE_IGNORED, tmp006_get_val, 4, 7},
+ {"I2C-Hinge C-Object", TEMP_SENSOR_TYPE_IGNORED, tmp006_get_val, 5, 7},
+ {"I2C-Charger D-Die", TEMP_SENSOR_TYPE_BOARD, tmp006_get_val, 6, 7},
+ {"I2C-Charger D-Object", TEMP_SENSOR_TYPE_CASE, tmp006_get_val, 7, 7},
#endif
#ifdef CONFIG_TASK_TEMPSENSOR
- {"ECInternal", TEMP_SENSOR_POWER_NONE, TEMP_SENSOR_TYPE_BOARD,
- chip_temp_sensor_get_val, 0, 4},
+ {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
#endif
#ifdef CONFIG_PECI
- {"PECI", TEMP_SENSOR_POWER_CPU, TEMP_SENSOR_TYPE_CPU,
- peci_temp_sensor_get_val, 0, 2},
+ {"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
#endif
};
diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c
index 210fb4e6c9..ddbb1a9a6c 100644
--- a/chip/lm4/peci.c
+++ b/chip/lm4/peci.c
@@ -5,8 +5,9 @@
/* PECI interface for Chrome EC */
-#include "board.h"
+#include "chipset.h"
#include "clock.h"
+#include "config.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
@@ -75,6 +76,9 @@ int peci_temp_sensor_get_val(int idx, int *temp_ptr)
int success_cnt = 0;
int i;
+ if (!chipset_in_state(CHIPSET_STATE_ON))
+ return EC_ERROR_NOT_POWERED;
+
for (i = 0; i < TEMP_AVG_LENGTH; ++i) {
if (temp_vals[i] >= 0) {
success_cnt++;
diff --git a/common/temp_sensor.c b/common/temp_sensor.c
index 333ed1d266..ee1299f78d 100644
--- a/common/temp_sensor.c
+++ b/common/temp_sensor.c
@@ -36,21 +36,6 @@ int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr)
return sensor->read(sensor->idx, temp_ptr);
}
-int temp_sensor_powered(enum temp_sensor_id id)
-{
- int flag = temp_sensors[id].power_flags;
-
- if (flag & TEMP_SENSOR_POWER_VS &&
- gpio_get_level(GPIO_PGOOD_1_8VS) == 0)
- return 0;
-
- if (flag & TEMP_SENSOR_POWER_CPU &&
- !chipset_in_state(CHIPSET_STATE_ON))
- return 0;
-
- return 1;
-}
-
void poll_slow_sensors(void)
{
/* Poll every second */
@@ -86,15 +71,16 @@ static void update_mapped_memory(void)
EC_TEMP_SENSOR_B_ENTRIES)
break;
- if (!temp_sensor_powered(i)) {
+ switch (temp_sensor_read(i, &t)) {
+ case EC_ERROR_NOT_POWERED:
*mptr = EC_TEMP_SENSOR_NOT_POWERED;
- continue;
- }
-
- if (temp_sensor_read(i, &t))
- *mptr = EC_TEMP_SENSOR_ERROR;
- else
+ break;
+ case EC_SUCCESS:
*mptr = t - EC_TEMP_SENSOR_OFFSET;
+ break;
+ default:
+ *mptr = EC_TEMP_SENSOR_ERROR;
+ }
}
}
diff --git a/common/thermal.c b/common/thermal.c
index 6b4f3fa355..a300497bde 100644
--- a/common/thermal.c
+++ b/common/thermal.c
@@ -173,6 +173,7 @@ static void thermal_process(void)
int i, j;
int cur_temp;
int flag;
+ int rv;
for (i = 0; i < THRESHOLD_COUNT + THERMAL_FAN_STEPS; ++i)
overheated[i] = 0;
@@ -185,11 +186,12 @@ static void thermal_process(void)
flag = thermal_config[type].config_flags;
- if (!temp_sensor_powered(i))
+ rv = temp_sensor_read(i, &cur_temp);
+ if (rv == EC_ERROR_NOT_POWERED) {
+ /* Sensor not powered; ignore it */
continue;
-
- if (temp_sensor_read(i, &cur_temp)) {
- /* Sensor failure. */
+ } else if (rv) {
+ /* Other sensor failure */
if (flag & THERMAL_CONFIG_WARNING_ON_FAIL)
smi_sensor_failure_warning();
continue;
diff --git a/common/tmp006.c b/common/tmp006.c
index edb20af586..d7407397a7 100644
--- a/common/tmp006.c
+++ b/common/tmp006.c
@@ -217,7 +217,11 @@ int tmp006_get_val(int idx, int *temp_ptr)
* Note: idx is a thermal sensor index, where the top N-1 bits are the
* TMP006 index and the bottom bit is (0=die, 1=remote).
*/
- const struct tmp006_data_t *tdata = tmp006_data + (idx >> 1);
+ int tidx = idx >> 1;
+ const struct tmp006_data_t *tdata = tmp006_data + tidx;
+
+ if (tdata->fail & FAIL_POWER)
+ return EC_ERROR_NOT_POWERED;
/* Check the low bit to determine which temperature to read. */
if ((idx & 0x1) == 0)
diff --git a/include/common.h b/include/common.h
index 5441efdc99..ca772b303f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -41,10 +41,14 @@ enum ec_error_list {
EC_ERROR_TIMEOUT = 4,
/* Invalid argument */
EC_ERROR_INVAL = 5,
- /* Already in use */
+ /* Already in use, or not ready yet */
EC_ERROR_BUSY = 6,
/* Access denied */
EC_ERROR_ACCESS_DENIED = 7,
+ /* Failed because component does not have power */
+ EC_ERROR_NOT_POWERED = 8,
+ /* Failed because component is not calibrated */
+ EC_ERROR_NOT_CALIBRATED = 9,
/* Invalid console command param (PARAMn means parameter n is bad) */
EC_ERROR_PARAM1 = 11,
EC_ERROR_PARAM2 = 12,
diff --git a/include/temp_sensor.h b/include/temp_sensor.h
index 9de57a0c71..04b7e868ff 100644
--- a/include/temp_sensor.h
+++ b/include/temp_sensor.h
@@ -11,10 +11,6 @@
#include "common.h"
#include "board.h"
-#define TEMP_SENSOR_POWER_NONE 0x0
-#define TEMP_SENSOR_POWER_VS 0x1
-#define TEMP_SENSOR_POWER_CPU 0x2
-
/* "enum temp_sensor_id" must be defined for each board in board.h. */
enum temp_sensor_id;
@@ -34,8 +30,6 @@ enum temp_sensor_type {
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 in K into temp_ptr; return non-zero if error. */
@@ -57,7 +51,4 @@ struct temp_sensor_t {
*/
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);
-
#endif /* __CROS_EC_TEMP_SENSOR_H */