Branch data Line data Source code
1 : : /* 2 : : * Copyright (c) 2019 Nordic Semiconductor ASA 3 : : * 4 : : * SPDX-License-Identifier: Apache-2.0 5 : : */ 6 : : 7 : : /** 8 : : * @file 9 : : * @brief System/hardware module for Nordic Semiconductor nRF53 family processor 10 : : * 11 : : * This module provides routines to initialize and support board-level hardware 12 : : * for the Nordic Semiconductor nRF53 family processor. 13 : : */ 14 : : 15 : : #include <kernel.h> 16 : : #include <init.h> 17 : : #include <arch/arm/aarch32/cortex_m/cmsis.h> 18 : : #include <soc/nrfx_coredep.h> 19 : : #include <logging/log.h> 20 : : #include <nrf_erratas.h> 21 : : #if defined(CONFIG_SOC_NRF5340_CPUAPP) 22 : : #include <drivers/gpio.h> 23 : : #include <devicetree.h> 24 : : #include <hal/nrf_cache.h> 25 : : #include <hal/nrf_gpio.h> 26 : : #include <hal/nrf_oscillators.h> 27 : : #include <hal/nrf_regulators.h> 28 : : #elif defined(CONFIG_SOC_NRF5340_CPUNET) 29 : : #include <hal/nrf_nvmc.h> 30 : : #endif 31 : : #include <soc_secure.h> 32 : : 33 : : #define PIN_XL1 0 34 : : #define PIN_XL2 1 35 : : 36 : : #ifdef CONFIG_RUNTIME_NMI 37 : : extern void z_arm_nmi_init(void); 38 : : #define NMI_INIT() z_arm_nmi_init() 39 : : #else 40 : : #define NMI_INIT() 41 : : #endif 42 : : 43 : : #if defined(CONFIG_SOC_NRF5340_CPUAPP) 44 : : #include <system_nrf5340_application.h> 45 : : #elif defined(CONFIG_SOC_NRF5340_CPUNET) 46 : : #include <system_nrf5340_network.h> 47 : : #else 48 : : #error "Unknown nRF53 SoC." 49 : : #endif 50 : : 51 : : #if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_gpio_forwarder) && \ 52 : : defined(CONFIG_BOARD_ENABLE_CPUNET) && \ 53 : : (!defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(CONFIG_BUILD_WITH_TFM)) 54 : : #define NRF_GPIO_FORWARDER_FOR_NRF5340_CPUAPP_ENABLED 55 : : #endif 56 : : 57 : : #if defined(NRF_GPIO_FORWARDER_FOR_NRF5340_CPUAPP_ENABLED) 58 : : #define GPIOS_PSEL_BY_IDX(node_id, prop, idx) \ 59 : : NRF_DT_GPIOS_TO_PSEL_BY_IDX(node_id, prop, idx), 60 : : #define ALL_GPIOS_IN_NODE(node_id) \ 61 : : DT_FOREACH_PROP_ELEM(node_id, gpios, GPIOS_PSEL_BY_IDX) 62 : : #define ALL_GPIOS_IN_FORWARDER(node_id) \ 63 : : DT_FOREACH_CHILD(node_id, ALL_GPIOS_IN_NODE) 64 : : #endif 65 : : 66 : : #define LOG_LEVEL CONFIG_SOC_LOG_LEVEL 67 : : LOG_MODULE_REGISTER(soc); 68 : : 69 : 1 : static int nordicsemi_nrf53_init(const struct device *arg) 70 : : { 71 : : uint32_t key; 72 : : 73 : : ARG_UNUSED(arg); 74 : : 75 : 1 : key = irq_lock(); 76 : : 77 : : #if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF_ENABLE_CACHE) 78 : : #if !defined(CONFIG_BUILD_WITH_TFM) 79 : : /* Enable the instruction & data cache. 80 : : * This can only be done from secure code. 81 : : * This is handled by the TF-M platform so we skip it when TF-M is 82 : : * enabled. 83 : : */ 84 : 1 : nrf_cache_enable(NRF_CACHE); 85 : : #endif 86 : : #elif defined(CONFIG_SOC_NRF5340_CPUNET) && defined(CONFIG_NRF_ENABLE_CACHE) 87 : : nrf_nvmc_icache_config_set(NRF_NVMC, NRF_NVMC_ICACHE_ENABLE); 88 : : #endif 89 : : 90 : : #if defined(CONFIG_SOC_ENABLE_LFXO) 91 : 1 : nrf_oscillators_lfxo_cap_set(NRF_OSCILLATORS, 92 : : IS_ENABLED(CONFIG_SOC_LFXO_CAP_INT_6PF) ? 93 : : NRF_OSCILLATORS_LFXO_CAP_6PF : 94 : : IS_ENABLED(CONFIG_SOC_LFXO_CAP_INT_7PF) ? 95 : : NRF_OSCILLATORS_LFXO_CAP_7PF : 96 : : IS_ENABLED(CONFIG_SOC_LFXO_CAP_INT_9PF) ? 97 : : NRF_OSCILLATORS_LFXO_CAP_9PF : 98 : : NRF_OSCILLATORS_LFXO_CAP_EXTERNAL); 99 : : #if !defined(CONFIG_BUILD_WITH_TFM) 100 : : /* This can only be done from secure code. 101 : : * This is handled by the TF-M platform so we skip it when TF-M is 102 : : * enabled. 103 : : */ 104 : 1 : nrf_gpio_pin_mcu_select(PIN_XL1, NRF_GPIO_PIN_MCUSEL_PERIPHERAL); 105 : 1 : nrf_gpio_pin_mcu_select(PIN_XL2, NRF_GPIO_PIN_MCUSEL_PERIPHERAL); 106 : : #endif /* !defined(CONFIG_BUILD_WITH_TFM) */ 107 : : #endif /* defined(CONFIG_SOC_ENABLE_LFXO) */ 108 : : #if defined(CONFIG_SOC_HFXO_CAP_INTERNAL) 109 : : /* This register is only accessible from secure code. */ 110 : : uint32_t xosc32mtrim = soc_secure_read_xosc32mtrim(); 111 : : /* As specified in the nRF5340 PS: 112 : : * CAPVALUE = (((FICR->XOSC32MTRIM.SLOPE+56)*(CAPACITANCE*2-14)) 113 : : * +((FICR->XOSC32MTRIM.OFFSET-8)<<4)+32)>>6; 114 : : * where CAPACITANCE is the desired capacitor value in pF, holding any 115 : : * value between 7.0 pF and 20.0 pF in 0.5 pF steps. 116 : : */ 117 : : uint32_t slope = (xosc32mtrim & FICR_XOSC32MTRIM_SLOPE_Msk) 118 : : >> FICR_XOSC32MTRIM_SLOPE_Pos; 119 : : uint32_t offset = (xosc32mtrim & FICR_XOSC32MTRIM_OFFSET_Msk) 120 : : >> FICR_XOSC32MTRIM_OFFSET_Pos; 121 : : uint32_t capvalue = 122 : : ((slope + 56) * (CONFIG_SOC_HFXO_CAP_INT_VALUE_X2 - 14) 123 : : + ((offset - 8) << 4) + 32) >> 6; 124 : : 125 : : nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS, true, capvalue); 126 : : #elif defined(CONFIG_SOC_HFXO_CAP_EXTERNAL) 127 : : nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS, false, 0); 128 : : #endif 129 : : 130 : : #if defined(CONFIG_SOC_DCDC_NRF53X_APP) 131 : 1 : nrf_regulators_dcdcen_set(NRF_REGULATORS, true); 132 : : #endif 133 : : #if defined(CONFIG_SOC_DCDC_NRF53X_NET) 134 : 1 : nrf_regulators_dcdcen_radio_set(NRF_REGULATORS, true); 135 : : #endif 136 : : #if defined(CONFIG_SOC_DCDC_NRF53X_HV) 137 : 1 : nrf_regulators_dcdcen_vddh_set(NRF_REGULATORS, true); 138 : : #endif 139 : : 140 : : #if defined(NRF_GPIO_FORWARDER_FOR_NRF5340_CPUAPP_ENABLED) 141 : : static const uint8_t forwarded_psels[] = { 142 : : DT_FOREACH_STATUS_OKAY(nordic_nrf_gpio_forwarder, ALL_GPIOS_IN_FORWARDER) 143 : : }; 144 : : 145 : : for (int i = 0; i < ARRAY_SIZE(forwarded_psels); i++) { 146 : : soc_secure_gpio_pin_mcu_select(forwarded_psels[i], NRF_GPIO_PIN_MCUSEL_NETWORK); 147 : : } 148 : : 149 : : #endif 150 : : 151 : : /* Install default handler that simply resets the CPU 152 : : * if configured in the kernel, NOP otherwise 153 : : */ 154 : : NMI_INIT(); 155 : : 156 : 1 : irq_unlock(key); 157 : : 158 : 1 : return 0; 159 : : } 160 : : 161 : 1791410 : void arch_busy_wait(uint32_t time_us) 162 : : { 163 : 1791410 : nrfx_coredep_delay_us(time_us); 164 : 1791410 : } 165 : : 166 : : SYS_INIT(nordicsemi_nrf53_init, PRE_KERNEL_1, 0);