From 2218469224aaba6dc45516f52d5f80f8e33e5511 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Thu, 9 May 2024 13:24:48 +0200 Subject: [PATCH] mpsl: fem: add kconfig MPSL_FEM_INIT_PRIORITY The nrf2220 and nrf2240 devices require that mpsl_fem_init operation happens before the initialization of I2C if the TWI interface is used with these devices. This was achieved by hardcoded 49 value which is less than default value of Kconfig option I2C_INIT_PRIORITY. This commit removes the magic value form SYS_INIT(..., 49) and introduces a new Kconfig option MPSL_FEM_INIT_PRIORITY. The default value for MPSL_FEM_INIT_PRIORITY in case of nrf2220 or nrf2240 with TWI is still hardcoded to 49 due to following limitations: 1) The Kconfig compiler does not allow compile-time calculation of default value like: config MPSL_FEM_INIT_PRIORITY default (I2C_INIT_PRIORITY-1) if ... 2) The third parameter of SYS_INIT must be a literal or come from a macro expanding to literal. It cannot expand to expression. So following is impossible: #define FEM_INIT_PRIO (CONFIG_I2C_INIT_PRIORITY - 1) SYS_INIT(mpsl_fem_init, POST_KERNEL, FEM_INIT_PRIO); Providing Kconfig option MPSL_FEM_INIT_PRIORITY with appropriate BUILD_ASSERT gives ability to have correct priority of FEM initialization in case the Kconfig I2C_INIT_PRIORITY is changed. For nrf21540_gpio, nrf21540_gpio_spi and simple_gpio the default value is equal to KERNEL_INIT_PRIORITY_DEVICE (no change in default value and behavior) is used. The SYS_INIT priority at which legacy forwarding of pins happens (mpsl_fem_host_init sys init priority) is intentionally not affected. Signed-off-by: Andrzej Kuros --- subsys/mpsl/fem/Kconfig | 7 +++++++ subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c | 2 +- .../fem/nrf21540_gpio_spi/mpsl_fem_nrf21540_gpio_spi.c | 2 +- subsys/mpsl/fem/nrf2220/mpsl_fem_nrf2220.c | 8 +++++++- subsys/mpsl/fem/nrf2240/mpsl_fem_nrf2240.c | 8 +++++++- subsys/mpsl/fem/simple_gpio/mpsl_fem_simple_gpio.c | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/subsys/mpsl/fem/Kconfig b/subsys/mpsl/fem/Kconfig index 9cbb5a1f2fb6..7cf12057f1cb 100644 --- a/subsys/mpsl/fem/Kconfig +++ b/subsys/mpsl/fem/Kconfig @@ -277,6 +277,13 @@ config MPSL_FEM_USE_TWIM_STUB (MPSL_FEM_NRF2240 && !MPSL_FEM_NRF2240_TWI_SUPPORT) default y +config MPSL_FEM_INIT_PRIORITY + int "Init priority of the Front-End Module support code" + depends on MPSL_FEM + default 49 if (MPSL_FEM_NRF2220 && MPSL_FEM_NRF2220_TWI_SUPPORT) || \ + (MPSL_FEM_NRF2240 && MPSL_FEM_NRF2240_TWI_SUPPORT) + default KERNEL_INIT_PRIORITY_DEVICE + module=MPSL_FEM module-str=MPSL_FEM source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" diff --git a/subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c b/subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c index 071895f5baf2..baf301ed15f5 100644 --- a/subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c +++ b/subsys/mpsl/fem/nrf21540_gpio/mpsl_fem_nrf21540_gpio.c @@ -224,7 +224,7 @@ static int mpsl_fem_init(void) return fem_nrf21540_gpio_configure(); } -SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY); #else /* !defined(CONFIG_MPSL_FEM_PIN_FORWARDER) */ diff --git a/subsys/mpsl/fem/nrf21540_gpio_spi/mpsl_fem_nrf21540_gpio_spi.c b/subsys/mpsl/fem/nrf21540_gpio_spi/mpsl_fem_nrf21540_gpio_spi.c index 06d6147f8739..ba4e26cf2e14 100644 --- a/subsys/mpsl/fem/nrf21540_gpio_spi/mpsl_fem_nrf21540_gpio_spi.c +++ b/subsys/mpsl/fem/nrf21540_gpio_spi/mpsl_fem_nrf21540_gpio_spi.c @@ -291,6 +291,6 @@ static int mpsl_fem_init(void) return fem_nrf21540_gpio_spi_configure(); } -SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY); #endif /* !defined(CONFIG_MPSL_FEM_PIN_FORWARDER) */ diff --git a/subsys/mpsl/fem/nrf2220/mpsl_fem_nrf2220.c b/subsys/mpsl/fem/nrf2220/mpsl_fem_nrf2220.c index 561576ce5229..c966ca7c0874 100644 --- a/subsys/mpsl/fem/nrf2220/mpsl_fem_nrf2220.c +++ b/subsys/mpsl/fem/nrf2220/mpsl_fem_nrf2220.c @@ -225,6 +225,12 @@ static int mpsl_fem_init(void) return fem_nrf2220_configure(); } -SYS_INIT(mpsl_fem_init, POST_KERNEL, 49); +#if defined(CONFIG_I2C) && \ + DT_NODE_HAS_PROP(DT_NODELABEL(nrf_radio_fem), twi_if) +BUILD_ASSERT(CONFIG_MPSL_FEM_INIT_PRIORITY < CONFIG_I2C_INIT_PRIORITY, + "The initialization of nRF2220 Front-End Module must happen before initialization of I2C"); +#endif + +SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY); #endif /* defined(CONFIG_MPSL_FEM_NRF2220) */ diff --git a/subsys/mpsl/fem/nrf2240/mpsl_fem_nrf2240.c b/subsys/mpsl/fem/nrf2240/mpsl_fem_nrf2240.c index b6a1a760da80..bff238205842 100644 --- a/subsys/mpsl/fem/nrf2240/mpsl_fem_nrf2240.c +++ b/subsys/mpsl/fem/nrf2240/mpsl_fem_nrf2240.c @@ -248,6 +248,12 @@ static int mpsl_fem_init(void) return fem_nrf2240_configure(); } -SYS_INIT(mpsl_fem_init, POST_KERNEL, 49); +#if defined(CONFIG_I2C) && \ + DT_NODE_HAS_PROP(DT_NODELABEL(nrf_radio_fem), twi_if) +BUILD_ASSERT(CONFIG_MPSL_FEM_INIT_PRIORITY < CONFIG_I2C_INIT_PRIORITY, + "The initialization of nRF2240 Front-End Module must happen before initialization of I2C"); +#endif + +SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY); #endif /* defined(CONFIG_MPSL_FEM_NRF2240) */ diff --git a/subsys/mpsl/fem/simple_gpio/mpsl_fem_simple_gpio.c b/subsys/mpsl/fem/simple_gpio/mpsl_fem_simple_gpio.c index afbea75a9880..2d2a50c29566 100644 --- a/subsys/mpsl/fem/simple_gpio/mpsl_fem_simple_gpio.c +++ b/subsys/mpsl/fem/simple_gpio/mpsl_fem_simple_gpio.c @@ -140,7 +140,7 @@ static int mpsl_fem_init(void) return fem_simple_gpio_configure(); } -SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +SYS_INIT(mpsl_fem_init, POST_KERNEL, CONFIG_MPSL_FEM_INIT_PRIORITY); #else /* !defined(CONFIG_MPSL_FEM_PIN_FORWARDER) */