From dc4ee57307e5df5400ee5dbea44cbaaf94f3ba57 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 14 Aug 2012 12:49:30 +0800 Subject: 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. Change-Id: I5c84d9696b4876fdfcf14c3a416cbc09c040d4ee Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/30138 Reviewed-by: Vincent Palatin --- chip/lm4/chip_temp_sensor.c | 9 +++++++++ chip/lm4/peci.c | 5 +++++ 2 files changed, 14 insertions(+) (limited to 'chip/lm4') 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); -- cgit v1.2.1