summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2013-08-19 15:22:42 -0700
committerChromeBot <chrome-bot@google.com>2013-08-19 15:57:26 -0700
commit495192cee9b615c033e4553a2c9f67b6bec8c9a0 (patch)
tree7661769838d2ca1f90cc49ef0e2bf792c7e6ad0a
parentc7d7e684fa222131622235e55584cc1bf6d35012 (diff)
downloadchrome-ec-495192cee9b615c033e4553a2c9f67b6bec8c9a0.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. Original-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> (cherry picked from commit e1f20537e52ae2f0725c588ff0caeab5159394a0) Change-Id: I0cd72114d494cb89724528af01f0df5cb0724235 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/66257
-rw-r--r--board/falco/board.c6
-rw-r--r--board/peppy/board.c6
-rw-r--r--board/slippy/board.c6
-rw-r--r--common/temp_sensor_g781.c34
-rw-r--r--include/hooks.h2
-rw-r--r--include/temp_sensor_g781.h3
6 files changed, 38 insertions, 19 deletions
diff --git a/board/falco/board.c b/board/falco/board.c
index 3b9a197584..690679499c 100644
--- a/board/falco/board.c
+++ b/board/falco/board.c
@@ -176,8 +176,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 5a0cc05d5d..22f921a254 100644
--- a/board/peppy/board.c
+++ b/board/peppy/board.c
@@ -169,8 +169,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 fbeb7e7224..6c8f283d8f 100644
--- a/board/slippy/board.c
+++ b/board/slippy/board.c
@@ -169,8 +169,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