Skip to content

Commit 7638b2c

Browse files
nordic-krchmstasiaknordic
authored andcommitted
[nrf fromlist] drivers: serial: nrfx_uarte: Add support for device deinit
Add device deinit function. Support is optional as it is not widely used and it enables pinctrl sleep state so it impacts memory footprint. Upstream PR #: 93273 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 6453957 commit 7638b2c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

drivers/serial/Kconfig.nrfx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ config UART_NRFX_UARTE_NO_IRQ
4343
When enabled, then interrupt handler is not used at all and it is possible
4444
to get to the lowest power state after uart_poll_out if receiver is not used.
4545

46+
config UART_NRFX_UARTE_DEINIT
47+
bool "Support deinit"
48+
depends on UART_NRFX_UARTE
49+
imply PINCTRL_KEEP_SLEEP_STATE
50+
help
51+
When enabled then UART driver support device_deinit.
52+
4653
config UART_NRFX_UARTE_LEGACY_SHIM
4754
bool "Legacy UARTE shim"
4855
depends on UART_NRFX_UARTE

drivers/serial/uart_nrfx_uarte.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,22 @@ static int uarte_instance_init(const struct device *dev,
26032603
return pm_device_driver_init(dev, uarte_nrfx_pm_action);
26042604
}
26052605

2606+
static int uarte_instance_deinit(const struct device *dev)
2607+
{
2608+
if (IS_ENABLED(CONFIG_PM_DEVICE)) {
2609+
enum pm_device_state state;
2610+
2611+
/* PM must have suspended the device before driver can be deinitialized. */
2612+
(void)pm_device_state_get(dev, &state);
2613+
return (state == PM_DEVICE_STATE_SUSPENDED) || (state == PM_DEVICE_STATE_OFF) ?
2614+
0 : -EBUSY;
2615+
}
2616+
2617+
uarte_pm_suspend(dev);
2618+
2619+
return 0;
2620+
}
2621+
26062622
#define UARTE_GET_ISR(idx) \
26072623
COND_CODE_1(CONFIG_UART_##idx##_ASYNC, (uarte_nrfx_isr_async), (uarte_nrfx_isr_int))
26082624

@@ -2793,8 +2809,10 @@ static int uarte_instance_init(const struct device *dev,
27932809
PM_DEVICE_DT_DEFINE(UARTE(idx), uarte_nrfx_pm_action, \
27942810
UARTE_PM_ISR_SAFE(idx)); \
27952811
\
2796-
DEVICE_DT_DEFINE(UARTE(idx), \
2812+
DEVICE_DT_DEINIT_DEFINE(UARTE(idx), \
27972813
uarte_##idx##_init, \
2814+
IS_ENABLED(CONFIG_UART_NRFX_UARTE_DEINIT) ? \
2815+
uarte_instance_deinit : NULL, \
27982816
PM_DEVICE_DT_GET(UARTE(idx)), \
27992817
&uarte_##idx##_data, \
28002818
&uarte_##idx##z_config, \

0 commit comments

Comments
 (0)