Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions applications/connectivity_bridge/src/modules/uart_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

#include <zephyr/types.h>
#include <zephyr/sys/ring_buffer.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>

#define MODULE uart_handler
#include "module_state_event.h"
Expand Down Expand Up @@ -39,6 +40,10 @@ static const struct device *devices[] = {
#define UART_SET_PM_STATE false
#endif

#if UART_SET_PM_STATE
atomic_t device_pm_requested = ATOMIC_INIT(0);
#endif

struct uart_rx_buf {
atomic_t ref_counter;
size_t len;
Expand Down Expand Up @@ -231,14 +236,23 @@ static void set_uart_power_state(uint8_t dev_idx, bool active)
{
#if UART_SET_PM_STATE
const struct device *dev = devices[dev_idx];
const char *action;
int err;
enum pm_device_action action;

action = active ? PM_DEVICE_ACTION_RESUME : PM_DEVICE_ACTION_SUSPEND;
if (active) {
if (!atomic_test_and_set_bit(&device_pm_requested, dev_idx)) {
action = "pm_device_runtime_get";
err = pm_device_runtime_get(dev);
}
} else {
if (atomic_test_and_clear_bit(&device_pm_requested, dev_idx)) {
action = "pm_device_runtime_put";
err = pm_device_runtime_put(dev);
}
}

err = pm_device_action_run(dev, action);
if ((err < 0) && (err != -EALREADY)) {
LOG_ERR("pm_device_action_run failed: %d", err);
if (err < 0) {
LOG_ERR("%s failed: %d", action, err);
}
#endif
}
Expand Down
14 changes: 7 additions & 7 deletions applications/nrf_desktop/src/hw_interface/wheel.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <pinctrl_soc.h>

#include <app_event_manager.h>
Expand Down Expand Up @@ -262,13 +262,13 @@ static int enable_qdec(enum state next_state)

int err = 0;

/* QDEC device driver starts in PM_DEVICE_STATE_ACTIVE state. */
if (state != STATE_DISABLED) {
err = pm_device_action_run(qdec_dev, PM_DEVICE_ACTION_RESUME);
/* QDEC device driver starts in PM_DEVICE_STATE_SUSPENDED state. */
if (state == STATE_DISABLED) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check here should be removed. Now we should always call pm_device_runtime_get here (also after we return from the suspended state), right?

err = pm_device_runtime_get(qdec_dev);
}

if (err) {
LOG_ERR("Cannot resume QDEC");
LOG_ERR("Cannot get QDEC");
return err;
}

Expand Down Expand Up @@ -304,9 +304,9 @@ static int disable_qdec(enum state next_state)
return err;
}

err = pm_device_action_run(qdec_dev, PM_DEVICE_ACTION_SUSPEND);
err = pm_device_runtime_put(qdec_dev);
if (err) {
LOG_ERR("Cannot suspend QDEC");
LOG_ERR("Cannot put QDEC");
} else {
err = setup_wakeup();
if (!err) {
Expand Down
44 changes: 33 additions & 11 deletions applications/serial_lte_modem/src/slm_at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#include <zephyr/drivers/uart.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/sys/ring_buffer.h>
#include <zephyr/sys/atomic.h>
LOG_MODULE_REGISTER(slm_at_host, CONFIG_SLM_LOG_LEVEL);

#define SLM_SYNC_STR "Ready\r\n"
Expand Down Expand Up @@ -53,11 +54,33 @@ static uint8_t quit_str_partial_match;
K_MUTEX_DEFINE(mutex_data); /* Protects the data_rb and quit_str_partial_match. */

static struct k_work raw_send_scheduled_work;
static bool slm_uart_dev_active;

/* global functions defined in different files */
int slm_at_init(void);
void slm_at_uninit(void);

static int set_uart_dev_power_state(bool active)
{
int err;

if ((active && slm_uart_dev_active) || (!active && !slm_uart_dev_active)) {
return 0;
}

if (active) {
err = pm_device_runtime_get(slm_uart_dev);
} else {
err = pm_device_runtime_put(slm_uart_dev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Test power consumption with AT#XSLEEP=2 after this change.

}

if (err == 0) {
slm_uart_dev_active = active;
}

return err;
}

static enum slm_operation_mode get_slm_mode(void)
{
enum slm_operation_mode mode;
Expand Down Expand Up @@ -506,10 +529,7 @@ static int slm_at_send_indicate(const uint8_t *data, size_t len,
}

if (indicate) {
enum pm_device_state state = PM_DEVICE_STATE_OFF;

pm_device_state_get(slm_uart_dev, &state);
if (state != PM_DEVICE_STATE_ACTIVE) {
if (!slm_uart_dev_is_active()) {
slm_ctrl_pin_indicate();
}
}
Expand Down Expand Up @@ -1006,10 +1026,7 @@ static int at_host_power_off(bool shutting_down)
if (!err || shutting_down) {

/* Power off UART module */
err = pm_device_action_run(slm_uart_dev, PM_DEVICE_ACTION_SUSPEND);
if (err == -EALREADY) {
err = 0;
}
err = set_uart_dev_power_state(false);
if (err) {
LOG_WRN("Failed to suspend UART. (%d)", err);
if (!shutting_down) {
Expand All @@ -1033,9 +1050,9 @@ int slm_at_host_power_off(void)

int slm_at_host_power_on(void)
{
const int err = pm_device_action_run(slm_uart_dev, PM_DEVICE_ACTION_RESUME);
const int err = set_uart_dev_power_state(true);

if (err && err != -EALREADY) {
if (err) {
LOG_ERR("Failed to resume UART. (%d)", err);
return err;
}
Expand All @@ -1047,6 +1064,11 @@ int slm_at_host_power_on(void)
return 0;
}

bool slm_uart_dev_is_active(void)
{
return slm_uart_dev_active;
}

void slm_at_host_uninit(void)
{
k_mutex_lock(&mutex_mode, K_FOREVER);
Expand Down
3 changes: 3 additions & 0 deletions applications/serial_lte_modem/src/slm_at_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ int slm_at_host_power_off(void);
/** @brief Counterpart to @c slm_at_host_power_off(). */
int slm_at_host_power_on(void);

/** Check if UART is active */
bool slm_uart_dev_is_active(void);

/**
* @brief Uninitialize AT host for serial LTE modem
*/
Expand Down
4 changes: 1 addition & 3 deletions applications/serial_lte_modem/src/slm_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ static void ppp_data_passing_thread(void*, void*, void*)
{
const size_t mtu = net_if_get_mtu(ppp_iface);
struct zsock_pollfd fds[PPP_FDS_COUNT];
enum pm_device_state state = PM_DEVICE_STATE_OFF;

for (size_t i = 0; i != ARRAY_SIZE(fds); ++i) {
fds[i].fd = ppp_fds[i];
Expand Down Expand Up @@ -745,8 +744,7 @@ static void ppp_data_passing_thread(void*, void*, void*)

/* When DL data is received from the network, check if UART is suspended */
if (src == MODEM_FD_IDX) {
pm_device_state_get(ppp_uart_dev, &state);
if (state != PM_DEVICE_STATE_ACTIVE) {
if (!slm_uart_dev_is_active()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a different UART in some use cases, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In this case we should be checking ppp_uart_dev, which is either ncs_slm_uart or ncs_slm_ppp_uart.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, we are missing putting the second UART to sleep, for which there is a Jira ticket. I think that it might be reasonable to remove the changes in this file and we could implement those later.

LOG_DBG("PPP data received but UART not active");
slm_ctrl_pin_indicate();
}
Expand Down
4 changes: 1 addition & 3 deletions applications/serial_lte_modem/src/slm_uart_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@ static int tx_start(void)
uint8_t *buf;
size_t len;
int err;
enum pm_device_state state = PM_DEVICE_STATE_OFF;

pm_device_state_get(slm_uart_dev, &state);
if (state != PM_DEVICE_STATE_ACTIVE) {
if (!slm_uart_dev_is_active()) {
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
pinctrl-1 = <&i2c130_sleep>;
pinctrl-names = "default", "sleep";
zephyr,concat-buf-size = <255>;
zephyr,pm-device-runtime-auto;

bme688: bme688@76 {
compatible = "bosch,bme680";
Expand Down Expand Up @@ -83,7 +82,6 @@
pinctrl-1 = <&spi131_sleep>;
pinctrl-names = "default", "sleep";
overrun-character = <0x00>;
zephyr,pm-device-runtime-auto;
cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>,
<&gpio1 2 GPIO_ACTIVE_LOW>;

Expand Down
2 changes: 0 additions & 2 deletions doc/nrf/drivers/mspi_sqspi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ See the following configuration example for the nRF54L15 SoC:
#size-cells = <0>;
reg = <0x3c00 0x200>;
status = "okay";
zephyr,pm-device-runtime-auto;
};
};
};
Expand Down Expand Up @@ -162,7 +161,6 @@ The following example configuration for the nRF54H20 SoC sets up the necessary p
#address-cells = <1>;
#size-cells = <0>;
reg = <0x3e00 0x200>;
zephyr,pm-device-runtime-auto;
memory-regions = <&sqspi_buffers>;
};
};
Expand Down
7 changes: 0 additions & 7 deletions dts/common/nordic/nrf54lm20a.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@
interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi20: spi@c6000 {
Expand Down Expand Up @@ -361,7 +360,6 @@
interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi21: spi@c7000 {
Expand Down Expand Up @@ -400,7 +398,6 @@
interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi22: spi@c8000 {
Expand Down Expand Up @@ -535,7 +532,6 @@
interrupts = <213 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

nfct: nfct@d6000 {
Expand Down Expand Up @@ -625,7 +621,6 @@
interrupts = <237 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi23: spi@ed000 {
Expand Down Expand Up @@ -664,7 +659,6 @@
interrupts = <238 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi24: spi@ee000 {
Expand Down Expand Up @@ -715,7 +709,6 @@
interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi30: spi@104000 {
Expand Down
4 changes: 0 additions & 4 deletions dts/common/nordic/nrf54lv10a.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi20: spi@c6000 {
Expand Down Expand Up @@ -306,7 +305,6 @@
interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi21: spi@c7000 {
Expand Down Expand Up @@ -400,7 +398,6 @@
interrupts = <213 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

temp: temp@d7000 {
Expand Down Expand Up @@ -457,7 +454,6 @@
interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>;
easydma-maxcnt-bits = <16>;
status = "disabled";
zephyr,pm-device-runtime-auto;
};

spi30: spi@104000 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
/delete-node/ &button3;

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
/delete-node/ &button3;

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
/delete-node/ &button3;

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
/delete-node/ &button3;

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
/delete-node/ &button3;

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
/delete-node/ &button3;

&uart30 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
*/

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
*/

&uart20 {
zephyr,pm-device-runtime-auto;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
*/

&uart20 {
zephyr,pm-device-runtime-auto;
};
Loading
Loading