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)