diff options
author | Vic Yang <victoryang@chromium.org> | 2012-08-14 12:49:30 +0800 |
---|---|---|
committer | David James <davidjames@google.com> | 2012-08-14 04:51:27 -0700 |
commit | 422d185a926bef172ee9b0ca2de3780d796d8a82 (patch) | |
tree | 8aa813357db8a1da2493fd189db9209f4e069538 | |
parent | 31141f2218540e87d01d5834a29ffff3b3c76255 (diff) | |
download | chrome-ec-422d185a926bef172ee9b0ca2de3780d796d8a82.tar.gz |
Initialize temperature reading buffer to sane values
This is to prevent temperature value being read before the first time we
poll sensors causes unexpected error.
BUG=chrome-os-partner:12614
TEST="sysjump RW" and then "temps" immediately. Check all temperature
readings are near 300 K.
Original-Change-Id: I5c84d9696b4876fdfcf14c3a416cbc09c040d4ee
Signed-off-by: Vic Yang <victoryang@chromium.org>
(cherry picked from commit 208e08322d4ce9ed08901a4c43ac9db40cfe392e)
Change-Id: Ie12ed3bf6733fb45aaafc77de80e5a0adf37e42c
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/30141
(cherry picked from commit c981712156eff1ee68bf375f95cca05c5885af2c)
-rw-r--r-- | chip/lm4/chip_temp_sensor.c | 9 | ||||
-rw-r--r-- | chip/lm4/peci.c | 5 | ||||
-rw-r--r-- | common/temp_sensor.c | 28 | ||||
-rw-r--r-- | common/tmp006.c | 20 |
4 files changed, 57 insertions, 5 deletions
diff --git a/chip/lm4/chip_temp_sensor.c b/chip/lm4/chip_temp_sensor.c index 657f582275..fb9084e82e 100644 --- a/chip/lm4/chip_temp_sensor.c +++ b/chip/lm4/chip_temp_sensor.c @@ -7,6 +7,7 @@ #include "adc.h" #include "board.h" +#include "hooks.h" #include "temp_sensor.h" static int last_val; @@ -22,3 +23,11 @@ int chip_temp_sensor_get_val(int idx) { return last_val; } + +static int chip_temp_sensor_init(void) +{ + /* Initialize temperature reading to a sane value. */ + last_val = 300; /* 27 C */ + return EC_SUCCESS; +} +DECLARE_HOOK(HOOK_INIT, chip_temp_sensor_init, HOOK_PRIO_DEFAULT); diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c index 1ea876fbcd..4091ee8640 100644 --- a/chip/lm4/peci.c +++ b/chip/lm4/peci.c @@ -139,6 +139,7 @@ DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp, static int peci_init(void) { volatile uint32_t scratch __attribute__((unused)); + int i; /* Enable the PECI module and delay a few clocks */ LM4_SYSTEM_RCGCPECI = 1; @@ -150,6 +151,10 @@ static int peci_init(void) /* Set initial clock frequency */ peci_freq_changed(); + /* Initialize temperature reading buffer to a sane value. */ + for (i = 0; i < TEMP_AVG_LENGTH; ++i) + temp_vals[i] = 300; /* 27 C */ + return EC_SUCCESS; } DECLARE_HOOK(HOOK_INIT, peci_init, HOOK_PRIO_DEFAULT); diff --git a/common/temp_sensor.c b/common/temp_sensor.c index 9f653612f0..cdad3ebd1f 100644 --- a/common/temp_sensor.c +++ b/common/temp_sensor.c @@ -106,12 +106,30 @@ static void update_mapped_memory(void) void temp_sensor_task(void) { int i; + uint8_t *base, *base_b; + + /* + * Initialize memory-mapped data. We initialize valid sensors to 23 C + * so that if a temperature value is read before we actually poll the + * sensors, we don't end up with an insane value. + */ + base = host_get_memmap(EC_MEMMAP_TEMP_SENSOR); + base_b = host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B); + for (i = 0; i < TEMP_SENSOR_COUNT; ++i) { + if (i < EC_TEMP_SENSOR_ENTRIES) + base[i] = 0x60; /* 23 C */ + else + base_b[i - EC_TEMP_SENSOR_ENTRIES] = 0x60; /* 23 C */ + } - /* Initialize memory-mapped data */ - memset(host_get_memmap(EC_MEMMAP_TEMP_SENSOR), - EC_TEMP_SENSOR_NOT_PRESENT, EC_TEMP_SENSOR_ENTRIES); - memset(host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B), - EC_TEMP_SENSOR_NOT_PRESENT, EC_TEMP_SENSOR_B_ENTRIES); + /* Set the rest of memory region to SENSOR_NOT_PRESENT */ + for (; i < EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES; ++i) { + if (i < EC_TEMP_SENSOR_ENTRIES) + base[i] = EC_TEMP_SENSOR_NOT_PRESENT; + else + base_b[i - EC_TEMP_SENSOR_ENTRIES] = + EC_TEMP_SENSOR_NOT_PRESENT; + } /* Temp sensor data is present, with B range supported. */ *host_get_memmap(EC_MEMMAP_THERMAL_VERSION) = 2; diff --git a/common/tmp006.c b/common/tmp006.c index 819ecda7c2..a0c6e3e455 100644 --- a/common/tmp006.c +++ b/common/tmp006.c @@ -10,6 +10,7 @@ #include "console.h" #include "fpu.h" #include "gpio.h" +#include "hooks.h" #include "i2c.h" #include "math.h" #include "task.h" @@ -273,6 +274,25 @@ int tmp006_poll(void) return rv1; } +static int tmp006_init(void) +{ + int i, j; + + /* + * Set temperature value to 27 C and we will update it later when + * polled by temperature sensor module. + */ + for (i = 0; i < TMP006_COUNT; ++i) { + for (j = 0; j < 4; ++j) + tmp006_data[i].t[j] = 30000; /* 27 C */ + tmp006_data[i].tidx = 0; + /* TODO(victoryang): Default value for V? */ + } + + return EC_SUCCESS; +} +DECLARE_HOOK(HOOK_INIT, tmp006_init, HOOK_PRIO_DEFAULT); + /*****************************************************************************/ /* Console commands */ |