blob: 6209fea892cd0597433d3ea885d942ed3e7b5574 [file] [log] [blame]
Bai Ping06e325e2018-10-28 00:12:34 +08001/*
Jacky Bai0d079202020-01-07 16:44:46 +08002 * Copyright (c) 2018-2023, ARM Limited and Contributors. All rights reserved.
Bai Ping06e325e2018-10-28 00:12:34 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <stdbool.h>
8
Bai Ping06e325e2018-10-28 00:12:34 +08009#include <arch.h>
10#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <common/debug.h>
12#include <lib/mmio.h>
13#include <lib/psci/psci.h>
14
Jacky Bai0d079202020-01-07 16:44:46 +080015#include <dram.h>
Bai Ping06e325e2018-10-28 00:12:34 +080016#include <gpc.h>
Jacky Baif7dc4012019-03-06 16:58:18 +080017#include <imx8m_psci.h>
Bai Ping06e325e2018-10-28 00:12:34 +080018#include <plat_imx8.h>
Bai Ping06e325e2018-10-28 00:12:34 +080019
Bai Ping06e325e2018-10-28 00:12:34 +080020int imx_validate_power_state(unsigned int power_state,
21 psci_power_state_t *req_state)
22{
23 int pwr_lvl = psci_get_pstate_pwrlvl(power_state);
24 int pwr_type = psci_get_pstate_type(power_state);
25 int state_id = psci_get_pstate_id(power_state);
26
27 if (pwr_lvl > PLAT_MAX_PWR_LVL)
28 return PSCI_E_INVALID_PARAMS;
29
30 if (pwr_type == PSTATE_TYPE_STANDBY) {
31 CORE_PWR_STATE(req_state) = PLAT_MAX_RET_STATE;
32 CLUSTER_PWR_STATE(req_state) = PLAT_MAX_RET_STATE;
33 }
34
35 if (pwr_type == PSTATE_TYPE_POWERDOWN && state_id == 0x33) {
36 CORE_PWR_STATE(req_state) = PLAT_MAX_OFF_STATE;
37 CLUSTER_PWR_STATE(req_state) = PLAT_MAX_RET_STATE;
38 }
39
40 return PSCI_E_SUCCESS;
41}
42
Bai Ping06e325e2018-10-28 00:12:34 +080043void imx_domain_suspend(const psci_power_state_t *target_state)
44{
Lucas Stachd36013e2022-12-08 16:44:00 +010045 uint64_t base_addr = BL31_START;
Bai Ping06e325e2018-10-28 00:12:34 +080046 uint64_t mpidr = read_mpidr_el1();
47 unsigned int core_id = MPIDR_AFFLVL0_VAL(mpidr);
48
49 if (is_local_state_off(CORE_PWR_STATE(target_state))) {
50 /* disable the cpu interface */
51 plat_gic_cpuif_disable();
52 imx_set_cpu_secure_entry(core_id, base_addr);
53 imx_set_cpu_lpm(core_id, true);
54 } else {
55 dsb();
56 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT);
57 isb();
58 }
59
60 if (is_local_state_off(CLUSTER_PWR_STATE(target_state)))
61 imx_set_cluster_powerdown(core_id, true);
62 else
63 imx_set_cluster_standby(true);
64
65 if (is_local_state_retn(SYSTEM_PWR_STATE(target_state))) {
Jacky Baif7dc4012019-03-06 16:58:18 +080066 imx_set_sys_lpm(core_id, true);
Jacky Bai0d079202020-01-07 16:44:46 +080067 dram_enter_retention();
Bai Ping06e325e2018-10-28 00:12:34 +080068 }
69}
70
71void imx_domain_suspend_finish(const psci_power_state_t *target_state)
72{
73 uint64_t mpidr = read_mpidr_el1();
74 unsigned int core_id = MPIDR_AFFLVL0_VAL(mpidr);
75
76 /* check the system level status */
77 if (is_local_state_retn(SYSTEM_PWR_STATE(target_state))) {
Jacky Bai0d079202020-01-07 16:44:46 +080078 dram_exit_retention();
Jacky Baif7dc4012019-03-06 16:58:18 +080079 imx_set_sys_lpm(core_id, false);
Bai Ping06e325e2018-10-28 00:12:34 +080080 imx_clear_rbc_count();
81 }
82
83 /* check the cluster level power status */
84 if (is_local_state_off(CLUSTER_PWR_STATE(target_state)))
85 imx_set_cluster_powerdown(core_id, false);
86 else
87 imx_set_cluster_standby(false);
88
89 /* check the core level power status */
90 if (is_local_state_off(CORE_PWR_STATE(target_state))) {
91 /* clear the core lpm setting */
92 imx_set_cpu_lpm(core_id, false);
93 /* enable the gic cpu interface */
94 plat_gic_cpuif_enable();
95 } else {
96 write_scr_el3(read_scr_el3() & (~0x4));
97 isb();
98 }
99}
100
101void imx_get_sys_suspend_power_state(psci_power_state_t *req_state)
102{
103 unsigned int i;
104
105 for (i = IMX_PWR_LVL0; i < PLAT_MAX_PWR_LVL; i++)
106 req_state->pwr_domain_state[i] = PLAT_STOP_OFF_STATE;
107
108 req_state->pwr_domain_state[PLAT_MAX_PWR_LVL] = PLAT_MAX_RET_STATE;
109}
110
Bai Ping06e325e2018-10-28 00:12:34 +0800111static const plat_psci_ops_t imx_plat_psci_ops = {
112 .pwr_domain_on = imx_pwr_domain_on,
113 .pwr_domain_on_finish = imx_pwr_domain_on_finish,
114 .pwr_domain_off = imx_pwr_domain_off,
115 .validate_ns_entrypoint = imx_validate_ns_entrypoint,
116 .validate_power_state = imx_validate_power_state,
117 .cpu_standby = imx_cpu_standby,
118 .pwr_domain_suspend = imx_domain_suspend,
119 .pwr_domain_suspend_finish = imx_domain_suspend_finish,
120 .pwr_domain_pwr_down_wfi = imx_pwr_domain_pwr_down_wfi,
121 .get_sys_suspend_power_state = imx_get_sys_suspend_power_state,
122 .system_reset = imx_system_reset,
Igor Opaniuk73999bd2021-06-03 15:00:26 +0300123 .system_reset2 = imx_system_reset2,
Bai Ping06e325e2018-10-28 00:12:34 +0800124 .system_off = imx_system_off,
125};
126
127/* export the platform specific psci ops */
128int plat_setup_psci_ops(uintptr_t sec_entrypoint,
129 const plat_psci_ops_t **psci_ops)
130{
131 imx_mailbox_init(sec_entrypoint);
132 /* sec_entrypoint is used for warm reset */
133 *psci_ops = &imx_plat_psci_ops;
134
135 return 0;
136}