Skip to content

Commit ebd6b52

Browse files
committed
boards: beagle: beagleconnect_freedom: Use sky13317
- Use antenna switch sky13317 instead of hack - Base the board_antenna file on cc1352p1_launchxl/board_antenna.c Signed-off-by: Ayush Singh <[email protected]>
1 parent db7c343 commit ebd6b52

File tree

3 files changed

+82
-53
lines changed

3 files changed

+82
-53
lines changed

boards/beagle/beagleconnect_freedom/beagleconnect_freedom-pinctrl.dtsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@
8181
/* On-board antenna pinmux states */
8282
board_ant_tx_pa_off: board_ant_tx_pa_off {
8383
pinmux = <29 IOC_PORT_GPIO>;
84+
bias-disable;
8485
};
8586
board_ant_tx_pa_on: board_ant_tx_pa_on {
8687
pinmux = <29 IOC_PORT_RFC_GPO3>;
88+
bias-disable;
8789
};
8890
board_ant_subg_off: board_ant_subg_off {
8991
pinmux = <30 IOC_PORT_GPIO>;
92+
bias-disable;
9093
};
9194
board_ant_subg_on: board_ant_subg_on {
9295
pinmux = <30 IOC_PORT_RFC_GPO0>;
96+
bias-disable;
9397
};
9498
};

boards/beagle/beagleconnect_freedom/beagleconnect_freedom.dts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,33 @@
4242
};
4343
};
4444

45+
/**
46+
* The BeagleConnect Freedom has an on-board antenna switch (SKY13317-373LF) used to select
47+
* the appropriate RF signal port based on the currently-used PHY.
48+
*
49+
* Truth table:
50+
*
51+
* Path DIO29 DIO30
52+
* =========== ===== =====
53+
* Off 0 0
54+
* Sub-1 GHz 0 1 // DIO30 mux to IOC_PORT_RFC_GPO0 for auto
55+
* 20 dBm TX 1 0 // DIO29 mux to IOC_PORT_RFC_GPO3 for auto
56+
*/
57+
antenna_mux0: antenna_mux0 {
58+
compatible = "skyworks,sky13317";
59+
status = "okay";
60+
gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>, <&gpio0 30 GPIO_ACTIVE_HIGH>;
61+
pinctrl-0 = <&board_ant_tx_pa_off &board_ant_subg_off>;
62+
pinctrl-1 = <&board_ant_tx_pa_off &board_ant_subg_on>;
63+
pinctrl-2 = <&board_ant_tx_pa_on &board_ant_subg_on>;
64+
pinctrl-names = "default", "ant_subg", "ant_subg_pa";
65+
};
66+
4567
leds: leds {
4668
compatible = "gpio-leds";
4769
led0: led_0 {
4870
gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>; // 2.4GHz TX/RX
4971
};
50-
51-
/* U.FL connector switch */
52-
rf_sw: rf_sw {
53-
gpios =
54-
<&gpio0 29 GPIO_ACTIVE_HIGH>, // SubG TX +20dB
55-
<&gpio0 30 GPIO_ACTIVE_HIGH>; // SubG TX/RX 0dB
56-
};
5772
};
5873

5974
sens_i2c: sensor-switch {
@@ -187,7 +202,7 @@
187202
};
188203

189204
&ieee802154 {
190-
status = "okay";
205+
status = "disabled";
191206
};
192207

193208
&ieee802154g {
Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
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

3035
const 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

Comments
 (0)