blob: df842e808e41264f2c27428e42f395b3134e8287 [file] [log] [blame]
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02001/*
Antonio Nino Diaz6766bb12018-10-26 11:12:31 +01002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Antonio Nino Diaz6766bb12018-10-26 11:12:31 +01009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <context.h>
15#include <lib/el3_runtime/context_mgmt.h>
16#include <lib/mmio.h>
17#include <lib/psci/psci.h>
18#include <plat/common/platform.h>
19
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020020#include "hi3798cv200.h"
21#include "plat_private.h"
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020022
23#define REG_PERI_CPU_RVBARADDR 0xF8A80034
24#define REG_PERI_CPU_AARCH_MODE 0xF8A80030
25
26#define REG_CPU_LP_CPU_SW_BEGIN 10
27#define CPU_REG_COREPO_SRST 12
28#define CPU_REG_CORE_SRST 8
29
30static void poplar_cpu_standby(plat_local_state_t cpu_state)
31{
32 dsb();
33 wfi();
34}
35
36static int poplar_pwr_domain_on(u_register_t mpidr)
37{
38 unsigned int cpu = plat_core_pos_by_mpidr(mpidr);
39 unsigned int regval, regval_bak;
40
41 /* Select 400MHz before start slave cores */
42 regval_bak = mmio_read_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP));
43 mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), 0x206);
44 mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), 0x606);
45
46 /* Clear the slave cpu arm_por_srst_req reset */
47 regval = mmio_read_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST));
48 regval &= ~(1 << (cpu + CPU_REG_COREPO_SRST));
49 mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST), regval);
50
51 /* Clear the slave cpu reset */
52 regval = mmio_read_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST));
53 regval &= ~(1 << (cpu + CPU_REG_CORE_SRST));
54 mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST), regval);
55
56 /* Restore cpu frequency */
57 regval = regval_bak & (~(1 << REG_CPU_LP_CPU_SW_BEGIN));
58 mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), regval);
59 mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), regval_bak);
60
61 return PSCI_E_SUCCESS;
62}
63
64static void poplar_pwr_domain_off(const psci_power_state_t *target_state)
65{
66 assert(0);
67}
68
69static void poplar_pwr_domain_suspend(const psci_power_state_t *target_state)
70{
71 assert(0);
72}
73
74static void poplar_pwr_domain_on_finish(const psci_power_state_t *target_state)
75{
76 assert(target_state->pwr_domain_state[MPIDR_AFFLVL0] ==
77 PLAT_MAX_OFF_STATE);
78
79 /* Enable the gic cpu interface */
Antonio Nino Diaz6766bb12018-10-26 11:12:31 +010080 poplar_gic_pcpu_init();
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020081
82 /* Program the gic per-cpu distributor or re-distributor interface */
Antonio Nino Diaz6766bb12018-10-26 11:12:31 +010083 poplar_gic_cpuif_enable();
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020084}
85
86static void poplar_pwr_domain_suspend_finish(
87 const psci_power_state_t *target_state)
88{
89 assert(0);
90}
91
92static void __dead2 poplar_system_off(void)
93{
94 ERROR("Poplar System Off: operation not handled.\n");
Yang Xiwen5330b292024-03-12 21:48:08 +080095 /* Turn off watchdog0 before panic() */
96 mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0xc00), 0x1ACCE551);
97 mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0x8), 0x00000000);
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020098 panic();
99}
100
101static void __dead2 poplar_system_reset(void)
102{
103 mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0xc00), 0x1ACCE551);
104 mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0x0), 0x00000100);
105 mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0x8), 0x00000003);
106
107 wfi();
108 ERROR("Poplar System Reset: operation not handled.\n");
109 panic();
110}
111
112static int32_t poplar_validate_power_state(unsigned int power_state,
113 psci_power_state_t *req_state)
114{
115 VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
116
117 int pstate = psci_get_pstate_type(power_state);
118
119 assert(req_state);
120
121 /* Sanity check the requested state */
122 if (pstate == PSTATE_TYPE_STANDBY)
123 req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE;
124 else
125 req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE;
126
127 /* We expect the 'state id' to be zero */
128 if (psci_get_pstate_id(power_state))
129 return PSCI_E_INVALID_PARAMS;
130
131 return PSCI_E_SUCCESS;
132}
133
134static int poplar_validate_ns_entrypoint(uintptr_t entrypoint)
135{
136 /*
137 * Check if the non secure entrypoint lies within the non
138 * secure DRAM.
139 */
140 if ((entrypoint >= DDR_BASE) && (entrypoint < (DDR_BASE + DDR_SIZE)))
141 return PSCI_E_SUCCESS;
142
143 return PSCI_E_INVALID_ADDRESS;
144}
145
146static void poplar_get_sys_suspend_power_state(psci_power_state_t *req_state)
147{
148 int i;
149
150 for (i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++)
151 req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
152}
153
154static const plat_psci_ops_t poplar_plat_psci_ops = {
155 .cpu_standby = poplar_cpu_standby,
156 .pwr_domain_on = poplar_pwr_domain_on,
157 .pwr_domain_off = poplar_pwr_domain_off,
158 .pwr_domain_suspend = poplar_pwr_domain_suspend,
159 .pwr_domain_on_finish = poplar_pwr_domain_on_finish,
160 .pwr_domain_suspend_finish = poplar_pwr_domain_suspend_finish,
161 .system_off = poplar_system_off,
162 .system_reset = poplar_system_reset,
163 .validate_power_state = poplar_validate_power_state,
164 .validate_ns_entrypoint = poplar_validate_ns_entrypoint,
165 .get_sys_suspend_power_state = poplar_get_sys_suspend_power_state,
166};
167
168int plat_setup_psci_ops(uintptr_t sec_entrypoint,
169 const plat_psci_ops_t **psci_ops)
170{
171 *psci_ops = &poplar_plat_psci_ops;
172
173 mmio_write_32((uintptr_t)REG_PERI_CPU_AARCH_MODE, 0xF);
174 mmio_write_32((uintptr_t)REG_PERI_CPU_RVBARADDR, sec_entrypoint);
175 return 0;
176}