diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-26 16:33:30 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-11-01 12:45:22 -0700 |
commit | d83f42bdc8b61773efc17e0194e5abe26109128d (patch) | |
tree | e8351b0f756dff9aac9d6b919037c1f3b283c644 /chip/lm4/peci.c | |
parent | 742ec5a1ff3a058bf6f1753bafde9e3e57d44f58 (diff) | |
download | chrome-ec-d83f42bdc8b61773efc17e0194e5abe26109128d.tar.gz |
Switch temp sensor polling to use hooks instead of task
This reduces memory / code size, and gets rid of ifdefs in temp_sensor.c.
BUG=chrome-os-partner:15714
BRANCH=none
TEST=boot system and run 'ectool temps all' every few seconds
- ectool temps all
The numbers should update over time.
Change-Id: Idaac7e6e4cbc1d6689f5d3b607c623a5cc536a4f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36940
Diffstat (limited to 'chip/lm4/peci.c')
-rw-r--r-- | chip/lm4/peci.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c index ff56f7ec47..b547165b49 100644 --- a/chip/lm4/peci.c +++ b/chip/lm4/peci.c @@ -40,7 +40,9 @@ static int temp_vals[TEMP_AVG_LENGTH]; static int temp_idx = 0; -/* Configures the GPIOs for the PECI module. */ +/** + * Configure the GPIOs for the PECI module. + */ static void configure_gpios(void) { /* PJ6 alternate function 1 = PECI Tx */ @@ -50,7 +52,6 @@ static void configure_gpios(void) LM4_GPIO_DEN(LM4_GPIO_J) &= ~0x80; } - int peci_get_cpu_temp(void) { int v = LM4_PECI_M0D0 & 0xffff; @@ -61,15 +62,6 @@ int peci_get_cpu_temp(void) return v >> 6; } - -int peci_temp_sensor_poll(void) -{ - temp_vals[temp_idx] = peci_get_cpu_temp(); - temp_idx = (temp_idx + 1) & (TEMP_AVG_LENGTH - 1); - return EC_SUCCESS; -} - - int peci_temp_sensor_get_val(int idx, int *temp_ptr) { int sum = 0; @@ -93,6 +85,13 @@ int peci_temp_sensor_get_val(int idx, int *temp_ptr) return EC_SUCCESS; } +static void peci_temp_sensor_poll(void) +{ + temp_vals[temp_idx] = peci_get_cpu_temp(); + temp_idx = (temp_idx + 1) & (TEMP_AVG_LENGTH - 1); +} +DECLARE_HOOK(HOOK_TICK, peci_temp_sensor_poll, HOOK_PRIO_DEFAULT); + static void peci_freq_changed(void) { int freq = clock_get_freq(); @@ -101,8 +100,10 @@ static void peci_freq_changed(void) /* Disable polling while reconfiguring */ LM4_PECI_CTL = 0; - /* Calculate baud setting from desired rate, compensating for internal - * and external delays. */ + /* + * Calculate baud setting from desired rate, compensating for internal + * and external delays. + */ baud = freq / (4 * PECI_BAUD_RATE) - 2; baud -= (freq / 1000000) * (PECI_TD_FET_NS + PECI_TD_INT_NS) / 1000; @@ -117,27 +118,6 @@ static void peci_freq_changed(void) } DECLARE_HOOK(HOOK_FREQ_CHANGE, peci_freq_changed, HOOK_PRIO_DEFAULT - 1); -/*****************************************************************************/ -/* Console commands */ - -static int command_peci_temp(int argc, char **argv) -{ - int t = peci_get_cpu_temp(); - if (t == -1) { - ccprintf("PECI error 0x%04x\n", LM4_PECI_M0D0 & 0xffff); - return EC_ERROR_UNKNOWN; - } - ccprintf("CPU temp = %d K = %d C\n", t, t - 273); - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp, - NULL, - "Print CPU temperature", - NULL); - -/*****************************************************************************/ -/* Initialization */ - static void peci_init(void) { volatile uint32_t scratch __attribute__((unused)); @@ -158,3 +138,21 @@ static void peci_init(void) temp_vals[i] = 300; /* 27 C */ } DECLARE_HOOK(HOOK_INIT, peci_init, HOOK_PRIO_DEFAULT); + +/*****************************************************************************/ +/* Console commands */ + +static int command_peci_temp(int argc, char **argv) +{ + int t = peci_get_cpu_temp(); + if (t == -1) { + ccprintf("PECI error 0x%04x\n", LM4_PECI_M0D0 & 0xffff); + return EC_ERROR_UNKNOWN; + } + ccprintf("CPU temp = %d K = %d C\n", t, t - 273); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp, + NULL, + "Print CPU temperature", + NULL); |