1 /* 2 * Copyright (c) 2021 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /* 8 * Generic helper macros for getting radio front-end module (FEM) 9 * settings from devicetree. The main task here is to check the 10 * devicetree compatible of the node the fem property points at, and 11 * pull in a subheader that translates from that compatible's specific 12 * properties to the generic macros required by the nRF5 radio HAL. 13 */ 14 15 #include <zephyr/devicetree.h> 16 #include <zephyr/dt-bindings/gpio/gpio.h> 17 18 #if DT_NODE_HAS_PROP(DT_NODELABEL(radio), fem) 19 #define FEM_NODE DT_PHANDLE(DT_NODELABEL(radio), fem) 20 #if DT_NODE_HAS_STATUS_OKAY(FEM_NODE) 21 #define HAL_RADIO_HAVE_FEM 22 #endif /* DT_NODE_HAS_STATUS_OKAY(FEM_NODE) */ 23 #endif /* DT_NODE_HAS_PROP(DT_NODELABEL(radio), fem)) */ 24 25 /* Does FEM_NODE have a particular DT compatible? */ 26 #define FEM_HAS_COMPAT(compat) DT_NODE_HAS_COMPAT(FEM_NODE, compat) 27 28 /* Does FEM_NODE have a particular DT property defined? */ 29 #define FEM_HAS_PROP(prop) DT_NODE_HAS_PROP(FEM_NODE, prop) 30 31 /* 32 * Device-specific settings are pulled in based FEM_NODE's compatible 33 * property. 34 */ 35 36 #ifdef HAL_RADIO_HAVE_FEM 37 #if FEM_HAS_COMPAT(generic_fem_two_ctrl_pins) 38 #include "radio_nrf5_fem_generic.h" 39 #elif FEM_HAS_COMPAT(nordic_nrf21540_fem) 40 #include "radio_nrf5_fem_nrf21540.h" 41 #else 42 #error "radio node fem property has an unsupported compatible" 43 #endif /* FEM_HAS_COMPAT(generic_fem_two_ctrl_pins) */ 44 #endif /* HAL_RADIO_HAVE_FEM */ 45 46 /* 47 * Define POL_INV macros expected by radio_nrf5_dppi as needed. 48 */ 49 50 #ifdef HAL_RADIO_GPIO_HAVE_PA_PIN 51 #if DT_GPIO_FLAGS(FEM_NODE, HAL_RADIO_GPIO_PA_PROP) & GPIO_ACTIVE_LOW 52 #define HAL_RADIO_GPIO_PA_POL_INV 1 53 #endif 54 #endif /* HAL_RADIO_GPIO_HAVE_PA_PIN */ 55 56 #ifdef HAL_RADIO_GPIO_HAVE_LNA_PIN 57 #if DT_GPIO_FLAGS(FEM_NODE, HAL_RADIO_GPIO_LNA_PROP) & GPIO_ACTIVE_LOW 58 #define HAL_RADIO_GPIO_LNA_POL_INV 1 59 #endif 60 #endif /* HAL_RADIO_GPIO_HAVE_LNA_PIN */ 61