Skip to content

drivers: serial: nrfx_uarte: Add support for device deinit #93273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions drivers/pinctrl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ config PINCTRL_DYNAMIC
runtime. This can be useful, for example, to change the pins assigned to a
peripheral at early boot stages depending on a certain input.

config PINCTRL_KEEP_SLEEP_STATE
bool "Keep sleep state"
default y if PM || PM_DEVICE

source "drivers/pinctrl/Kconfig.b91"
source "drivers/pinctrl/Kconfig.bflb"
source "drivers/pinctrl/Kconfig.ambiq"
Expand Down
7 changes: 7 additions & 0 deletions drivers/serial/Kconfig.nrfx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ config UART_NRFX_UARTE_NO_IRQ
When enabled, then interrupt handler is not used at all and it is possible
to get to the lowest power state after uart_poll_out if receiver is not used.

config UART_NRFX_UARTE_DEINIT
bool "Support deinit"
depends on UART_NRFX_UARTE
imply PINCTRL_KEEP_SLEEP_STATE
help
When enabled then UART driver support device_deinit.

config UART_NRFX_UARTE_LEGACY_SHIM
bool "Legacy UARTE shim"
depends on UART_NRFX_UARTE
Expand Down
20 changes: 19 additions & 1 deletion drivers/serial/uart_nrfx_uarte.c
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,22 @@ static int uarte_instance_init(const struct device *dev,
return pm_device_driver_init(dev, uarte_nrfx_pm_action);
}

static int uarte_instance_deinit(const struct device *dev)
{
if (IS_ENABLED(CONFIG_PM_DEVICE)) {
enum pm_device_state state;

/* PM must have suspended the device before driver can be deinitialized. */
(void)pm_device_state_get(dev, &state);
return (state == PM_DEVICE_STATE_SUSPENDED) || (state == PM_DEVICE_STATE_OFF) ?
0 : -EBUSY;
}

uarte_pm_suspend(dev);

return 0;
}

#define UARTE_GET_ISR(idx) \
COND_CODE_1(CONFIG_UART_##idx##_ASYNC, (uarte_nrfx_isr_async), (uarte_nrfx_isr_int))

Expand Down Expand Up @@ -2706,8 +2722,10 @@ static int uarte_instance_init(const struct device *dev,
PM_DEVICE_DT_DEFINE(UARTE(idx), uarte_nrfx_pm_action, \
UARTE_PM_ISR_SAFE(idx)); \
\
DEVICE_DT_DEFINE(UARTE(idx), \
DEVICE_DT_DEINIT_DEFINE(UARTE(idx), \
uarte_##idx##_init, \
IS_ENABLED(CONFIG_UART_NRFX_UARTE_DEINIT) ? \
uarte_instance_deinit : NULL, \
PM_DEVICE_DT_GET(UARTE(idx)), \
&uarte_##idx##_data, \
&uarte_##idx##z_config, \
Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/drivers/pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct pinctrl_dev_config {

/** @cond INTERNAL_HIDDEN */

#if !defined(CONFIG_PM) && !defined(CONFIG_PM_DEVICE)
#if !defined(CONFIG_PINCTRL_KEEP_SLEEP_STATE)
/** Out of power management configurations, ignore "sleep" state. */
#define PINCTRL_SKIP_SLEEP 1
#endif
Expand Down