Skip to content

Commit ca8949e

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 ca8949e

File tree

3 files changed

+78
-56
lines changed

3 files changed

+78
-56
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: 22 additions & 7 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 {

boards/beagle/beagleconnect_freedom/board_antenna.c

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Copyright (c) 2021 Florin Stancu
44
* Copyright (c) 2021 Jason Kridner, BeagleBoard.org Foundation
5+
* Copyright (c) 2024 Ayush Singh <[email protected]>
56
*
67
*/
78

@@ -10,22 +11,26 @@
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,44 @@ 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+
static const struct pinctrl_dev_config *ant_pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0);
51+
static const struct gpio_dt_spec ant_gpios[] = {
52+
DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(antenna_mux0), gpios, GPIO_DT_SPEC_GET_BY_IDX, (,))};
53+
4154
/**
4255
* Antenna switch GPIO init routine.
4356
*/
44-
static int board_antenna_init(void)
57+
static int board_antenna_init(const struct device *dev)
4558
{
59+
ARG_UNUSED(dev);
60+
int i;
4661

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);
62+
/* default pinctrl configuration: set all antenna mux control pins as GPIOs */
63+
pinctrl_apply_state(ant_pcfg, PINCTRL_STATE_DEFAULT);
64+
/* set all GPIOs to 0 (all RF paths disabled) */
65+
for (i = 0; i < ARRAY_SIZE(ant_gpios); i++) {
66+
gpio_pin_configure_dt(&ant_gpios[i], 0);
67+
}
5268
return 0;
5369
}
5470

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)
71+
/**
72+
* Custom TI RFCC26XX callback for switching the on-board antenna mux on radio setup.
73+
*/
74+
static void board_cc13xx_rf_callback(RF_Handle client, RF_GlobalEvent events, void *arg)
5875
{
5976
bool sub1GHz = false;
6077
uint8_t loDivider = 0;
78+
int i;
6179

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);
80+
/* Clear all antenna switch GPIOs (for all cases). */
81+
for (i = 0; i < ARRAY_SIZE(ant_gpios); i++) {
82+
gpio_pin_configure_dt(&ant_gpios[i], 0);
83+
}
6584

6685
if (events & RF_GlobalEventRadioSetup) {
6786
/* Decode the current PA configuration. */
@@ -74,43 +93,27 @@ void board_cc13xx_rf_callback(RF_Handle client, RF_GlobalEvent events, void *arg
7493
case (CMD_RADIO_SETUP):
7594
case (CMD_BLE5_RADIO_SETUP):
7695
loDivider = RF_LODIVIDER_MASK & setupCommand->common.loDivider;
77-
/* Sub-1GHz front-end. */
78-
if (loDivider != 0)
79-
sub1GHz = true;
8096
break;
8197
case (CMD_PROP_RADIO_DIV_SETUP):
8298
loDivider = RF_LODIVIDER_MASK & setupCommand->prop_div.loDivider;
83-
/* Sub-1GHz front-end. */
84-
if (loDivider != 0)
85-
sub1GHz = true;
8699
break;
87100
default:
88101
break;
89102
}
103+
sub1GHz = (loDivider != 0);
90104

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);
105+
if (sub1GHz) {
106+
if (paType == RF_TxPowerTable_HighPA) {
107+
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 */
108+
/* is sometimes not de-asserted on CC1352 Rev A. */
109+
pinctrl_apply_state(ant_pcfg, PINCTRL_STATE_ANT_SUBG_PA);
110+
} else {
111+
pinctrl_apply_state(ant_pcfg, PINCTRL_STATE_ANT_SUBG);
112+
/* Manually set the sub-GHZ antenna switch DIO */
113+
gpio_pin_configure_dt(&ant_gpios[BOARD_ANT_GPIO_SUBG], 1);
114+
}
108115
}
109116
} 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);
117+
pinctrl_apply_state(ant_pcfg, PINCTRL_STATE_DEFAULT);
115118
}
116119
}

0 commit comments

Comments
 (0)