diff options
author | Dave Parker <dparker@chromium.org> | 2013-08-11 10:46:44 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-08-13 13:07:54 -0700 |
commit | e1f20537e52ae2f0725c588ff0caeab5159394a0 (patch) | |
tree | bf0e1e65a3e1551f07b6efb0c95a1f41c85b1ef8 | |
parent | 39421848c6bfe0881fc8e6eca3a5656a91662638 (diff) | |
download | chrome-ec-e1f20537e52ae2f0725c588ff0caeab5159394a0.tar.gz |
Poll and cache g781 temperature values
BUG=chromium:271236
BRANCH=falco,peppy
TEST=Run 'ectool temps all' Verify temp. values are present
for the g781.
Change-Id: I2ea8aff9e256167bf04abc959f971da94fc51e77
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/65597
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | board/falco/board.c | 6 | ||||
-rw-r--r-- | board/peppy/board.c | 6 | ||||
-rw-r--r-- | board/slippy/board.c | 6 | ||||
-rw-r--r-- | common/temp_sensor_g781.c | 34 | ||||
-rw-r--r-- | include/hooks.h | 2 | ||||
-rw-r--r-- | include/temp_sensor_g781.h | 3 |
6 files changed, 38 insertions, 19 deletions
diff --git a/board/falco/board.c b/board/falco/board.c index acb601b917..b2c53791af 100644 --- a/board/falco/board.c +++ b/board/falco/board.c @@ -194,8 +194,10 @@ BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED); const struct temp_sensor_t temp_sensors[] = { {"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2}, {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4}, - {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4}, - {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4}, + {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, + G781_IDX_INTERNAL, 4}, + {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, + G781_IDX_EXTERNAL, 4}, }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); diff --git a/board/peppy/board.c b/board/peppy/board.c index bfba521292..540247e191 100644 --- a/board/peppy/board.c +++ b/board/peppy/board.c @@ -185,8 +185,10 @@ BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED); const struct temp_sensor_t temp_sensors[] = { {"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2}, {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4}, - {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4}, - {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4}, + {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, + G781_IDX_INTERNAL, 4}, + {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, + G781_IDX_EXTERNAL, 4}, }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); diff --git a/board/slippy/board.c b/board/slippy/board.c index 8273ca4e3f..c05e5dc5be 100644 --- a/board/slippy/board.c +++ b/board/slippy/board.c @@ -185,8 +185,10 @@ BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED); const struct temp_sensor_t temp_sensors[] = { {"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2}, {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4}, - {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4}, - {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4}, + {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, + G781_IDX_INTERNAL, 4}, + {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, + G781_IDX_EXTERNAL, 4}, }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); diff --git a/common/temp_sensor_g781.c b/common/temp_sensor_g781.c index 267cc4a0e5..96dd18ea60 100644 --- a/common/temp_sensor_g781.c +++ b/common/temp_sensor_g781.c @@ -8,9 +8,13 @@ #include "common.h" #include "console.h" #include "i2c.h" +#include "hooks.h" #include "temp_sensor_g781.h" #include "util.h" +static int g781_temp_val_local; +static int g781_temp_val_remote; + static int g781_read8(const int offset, int *data_ptr) { return i2c_read8(I2C_PORT_THERMAL, G781_I2C_ADDR, offset, data_ptr); @@ -44,32 +48,36 @@ static int g781_set_temp(const int offset, int temp) int g781_get_val(int idx, int *temp_ptr) { - int offset; - int rv; - if (!board_g781_has_power()) return EC_ERROR_NOT_POWERED; switch (idx) { - case 0: - offset = G781_TEMP_LOCAL; + case G781_IDX_INTERNAL: + *temp_ptr = g781_temp_val_local; break; - case 1: - offset = G781_TEMP_REMOTE; + case G781_IDX_EXTERNAL: + *temp_ptr = g781_temp_val_remote; break; default: return EC_ERROR_UNKNOWN; } - rv = g781_get_temp(offset, temp_ptr); - if (rv < 0) - return rv; - - /* Temperature from sensor is in degrees Celsius */ - *temp_ptr = C_TO_K(*temp_ptr); return EC_SUCCESS; } +static void g781_temp_sensor_poll(void) +{ + if (!board_g781_has_power()) + return; + + g781_get_temp(G781_TEMP_LOCAL, &g781_temp_val_local); + g781_temp_val_local = C_TO_K(g781_temp_val_local); + + g781_get_temp(G781_TEMP_REMOTE, &g781_temp_val_remote); + g781_temp_val_remote = C_TO_K(g781_temp_val_remote); +} +DECLARE_HOOK(HOOK_SECOND, g781_temp_sensor_poll, HOOK_PRIO_TEMP_SENSOR); + static int g781_show_status(void) { int value; diff --git a/include/hooks.h b/include/hooks.h index d00d0b649f..d4bcea5ba8 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -16,6 +16,8 @@ enum hook_priority { HOOK_PRIO_DEFAULT = 5000, /* Default priority */ HOOK_PRIO_LAST = 9999, /* Lowest priority */ + /* Specific values to lump related hooks together */ + HOOK_PRIO_TEMP_SENSOR = 6000, /* Specific hook vales for HOOK_INIT */ /* DMA inits before ADC, I2C, SPI */ HOOK_PRIO_INIT_DMA = HOOK_PRIO_FIRST + 1, diff --git a/include/temp_sensor_g781.h b/include/temp_sensor_g781.h index ce79cb0d05..6463155659 100644 --- a/include/temp_sensor_g781.h +++ b/include/temp_sensor_g781.h @@ -10,6 +10,9 @@ #define G781_I2C_ADDR 0x98 /* 7-bit address is 0x4C */ +#define G781_IDX_INTERNAL 0 +#define G781_IDX_EXTERNAL 1 + /* Chip-specific commands */ #define G781_TEMP_LOCAL 0x00 #define G781_TEMP_REMOTE 0x01 |