From 2446213965714e9fe266c31ae0548cc7d5caf70a Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 31 Oct 2025 17:39:30 +0100 Subject: [PATCH] [nrf fromlist] shell: backends: uart: implement pm_device_runtime The UART device used by the backend needs to be gotten before use, and put after. In limited cases, device drivers call pm_device_runtime_get() as part of the call to uart_rx_enable(), this is not the case for polling, nor interrupt driven API calls for most if not all drivers, nor is that expected. Implement pm_device_runtime calls in shell uart backend similar to the logging uart backend to support all uart drivers in all configurations. Upstream PR #: 98681 Signed-off-by: Bjarki Arge Andreasen --- subsys/shell/backends/shell_uart.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/subsys/shell/backends/shell_uart.c b/subsys/shell/backends/shell_uart.c index 1d19ce19a318..a65c2fb16aef 100644 --- a/subsys/shell/backends/shell_uart.c +++ b/subsys/shell/backends/shell_uart.c @@ -13,6 +13,7 @@ #include #include #include +#include #define LOG_MODULE_NAME shell_uart LOG_MODULE_REGISTER(shell_uart); @@ -290,6 +291,7 @@ static int init(const struct shell_transport *transport, void *context) { struct shell_uart_common *common = (struct shell_uart_common *)transport->ctx; + int ret; common->dev = (const struct device *)config; common->handler = evt_handler; @@ -300,6 +302,11 @@ static int init(const struct shell_transport *transport, k_fifo_init(&common->smp.buf_ready); #endif + ret = pm_device_runtime_get(common->dev); + if (ret < 0) { + return ret; + } + if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC)) { async_init((struct shell_uart_async *)transport->ctx); } else if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_INTERRUPT_DRIVEN)) { @@ -331,6 +338,8 @@ static void polling_uninit(struct shell_uart_polling *sh_uart) static int uninit(const struct shell_transport *transport) { + struct shell_uart_common *common = (struct shell_uart_common *)transport->ctx; + if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC)) { async_uninit((struct shell_uart_async *)transport->ctx); } else if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_INTERRUPT_DRIVEN)) { @@ -339,7 +348,7 @@ static int uninit(const struct shell_transport *transport) polling_uninit((struct shell_uart_polling *)transport->ctx); } - return 0; + return pm_device_runtime_put(common->dev); } static int enable(const struct shell_transport *transport, bool blocking_tx)