1 /*
2 * Copyright (c) 2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/pm/pm.h>
9 #include <zephyr/pm/policy.h>
10 #include <zephyr/device.h>
11 #include <zephyr/init.h>
12 #include <zephyr/irq.h>
13 #include <zephyr/logging/log_core.h>
14 #include <stdio.h>
15 #include <zephyr/drivers/interrupt_controller/ioapic.h>
16
17 #include <zephyr/logging/log.h>
18 LOG_MODULE_REGISTER(pm_service, CONFIG_PM_LOG_LEVEL);
19
20 /* low power modes */
21 #define FW_D0 0
22 #define FW_D0i0 1
23 #define FW_D0i1 2
24 #define FW_D0i2 3
25 #define FW_D0i3 4
26
27 extern void sedi_pm_enter_power_state(int state);
28
pm_state_set(enum pm_state state,uint8_t substate_id)29 void pm_state_set(enum pm_state state, uint8_t substate_id)
30 {
31 LOG_DBG(" -> SoC D0i%u, idle=%u ms", substate_id,
32 k_ticks_to_ms_floor32(_kernel.idle));
33
34 switch (state) {
35 case PM_STATE_RUNTIME_IDLE:
36 sedi_pm_enter_power_state(FW_D0i0);
37 break;
38 case PM_STATE_SUSPEND_TO_IDLE:
39 sedi_pm_enter_power_state(FW_D0i1);
40 break;
41 case PM_STATE_SUSPEND_TO_RAM:
42 sedi_pm_enter_power_state(FW_D0i2);
43 break;
44 case PM_STATE_SUSPEND_TO_DISK:
45 sedi_pm_enter_power_state(FW_D0i3);
46 break;
47 default:
48 LOG_DBG("Unsupported power state %u", state);
49 break;
50 }
51
52 LOG_DBG("SoC D0i%u ->", substate_id);
53 }
54
55 /* Handle SOC specific activity after Low Power Mode Exit */
pm_state_exit_post_ops(enum pm_state state,uint8_t substate_id)56 void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
57 {
58 ARG_UNUSED(state);
59 ARG_UNUSED(substate_id);
60 __asm__ volatile ("sti" ::: "memory");
61 }
62
63 #if defined(CONFIG_REBOOT) && !defined(CONFIG_REBOOT_RST_CNT)
64 extern void sedi_pm_reset(void);
65
sys_arch_reboot(int type)66 void sys_arch_reboot(int type)
67 {
68 ARG_UNUSED(type);
69 sedi_pm_reset();
70 }
71 #endif
72
73 extern void sedi_pm_init(void);
74
ish_sedi_pm_init(void)75 static int ish_sedi_pm_init(void)
76 {
77 sedi_pm_init();
78
79 return 0;
80 }
81
82 SYS_INIT(ish_sedi_pm_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
83