-
Notifications
You must be signed in to change notification settings - Fork 786
Expand file tree
/
Copy pathsoc.c
More file actions
198 lines (159 loc) · 5.97 KB
/
soc.c
File metadata and controls
198 lines (159 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (c) 2024 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/cache.h>
#include <zephyr/devicetree.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#ifdef CONFIG_LOG_FRONTEND_STMESP
#include <zephyr/logging/log_frontend_stmesp.h>
#endif
#include <hal/nrf_gpio.h>
#include <hal/nrf_hsfll.h>
#include <hal/nrf_lrcconf.h>
#include <hal/nrf_spu.h>
#include <hal/nrf_memconf.h>
#include <hal/nrf_nfct.h>
#include <lib/nrfx_coredep.h>
#include <soc_lrcconf.h>
#include "soc_power.h"
#include <dmm.h>
#if defined(CONFIG_SOC_NRF54H20_CPURAD_ENABLE)
#include <ironside/se/api.h>
#endif
LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL);
#if defined(NRF_APPLICATION)
#define HSFLL_NODE DT_NODELABEL(cpuapp_hsfll)
#elif defined(NRF_RADIOCORE)
#define HSFLL_NODE DT_NODELABEL(cpurad_hsfll)
#endif
#ifdef CONFIG_USE_DT_CODE_PARTITION
#define FLASH_LOAD_ADDRESS DT_REG_ADDR(DT_CHOSEN(zephyr_code_partition))
#elif defined(CONFIG_FLASH_LOAD_OFFSET)
#define FLASH_LOAD_ADDRESS (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET)
#endif
#define PARTITION_IS_RUNNING_APP_PARTITION(label) \
DT_SAME_NODE(PARTITION_NODE_MTD(DT_CHOSEN(zephyr_code_partition)), \
PARTITION_MTD(label)) && \
(PARTITION_ADDRESS(label) <= FLASH_LOAD_ADDRESS && \
PARTITION_ADDRESS(label) + PARTITION_SIZE(label) > \
FLASH_LOAD_ADDRESS)
#define FICR_ADDR_GET(node_id, name) \
DT_REG_ADDR(DT_PHANDLE_BY_NAME(node_id, nordic_ficrs, name)) + \
DT_PHA_BY_NAME(node_id, nordic_ficrs, name, offset)
#define SPU_INSTANCE_GET(p_addr) \
((NRF_SPU_Type *)((p_addr) & (ADDRESS_REGION_Msk | \
ADDRESS_SECURITY_Msk | \
ADDRESS_DOMAIN_Msk | \
ADDRESS_BUS_Msk)))
static int trim_hsfll(void)
{
#if defined(HSFLL_NODE)
NRF_HSFLL_Type *hsfll = (NRF_HSFLL_Type *)DT_REG_ADDR(HSFLL_NODE);
nrf_hsfll_trim_t trim = {
.vsup = sys_read32(FICR_ADDR_GET(HSFLL_NODE, vsup)),
.coarse = sys_read32(FICR_ADDR_GET(HSFLL_NODE, coarse)),
.fine = sys_read32(FICR_ADDR_GET(HSFLL_NODE, fine))
};
LOG_DBG("Trim: HSFLL VSUP: 0x%.8x", trim.vsup);
LOG_DBG("Trim: HSFLL COARSE: 0x%.8x", trim.coarse);
LOG_DBG("Trim: HSFLL FINE: 0x%.8x", trim.fine);
nrf_hsfll_clkctrl_mult_set(hsfll,
DT_PROP(HSFLL_NODE, clock_frequency) /
DT_PROP(DT_CLOCKS_CTLR(HSFLL_NODE), clock_frequency));
nrf_hsfll_trim_set(hsfll, &trim);
nrf_hsfll_task_trigger(hsfll, NRF_HSFLL_TASK_FREQ_CHANGE);
/* HSFLL task frequency change needs to be triggered twice to take effect.*/
nrf_hsfll_task_trigger(hsfll, NRF_HSFLL_TASK_FREQ_CHANGE);
LOG_DBG("NRF_HSFLL->TRIM.VSUP = %d", hsfll->TRIM.VSUP);
LOG_DBG("NRF_HSFLL->TRIM.COARSE = %d", hsfll->TRIM.COARSE);
LOG_DBG("NRF_HSFLL->TRIM.FINE = %d", hsfll->TRIM.FINE);
#endif /* defined(HSFLL_NODE) */
return 0;
}
#if defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_HOOK) && !defined(CONFIG_NRF_CUSTOM_ON_ENTER_CPU_IDLE_HOOK)
bool z_arm_on_enter_cpu_idle(void)
{
#ifdef CONFIG_LOG_FRONTEND_STMESP
log_frontend_stmesp_pre_sleep();
#endif
return true;
}
#endif
void soc_early_init_hook(void)
{
int err;
sys_cache_instr_enable();
sys_cache_data_enable();
nrf_power_domain_init();
trim_hsfll();
err = dmm_init();
__ASSERT_NO_MSG(err == 0);
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(ccm030))
/* DMASEC is set to non-secure by default, which prevents CCM from
* accessing secure memory. Change DMASEC to secure.
*/
uint32_t ccm030_addr = DT_REG_ADDR(DT_NODELABEL(ccm030));
NRF_SPU_Type *spu = SPU_INSTANCE_GET(ccm030_addr);
nrf_spu_periph_perm_dmasec_set(spu, nrf_address_slave_get(ccm030_addr), true);
#endif
if (((IS_ENABLED(CONFIG_SOC_NRF54H20_CPUAPP) &&
DT_NODE_HAS_STATUS(DT_NODELABEL(nfct), disabled)) ||
DT_NODE_HAS_STATUS(DT_NODELABEL(nfct), reserved)) &&
DT_PROP_OR(DT_NODELABEL(nfct), nfct_pins_as_gpios, 0)) {
nrf_nfct_pad_config_enable_set(NRF_NFCT, false);
}
/* This is a workaround for not yet having upstream patches for properly handling
* pin retention. It should be removed as part of the next upmerge.
*/
if (IS_ENABLED(CONFIG_SOC_NRF54H20_DISABLE_ALL_GPIO_RETENTION_WORKAROUND)) {
NRF_GPIO_Type *gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
for (int i = 0; i < NRFX_ARRAY_SIZE(gpio_regs); i++) {
nrf_gpio_port_retain_set(gpio_regs[i], 0);
}
}
}
#if defined(CONFIG_SOC_LATE_INIT_HOOK)
void soc_late_init_hook(void)
{
#if defined(CONFIG_SOC_NRF54H20_CPURAD_ENABLE)
int err_cpuconf;
/* The msg will be used for communication prior to IPC
* communication being set up. But at this moment no such
* communication is required.
*/
uint8_t *msg = NULL;
size_t msg_size = 0;
void *radiocore_address = NULL;
#if DT_NODE_EXISTS(DT_NODELABEL(cpurad_slot1_partition))
if (PARTITION_IS_RUNNING_APP_PARTITION(cpuapp_slot1_partition)) {
radiocore_address = (void *)(PARTITION_ADDRESS(cpurad_slot1_partition) +
CONFIG_ROM_START_OFFSET);
} else {
radiocore_address = (void *)(PARTITION_ADDRESS(cpurad_slot0_partition) +
CONFIG_ROM_START_OFFSET);
}
#else
radiocore_address =
(void *)(PARTITION_ADDRESS(cpurad_slot0_partition) + CONFIG_ROM_START_OFFSET);
#endif
if (IS_ENABLED(CONFIG_SOC_NRF54H20_CPURAD_ENABLE_CHECK_VTOR) &&
sys_read32((mem_addr_t)radiocore_address) == 0xFFFFFFFFUL) {
LOG_ERR("Radiocore is not programmed, it will not be started");
return;
}
bool cpu_wait = IS_ENABLED(CONFIG_SOC_NRF54H20_CPURAD_ENABLE_DEBUG_WAIT);
err_cpuconf = ironside_se_cpuconf(NRF_PROCESSOR_RADIOCORE, radiocore_address, cpu_wait, msg,
msg_size);
__ASSERT(err_cpuconf == 0, "err_cpuconf was %d", err_cpuconf);
#endif /* CONFIG_SOC_NRF54H20_CPURAD_ENABLE */
}
#endif
void arch_busy_wait(uint32_t time_us)
{
nrfx_coredep_delay_us(time_us);
}