2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
10 #include <arch_helpers.h>
11 #include <common/debug.h>
13 #include <lib/psci/psci.h>
16 #include <plat_imx8.h>
18 #define CORE_PWR_STATE(state) ((state)->pwr_domain_state[MPIDR_AFFLVL0])
19 #define CLUSTER_PWR_STATE(state) ((state)->pwr_domain_state[MPIDR_AFFLVL1])
20 #define SYSTEM_PWR_STATE(state) ((state)->pwr_domain_state[PLAT_MAX_PWR_LVL])
22 int imx_pwr_domain_on(u_register_t mpidr
)
25 uint64_t base_addr
= BL31_BASE
;
27 core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
29 /* set the secure entrypoint */
30 imx_set_cpu_secure_entry(core_id
, base_addr
);
31 /* power up the core */
32 imx_set_cpu_pwr_on(core_id
);
34 return PSCI_E_SUCCESS
;
37 void imx_pwr_domain_on_finish(const psci_power_state_t
*target_state
)
39 /* program the GIC per cpu dist and rdist interface */
41 /* enable the GICv3 cpu interface */
42 plat_gic_cpuif_enable();
45 void imx_pwr_domain_off(const psci_power_state_t
*target_state
)
47 uint64_t mpidr
= read_mpidr_el1();
48 unsigned int core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
50 /* disable the GIC cpu interface first */
51 plat_gic_cpuif_disable();
52 /* config the core for power down */
53 imx_set_cpu_pwr_off(core_id
);
56 int imx_validate_ns_entrypoint(uintptr_t ns_entrypoint
)
58 /* The non-secure entrypoint should be in RAM space */
59 if (ns_entrypoint
< PLAT_NS_IMAGE_OFFSET
)
60 return PSCI_E_INVALID_PARAMS
;
62 return PSCI_E_SUCCESS
;
65 int imx_validate_power_state(unsigned int power_state
,
66 psci_power_state_t
*req_state
)
68 int pwr_lvl
= psci_get_pstate_pwrlvl(power_state
);
69 int pwr_type
= psci_get_pstate_type(power_state
);
70 int state_id
= psci_get_pstate_id(power_state
);
72 if (pwr_lvl
> PLAT_MAX_PWR_LVL
)
73 return PSCI_E_INVALID_PARAMS
;
75 if (pwr_type
== PSTATE_TYPE_STANDBY
) {
76 CORE_PWR_STATE(req_state
) = PLAT_MAX_RET_STATE
;
77 CLUSTER_PWR_STATE(req_state
) = PLAT_MAX_RET_STATE
;
80 if (pwr_type
== PSTATE_TYPE_POWERDOWN
&& state_id
== 0x33) {
81 CORE_PWR_STATE(req_state
) = PLAT_MAX_OFF_STATE
;
82 CLUSTER_PWR_STATE(req_state
) = PLAT_MAX_RET_STATE
;
85 return PSCI_E_SUCCESS
;
88 void imx_cpu_standby(plat_local_state_t cpu_state
)
91 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT
);
96 write_scr_el3(read_scr_el3() & (~SCR_FIQ_BIT
));
100 void imx_domain_suspend(const psci_power_state_t
*target_state
)
102 uint64_t base_addr
= BL31_BASE
;
103 uint64_t mpidr
= read_mpidr_el1();
104 unsigned int core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
106 if (is_local_state_off(CORE_PWR_STATE(target_state
))) {
107 /* disable the cpu interface */
108 plat_gic_cpuif_disable();
109 imx_set_cpu_secure_entry(core_id
, base_addr
);
110 imx_set_cpu_lpm(core_id
, true);
113 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT
);
117 if (is_local_state_off(CLUSTER_PWR_STATE(target_state
)))
118 imx_set_cluster_powerdown(core_id
, true);
120 imx_set_cluster_standby(true);
122 if (is_local_state_retn(SYSTEM_PWR_STATE(target_state
))) {
123 imx_set_sys_lpm(true);
127 void imx_domain_suspend_finish(const psci_power_state_t
*target_state
)
129 uint64_t mpidr
= read_mpidr_el1();
130 unsigned int core_id
= MPIDR_AFFLVL0_VAL(mpidr
);
132 /* check the system level status */
133 if (is_local_state_retn(SYSTEM_PWR_STATE(target_state
))) {
134 imx_set_sys_lpm(false);
135 imx_clear_rbc_count();
138 /* check the cluster level power status */
139 if (is_local_state_off(CLUSTER_PWR_STATE(target_state
)))
140 imx_set_cluster_powerdown(core_id
, false);
142 imx_set_cluster_standby(false);
144 /* check the core level power status */
145 if (is_local_state_off(CORE_PWR_STATE(target_state
))) {
146 /* clear the core lpm setting */
147 imx_set_cpu_lpm(core_id
, false);
148 /* enable the gic cpu interface */
149 plat_gic_cpuif_enable();
151 write_scr_el3(read_scr_el3() & (~0x4));
156 void imx_get_sys_suspend_power_state(psci_power_state_t
*req_state
)
160 for (i
= IMX_PWR_LVL0
; i
< PLAT_MAX_PWR_LVL
; i
++)
161 req_state
->pwr_domain_state
[i
] = PLAT_STOP_OFF_STATE
;
163 req_state
->pwr_domain_state
[PLAT_MAX_PWR_LVL
] = PLAT_MAX_RET_STATE
;
166 void __dead2
imx_system_reset(void)
168 uintptr_t wdog_base
= IMX_WDOG_BASE
;
172 val
= mmio_read_16(wdog_base
);
173 #ifdef IMX_WDOG_B_RESET
174 val
= (val
& 0x00FF) | WDOG_WCR_WDZST
| WDOG_WCR_WDE
|
175 WDOG_WCR_WDT
| WDOG_WCR_SRS
;
177 val
= (val
& 0x00FF) | WDOG_WCR_WDZST
| WDOG_WCR_SRS
;
179 mmio_write_16(wdog_base
, val
);
181 mmio_write_16(wdog_base
+ WDOG_WSR
, 0x5555);
182 mmio_write_16(wdog_base
+ WDOG_WSR
, 0xaaaa);
189 void __dead2
imx_system_off(void)
191 mmio_write_32(IMX_SNVS_BASE
+ SNVS_LPCR
, SNVS_LPCR_SRTC_ENV
|
192 SNVS_LPCR_DP_EN
| SNVS_LPCR_TOP
);
198 void __dead2
imx_pwr_domain_pwr_down_wfi(const psci_power_state_t
*target_state
)
200 if (is_local_state_off(CLUSTER_PWR_STATE(target_state
)))
207 static const plat_psci_ops_t imx_plat_psci_ops
= {
208 .pwr_domain_on
= imx_pwr_domain_on
,
209 .pwr_domain_on_finish
= imx_pwr_domain_on_finish
,
210 .pwr_domain_off
= imx_pwr_domain_off
,
211 .validate_ns_entrypoint
= imx_validate_ns_entrypoint
,
212 .validate_power_state
= imx_validate_power_state
,
213 .cpu_standby
= imx_cpu_standby
,
214 .pwr_domain_suspend
= imx_domain_suspend
,
215 .pwr_domain_suspend_finish
= imx_domain_suspend_finish
,
216 .pwr_domain_pwr_down_wfi
= imx_pwr_domain_pwr_down_wfi
,
217 .get_sys_suspend_power_state
= imx_get_sys_suspend_power_state
,
218 .system_reset
= imx_system_reset
,
219 .system_off
= imx_system_off
,
222 /* export the platform specific psci ops */
223 int plat_setup_psci_ops(uintptr_t sec_entrypoint
,
224 const plat_psci_ops_t
**psci_ops
)
226 imx_mailbox_init(sec_entrypoint
);
227 /* sec_entrypoint is used for warm reset */
228 *psci_ops
= &imx_plat_psci_ops
;