summaryrefslogtreecommitdiff
path: root/chip/mec1322/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip/mec1322/clock.c')
-rw-r--r--chip/mec1322/clock.c79
1 files changed, 34 insertions, 45 deletions
diff --git a/chip/mec1322/clock.c b/chip/mec1322/clock.c
index ce07284891..c9fc68d58a 100644
--- a/chip/mec1322/clock.c
+++ b/chip/mec1322/clock.c
@@ -1,10 +1,11 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
+/* Copyright 2013 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Clocks and power management settings */
+#include "builtin/assert.h"
#include "clock.h"
#include "common.h"
#include "console.h"
@@ -24,13 +25,13 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CLOCK, outstr)
-#define CPRINTS(format, args...) cprints(CC_CLOCK, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CLOCK, format, ##args)
#ifdef CONFIG_LOW_POWER_IDLE
/* Recovery time for HvySlp2 is 0 usec */
-#define HEAVY_SLEEP_RECOVER_TIME_USEC 75
+#define HEAVY_SLEEP_RECOVER_TIME_USEC 75
-#define SET_HTIMER_DELAY_USEC 200
+#define SET_HTIMER_DELAY_USEC 200
static int idle_sleep_cnt;
static int idle_dsleep_cnt;
@@ -40,7 +41,7 @@ static uint64_t total_idle_dsleep_time_us;
* Fixed amount of time to keep the console in use flag true after boot in
* order to give a permanent window in which the heavy sleep mode is not used.
*/
-#define CONSOLE_IN_USE_ON_BOOT_TIME (15*SECOND)
+#define CONSOLE_IN_USE_ON_BOOT_TIME (15 * SECOND)
static int console_in_use_timeout_sec = 60;
static timestamp_t console_expire_time;
#endif /*CONFIG_LOW_POWER_IDLE */
@@ -50,7 +51,8 @@ static int freq = 48000000;
void clock_wait_cycles(uint32_t cycles)
{
asm volatile("1: subs %0, #1\n"
- " bne 1b\n" : "+r"(cycles));
+ " bne 1b\n"
+ : "+r"(cycles));
}
int clock_get_freq(void)
@@ -104,8 +106,8 @@ DECLARE_HOOK(HOOK_INIT, clock_turbo_disable, HOOK_PRIO_INIT_VBOOT_HASH + 1);
static void htimer_init(void)
{
MEC1322_INT_BLK_EN |= BIT(17);
- MEC1322_INT_ENABLE(17) |= BIT(20); /* GIRQ=17, aggregator bit = 20 */
- MEC1322_HTIMER_PRELOAD = 0; /* disable at beginning */
+ MEC1322_INT_ENABLE(17) |= BIT(20); /* GIRQ=17, aggregator bit = 20 */
+ MEC1322_HTIMER_PRELOAD = 0; /* disable at beginning */
task_enable_irq(MEC1322_IRQ_HTIMER);
}
@@ -120,7 +122,6 @@ static void htimer_init(void)
static void system_set_htimer_alarm(uint32_t seconds, uint32_t microseconds)
{
if (seconds || microseconds) {
-
if (seconds > 2) {
/* count from 2 sec to 2 hrs, mec1322 sec 18.10.2 */
ASSERT(seconds <= 0xffff / 8);
@@ -154,19 +155,18 @@ static timestamp_t system_get_htimer(void)
uint16_t count;
timestamp_t time;
- count = MEC1322_HTIMER_COUNT;
-
+ count = MEC1322_HTIMER_COUNT;
if (MEC1322_HTIMER_CONTROL == 1) /* if > 2 sec */
/* 0.125 sec per count */
time.le.lo = (uint32_t)(count * 125000);
- else /* if < 2 sec */
+ else /* if < 2 sec */
/* 30.5(=61/2)usec per count */
time.le.lo = (uint32_t)(count * 61 / 2);
time.le.hi = 0;
- return time; /* in uSec */
+ return time; /* in uSec */
}
/**
@@ -220,7 +220,7 @@ static void prepare_for_deep_sleep(void)
MEC1322_LPC_ACT = 0x0;
#endif
- MEC1322_PCR_SYS_SLP_CTL = 0x2; /* heavysleep 2 */
+ MEC1322_PCR_SYS_SLP_CTL = 0x2; /* heavysleep 2 */
CPU_NVIC_ST_CTRL &= ~ST_TICKINT; /* SYS_TICK_INT_DISABLE */
}
@@ -248,7 +248,7 @@ static void resume_from_deep_sleep(void)
MEC1322_PCR_HOST_SLP_EN &= MEC1322_PCR_HOST_SLP_EN_WAKE;
MEC1322_PCR_EC_SLP_EN2 &= MEC1322_PCR_EC_SLP_EN2_WAKE;
- MEC1322_PCR_SYS_SLP_CTL = 0xF8; /* default */
+ MEC1322_PCR_SYS_SLP_CTL = 0xF8; /* default */
#ifndef CONFIG_POWER_S0IX
/* Enable LPC */
@@ -256,7 +256,6 @@ static void resume_from_deep_sleep(void)
#endif
}
-
void clock_refresh_console_in_use(void)
{
disable_sleep(SLEEP_MASK_CONSOLE);
@@ -284,7 +283,6 @@ void __idle(void)
disable_sleep(SLEEP_MASK_CONSOLE);
console_expire_time.val = get_time().val + CONSOLE_IN_USE_ON_BOOT_TIME;
-
/*
* Print when the idle task starts. This is the lowest priority task,
* so this only starts once all other tasks have gotten a chance to do
@@ -296,7 +294,7 @@ void __idle(void)
/* Disable interrupts */
interrupt_disable();
- t0 = get_time(); /* uSec */
+ t0 = get_time(); /* uSec */
/* __hw_clock_event_get() is next programmed timer event */
next_delay = __hw_clock_event_get() - t0.le.lo;
@@ -308,14 +306,12 @@ void __idle(void)
/* check if there enough time for deep sleep */
if (DEEP_SLEEP_ALLOWED && time_for_dsleep) {
-
-
/*
* Check if the console use has expired and console
* sleep is masked by GPIO(UART-RX) interrupt.
*/
if ((sleep_mask & SLEEP_MASK_CONSOLE) &&
- t0.val > console_expire_time.val) {
+ t0.val > console_expire_time.val) {
/* allow console to sleep. */
enable_sleep(SLEEP_MASK_CONSOLE);
@@ -330,11 +326,10 @@ void __idle(void)
CPRINTS("Disable console in deepsleep");
}
-
/* UART is not being used */
- uart_ready_for_deepsleep = LOW_SPEED_DEEP_SLEEP_ALLOWED
- && !uart_tx_in_progress()
- && uart_buffer_empty();
+ uart_ready_for_deepsleep =
+ LOW_SPEED_DEEP_SLEEP_ALLOWED &&
+ !uart_tx_in_progress() && uart_buffer_empty();
/*
* Since MEC1322's heavysleep modes requires all block
@@ -342,7 +337,6 @@ void __idle(void)
* decision factor of heavysleep of EC.
*/
if (uart_ready_for_deepsleep) {
-
idle_dsleep_cnt++;
/*
@@ -369,10 +363,9 @@ void __idle(void)
}
/* Wait for interrupt: goes into deep sleep. */
- asm("wfi");
+ cpu_enter_suspend_mode();
if (uart_ready_for_deepsleep) {
-
resume_from_deep_sleep();
/*
@@ -390,8 +383,8 @@ void __idle(void)
/* disable/clear htimer wakeup interrupt */
system_reset_htimer_alarm();
- t1.val = t0.val +
- (uint64_t)(max_sleep_time - ht_t1.le.lo);
+ t1.val = t0.val + (uint64_t)(max_sleep_time -
+ ht_t1.le.lo);
force_time(t1);
@@ -400,15 +393,13 @@ void __idle(void)
/* Record time spent in deep sleep. */
total_idle_dsleep_time_us +=
- (uint64_t)(max_sleep_time - ht_t1.le.lo);
+ (uint64_t)(max_sleep_time -
+ ht_t1.le.lo);
}
} else { /* CPU 'Sleep' mode */
-
idle_sleep_cnt++;
-
- asm("wfi");
-
+ cpu_enter_suspend_mode();
}
interrupt_enable();
@@ -419,7 +410,7 @@ void __idle(void)
/**
* Print low power idle statistics
*/
-static int command_idle_stats(int argc, char **argv)
+static int command_idle_stats(int argc, const char **argv)
{
timestamp_t ts = get_time();
@@ -427,19 +418,18 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that deep-sleep: %d\n", idle_dsleep_cnt);
ccprintf("Total Time spent in deep-sleep(sec): %.6lld(s)\n",
- total_idle_dsleep_time_us);
+ total_idle_dsleep_time_us);
ccprintf("Total time on: %.6llds\n\n", ts.val);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(idlestats, command_idle_stats,
- "",
+DECLARE_CONSOLE_COMMAND(idlestats, command_idle_stats, "",
"Print last idle stats");
#endif /* defined(CONFIG_CMD_IDLE_STATS) */
/**
* Configure deep sleep clock settings.
*/
-static int command_dsleep(int argc, char **argv)
+static int command_dsleep(int argc, const char **argv)
{
int v;
@@ -449,9 +439,9 @@ static int command_dsleep(int argc, char **argv)
* Force deep sleep not to use heavy sleep mode or
* allow it to use the heavy sleep mode.
*/
- if (v) /* 'on' */
+ if (v) /* 'on' */
disable_sleep(SLEEP_MASK_FORCE_NO_LOW_SPEED);
- else /* 'off' */
+ else /* 'off' */
enable_sleep(SLEEP_MASK_FORCE_NO_LOW_SPEED);
} else {
/* Set console in use timeout. */
@@ -469,12 +459,11 @@ static int command_dsleep(int argc, char **argv)
ccprintf("Sleep mask: %08x\n", sleep_mask);
ccprintf("Console in use timeout: %d sec\n",
- console_in_use_timeout_sec);
+ console_in_use_timeout_sec);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(dsleep, command_dsleep,
- "[ on | off | <timeout> sec]",
+DECLARE_CONSOLE_COMMAND(dsleep, command_dsleep, "[ on | off | <timeout> sec]",
"Deep sleep clock settings:\nUse 'on' to force deep "
"sleep NOT to enter heavysleep mode.\nUse 'off' to "
"allow deep sleep to use heavysleep whenever conditions"