From a964742c0f73f5cb9a74092c2e5130add032415b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 29 Sep 2025 09:06:40 +0200 Subject: [PATCH 1/5] [nrf fromlist] soc: nordic: nrf54h: increase default log stack size if CONFIG_PM=y The default log process thread stack size needs to be increased to account for the recursion into resuming power domains, which may happen within char_out for some backends like uart. Upstream PR #: 96695 Signed-off-by: Bjarki Arge Andreasen --- soc/nordic/nrf54h/Kconfig.defconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/soc/nordic/nrf54h/Kconfig.defconfig b/soc/nordic/nrf54h/Kconfig.defconfig index a1b7961f300..3e4c6181098 100644 --- a/soc/nordic/nrf54h/Kconfig.defconfig +++ b/soc/nordic/nrf54h/Kconfig.defconfig @@ -40,6 +40,13 @@ if PM config PM_DEVICE default y +if LOG + +config LOG_PROCESS_THREAD_STACK_SIZE + default 1536 + +endif # LOG + endif # PM if PM_DEVICE From 73b446168be041ae4939297bb9d86919405ab35a Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 29 Sep 2025 11:46:50 +0200 Subject: [PATCH 2/5] [nrf fromlist] drivers: adc: nrfx_saadc: implement PM device runtime The NRFX SAADC device driver needs to implement PM DEVICE for it to work with power domains, which is required for some SoCs. Inline PM device runtime "self get/put" pm has been implemented for the normal sync read API. Upstream PR #: 96711 Signed-off-by: Bjarki Arge Andreasen --- drivers/adc/adc_nrfx_saadc.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 06035e2c3c5..10b13073c23 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include LOG_MODULE_REGISTER(adc_nrfx_saadc, CONFIG_ADC_LOG_LEVEL); @@ -724,10 +726,19 @@ static int adc_nrfx_read(const struct device *dev, { int error; + error = pm_device_runtime_get(dev); + if (error) { + return error; + } + adc_context_lock(&m_data.ctx, false, NULL); error = start_read(dev, sequence); adc_context_release(&m_data.ctx, error); + if (pm_device_runtime_put(dev)) { + LOG_ERR("PM put failed"); + } + return error; } @@ -777,6 +788,13 @@ static void event_handler(const nrfx_saadc_evt_t *event) } } +static int saadc_pm_handler(const struct device *dev, enum pm_device_action action) +{ + ARG_UNUSED(dev); + ARG_UNUSED(action); + return 0; +} + static int init_saadc(const struct device *dev) { nrfx_err_t err; @@ -794,7 +812,7 @@ static int init_saadc(const struct device *dev) adc_context_unlock_unconditionally(&m_data.ctx); - return 0; + return pm_device_driver_init(dev, saadc_pm_handler); } static DEVICE_API(adc, adc_nrfx_driver_api) = { @@ -837,5 +855,7 @@ DT_FOREACH_CHILD(DT_DRV_INST(0), VALIDATE_CHANNEL_CONFIG) NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(0)); -DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL, - CONFIG_ADC_INIT_PRIORITY, &adc_nrfx_driver_api); +PM_DEVICE_DT_INST_DEFINE(0, saadc_pm_handler); +DEVICE_DT_INST_DEFINE(0, init_saadc, PM_DEVICE_DT_INST_GET(0), NULL, + NULL, POST_KERNEL, CONFIG_ADC_INIT_PRIORITY, + &adc_nrfx_driver_api); From 309eab97f6923fc6aeea074c11819870579063f3 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 29 Sep 2025 11:51:05 +0200 Subject: [PATCH 3/5] [nrf fromlist] dts: vendor: nordic: nrf54h: move adc and comp to gdpwr_slow_main The ADC and COMP on the nrf54h20 both have all of their analog inputs routed to pads in different power domains than themselves, this means the device drivers for both of them need to request the pads to be resumed when active to allow any reading of the pads. To keep the drivers simple, we can rely on HW to keep the power domain the COMP and ADC are in powered, which happens automatically when the ADC or COMP is ENABLED. We can then place them on the power domain of their pads in the devicetree. This ensures the pads are powered and not retained while the devices are RESUMED. Upstream PR #: 96711 Signed-off-by: Bjarki Arge Andreasen --- dts/vendor/nordic/nrf54h20.dtsi | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dts/vendor/nordic/nrf54h20.dtsi b/dts/vendor/nordic/nrf54h20.dtsi index 4644cb383ec..05003cf55e8 100644 --- a/dts/vendor/nordic/nrf54h20.dtsi +++ b/dts/vendor/nordic/nrf54h20.dtsi @@ -991,7 +991,13 @@ interrupts = <386 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; #io-channel-cells = <1>; - power-domains = <&gdpwr_slow_active>; + /* + * This device is actually in the gdpwr_slow_active domain, but + * all of its analog inputs are routed to pads in the + * gdpwr_slow_main. Request gdpwr_slow_main and rely on the + * device HW to force its own power domain on while ENABLED. + */ + power-domains = <&gdpwr_slow_main>; zephyr,pm-device-runtime-auto; }; @@ -1004,7 +1010,13 @@ reg = <0x983000 0x1000>; status = "disabled"; interrupts = <387 NRF_DEFAULT_IRQ_PRIORITY>; - power-domains = <&gdpwr_slow_active>; + /* + * This device is actually in the gdpwr_slow_active domain, but + * all of its analog inputs are routed to pads in the + * gdpwr_slow_main. Request gdpwr_slow_main and rely on the + * device HW to force its own power domain on while ENABLED. + */ + power-domains = <&gdpwr_slow_main>; }; temp: temperature-sensor@984000 { From 3e5e4c7058e8b62c74db56e6ce864a2cafa12b05 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 25 Jul 2025 14:18:18 +0200 Subject: [PATCH 4/5] [nrf fromtree] pm: device: runtime: add PM_DEVICE_RUNTIME_DEFAULT_ENABLE Many SoCs which use PM_DEVICE_RUNTIME need every device in the system to have PM_DEVICE_RUNTIME enabled to function. Currently, this is only possible by adding zephyr,pm-device-runtime-auto; to every node in every devicetree which could potentially implement device power management. This is very error prone since its easy to miss a node, especially if users apply overlays, where users need to know and remember to apply or reapply this property. This commit adds a Kconfig, disabled by default, which automatically treats every device as if it had the zephyr,pm-device-runtime-auto property added to every node. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 34c51c5ab47bec2202f3c81c4f87824a6c539c2e) --- subsys/pm/Kconfig | 9 +++++++++ subsys/pm/device.c | 3 ++- subsys/pm/device_runtime.c | 9 +++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/subsys/pm/Kconfig b/subsys/pm/Kconfig index 53c649799cc..eed38a96088 100644 --- a/subsys/pm/Kconfig +++ b/subsys/pm/Kconfig @@ -182,6 +182,15 @@ endif #PM_DEVICE_RUNTIME_USE_DEDICATED_WQ endchoice endif # PM_DEVICE_RUNTIME_ASYNC + +config PM_DEVICE_RUNTIME_DEFAULT_ENABLE + bool "PM device runtime enable by default" + help + Enable PM device runtime by default for all devices when they are + initialized. This option is identical to adding the devicetree + property zephyr,pm-device-runtime-auto to all nodes in the + devicetree. + endif # PM_DEVICE_RUNTIME config PM_DEVICE_SHELL diff --git a/subsys/pm/device.c b/subsys/pm/device.c index 2d7bb3176c3..c74eea661f0 100644 --- a/subsys/pm/device.c +++ b/subsys/pm/device.c @@ -388,7 +388,8 @@ int pm_device_driver_init(const struct device *dev, /* If device will have PM device runtime enabled */ if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) && - atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) { + (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE) || + atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO))) { return 0; } diff --git a/subsys/pm/device_runtime.c b/subsys/pm/device_runtime.c index 490d7de4933..104d1fdb595 100644 --- a/subsys/pm/device_runtime.c +++ b/subsys/pm/device_runtime.c @@ -401,10 +401,15 @@ int pm_device_runtime_auto_enable(const struct device *dev) { struct pm_device_base *pm = dev->pm_base; - /* No action needed if PM_DEVICE_FLAG_RUNTIME_AUTO is not enabled */ - if (!pm || !atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) { + if (!pm) { return 0; } + + if (!IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE) && + !atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) { + return 0; + } + return pm_device_runtime_enable(dev); } From 131e9f78604f060fd76ef49646b8e92028388c21 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 25 Jul 2025 14:24:58 +0200 Subject: [PATCH 5/5] [nrf fromtree] soc: nordic: enable CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE for all Enable CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE by default for all nordic SoCs if CONFIG_PM_DEVICE_RUNTIME is used. This will ensure consistent behavior across all nordic SoCs and remove the need for pasting the devicetree propert zephyr,pm-device-runtime-auto everywhere. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 61a9d6aa45868d65b4d24c257a2799a62fb9d32d) --- soc/nordic/common/Kconfig.defconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soc/nordic/common/Kconfig.defconfig b/soc/nordic/common/Kconfig.defconfig index 077a73ad24d..846151dd11a 100644 --- a/soc/nordic/common/Kconfig.defconfig +++ b/soc/nordic/common/Kconfig.defconfig @@ -6,3 +6,6 @@ if RISCV_CORE_NORDIC_VPR rsource "vpr/Kconfig.defconfig" endif # RISCV_CORE_NORDIC_VPR + +config PM_DEVICE_RUNTIME_DEFAULT_ENABLE + default y if PM_DEVICE_RUNTIME