drivers: lora: sx1276: support TCXO power control
Add support for TCXO power control using GPIO pin. Some boards (including B-L072Z-LRWAN1 already supported in Zephyr) need delay applied after powering on TCXO, so add device-tree property allowing to configure that as well. Cache information about TCXO power status, so subsequent requests to enable it will not result in unnecessary delays. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
parent
2aa161a121
commit
35328cc537
2 changed files with 60 additions and 1 deletions
|
@ -39,6 +39,16 @@ LOG_MODULE_REGISTER(sx1276);
|
|||
#define GPIO_PA_BOOST_ENABLE_FLAGS \
|
||||
DT_INST_GPIO_FLAGS(0, pa_boost_enable_gpios)
|
||||
|
||||
#define GPIO_TCXO_POWER_PIN DT_INST_GPIO_PIN(0, tcxo_power_gpios)
|
||||
#define GPIO_TCXO_POWER_FLAGS DT_INST_GPIO_FLAGS(0, tcxo_power_gpios)
|
||||
|
||||
#if DT_INST_NODE_HAS_PROP(0, tcxo_power_startup_delay_ms)
|
||||
#define TCXO_POWER_STARTUP_DELAY_MS \
|
||||
DT_INST_PROP(0, tcxo_power_startup_delay_ms)
|
||||
#else
|
||||
#define TCXO_POWER_STARTUP_DELAY_MS 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Those macros must be in sync with 'power-amplifier-output' dts property.
|
||||
*/
|
||||
|
@ -105,6 +115,10 @@ static struct sx1276_data {
|
|||
#if DT_INST_NODE_HAS_PROP(0, rfo_enable_gpios) && \
|
||||
DT_INST_NODE_HAS_PROP(0, pa_boost_enable_gpios)
|
||||
uint8_t tx_power;
|
||||
#endif
|
||||
#if DT_INST_NODE_HAS_PROP(0, tcxo_power_gpios)
|
||||
struct device *tcxo_power;
|
||||
bool tcxo_power_enabled;
|
||||
#endif
|
||||
struct device *spi;
|
||||
struct spi_config spi_cfg;
|
||||
|
@ -165,7 +179,25 @@ void SX1276SetAntSwLowPower(bool low_power)
|
|||
|
||||
void SX1276SetBoardTcxo(uint8_t state)
|
||||
{
|
||||
/* TODO */
|
||||
#if DT_INST_NODE_HAS_PROP(0, tcxo_power_gpios)
|
||||
bool enable = state;
|
||||
|
||||
if (enable == dev_data.tcxo_power_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
gpio_pin_set(dev_data.tcxo_power, GPIO_TCXO_POWER_PIN, 1);
|
||||
|
||||
if (TCXO_POWER_STARTUP_DELAY_MS > 0) {
|
||||
k_sleep(K_MSEC(TCXO_POWER_STARTUP_DELAY_MS));
|
||||
}
|
||||
} else {
|
||||
gpio_pin_set(dev_data.tcxo_power, GPIO_TCXO_POWER_PIN, 0);
|
||||
}
|
||||
|
||||
dev_data.tcxo_power_enabled = enable;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SX1276SetAntSw(uint8_t opMode)
|
||||
|
@ -192,6 +224,8 @@ void SX1276SetAntSw(uint8_t opMode)
|
|||
|
||||
void SX1276Reset(void)
|
||||
{
|
||||
SX1276SetBoardTcxo(true);
|
||||
|
||||
gpio_pin_configure(dev_data.reset, GPIO_RESET_PIN,
|
||||
GPIO_OUTPUT_ACTIVE | GPIO_RESET_FLAGS);
|
||||
|
||||
|
@ -485,6 +519,19 @@ static int sx1276_lora_init(struct device *dev)
|
|||
dev_data.spi_cfg.cs = &spi_cs;
|
||||
#endif
|
||||
|
||||
#if DT_INST_NODE_HAS_PROP(0, tcxo_power_gpios)
|
||||
dev_data.tcxo_power = device_get_binding(
|
||||
DT_INST_GPIO_LABEL(0, tcxo_power_gpios));
|
||||
if (!dev_data.tcxo_power) {
|
||||
LOG_ERR("Cannot get pointer to %s device",
|
||||
DT_INST_GPIO_LABEL(0, tcxo_power_gpios));
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
gpio_pin_configure(dev_data.tcxo_power, GPIO_TCXO_POWER_PIN,
|
||||
GPIO_OUTPUT_INACTIVE | GPIO_TCXO_POWER_FLAGS);
|
||||
#endif
|
||||
|
||||
/* Setup Reset gpio */
|
||||
dev_data.reset = device_get_binding(
|
||||
DT_INST_GPIO_LABEL(0, reset_gpios));
|
||||
|
|
|
@ -54,3 +54,15 @@ properties:
|
|||
required: false
|
||||
description: |
|
||||
PA_BOOST antenna output enable pin.
|
||||
|
||||
tcxo-power-gpios:
|
||||
type: phandle-array
|
||||
required: false
|
||||
description: |
|
||||
TCXO power enable pin.
|
||||
|
||||
tcxo-power-startup-delay-ms:
|
||||
type: int
|
||||
required: false
|
||||
description: |
|
||||
Delay which has to be applied after enabling TCXO power.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue