summaryrefslogtreecommitdiff
path: root/chip/it83xx/clock.c
diff options
context:
space:
mode:
authorDino Li <Dino.Li@ite.com.tw>2016-09-21 11:21:15 +0800
committerchrome-bot <chrome-bot@chromium.org>2016-09-21 19:37:17 -0700
commit0174d4f85bc83d9081c39de1d5399cab45c61a72 (patch)
treebcbd9a3b40e347822a7e864d23dd3e97f095bcef /chip/it83xx/clock.c
parentc5d03154ee5e5d49d6d1c731dd22a551e1e6c04c (diff)
downloadchrome-ec-0174d4f85bc83d9081c39de1d5399cab45c61a72.tar.gz
it83xx: EC sleep mode for system hibernate
The typical power consumption in sleep mode is 65uA. IT83xx uses deep doze mode for low power idle task. The typical power consumption in this state is 280uA (depends on EC tasks, it should be more) and the wake up time is in microsecond. We are using deep doze mode for low power idle task instead of sleep mode is because the wake up time will be 6ms more. While in system hibernate (EC sleep mode), EC won't wake up frequently so we can keep the power consumption at 65uA. Signed-off-by: Dino Li <dino.li@ite.com.tw> BRANCH=none BUG=none TEST=- hibernate 0 [1|999999] - hibernate [1|5|10|600] - hibernate then press power button. - hibernate then lid open. Change-Id: I94884c010264f01ede4950c6bb1b0a444d7b1e6d Reviewed-on: https://chromium-review.googlesource.com/383332 Commit-Ready: Dino Li <dino0303@gmail.com> Tested-by: Dino Li <dino0303@gmail.com> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/it83xx/clock.c')
-rw-r--r--chip/it83xx/clock.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/chip/it83xx/clock.c b/chip/it83xx/clock.c
index ab542aae6e..c353c7b326 100644
--- a/chip/it83xx/clock.c
+++ b/chip/it83xx/clock.c
@@ -10,6 +10,8 @@
#include "console.h"
#include "hwtimer.h"
#include "hwtimer_chip.h"
+#include "intc.h"
+#include "irq_chip.h"
#include "registers.h"
#include "system.h"
#include "task.h"
@@ -31,6 +33,7 @@ static int idle_doze_cnt;
static int idle_sleep_cnt;
static uint64_t total_idle_sleep_time_us;
static int allow_sleep;
+static uint32_t ec_sleep;
/*
* 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.
@@ -348,10 +351,66 @@ static int clock_allow_low_power_idle(void)
return 1;
}
+int clock_ec_wake_from_sleep(void)
+{
+ return ec_sleep;
+}
+
+void __enter_hibernate(uint32_t seconds, uint32_t microseconds)
+{
+ int i;
+
+ /* disable all interrupts */
+ interrupt_disable();
+ for (i = 0; i < IT83XX_IRQ_COUNT; i++) {
+ chip_disable_irq(i);
+ chip_clear_pending_irq(i);
+ }
+ /* bit5: watchdog is disabled. */
+ IT83XX_ETWD_ETWCTRL |= (1 << 5);
+ /* Setup GPIOs for hibernate */
+ if (board_hibernate_late)
+ board_hibernate_late();
+
+ if (seconds || microseconds) {
+ /* At least 1 ms for hibernate. */
+ uint64_t c = (seconds * 1000 + microseconds / 1000 + 1) * 1024;
+
+ uint64divmod(&c, 1000);
+ /* enable a 56-bit timer and clock source is 1.024 KHz */
+ ext_timer_stop(FREE_EXT_TIMER_L, 1);
+ ext_timer_stop(FREE_EXT_TIMER_H, 1);
+ IT83XX_ETWD_ETXPSR(FREE_EXT_TIMER_L) = EXT_PSR_1P024K_HZ;
+ IT83XX_ETWD_ETXPSR(FREE_EXT_TIMER_H) = EXT_PSR_1P024K_HZ;
+ IT83XX_ETWD_ETXCNTLR(FREE_EXT_TIMER_L) = c & 0xffffff;
+ IT83XX_ETWD_ETXCNTLR(FREE_EXT_TIMER_H) = (c >> 24) & 0xffffffff;
+ ext_timer_start(FREE_EXT_TIMER_H, 1);
+ ext_timer_start(FREE_EXT_TIMER_L, 0);
+ }
+
+ for (i = 0; i < hibernate_wake_pins_used; ++i)
+ gpio_enable_interrupt(hibernate_wake_pins[i]);
+
+ /* EC sleep */
+ ec_sleep = 1;
+ clock_ec_pll_ctrl(EC_PLL_SLEEP);
+ interrupt_enable();
+ /* standby instruction */
+ asm("standby wake_grant");
+
+ /* we should never reach that point */
+ while (1)
+ ;
+}
+
void clock_sleep_mode_wakeup_isr(void)
{
uint32_t st_us, c;
+ /* trigger a reboot if wake up EC from sleep mode (system hibernate) */
+ if (clock_ec_wake_from_sleep())
+ system_reset(SYSTEM_RESET_HARD);
+
if (IT83XX_ECPM_PLLCTRL == EC_PLL_DEEP_DOZE) {
clock_ec_pll_ctrl(EC_PLL_DOZE);