Skip to content

Commit 01d0720

Browse files
SebastianBoemstasiaknordic
authored andcommitted
[nrf noup] soc: nordic: nrf54l: Port Soc.c to be compatible with TFM
In this patch we do several things to be able to configure power and clocks when NRF_OSCILLATORS and NRF_REGULATORS is secure. We port soc.c to TF-M so that the TF-M image can do the same configuration that would normally be done by the Zephyr image. This is done by explicitly including autoconf.h for instance. We also ifdef-out the configuration when nordicsemi_nrf54l_init is invoked from a non-secure image, because the peripherals are secure. Signed-off-by: Sebastian Bøe <[email protected]> (cherry picked from commit 962fa00) (cherry picked from commit 028f0c4)
1 parent 933108c commit 01d0720

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

soc/nordic/nrf54l/soc.c

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@
1212
* for the Nordic Semiconductor nRF54L family processor.
1313
*/
1414

15+
#ifdef __NRF_TFM__
16+
#include <autoconf.h>
17+
#endif
18+
1519
#include <zephyr/devicetree.h>
1620
#include <zephyr/dt-bindings/regulator/nrf5x.h>
1721
#include <zephyr/kernel.h>
1822
#include <zephyr/devicetree.h>
1923
#include <zephyr/init.h>
2024
#include <zephyr/logging/log.h>
25+
26+
#ifndef __NRF_TFM__
2127
#include <zephyr/cache.h>
28+
#endif
29+
2230
#include <zephyr/dt-bindings/regulator/nrf5x.h>
2331

2432
#if defined(NRF_APPLICATION)
@@ -40,17 +48,9 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL);
4048
#define HFXO_NODE DT_NODELABEL(hfxo)
4149
#endif
4250

43-
static int nordicsemi_nrf54l_init(void)
44-
{
45-
/* Update the SystemCoreClock global variable with current core clock
46-
* retrieved from hardware state.
47-
*/
48-
SystemCoreClockUpdate();
49-
5051
#if defined(NRF_APPLICATION)
51-
/* Enable ICACHE */
52-
sys_cache_instr_enable();
53-
52+
static inline void power_and_clock_configuration(void)
53+
{
5454
#if DT_ENUM_HAS_VALUE(LFXO_NODE, load_capacitors, internal)
5555
uint32_t xosc32ktrim = NRF_FICR->XOSC32KTRIM;
5656

@@ -77,16 +77,16 @@ static int nordicsemi_nrf54l_init(void)
7777
* NOTE: The desired capacitance value is used in encoded from in INTCAP calculation formula
7878
* That is different than in case of HFXO.
7979
*/
80-
uint32_t cap_val_encoded = (((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) - 4000UL)
81-
* 2UL) / 1000UL);
80+
uint32_t cap_val_encoded =
81+
(((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) - 4000UL) * 2UL) / 1000UL);
8282

8383
/* Calculation of INTCAP code before rounding. Min that calculations here are done on
8484
* values multiplied by 2^9, e.g. 0.765625 * 2^9 = 392.
8585
* offset_k should be divided by 2^6, but to add it to value shifted by 2^9 we have to
8686
* multiply it be 2^3.
8787
*/
88-
uint32_t mid_val = (cap_val_encoded - 4UL) * (uint32_t)(slope_k + 392UL)
89-
+ (offset_k << 3UL);
88+
uint32_t mid_val =
89+
(cap_val_encoded - 4UL) * (uint32_t)(slope_k + 392UL) + (offset_k << 3UL);
9090

9191
/* Get integer part of the INTCAP code */
9292
uint32_t lfxo_intcap = mid_val >> 9UL;
@@ -132,8 +132,9 @@ static int nordicsemi_nrf54l_init(void)
132132
*/
133133
uint32_t cap_val_femto_f = DT_PROP(HFXO_NODE, load_capacitance_femtofarad);
134134

135-
uint32_t mid_val_intcap = (((cap_val_femto_f - 5500UL) * (uint32_t)(slope_m + 791UL))
136-
+ (offset_m << 2UL) * 1000UL) >> 8UL;
135+
uint32_t mid_val_intcap = (((cap_val_femto_f - 5500UL) * (uint32_t)(slope_m + 791UL)) +
136+
(offset_m << 2UL) * 1000UL) >>
137+
8UL;
137138

138139
/* Convert the calculated value to piko Farads */
139140
uint32_t hfxo_intcap = mid_val_intcap / 1000;
@@ -163,9 +164,40 @@ static int nordicsemi_nrf54l_init(void)
163164
#endif
164165
nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true);
165166
#endif
166-
167+
}
167168
#endif /* NRF_APPLICATION */
168169

170+
int nordicsemi_nrf54l_init(void)
171+
{
172+
/* Update the SystemCoreClock global variable with current core clock
173+
* retrieved from hardware state.
174+
*/
175+
#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(__NRF_TFM__)
176+
/* Currently not supported for non-secure */
177+
SystemCoreClockUpdate();
178+
#endif
179+
180+
#ifdef __NRF_TFM__
181+
/* TF-M enables the instruction cache from target_cfg.c, so we
182+
* don't need to enable it here.
183+
*/
184+
#else
185+
/* Enable ICACHE */
186+
sys_cache_instr_enable();
187+
#endif
188+
189+
/* NRF_REGULATORS and NRF_OSCILLATORS are configured to be secure
190+
* as NRF_REGULATORS.POFCON is needed by the secure domain to
191+
* prevent glitches when the power supply is attacked.
192+
*
193+
* NRF_OSCILLATORS is also configured as secure because of a HW limitation
194+
* that requires them to be configured with the same security property.
195+
*/
196+
#if (defined(NRF_APPLICATION) && !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)) || \
197+
defined(__NRF_TFM__)
198+
power_and_clock_configuration();
199+
#endif
200+
169201
return 0;
170202
}
171203

0 commit comments

Comments
 (0)