Skip to content
Merged
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
36 changes: 34 additions & 2 deletions drivers/adc/adc_nrfx_saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <zephyr/dt-bindings/adc/nrf-saadc-v3.h>
#include <zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h>
#include <zephyr/linker/devicetree_regions.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>

#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL
#include <zephyr/logging/log.h>
Expand Down Expand Up @@ -168,6 +170,26 @@ static int adc_convert_acq_time(uint16_t acquisition_time, nrf_saadc_acqtime_t *
return result;
}

static int saadc_pm_hook(const struct device *dev, enum pm_device_action action)
{
ARG_UNUSED(dev);

switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
nrf_saadc_disable(NRF_SAADC);
return 0;

case PM_DEVICE_ACTION_RESUME:
nrf_saadc_enable(NRF_SAADC);
return 0;

default:
break;
}

return -ENOTSUP;
}

/* Implementation of the ADC driver API function: adc_channel_setup. */
static int adc_nrfx_channel_setup(const struct device *dev,
const struct adc_channel_cfg *channel_cfg)
Expand Down Expand Up @@ -320,7 +342,11 @@ static int adc_nrfx_channel_setup(const struct device *dev,

static void adc_context_start_sampling(struct adc_context *ctx)
{
#if defined(CONFIG_PM_DEVICE_RUNTIME)
pm_device_runtime_get(DEVICE_DT_INST_GET(0));
#else
nrf_saadc_enable(NRF_SAADC);
#endif

if (ctx->sequence.calibrate) {
nrf_saadc_task_trigger(NRF_SAADC,
Expand Down Expand Up @@ -623,7 +649,12 @@ static void saadc_irq_handler(const struct device *dev)
nrf_saadc_event_clear(NRF_SAADC, NRF_SAADC_EVENT_END);

nrf_saadc_task_trigger(NRF_SAADC, NRF_SAADC_TASK_STOP);

#if defined(CONFIG_PM_DEVICE_RUNTIME)
pm_device_runtime_put(DEVICE_DT_INST_GET(0));
#else
nrf_saadc_disable(NRF_SAADC);
#endif

if (has_single_ended(&m_data.ctx.sequence)) {
correct_single_ended(&m_data.ctx.sequence);
Expand Down Expand Up @@ -663,7 +694,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_hook);
}

static DEVICE_API(adc, adc_nrfx_driver_api) = {
Expand Down Expand Up @@ -693,9 +724,10 @@ static DEVICE_API(adc, adc_nrfx_driver_api) = {
#define SAADC_INIT(inst) \
BUILD_ASSERT((inst) == 0, \
"multiple instances not supported"); \
PM_DEVICE_DT_INST_DEFINE(0, saadc_pm_hook, 1); \
DEVICE_DT_INST_DEFINE(0, \
init_saadc, \
NULL, \
PM_DEVICE_DT_INST_GET(0), \
NULL, \
NULL, \
POST_KERNEL, \
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52805.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

timer0: timer@40008000 {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52810.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};
timer0: timer@40008000 {
compatible = "nordic,nrf-timer";
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52811.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

timer0: timer@40008000 {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52832.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

timer0: timer@40008000 {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52833.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

timer0: timer@40008000 {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf52840.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

timer0: timer@40008000 {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ adc: adc@e000 {
interrupts = <14 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

timer0: timer@f000 {
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nordic/nrf91_peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ adc: adc@e000 {
interrupts = <14 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

dppic0: dppic: dppic@17000 {
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54h20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@
status = "disabled";
#io-channel-cells = <1>;
power-domains = <&gpd NRF_GPD_SLOW_ACTIVE>;
zephyr,pm-device-runtime-auto;
};

comp: comparator@983000 {
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54l09.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
interrupts = <213 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

temp: temp@d7000 {
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54l20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
interrupts = <213 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

nfct: nfct@d6000 {
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf54l_05_10_15.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@
interrupts = <213 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

nfct: nfct@d6000 {
Expand Down
1 change: 1 addition & 0 deletions dts/common/nordic/nrf9280.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@
interrupts = <386 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
#io-channel-cells = <1>;
zephyr,pm-device-runtime-auto;
};

comp: comparator@983000 {
Expand Down