1- /* SPDX-License-Identifier: Apache-2.0
2- *
1+ /*
32 * Copyright (c) 2021 Florin Stancu
43 * Copyright (c) 2021 Jason Kridner, BeagleBoard.org Foundation
4+ * Copyright (c) 2024 Ayush Singh <[email protected] > 55 *
6+ * SPDX-License-Identifier: Apache-2.0
67 */
78
89/*
910 * Implements the RF driver callback to configure the on-board antenna
1011 * switch.
1112 */
1213
13- #include <zephyr/kernel.h>
14- #include <zephyr/device.h>
14+ #define DT_DRV_COMPAT skyworks_sky13317
15+
1516#include <zephyr/init.h>
17+ #include <zephyr/device.h>
18+ #include <zephyr/drivers/gpio.h>
19+ #include <zephyr/drivers/pinctrl.h>
1620
1721#include <ti/drivers/rf/RF.h>
18- #include <driverlib/gpio.h>
19- #include <driverlib/ioc.h>
2022#include <driverlib/rom.h>
23+ #include <driverlib/interrupt.h>
2124
22- /* DIOs for RF antenna paths */
23- #define BOARD_RF_HIGH_PA 29 /* TODO: pull from DT */
24- #define BOARD_RF_SUB1GHZ 30 /* TODO: pull from DT */
25+ /* custom pinctrl states for the antenna mux */
26+ #define PINCTRL_STATE_ANT_SUBG 1
27+ #define PINCTRL_STATE_ANT_SUBG_PA 2
2528
26- static void board_cc13xx_rf_callback ( RF_Handle client , RF_GlobalEvent events ,
27- void * arg );
29+ #define BOARD_ANT_GPIO_PA 0
30+ #define BOARD_ANT_GPIO_SUBG 1
2831
32+ static int board_antenna_init (const struct device * dev );
33+ static void board_cc13xx_rf_callback (RF_Handle client , RF_GlobalEvent events , void * arg );
2934
3035const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = {
3136 .hwiPriority = INT_PRI_LEVEL7 ,
@@ -38,30 +43,46 @@ const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = {
3843 RF_GlobalEventRadioPowerDown ),
3944};
4045
46+ PINCTRL_DT_INST_DEFINE (0 );
47+ DEVICE_DT_INST_DEFINE (0 , board_antenna_init , NULL , NULL , NULL , POST_KERNEL ,
48+ CONFIG_BOARD_ANTENNA_INIT_PRIO , NULL );
49+
50+ #define GPIO_DT_SPEC (n , p , i ) GPIO_DT_SPEC_GET_BY_IDX(n, p, i),
51+
52+ static const struct pinctrl_dev_config * ant_pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET (0 );
53+ static const struct gpio_dt_spec ant_gpios [] = {
54+ DT_FOREACH_PROP_ELEM (DT_NODELABEL (antenna_mux0 ), gpios , GPIO_DT_SPEC )};
55+
4156/**
4257 * Antenna switch GPIO init routine.
4358 */
44- static int board_antenna_init (void )
59+ static int board_antenna_init (const struct device * dev )
4560{
61+ ARG_UNUSED (dev );
62+ int i ;
4663
47- /* set all paths to low */
48- IOCPinTypeGpioOutput (BOARD_RF_HIGH_PA );
49- GPIO_setOutputEnableDio (BOARD_RF_HIGH_PA , GPIO_OUTPUT_DISABLE );
50- IOCPinTypeGpioOutput (BOARD_RF_SUB1GHZ );
51- GPIO_setOutputEnableDio (BOARD_RF_SUB1GHZ , GPIO_OUTPUT_DISABLE );
64+ /* default pinctrl configuration: set all antenna mux control pins as GPIOs */
65+ pinctrl_apply_state (ant_pcfg , PINCTRL_STATE_DEFAULT );
66+ /* set all GPIOs to 0 (all RF paths disabled) */
67+ for (i = 0 ; i < ARRAY_SIZE (ant_gpios ); i ++ ) {
68+ gpio_pin_configure_dt (& ant_gpios [i ], 0 );
69+ }
5270 return 0 ;
5371}
5472
55- SYS_INIT (board_antenna_init , POST_KERNEL , CONFIG_BOARD_ANTENNA_INIT_PRIO );
56-
57- void board_cc13xx_rf_callback (RF_Handle client , RF_GlobalEvent events , void * arg )
73+ /**
74+ * Custom TI RFCC26XX callback for switching the on-board antenna mux on radio setup.
75+ */
76+ static void board_cc13xx_rf_callback (RF_Handle client , RF_GlobalEvent events , void * arg )
5877{
5978 bool sub1GHz = false;
6079 uint8_t loDivider = 0 ;
80+ int i ;
6181
62- /* Switch off all paths first. Needs to be done anyway in every sub-case below. */
63- GPIO_setOutputEnableDio (BOARD_RF_HIGH_PA , GPIO_OUTPUT_DISABLE );
64- GPIO_setOutputEnableDio (BOARD_RF_SUB1GHZ , GPIO_OUTPUT_DISABLE );
82+ /* Clear all antenna switch GPIOs (for all cases). */
83+ for (i = 0 ; i < ARRAY_SIZE (ant_gpios ); i ++ ) {
84+ gpio_pin_configure_dt (& ant_gpios [i ], 0 );
85+ }
6586
6687 if (events & RF_GlobalEventRadioSetup ) {
6788 /* Decode the current PA configuration. */
@@ -88,29 +109,18 @@ void board_cc13xx_rf_callback(RF_Handle client, RF_GlobalEvent events, void *arg
88109 break ;
89110 }
90111
91- /* Sub-1 GHz */
92- if (paType == RF_TxPowerTable_HighPA ) {
93- /* PA enable --> HIGH PA */
94- /* LNA enable --> Sub-1 GHz */
95- /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 */
96- /* is sometimes not de-asserted on CC1352 Rev A. */
97- IOCPortConfigureSet (BOARD_RF_HIGH_PA ,
98- IOC_PORT_RFC_GPO3 , IOC_IOMODE_NORMAL );
99- IOCPortConfigureSet (BOARD_RF_SUB1GHZ ,
100- IOC_PORT_RFC_GPO0 , IOC_IOMODE_NORMAL );
101- } else {
102- /* RF core active --> Sub-1 GHz */
103- IOCPortConfigureSet (BOARD_RF_HIGH_PA ,
104- IOC_PORT_GPIO , IOC_IOMODE_NORMAL );
105- IOCPortConfigureSet (BOARD_RF_SUB1GHZ ,
106- IOC_PORT_GPIO , IOC_IOMODE_NORMAL );
107- GPIO_setOutputEnableDio (BOARD_RF_SUB1GHZ , GPIO_OUTPUT_ENABLE );
112+ if (sub1GHz ) {
113+ if (paType == RF_TxPowerTable_HighPA ) {
114+ /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 */
115+ /* is sometimes not de-asserted on CC1352 Rev A. */
116+ pinctrl_apply_state (ant_pcfg , PINCTRL_STATE_ANT_SUBG_PA );
117+ } else {
118+ pinctrl_apply_state (ant_pcfg , PINCTRL_STATE_ANT_SUBG );
119+ /* Manually set the sub-GHZ antenna switch DIO */
120+ gpio_pin_configure_dt (& ant_gpios [BOARD_ANT_GPIO_SUBG ], 1 );
121+ }
108122 }
109123 } else {
110- /* Reset the IO multiplexer to GPIO functionality */
111- IOCPortConfigureSet (BOARD_RF_HIGH_PA ,
112- IOC_PORT_GPIO , IOC_IOMODE_NORMAL );
113- IOCPortConfigureSet (BOARD_RF_SUB1GHZ ,
114- IOC_PORT_GPIO , IOC_IOMODE_NORMAL );
124+ pinctrl_apply_state (ant_pcfg , PINCTRL_STATE_DEFAULT );
115125 }
116126}
0 commit comments