2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 #include <arch_helpers.h>
12 #include <plat_imx8.h>
16 #define CORE_PWR_STATE(state) ((state)->pwr_domain_state[MPIDR_AFFLVL0])
17 #define CLUSTER_PWR_STATE(state) ((state)->pwr_domain_state[MPIDR_AFFLVL1])
18 #define SYSTEM_PWR_STATE(state) ((state)->pwr_domain_state[PLAT_MAX_PWR_LVL])
20 int imx_pwr_domain_on(u_register_t mpidr
)
23 uint64_t base_addr
= BL31_BASE
;
25 core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
27 /* set the secure entrypoint */
28 imx_set_cpu_secure_entry(core_id
, base_addr
);
29 /* power up the core */
30 imx_set_cpu_pwr_on(core_id
);
32 return PSCI_E_SUCCESS
;
35 void imx_pwr_domain_on_finish(const psci_power_state_t
*target_state
)
37 /* program the GIC per cpu dist and rdist interface */
39 /* enable the GICv3 cpu interface */
40 plat_gic_cpuif_enable();
43 void imx_pwr_domain_off(const psci_power_state_t
*target_state
)
45 uint64_t mpidr
= read_mpidr_el1();
46 unsigned int core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
48 /* disable the GIC cpu interface first */
49 plat_gic_cpuif_disable();
50 /* config the core for power down */
51 imx_set_cpu_pwr_off(core_id
);
54 int imx_validate_ns_entrypoint(uintptr_t ns_entrypoint
)
56 /* The non-secure entrypoint should be in RAM space */
57 if (ns_entrypoint
< PLAT_NS_IMAGE_OFFSET
)
58 return PSCI_E_INVALID_PARAMS
;
60 return PSCI_E_SUCCESS
;
63 int imx_validate_power_state(unsigned int power_state
,
64 psci_power_state_t
*req_state
)
66 int pwr_lvl
= psci_get_pstate_pwrlvl(power_state
);
67 int pwr_type
= psci_get_pstate_type(power_state
);
68 int state_id
= psci_get_pstate_id(power_state
);
70 if (pwr_lvl
> PLAT_MAX_PWR_LVL
)
71 return PSCI_E_INVALID_PARAMS
;
73 if (pwr_type
== PSTATE_TYPE_STANDBY
) {
74 CORE_PWR_STATE(req_state
) = PLAT_MAX_RET_STATE
;
75 CLUSTER_PWR_STATE(req_state
) = PLAT_MAX_RET_STATE
;
78 if (pwr_type
== PSTATE_TYPE_POWERDOWN
&& state_id
== 0x33) {
79 CORE_PWR_STATE(req_state
) = PLAT_MAX_OFF_STATE
;
80 CLUSTER_PWR_STATE(req_state
) = PLAT_MAX_RET_STATE
;
83 return PSCI_E_SUCCESS
;
86 void imx_cpu_standby(plat_local_state_t cpu_state
)
89 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT
);
94 write_scr_el3(read_scr_el3() & (~SCR_FIQ_BIT
));
98 void imx_domain_suspend(const psci_power_state_t
*target_state
)
100 uint64_t base_addr
= BL31_BASE
;
101 uint64_t mpidr
= read_mpidr_el1();
102 unsigned int core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
104 if (is_local_state_off(CORE_PWR_STATE(target_state
))) {
105 /* disable the cpu interface */
106 plat_gic_cpuif_disable();
107 imx_set_cpu_secure_entry(core_id
, base_addr
);
108 imx_set_cpu_lpm(core_id
, true);
111 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT
);
115 if (is_local_state_off(CLUSTER_PWR_STATE(target_state
)))
116 imx_set_cluster_powerdown(core_id
, true);
118 imx_set_cluster_standby(true);
120 if (is_local_state_retn(SYSTEM_PWR_STATE(target_state
))) {
121 imx_set_sys_lpm(true);
125 void imx_domain_suspend_finish(const psci_power_state_t
*target_state
)
127 uint64_t mpidr
= read_mpidr_el1();
128 unsigned int core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
130 /* check the system level status */
131 if (is_local_state_retn(SYSTEM_PWR_STATE(target_state
))) {
132 imx_set_sys_lpm(false);
133 imx_clear_rbc_count();
136 /* check the cluster level power status */
137 if (is_local_state_off(CLUSTER_PWR_STATE(target_state
)))
138 imx_set_cluster_powerdown(core_id
, false);
140 imx_set_cluster_standby(false);
142 /* check the core level power status */
143 if (is_local_state_off(CORE_PWR_STATE(target_state
))) {
144 /* clear the core lpm setting */
145 imx_set_cpu_lpm(core_id
, false);
146 /* enable the gic cpu interface */
147 plat_gic_cpuif_enable();
149 write_scr_el3(read_scr_el3() & (~0x4));
154 void imx_get_sys_suspend_power_state(psci_power_state_t
*req_state
)
158 for (i
= IMX_PWR_LVL0
; i
< PLAT_MAX_PWR_LVL
; i
++)
159 req_state
->pwr_domain_state
[i
] = PLAT_STOP_OFF_STATE
;
161 req_state
->pwr_domain_state
[PLAT_MAX_PWR_LVL
] = PLAT_MAX_RET_STATE
;
164 void __dead2
imx_system_reset(void)
166 uintptr_t wdog_base
= IMX_WDOG_BASE
;
170 val
= mmio_read_16(wdog_base
);
171 #ifdef IMX_WDOG_B_RESET
172 val
= (val
& 0x00FF) | WDOG_WCR_WDZST
| WDOG_WCR_WDE
|
173 WDOG_WCR_WDT
| WDOG_WCR_SRS
;
175 val
= (val
& 0x00FF) | WDOG_WCR_WDZST
| WDOG_WCR_SRS
;
177 mmio_write_16(wdog_base
, val
);
179 mmio_write_16(wdog_base
+ WDOG_WSR
, 0x5555);
180 mmio_write_16(wdog_base
+ WDOG_WSR
, 0xaaaa);
187 void __dead2
imx_system_off(void)
189 mmio_write_32(IMX_SNVS_BASE
+ SNVS_LPCR
, SNVS_LPCR_SRTC_ENV
|
190 SNVS_LPCR_DP_EN
| SNVS_LPCR_TOP
);
196 void __dead2
imx_pwr_domain_pwr_down_wfi(const psci_power_state_t
*target_state
)
198 if (is_local_state_off(CLUSTER_PWR_STATE(target_state
)))
205 static const plat_psci_ops_t imx_plat_psci_ops
= {
206 .pwr_domain_on
= imx_pwr_domain_on
,
207 .pwr_domain_on_finish
= imx_pwr_domain_on_finish
,
208 .pwr_domain_off
= imx_pwr_domain_off
,
209 .validate_ns_entrypoint
= imx_validate_ns_entrypoint
,
210 .validate_power_state
= imx_validate_power_state
,
211 .cpu_standby
= imx_cpu_standby
,
212 .pwr_domain_suspend
= imx_domain_suspend
,
213 .pwr_domain_suspend_finish
= imx_domain_suspend_finish
,
214 .pwr_domain_pwr_down_wfi
= imx_pwr_domain_pwr_down_wfi
,
215 .get_sys_suspend_power_state
= imx_get_sys_suspend_power_state
,
216 .system_reset
= imx_system_reset
,
217 .system_off
= imx_system_off
,
220 /* export the platform specific psci ops */
221 int plat_setup_psci_ops(uintptr_t sec_entrypoint
,
222 const plat_psci_ops_t
**psci_ops
)
224 imx_mailbox_init(sec_entrypoint
);
225 /* sec_entrypoint is used for warm reset */
226 *psci_ops
= &imx_plat_psci_ops
;