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>
This commit is contained in:
Dave Parker
2013-08-11 10:46:44 -07:00
committed by ChromeBot
parent 39421848c6
commit e1f20537e5
6 changed files with 38 additions and 19 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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,

View File

@@ -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