summaryrefslogtreecommitdiff
path: root/chip/lm4/peci.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-04-06 09:33:41 -0700
committerRandall Spangler <rspangler@chromium.org>2012-04-09 10:33:35 -0700
commite9328ac4f63351b4282916034270aa86b7e74922 (patch)
treed0fde5840594c33709927a5a4d1fabfe0f858c26 /chip/lm4/peci.c
parent1a9a415cf68c6e8e3b31972c072c81ed886290ab (diff)
downloadchrome-ec-e9328ac4f63351b4282916034270aa86b7e74922.tar.gz
Support dynamically changing the system clock
Add nopll command to turn off the PLL, reducing the system clock to 16Mhz. Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=chrome-os-partner:8798 TEST=manual boot system press power button to boot x86 temps // should print all temperatures timerinfo timerinfo timerinfo // convince yourself this is counting up at about 1MHz nopll // this drops the system clock to 16MHz temps // should still print all temperatures timerinfo timerinfo timerinfo // should still be counting up at about 1MHz Change-Id: Ie29ceb17af348148bffadf63d60c1b731f4c3f6d
Diffstat (limited to 'chip/lm4/peci.c')
-rw-r--r--chip/lm4/peci.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c
index 75946a4e61..2dbbd914b3 100644
--- a/chip/lm4/peci.c
+++ b/chip/lm4/peci.c
@@ -6,6 +6,7 @@
/* PECI interface for Chrome EC */
#include "board.h"
+#include "clock.h"
#include "console.h"
#include "gpio.h"
#include "peci.h"
@@ -51,6 +52,7 @@ int peci_get_cpu_temp(void)
return v >> 6;
}
+
int peci_temp_sensor_poll(void)
{
last_temp_val = peci_get_cpu_temp();
@@ -61,11 +63,33 @@ int peci_temp_sensor_poll(void)
return EC_ERROR_UNKNOWN;
}
+
int peci_temp_sensor_get_val(int idx)
{
return last_temp_val;
}
+
+void peci_clock_changed(int freq)
+{
+ int baud;
+
+ /* Disable polling while reconfiguring */
+ LM4_PECI_CTL = 0;
+
+ /* 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;
+
+ /* Set baud rate and polling rate */
+ LM4_PECI_DIV = (baud << 16) |
+ (PECI_POLL_INTERVAL_MS * (freq / 1000 / 4096));
+
+ /* Set up temperature monitoring to report in degrees K */
+ LM4_PECI_CTL = ((PECI_TJMAX + 273) << 22) | 0x2001;
+}
+
/*****************************************************************************/
/* Console commands */
@@ -88,7 +112,6 @@ DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp);
int peci_init(void)
{
volatile uint32_t scratch __attribute__((unused));
- int baud;
/* Enable the PECI module and delay a few clocks */
LM4_SYSTEM_RCGCPECI = 1;
@@ -97,21 +120,8 @@ int peci_init(void)
/* Configure GPIOs */
configure_gpios();
- /* Disable polling while reconfiguring */
- LM4_PECI_CTL = 0;
-
- /* Calculate baud setting from desired rate, compensating for internal
- * and external delays. */
- baud = CPU_CLOCK / (4 * PECI_BAUD_RATE) - 2;
- baud -= (CPU_CLOCK / 1000000) * (PECI_TD_FET_NS + PECI_TD_INT_NS)
- / 1000;
-
- /* Set baud rate and polling rate */
- LM4_PECI_DIV = (baud << 16) |
- (PECI_POLL_INTERVAL_MS * (CPU_CLOCK / 1000 / 4096));
-
- /* Set up temperature monitoring to report in degrees K */
- LM4_PECI_CTL = ((PECI_TJMAX + 273) << 22) | 0x2001;
+ /* Set initial clock frequency */
+ peci_clock_changed(clock_get_freq());
return EC_SUCCESS;
}