Skip to content

Commit 351db5b

Browse files
committed
drivers: lora: sx126x: add low energy support
Add optional low-power sequencing for SX126x (GPIO and SUBGHZ radio control) so the host can turn the radio off between operations. Remove debug helpers dump_gpio() and dump_rf_ctrl(). Drop gridpoint_stm32wl_subghz_radio compat; use st,stm32wl-subghz-radio only. Signed-off-by: Jon Ringle <jringle@gridpoint.com>
1 parent ec4d477 commit 351db5b

3 files changed

Lines changed: 111 additions & 4 deletions

File tree

drivers/lora/loramac_node/sx126x.c

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ static const struct sx126x_config dev_config = {
5050
#if HAVE_GPIO_RX_ENABLE
5151
.rx_enable = GPIO_DT_SPEC_INST_GET(0, rx_enable_gpios),
5252
#endif
53+
#if HAVE_GPIO_FE_CTRL
54+
.fe_ctrl1_enable = GPIO_DT_SPEC_INST_GET(0, fe_ctrl1_enable_gpios),
55+
.fe_ctrl2_enable = GPIO_DT_SPEC_INST_GET(0, fe_ctrl2_enable_gpios),
56+
.fe_ctrl3_enable = GPIO_DT_SPEC_INST_GET(0, fe_ctrl3_enable_gpios),
57+
#endif
58+
5359
};
5460

61+
5562
static struct sx126x_data dev_data;
5663

5764
void SX126xWaitOnBusy(void);
@@ -253,29 +260,57 @@ void SX126xAntSwOff(void)
253260
#endif
254261
}
255262

263+
#if HAVE_GPIO_TX_ENABLE
256264
static void sx126x_set_tx_enable(int value)
257265
{
258-
#if HAVE_GPIO_TX_ENABLE
259266
gpio_pin_set_dt(&dev_config.tx_enable, value);
260-
#endif
261267
}
268+
#endif
262269

270+
#if HAVE_GPIO_RX_ENABLE
263271
static void sx126x_set_rx_enable(int value)
264272
{
265-
#if HAVE_GPIO_RX_ENABLE
266273
gpio_pin_set_dt(&dev_config.rx_enable, value);
274+
}
275+
#endif
276+
277+
278+
static void sx126x_set_fe_ctrl(int ctrl1, int ctrl2, int ctrl3)
279+
{
280+
#if HAVE_GPIO_FE_CTRL
281+
gpio_pin_set_dt(&dev_config.fe_ctrl1_enable, ctrl1);
282+
gpio_pin_set_dt(&dev_config.fe_ctrl2_enable, ctrl2);
283+
gpio_pin_set_dt(&dev_config.fe_ctrl3_enable, ctrl3);
267284
#endif
268285
}
269286

287+
270288
RadioOperatingModes_t SX126xGetOperatingMode(void)
271289
{
272290
return dev_data.mode;
273291
}
274292

293+
#if HAVE_GPIO_FE_CTRL
294+
static const enum {
295+
RFO_LP,
296+
RFO_HP,
297+
} pa_output = DT_INST_STRING_UPPER_TOKEN(0, power_amplifier_output);
298+
#endif
299+
300+
#define LORA_NODE DT_NODELABEL(lora)
301+
302+
275303
void SX126xSetOperatingMode(RadioOperatingModes_t mode)
276304
{
277305
LOG_DBG("SetOperatingMode: %s (%i)", sx126x_mode_name(mode), mode);
278306

307+
#if HAVE_GPIO_FE_CTRL
308+
const int off_fe_ctrl_lines[] = DT_PROP(LORA_NODE, off_fe_ctrl_lines);
309+
const int rx_fe_ctrl_lines[] = DT_PROP(LORA_NODE, rx_fe_ctrl_lines);
310+
const int txhp_fe_ctrl_lines[] = DT_PROP(LORA_NODE, txhp_fe_ctrl_lines);
311+
const int txlp_fe_ctrl_lines[] = DT_PROP(LORA_NODE, txlp_fe_ctrl_lines);
312+
#endif
313+
279314
dev_data.mode = mode;
280315

281316
/* To avoid inadvertently putting the RF switch in an
@@ -284,24 +319,43 @@ void SX126xSetOperatingMode(RadioOperatingModes_t mode)
284319
*/
285320
switch (mode) {
286321
case MODE_TX:
322+
#if HAVE_GPIO_TX_ENABLE
287323
sx126x_set_rx_enable(0);
288324
sx126x_set_tx_enable(1);
325+
#endif
326+
#if HAVE_GPIO_FE_CTRL
327+
if (pa_output == RFO_LP) {
328+
sx126x_set_fe_ctrl(txlp_fe_ctrl_lines[0], txlp_fe_ctrl_lines[1], txlp_fe_ctrl_lines[2]);
329+
} else {
330+
sx126x_set_fe_ctrl(txhp_fe_ctrl_lines[0], txhp_fe_ctrl_lines[1], txhp_fe_ctrl_lines[2]);
331+
}
332+
#endif
289333
break;
290334

291335
case MODE_RX:
292336
case MODE_RX_DC:
293337
case MODE_CAD:
338+
#if HAVE_GPIO_TX_ENABLE
294339
sx126x_set_tx_enable(0);
295340
sx126x_set_rx_enable(1);
341+
#endif
342+
#if HAVE_GPIO_FE_CTRL
343+
sx126x_set_fe_ctrl(rx_fe_ctrl_lines[0], rx_fe_ctrl_lines[1], rx_fe_ctrl_lines[2]);
344+
#endif
296345
break;
297346

298347
case MODE_SLEEP:
299348
/* Additionally disable the DIO1 interrupt to save power */
300349
sx126x_dio1_irq_disable(&dev_data);
301350
__fallthrough;
302351
default:
352+
#if HAVE_GPIO_TX_ENABLE
303353
sx126x_set_rx_enable(0);
304354
sx126x_set_tx_enable(0);
355+
#endif
356+
#if HAVE_GPIO_FE_CTRL
357+
sx126x_set_fe_ctrl(off_fe_ctrl_lines[0], off_fe_ctrl_lines[1], off_fe_ctrl_lines[2]);
358+
#endif
305359
break;
306360
}
307361
}
@@ -437,7 +491,14 @@ static int sx126x_lora_init(const struct device *dev)
437491

438492
if (sx12xx_configure_pin(antenna_enable, GPIO_OUTPUT_INACTIVE) ||
439493
sx12xx_configure_pin(rx_enable, GPIO_OUTPUT_INACTIVE) ||
440-
sx12xx_configure_pin(tx_enable, GPIO_OUTPUT_INACTIVE)) {
494+
sx12xx_configure_pin(tx_enable, GPIO_OUTPUT_INACTIVE)
495+
#if HAVE_GPIO_FE_CTRL
496+
|| sx12xx_configure_pin(fe_ctrl1_enable, GPIO_OUTPUT_INACTIVE)
497+
|| sx12xx_configure_pin(fe_ctrl2_enable, GPIO_OUTPUT_INACTIVE)
498+
|| sx12xx_configure_pin(fe_ctrl3_enable, GPIO_OUTPUT_INACTIVE)
499+
#endif
500+
)
501+
{
441502
return -EIO;
442503
}
443504

drivers/lora/loramac_node/sx126x_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
DT_INST_NODE_HAS_PROP(0, antenna_enable_gpios)
3535
#define HAVE_GPIO_TX_ENABLE DT_INST_NODE_HAS_PROP(0, tx_enable_gpios)
3636
#define HAVE_GPIO_RX_ENABLE DT_INST_NODE_HAS_PROP(0, rx_enable_gpios)
37+
#define HAVE_GPIO_FE_CTRL (DT_INST_NODE_HAS_PROP(0, fe_ctrl1_enable_gpios) && !DT_INST_NODE_HAS_PROP(0, tx_enable_gpios))
3738

3839
struct sx126x_config {
3940
struct spi_dt_spec bus;
@@ -46,6 +47,12 @@ struct sx126x_config {
4647
#if HAVE_GPIO_RX_ENABLE
4748
struct gpio_dt_spec rx_enable;
4849
#endif
50+
#if HAVE_GPIO_FE_CTRL
51+
struct gpio_dt_spec fe_ctrl3_enable;
52+
struct gpio_dt_spec fe_ctrl2_enable;
53+
struct gpio_dt_spec fe_ctrl1_enable;
54+
#endif
55+
4956
};
5057

5158
struct sx126x_data {

dts/bindings/lora/semtech,sx126x-base.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,45 @@ properties:
3535
Antenna switch RX enable GPIO. If set, the driver tracks the
3636
state of the radio and controls the RF switch.
3737
38+
txlp-fe-ctrl-lines:
39+
type: array
40+
description: |
41+
RF front-end GPIO bit values to enable transmit low-power. Array
42+
of 3 binary values corresponding to FE_CTRL1, FE_CTRL2, FE_CTRL3
43+
44+
txhp-fe-ctrl-lines:
45+
type: array
46+
description: |
47+
RF front-end GPIO bit values to enable transmit high-power. Array
48+
of 3 binary values corresponding to FE_CTRL1, FE_CTRL2, FE_CTRL3
49+
50+
rx-fe-ctrl-lines:
51+
type: array
52+
description: |
53+
RF front-end GPIO bit values to enable receive. Array
54+
of 3 binary values corresponding to FE_CTRL1, FE_CTRL2, FE_CTRL3
55+
56+
off-fe-ctrl-lines:
57+
type: array
58+
description: |
59+
RF front-end GPIO bit values to switch off antenna. Array
60+
of 3 binary values corresponding to FE_CTRL1, FE_CTRL2, FE_CTRL3
61+
62+
fe-ctrl1-enable-gpios:
63+
type: phandle-array
64+
description: |
65+
FE_CTRL1 signal GPIO controlling RF switch.
66+
67+
fe-ctrl2-enable-gpios:
68+
type: phandle-array
69+
description: |
70+
FE_CTRL2 signal GPIO controlling RF switch.
71+
72+
fe-ctrl3-enable-gpios:
73+
type: phandle-array
74+
description: |
75+
FE_CTRL3 signal GPIO controlling RF switch.
76+
3877
dio1-gpios:
3978
type: phandle-array
4079
description: |

0 commit comments

Comments
 (0)