Skip to content

Commit 5fd26a6

Browse files
bjarki-andreasenkartben
authored andcommitted
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. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent e5c37d4 commit 5fd26a6

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

drivers/adc/adc_nrfx_saadc.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <zephyr/linker/devicetree_regions.h>
1313
#include <zephyr/logging/log.h>
1414
#include <zephyr/irq.h>
15+
#include <zephyr/pm/device.h>
16+
#include <zephyr/pm/device_runtime.h>
1517
#include <dmm.h>
1618

1719
LOG_MODULE_REGISTER(adc_nrfx_saadc, CONFIG_ADC_LOG_LEVEL);
@@ -724,10 +726,19 @@ static int adc_nrfx_read(const struct device *dev,
724726
{
725727
int error;
726728

729+
error = pm_device_runtime_get(dev);
730+
if (error) {
731+
return error;
732+
}
733+
727734
adc_context_lock(&m_data.ctx, false, NULL);
728735
error = start_read(dev, sequence);
729736
adc_context_release(&m_data.ctx, error);
730737

738+
if (pm_device_runtime_put(dev)) {
739+
LOG_ERR("PM put failed");
740+
}
741+
731742
return error;
732743
}
733744

@@ -777,6 +788,13 @@ static void event_handler(const nrfx_saadc_evt_t *event)
777788
}
778789
}
779790

791+
static int saadc_pm_handler(const struct device *dev, enum pm_device_action action)
792+
{
793+
ARG_UNUSED(dev);
794+
ARG_UNUSED(action);
795+
return 0;
796+
}
797+
780798
static int init_saadc(const struct device *dev)
781799
{
782800
nrfx_err_t err;
@@ -794,7 +812,7 @@ static int init_saadc(const struct device *dev)
794812

795813
adc_context_unlock_unconditionally(&m_data.ctx);
796814

797-
return 0;
815+
return pm_device_driver_init(dev, saadc_pm_handler);
798816
}
799817

800818
static DEVICE_API(adc, adc_nrfx_driver_api) = {
@@ -837,5 +855,7 @@ DT_FOREACH_CHILD(DT_DRV_INST(0), VALIDATE_CHANNEL_CONFIG)
837855

838856
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(0));
839857

840-
DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL,
841-
CONFIG_ADC_INIT_PRIORITY, &adc_nrfx_driver_api);
858+
PM_DEVICE_DT_INST_DEFINE(0, saadc_pm_handler);
859+
DEVICE_DT_INST_DEFINE(0, init_saadc, PM_DEVICE_DT_INST_GET(0), NULL,
860+
NULL, POST_KERNEL, CONFIG_ADC_INIT_PRIORITY,
861+
&adc_nrfx_driver_api);

0 commit comments

Comments
 (0)