2016-07-03 11:05:39 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-07-03 11:05:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
#include <sys_io.h>
|
|
|
|
#include <misc/__assert.h>
|
|
|
|
#include <power.h>
|
|
|
|
#include <soc_power.h>
|
2016-12-22 05:26:17 +08:00
|
|
|
#include <soc.h>
|
2016-07-03 11:05:39 +08:00
|
|
|
|
2016-10-18 17:35:11 +08:00
|
|
|
#include "power_states.h"
|
2016-07-03 11:05:39 +08:00
|
|
|
|
2017-04-21 02:30:33 +08:00
|
|
|
#define _REG_TIMER_ICR ((volatile u32_t *) \
|
2016-11-08 22:21:03 +08:00
|
|
|
(CONFIG_LOAPIC_BASE_ADDRESS + LOAPIC_TIMER_ICR))
|
|
|
|
|
2016-07-03 11:05:39 +08:00
|
|
|
/* Variables used to save CPU state */
|
2017-04-21 02:30:33 +08:00
|
|
|
u64_t _pm_save_gdtr;
|
|
|
|
u64_t _pm_save_idtr;
|
|
|
|
u32_t _pm_save_esp;
|
2016-07-03 11:05:39 +08:00
|
|
|
|
2016-11-23 13:24:52 +08:00
|
|
|
extern void _power_soc_sleep(void);
|
|
|
|
extern void _power_restore_cpu_context(void);
|
|
|
|
extern void _power_soc_deep_sleep(void);
|
|
|
|
|
2016-10-18 17:35:11 +08:00
|
|
|
#if (defined(CONFIG_SYS_POWER_DEEP_SLEEP))
|
2017-04-21 02:30:33 +08:00
|
|
|
static u32_t *__x86_restore_info =
|
|
|
|
(u32_t *)CONFIG_BSP_SHARED_RESTORE_INFO_RAM_ADDR;
|
2016-10-18 17:35:11 +08:00
|
|
|
|
|
|
|
static void _deep_sleep(enum power_states state)
|
2016-07-03 11:05:39 +08:00
|
|
|
{
|
2016-10-18 17:35:11 +08:00
|
|
|
/*
|
|
|
|
* Setting resume vector inside the restore_cpu_context
|
|
|
|
* function since we have nothing to do before cpu context
|
|
|
|
* is restored. If necessary, it is possible to set the
|
|
|
|
* resume vector to a location where additional processing
|
|
|
|
* can be done before cpu context is restored and control
|
|
|
|
* transferred to _sys_soc_suspend.
|
|
|
|
*/
|
2016-11-23 13:24:52 +08:00
|
|
|
qm_x86_set_resume_vector(_power_restore_cpu_context,
|
2016-10-18 17:35:11 +08:00
|
|
|
*__x86_restore_info);
|
|
|
|
|
2017-02-02 09:12:34 +08:00
|
|
|
qm_power_soc_set_x86_restore_flag();
|
2016-10-18 17:35:11 +08:00
|
|
|
|
2016-11-23 13:24:52 +08:00
|
|
|
switch (state) {
|
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP_1:
|
|
|
|
_power_soc_sleep();
|
|
|
|
break;
|
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP:
|
2016-12-22 05:26:17 +08:00
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP_2:
|
2016-11-23 13:24:52 +08:00
|
|
|
_power_soc_deep_sleep();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-10-18 17:35:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void _sys_soc_set_power_state(enum power_states state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case SYS_POWER_STATE_CPU_LPS:
|
2017-02-02 09:12:34 +08:00
|
|
|
qm_power_cpu_c2lp();
|
2016-10-18 17:35:11 +08:00
|
|
|
break;
|
|
|
|
case SYS_POWER_STATE_CPU_LPS_1:
|
2017-02-02 09:12:34 +08:00
|
|
|
qm_power_cpu_c2();
|
2016-07-03 11:05:39 +08:00
|
|
|
break;
|
2016-10-18 17:35:11 +08:00
|
|
|
case SYS_POWER_STATE_CPU_LPS_2:
|
2017-02-02 09:12:34 +08:00
|
|
|
qm_power_cpu_c1();
|
2016-07-03 11:05:39 +08:00
|
|
|
break;
|
2016-10-18 17:35:11 +08:00
|
|
|
#if (defined(CONFIG_SYS_POWER_DEEP_SLEEP))
|
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP:
|
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP_1:
|
2016-12-22 05:26:17 +08:00
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP_2:
|
2016-10-18 17:35:11 +08:00
|
|
|
_deep_sleep(state);
|
2016-07-03 11:05:39 +08:00
|
|
|
break;
|
2016-10-18 17:35:11 +08:00
|
|
|
#endif
|
2016-07-03 11:05:39 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 17:35:11 +08:00
|
|
|
void _sys_soc_power_state_post_ops(enum power_states state)
|
2016-07-03 11:05:39 +08:00
|
|
|
{
|
2016-11-08 22:21:03 +08:00
|
|
|
switch (state) {
|
|
|
|
case SYS_POWER_STATE_CPU_LPS:
|
|
|
|
*_REG_TIMER_ICR = 1;
|
|
|
|
case SYS_POWER_STATE_CPU_LPS_1:
|
|
|
|
__asm__ volatile("sti");
|
|
|
|
break;
|
|
|
|
#if (defined(CONFIG_SYS_POWER_DEEP_SLEEP))
|
2016-12-22 05:26:17 +08:00
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP_2:
|
|
|
|
#ifdef CONFIG_ARC_INIT
|
|
|
|
_arc_init(NULL);
|
|
|
|
#endif /* CONFIG_ARC_INIT */
|
|
|
|
/* Fallthrough */
|
2016-11-08 22:21:03 +08:00
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP:
|
|
|
|
case SYS_POWER_STATE_DEEP_SLEEP_1:
|
|
|
|
__asm__ volatile("sti");
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2016-07-03 11:05:39 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-22 05:26:17 +08:00
|
|
|
|
|
|
|
bool _sys_soc_power_state_is_arc_ready(void)
|
|
|
|
{
|
|
|
|
return QM_SCSS_GP->gp0 & GP0_BIT_SLEEP_READY ? true : false;
|
|
|
|
}
|