Skip to content

Commit 2446213

Browse files
[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 <[email protected]>
1 parent b5cf3ea commit 2446213

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

subsys/shell/backends/shell_uart.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/init.h>
1414
#include <zephyr/logging/log.h>
1515
#include <zephyr/net_buf.h>
16+
#include <zephyr/pm/device_runtime.h>
1617

1718
#define LOG_MODULE_NAME shell_uart
1819
LOG_MODULE_REGISTER(shell_uart);
@@ -290,6 +291,7 @@ static int init(const struct shell_transport *transport,
290291
void *context)
291292
{
292293
struct shell_uart_common *common = (struct shell_uart_common *)transport->ctx;
294+
int ret;
293295

294296
common->dev = (const struct device *)config;
295297
common->handler = evt_handler;
@@ -300,6 +302,11 @@ static int init(const struct shell_transport *transport,
300302
k_fifo_init(&common->smp.buf_ready);
301303
#endif
302304

305+
ret = pm_device_runtime_get(common->dev);
306+
if (ret < 0) {
307+
return ret;
308+
}
309+
303310
if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC)) {
304311
async_init((struct shell_uart_async *)transport->ctx);
305312
} 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)
331338

332339
static int uninit(const struct shell_transport *transport)
333340
{
341+
struct shell_uart_common *common = (struct shell_uart_common *)transport->ctx;
342+
334343
if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC)) {
335344
async_uninit((struct shell_uart_async *)transport->ctx);
336345
} else if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_API_INTERRUPT_DRIVEN)) {
@@ -339,7 +348,7 @@ static int uninit(const struct shell_transport *transport)
339348
polling_uninit((struct shell_uart_polling *)transport->ctx);
340349
}
341350

342-
return 0;
351+
return pm_device_runtime_put(common->dev);
343352
}
344353

345354
static int enable(const struct shell_transport *transport, bool blocking_tx)

0 commit comments

Comments
 (0)