Skip to content

Conversation

nordic-krch
Copy link
Contributor

Add device deinit function. Support is optional as it is not widely used and it enables pinctrl sleep state so it impacts memory footprint.

Additionally, added option to create pinctrl sleep state. So far it was only created when power management was used but in case of deinit it is possible that it is used without PM and we still want to put pins into the default state.

Copy link

@dcpleung dcpleung assigned anangl and unassigned dcpleung Jul 17, 2025
kl-cruz
kl-cruz previously approved these changes Jul 18, 2025
@nvlsianpu
Copy link
Contributor

FYI @bjarki-andreasen

@nordic-krch
Copy link
Contributor Author

@bjarki-andreasen i've added option to keep sleep configuration for pinctrl (so far it was available only when PM was enabled). I think that this option would need to be enabled in SPIM as well as currently deinit will not set pins to the default state.

config UART_NRFX_UARTE_DEINIT
bool "Support deinit"
depends on UART_NRFX_UARTE
imply PINCTRL_KEEP_SLEEP_STATE
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing this on a driver level (all drivers will need sleep states set if deinit is used) extend the base nordic soc Kconfig with:

config PINCTRL_KEEP_SLEEP_STATE
        default y if DEVICE_DEINIT_SUPPORT

this will apply the config soc wide instead of forcing every driver to manually select or imply it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,

Comment on lines 2526 to 2537
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can now be done with

        return pm_device_driver_deinit(dev, uarte_nrfx_pm_action);

which calls uarte_pm_suspend() if needed using the pm_action_hook

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

When PM or PM_DEVICE is enabled pinctrl sleep state is using for
device suspension. However, there are cases where power management is
not used but we still want to be able to put pins to sleep state, e.g.
device deinit.

Signed-off-by: Krzysztof Chruściński <[email protected]>
Add device deinit function. Support is optional as it is not widely
used and it enables pinctrl sleep state so it impacts memory footprint.

Signed-off-by: Krzysztof Chruściński <[email protected]>
Copy link

@kartben kartben merged commit 5e83828 into zephyrproject-rtos:main Aug 22, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Pinctrl area: UART Universal Asynchronous Receiver-Transmitter platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants