1 /*
2  * Copyright (c) 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * This file contains helper macros for dealing with the devicetree
9  * radio node's fem property, in the case that it has compatible
10  * "nordic,nrf21540-fem".
11  *
12  * Do not include it directly.
13  *
14  * For nRF21540 devices:
15  *
16  *  Value             Property
17  *  ---------         --------
18  *  PA pin            tx-en-gpios
19  *  PA offset         tx-en-settle-time-us
20  *  LNA pin           rx-en-gpios
21  *  LNA offset        rx-en-settle-time-us
22  *  PDN pin           pdn-gpios
23  *  PDN offset        pdn-settle-time-us
24  *
25  * The spi-if property may point at a SPI device node representing the
26  * FEM's SPI control interface. See the binding for details.
27  */
28 
29 #define HAL_RADIO_FEM_IS_NRF21540 1
30 
31 #define HAL_RADIO_GPIO_PA_PROP_NAME         "tx-en-gpios"
32 #define HAL_RADIO_GPIO_PA_OFFSET_PROP_NAME  "tx-en-settle-time-us"
33 #define HAL_RADIO_GPIO_LNA_PROP_NAME        "rx-en-gpios"
34 #define HAL_RADIO_GPIO_LNA_OFFSET_PROP_NAME "rx-en-settle-time-us"
35 
36 /* This FEM's PA and LNA offset properties have defaults set. */
37 #define HAL_RADIO_GPIO_PA_OFFSET_MISSING 0
38 #define HAL_RADIO_GPIO_LNA_OFFSET_MISSING 0
39 
40 #if FEM_HAS_PROP(tx_en_gpios)
41 #define HAL_RADIO_GPIO_HAVE_PA_PIN 1
42 #define HAL_RADIO_GPIO_PA_PROP     tx_en_gpios
43 #define HAL_RADIO_GPIO_PA_OFFSET   DT_PROP(FEM_NODE, tx_en_settle_time_us)
44 #endif	/* FEM_HAS_PROP(tx_en_gpios) */
45 
46 #if FEM_HAS_PROP(rx_en_gpios)
47 #define HAL_RADIO_GPIO_HAVE_LNA_PIN 1
48 #define HAL_RADIO_GPIO_LNA_PROP     rx_en_gpios
49 #define HAL_RADIO_GPIO_LNA_OFFSET   DT_PROP(FEM_NODE, rx_en_settle_time_us)
50 #endif	/* FEM_HAS_PROP(rx_en_gpios) */
51 
52 /*
53  * The POL_INV macros defined below are just to keep things simple in
54  * radio_nrf5_dppi.h, which uses them.
55  */
56 
57 #if FEM_HAS_PROP(pdn_gpios)
58 #if DT_GPIO_FLAGS(FEM_NODE, pdn_gpios) & GPIO_ACTIVE_LOW
59 #define HAL_RADIO_GPIO_NRF21540_PDN_POL_INV 1
60 #endif	/* DT_GPIO_FLAGS(FEM_NODE, pdn_gpios) & GPIO_ACTIVE_LOW */
61 #endif	/* FEM_HAS_PROP(pdn_gpios) */
62 
63 #if FEM_HAS_PROP(spi_if)
64 /* This is the "SPI device" node, i.e. the one with compatible
65  * nordic,nrf21540-fem-spi.
66  */
67 #define FEM_SPI_DEV_NODE DT_PHANDLE(FEM_NODE, spi_if)
68 /* If the SPI device node has a chip select gpio... */
69 #if DT_SPI_DEV_HAS_CS_GPIOS(FEM_SPI_DEV_NODE)
70 /* set a macro indicating that, and... */
71 #define HAL_RADIO_FEM_NRF21540_HAS_CSN 1
72 /* use it to get the CSN polarity. */
73 #if DT_SPI_DEV_CS_GPIOS_FLAGS(FEM_SPI_DEV_NODE) & GPIO_ACTIVE_LOW
74 #define HAL_RADIO_GPIO_NRF21540_CSN_POL_INV 1
75 #endif	/* DT_SPI_DEV_CS_GPIOS_FLAGS(FEM_SPI_DEV_NODE) & GPIO_ACTIVE_LOW */
76 #endif	/* DT_SPI_DEV_HAS_CS_GPIOS(FEM_SPI_DEV_NODE) */
77 #endif	/* FEM_HAS_PROP(spi_if) */
78