Skip to content
Draft
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
26 changes: 23 additions & 3 deletions drivers/adc/adc_nrfx_saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <zephyr/linker/devicetree_regions.h>
#include <zephyr/logging/log.h>
#include <zephyr/irq.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <dmm.h>

LOG_MODULE_REGISTER(adc_nrfx_saadc, CONFIG_ADC_LOG_LEVEL);
Expand Down Expand Up @@ -724,10 +726,19 @@
{
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;
}

Expand Down Expand Up @@ -777,6 +788,13 @@
}
}

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;
Expand All @@ -794,7 +812,7 @@

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) = {
Expand Down Expand Up @@ -837,5 +855,7 @@

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);
16 changes: 14 additions & 2 deletions dts/vendor/nordic/nrf54h20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions soc/nordic/common/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions soc/nordic/nrf54h/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions subsys/pm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion subsys/pm/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 7 additions & 2 deletions subsys/pm/device_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading