drivers: adc: stm32: prevent pm while measurement in progress

Prevent PM while ADC measurement in progress.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
This commit is contained in:
Guillaume Gautier 2023-11-15 15:46:28 +01:00 committed by Carles Cufí
commit 20fd6a10e1

View file

@ -20,6 +20,7 @@
#include <zephyr/init.h> #include <zephyr/init.h>
#include <soc.h> #include <soc.h>
#include <zephyr/pm/device.h> #include <zephyr/pm/device.h>
#include <zephyr/pm/policy.h>
#include <stm32_ll_adc.h> #include <stm32_ll_adc.h>
#if defined(CONFIG_SOC_SERIES_STM32U5X) #if defined(CONFIG_SOC_SERIES_STM32U5X)
#include <stm32_ll_pwr.h> #include <stm32_ll_pwr.h>
@ -760,6 +761,8 @@ static void dma_callback(const struct device *dev, void *user_data,
* the address is in a non-cacheable SRAM region. * the address is in a non-cacheable SRAM region.
*/ */
adc_context_on_sampling_done(&data->ctx, dev); adc_context_on_sampling_done(&data->ctx, dev);
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE,
PM_ALL_SUBSTATES);
} else if (status < 0) { } else if (status < 0) {
LOG_ERR("DMA sampling complete, but DMA reported error %d", status); LOG_ERR("DMA sampling complete, but DMA reported error %d", status);
data->dma_error = status; data->dma_error = status;
@ -1060,6 +1063,8 @@ static void adc_stm32_isr(const struct device *dev)
if (++data->samples_count == data->channel_count) { if (++data->samples_count == data->channel_count) {
data->samples_count = 0; data->samples_count = 0;
adc_context_on_sampling_done(&data->ctx, dev); adc_context_on_sampling_done(&data->ctx, dev);
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE,
PM_ALL_SUBSTATES);
} }
} }
@ -1098,6 +1103,7 @@ static int adc_stm32_read(const struct device *dev,
int error; int error;
adc_context_lock(&data->ctx, false, NULL); adc_context_lock(&data->ctx, false, NULL);
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
error = start_read(dev, sequence); error = start_read(dev, sequence);
adc_context_release(&data->ctx, error); adc_context_release(&data->ctx, error);
@ -1113,6 +1119,7 @@ static int adc_stm32_read_async(const struct device *dev,
int error; int error;
adc_context_lock(&data->ctx, true, async); adc_context_lock(&data->ctx, true, async);
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
error = start_read(dev, sequence); error = start_read(dev, sequence);
adc_context_release(&data->ctx, error); adc_context_release(&data->ctx, error);