From 0a0bccabd84dc3109e240d11ba04a22b5968ddb3 Mon Sep 17 00:00:00 2001 From: Ioannis Damigos Date: Mon, 10 Jun 2024 15:35:21 +0300 Subject: [PATCH] drivers/smartbond: Fix PM device runtime support Removed PM device runtime support from drivers in PD_SYS domain. Update the rest device drivers to call pm_device_runtime_get/put() functions when CONFIG_PM_DEVICE_RUNTIME is enabled. Signed-off-by: Ioannis Damigos --- drivers/adc/adc_smartbond_gpadc.c | 38 +++----- drivers/adc/adc_smartbond_sdadc.c | 36 +++---- drivers/counter/counter_smartbond_timer.c | 55 +++++------ drivers/crypto/crypto_smartbond.c | 10 +- drivers/display/display_renesas_lcdc.c | 36 ++++--- drivers/dma/dma_smartbond.c | 9 +- drivers/entropy/entropy_smartbond.c | 16 +-- drivers/i2c/i2c_smartbond.c | 78 +++++++++++---- drivers/memc/memc_smartbond_nor_psram.c | 13 --- drivers/mipi_dbi/mipi_dbi_smartbond.c | 19 +--- drivers/serial/uart_smartbond.c | 97 ++++++++++++++++--- drivers/spi/spi_smartbond.c | 36 +++---- .../smartbond/da1469x/Kconfig.defconfig | 3 + 13 files changed, 238 insertions(+), 208 deletions(-) diff --git a/drivers/adc/adc_smartbond_gpadc.c b/drivers/adc/adc_smartbond_gpadc.c index 367d32110ea..76bdaede510 100644 --- a/drivers/adc/adc_smartbond_gpadc.c +++ b/drivers/adc/adc_smartbond_gpadc.c @@ -41,10 +41,6 @@ struct adc_smartbond_data { uint8_t sequence_channel_count; /* Index in buffer to store current value to */ uint8_t result_index; -#if defined(CONFIG_PM_DEVICE) - /* Flag to prevent sleep */ - ATOMIC_DEFINE(pm_policy_state_flag, 1); -#endif }; #define SMARTBOND_ADC_CHANNEL_COUNT 8 @@ -115,19 +111,12 @@ static int adc_smartbond_channel_setup(const struct device *dev, static inline void gpadc_smartbond_pm_policy_state_lock_get(const struct device *dev, struct adc_smartbond_data *data) { - #if defined(CONFIG_PM_DEVICE) -#if defined(CONFIG_PM_DEVICE_RUNTIME) pm_device_runtime_get(dev); -#endif - - if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) { - /* - * Prevent the SoC from entering the normal sleep state. - */ - pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } - + /* + * Prevent the SoC from entering the normal sleep state. + */ + pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); #endif } @@ -135,17 +124,12 @@ static inline void gpadc_smartbond_pm_policy_state_lock_put(const struct device struct adc_smartbond_data *data) { #if defined(CONFIG_PM_DEVICE) -#if defined(CONFIG_PM_DEVICE_RUNTIME) + /* + * Allow the SoC to enter the normal sleep state once GPADC is done. + */ + pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); pm_device_runtime_put(dev); #endif - - if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) { - /* - * Allow the SoC to enter the normal sleep state once GPADC is done. - */ - pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } -#endif } #define PER_CHANNEL_ADC_CONFIG_MASK (GPADC_GP_ADC_CTRL_REG_GP_ADC_SEL_Msk | \ @@ -259,8 +243,8 @@ static void adc_smartbond_isr(const struct device *dev) data->channel_read_mask ^= 1 << current_channel; if (data->channel_read_mask == 0) { - adc_context_on_sampling_done(&data->ctx, dev); gpadc_smartbond_pm_policy_state_lock_put(dev, data); + adc_context_on_sampling_done(&data->ctx, dev); } else { adc_context_start_sampling(&data->ctx); } @@ -275,8 +259,8 @@ static int adc_smartbond_read(const struct device *dev, int error; struct adc_smartbond_data *data = dev->data; - gpadc_smartbond_pm_policy_state_lock_get(dev, data); adc_context_lock(&data->ctx, false, NULL); + gpadc_smartbond_pm_policy_state_lock_get(dev, data); error = start_read(dev, sequence); adc_context_release(&data->ctx, error); @@ -292,8 +276,8 @@ static int adc_smartbond_read_async(const struct device *dev, struct adc_smartbond_data *data = dev->data; int error; - gpadc_smartbond_pm_policy_state_lock_get(dev, data); adc_context_lock(&data->ctx, true, async); + gpadc_smartbond_pm_policy_state_lock_get(dev, data); error = start_read(dev, sequence); adc_context_release(&data->ctx, error); diff --git a/drivers/adc/adc_smartbond_sdadc.c b/drivers/adc/adc_smartbond_sdadc.c index 5576a65bed1..0b95b1f48ec 100644 --- a/drivers/adc/adc_smartbond_sdadc.c +++ b/drivers/adc/adc_smartbond_sdadc.c @@ -40,10 +40,6 @@ struct sdadc_smartbond_data { uint8_t sequence_channel_count; /* Index in buffer to store current value to */ uint8_t result_index; -#if defined(CONFIG_PM_DEVICE) - /* Flag to prevent sleep */ - ATOMIC_DEFINE(pm_policy_state_flag, 1); -#endif }; #define SMARTBOND_SDADC_CHANNEL_COUNT 8 @@ -119,16 +115,11 @@ static inline void sdadc_smartbond_pm_policy_state_lock_get(const struct device struct sdadc_smartbond_data *data) { #if defined(CONFIG_PM_DEVICE) -#if defined(CONFIG_PM_DEVICE_RUNTIME) pm_device_runtime_get(dev); -#endif - - if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) { - /* - * Prevent the SoC from entering the normal sleep state. - */ - pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } + /* + * Prevent the SoC from entering the normal sleep state. + */ + pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); #endif } @@ -136,17 +127,12 @@ static inline void sdadc_smartbond_pm_policy_state_lock_put(const struct device struct sdadc_smartbond_data *data) { #if defined(CONFIG_PM_DEVICE) -#if defined(CONFIG_PM_DEVICE_RUNTIME) + /* + * Allow the SoC to enter the normal sleep state once sdadc is done. + */ + pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); pm_device_runtime_put(dev); #endif - - if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) { - /* - * Allow the SoC to enter the normal sleep state once sdadc is done. - */ - pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } -#endif } @@ -262,8 +248,8 @@ static void sdadc_smartbond_isr(const struct device *dev) data->channel_read_mask ^= 1 << current_channel; if (data->channel_read_mask == 0) { - adc_context_on_sampling_done(&data->ctx, dev); sdadc_smartbond_pm_policy_state_lock_put(dev, data); + adc_context_on_sampling_done(&data->ctx, dev); } else { adc_context_start_sampling(&data->ctx); } @@ -278,8 +264,8 @@ static int sdadc_smartbond_read(const struct device *dev, int error; struct sdadc_smartbond_data *data = dev->data; - sdadc_smartbond_pm_policy_state_lock_get(dev, data); adc_context_lock(&data->ctx, false, NULL); + sdadc_smartbond_pm_policy_state_lock_get(dev, data); error = start_read(dev, sequence); adc_context_release(&data->ctx, error); @@ -295,8 +281,8 @@ static int sdadc_smartbond_read_async(const struct device *dev, struct sdadc_smartbond_data *data = dev->data; int error; - sdadc_smartbond_pm_policy_state_lock_get(dev, data); adc_context_lock(&data->ctx, true, async); + sdadc_smartbond_pm_policy_state_lock_get(dev, data); error = start_read(dev, sequence); adc_context_release(&data->ctx, error); diff --git a/drivers/counter/counter_smartbond_timer.c b/drivers/counter/counter_smartbond_timer.c index c15bdfad86e..8dc3baba045 100644 --- a/drivers/counter/counter_smartbond_timer.c +++ b/drivers/counter/counter_smartbond_timer.c @@ -35,8 +35,7 @@ struct counter_smartbond_data { void *user_data; uint32_t guard_period; uint32_t freq; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) - ATOMIC_DEFINE(pm_policy_state_flag, 1); +#if defined(CONFIG_PM_DEVICE) uint8_t pdc_idx; #endif }; @@ -59,19 +58,17 @@ struct counter_smartbond_config { LOG_INSTANCE_PTR_DECLARE(log); }; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) -static void counter_smartbond_pm_policy_state_lock_get(struct counter_smartbond_data *data) +#if defined(CONFIG_PM_DEVICE) +static void counter_smartbond_pm_policy_state_lock_get(const struct device *dev) { - if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) { - pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } + pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); + pm_device_runtime_get(dev); } -static void counter_smartbond_pm_policy_state_lock_put(struct counter_smartbond_data *data) +static void counter_smartbond_pm_policy_state_lock_put(const struct device *dev) { - if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) { - pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } + pm_device_runtime_put(dev); + pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); } /* @@ -120,23 +117,18 @@ static void counter_smartbond_pdc_add(const struct device *dev) struct counter_smartbond_data *data = dev->data; uint8_t trigger = counter_smartbond_pdc_trigger_get(dev); - if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) { + data->pdc_idx = da1469x_pdc_add(trigger, MCU_PDC_MASTER_M33, PDC_XTAL_EN); + __ASSERT_NO_MSG(data->pdc_idx >= 0); - data->pdc_idx = da1469x_pdc_add(trigger, MCU_PDC_MASTER_M33, PDC_XTAL_EN); - __ASSERT_NO_MSG(data->pdc_idx >= 0); - - da1469x_pdc_set(data->pdc_idx); - da1469x_pdc_ack(data->pdc_idx); - } + da1469x_pdc_set(data->pdc_idx); + da1469x_pdc_ack(data->pdc_idx); } static void counter_smartbond_pdc_del(const struct device *dev) { struct counter_smartbond_data *data = dev->data; - if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) { - da1469x_pdc_del(data->pdc_idx); - } + da1469x_pdc_del(data->pdc_idx); } #endif @@ -145,24 +137,23 @@ static int counter_smartbond_start(const struct device *dev) const struct counter_smartbond_config *config = dev->config; TIMER2_Type *timer = config->timer; - /* Enable counter in free running mode */ - timer->TIMER2_CTRL_REG |= (TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk | - TIMER2_TIMER2_CTRL_REG_TIM_EN_Msk | - TIMER2_TIMER2_CTRL_REG_TIM_FREE_RUN_MODE_EN_Msk); - -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) if (!counter_smartbond_is_sleep_allowed(dev)) { - struct counter_smartbond_data *data = dev->data; /* * Power mode constraints should be applied as long as the device * is up and running. */ - counter_smartbond_pm_policy_state_lock_get(data); + counter_smartbond_pm_policy_state_lock_get(dev); } else { counter_smartbond_pdc_add(dev); } #endif + /* Enable counter in free running mode */ + timer->TIMER2_CTRL_REG |= (TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk | + TIMER2_TIMER2_CTRL_REG_TIM_EN_Msk | + TIMER2_TIMER2_CTRL_REG_TIM_FREE_RUN_MODE_EN_Msk); + return 0; } @@ -178,9 +169,9 @@ static int counter_smartbond_stop(const struct device *dev) TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk); data->callback = NULL; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) if (!counter_smartbond_is_sleep_allowed(dev)) { - counter_smartbond_pm_policy_state_lock_put(data); + counter_smartbond_pm_policy_state_lock_put(dev); } else { counter_smartbond_pdc_del(dev); } @@ -421,7 +412,7 @@ static uint32_t counter_smartbond_get_freq(const struct device *dev) return data->freq; } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static void counter_smartbond_resume(const struct device *dev) { const struct counter_smartbond_config *cfg = dev->config; diff --git a/drivers/crypto/crypto_smartbond.c b/drivers/crypto/crypto_smartbond.c index 7b8e33799b5..9899f46dd33 100644 --- a/drivers/crypto/crypto_smartbond.c +++ b/drivers/crypto/crypto_smartbond.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -936,7 +935,7 @@ static const struct crypto_driver_api crypto_smartbond_driver_api = { .query_hw_caps = crypto_smartbond_query_hw_caps }; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static int crypto_smartbond_pm_action(const struct device *dev, enum pm_device_action action) { @@ -984,14 +983,7 @@ static int crypto_smartbond_init(const struct device *dev) /* Controller should be initialized once a crypyographic session is requested */ crypto_smartbond_set_status(false); -#ifdef CONFIG_PM_DEVICE_RUNTIME - /* Make sure device state is marked as suspended */ - pm_device_init_suspended(dev); - - return pm_device_runtime_enable(dev); -#else return 0; -#endif } /* diff --git a/drivers/display/display_renesas_lcdc.c b/drivers/display/display_renesas_lcdc.c index a5d3d412a1a..6121f683476 100644 --- a/drivers/display/display_renesas_lcdc.c +++ b/drivers/display/display_renesas_lcdc.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -75,7 +74,7 @@ struct display_smartbond_data { struct k_sem dma_sync_sem; /* Granted DMA channel used for memory transfers */ int dma_channel; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) ATOMIC_DEFINE(pm_policy_state_flag, 1); #endif }; @@ -101,7 +100,7 @@ struct display_smartbond_config { static inline void lcdc_smartbond_pm_policy_state_lock_get(struct display_smartbond_data *data) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#ifdef CONFIG_PM_DEVICE if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) { /* * Prevent the SoC from etering the normal sleep state as PDC does not support @@ -114,7 +113,7 @@ static inline void lcdc_smartbond_pm_policy_state_lock_get(struct display_smartb static inline void lcdc_smartbond_pm_policy_state_lock_put(struct display_smartbond_data *data) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#ifdef CONFIG_PM_DEVICE if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) { /* Allow the SoC to enter the nornmal sleep state once LCDC is inactive */ pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); @@ -236,6 +235,7 @@ static int display_smartbond_dma_config(const struct device *dev) data->dma_cfg.dma_callback = display_smartbond_dma_cb; data->dma_cfg.block_count = 1; data->dma_cfg.head_block = &data->dma_block_cfg; + data->dma_cfg.error_callback_dis = 1; /* Request an arbitrary DMA channel */ data->dma_channel = dma_request_channel(data->dma, NULL); @@ -282,7 +282,7 @@ static int display_smartbond_resume(const struct device *dev) return display_smartbond_configure(dev); } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static void display_smartbond_dma_deconfig(const struct device *dev) { struct display_smartbond_data *data = dev->data; @@ -337,19 +337,27 @@ static int display_smartbond_init(const struct device *dev) IRQ_CONNECT(SMARTBOND_IRQN, SMARTBOND_IRQ_PRIO, smartbond_display_isr, DEVICE_DT_INST_GET(0), 0); -#ifdef CONFIG_PM_DEVICE_RUNTIME - /* Make sure device state is marked as suspended */ - pm_device_init_suspended(dev); - - ret = pm_device_runtime_enable(dev); -#else - /* Resume if either PM is not used at all or if PM without runtime is used. */ + /* + * Currently, there is no API to explicitly enable/disable the display controller. + * At the same time, the controller is set to continuous mode meaning that + * as long as a display panel is turned on, frame updates should happen all + * the time (otherwise contents on the display pane will be lost as the latter + * does not integrate an SDRAM memory to keep its frame). + * As such, resume/suspend operations are bound to blanking operations. + * That is, when the display is blanked on we can safely consider that display + * is no longer functional and thus, the controller can be suspended (allowing the + * SoC to enter the sleep state). Once the display is blanked off, then we consider + * that the controller should be resumed and sleep should be prevented at all + * (this is because the controller is powered by the same power domain used to + * power the application core). Side effect of the above is that the controller + * should be configured at initialization phase as display operations might + * be requested before the display is blanked off for the very first time. + */ ret = display_smartbond_resume(dev); if (ret == 0) { /* Display port should be enabled at this moment and so sleep is not allowed. */ lcdc_smartbond_pm_policy_state_lock_get(data); } -#endif return ret; } @@ -581,7 +589,7 @@ static int display_smartbond_write(const struct device *dev, return 0; } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static int display_smartbond_pm_action(const struct device *dev, enum pm_device_action action) { int ret = 0; diff --git a/drivers/dma/dma_smartbond.c b/drivers/dma/dma_smartbond.c index 493ac222836..9294197df63 100644 --- a/drivers/dma/dma_smartbond.c +++ b/drivers/dma/dma_smartbond.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -158,7 +157,7 @@ struct dma_smartbond_data { ATOMIC_DEFINE(channels_atomic, DMA_CHANNELS_COUNT); -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) ATOMIC_DEFINE(pm_policy_state_flag, 1); #endif @@ -185,7 +184,7 @@ static bool dma_smartbond_is_dma_active(void) static inline void dma_smartbond_pm_policy_state_lock_get(const struct device *dev) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) struct dma_smartbond_data *data = dev->data; if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) { @@ -196,7 +195,7 @@ static inline void dma_smartbond_pm_policy_state_lock_get(const struct device *d static inline void dma_smartbond_pm_policy_state_lock_put(const struct device *dev) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) struct dma_smartbond_data *data = dev->data; /* Make PM lock put has a matched PM lock get invocation */ @@ -965,7 +964,7 @@ static void smartbond_dma_isr(const void *arg) } } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static bool dma_smartbond_is_sleep_allowed(const struct device *dev) { struct dma_smartbond_data *data = dev->data; diff --git a/drivers/entropy/entropy_smartbond.c b/drivers/entropy/entropy_smartbond.c index fecb7b07491..24c57317a72 100644 --- a/drivers/entropy/entropy_smartbond.c +++ b/drivers/entropy/entropy_smartbond.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -48,7 +47,7 @@ struct entropy_smartbond_dev_data { RNG_POOL_DEFINE(isr, CONFIG_ENTROPY_SMARTBOND_ISR_POOL_SIZE); RNG_POOL_DEFINE(thr, CONFIG_ENTROPY_SMARTBOND_THR_POOL_SIZE); -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) ATOMIC_DEFINE(pm_policy_state_flag, 1); #endif }; @@ -64,7 +63,7 @@ static struct entropy_smartbond_dev_data entropy_smartbond_data; static inline void entropy_smartbond_pm_policy_state_lock_get(const struct device *dev) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) struct entropy_smartbond_dev_data *data = dev->data; if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) { @@ -79,7 +78,7 @@ static inline void entropy_smartbond_pm_policy_state_lock_get(const struct devic static inline void entropy_smartbond_pm_policy_state_lock_put(const struct device *dev) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) struct entropy_smartbond_dev_data *data = dev->data; if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) { @@ -379,7 +378,7 @@ static int entropy_smartbond_get_entropy_isr(const struct device *dev, uint8_t * return cnt; } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static int entropy_smartbond_pm_action(const struct device *dev, enum pm_device_action action) { int ret = 0; @@ -433,13 +432,6 @@ static int entropy_smartbond_init(const struct device *dev) trng_enable(true); -#ifdef CONFIG_PM_DEVICE_RUNTIME - /* Make sure device state is marked as suspended */ - pm_device_init_suspended(dev); - - return pm_device_runtime_enable(dev); -#endif - return 0; } diff --git a/drivers/i2c/i2c_smartbond.c b/drivers/i2c/i2c_smartbond.c index 2c3e6141641..22c809432b0 100644 --- a/drivers/i2c/i2c_smartbond.c +++ b/drivers/i2c/i2c_smartbond.c @@ -35,14 +35,14 @@ struct i2c_smartbond_data { uint32_t transmit_cnt, receive_cnt; i2c_callback_t cb; void *userdata; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) ATOMIC_DEFINE(pm_policy_state_flag, 1); #endif }; -static inline void i2c_smartbond_pm_policy_state_lock_get(struct i2c_smartbond_data *data) +#if defined(CONFIG_PM_DEVICE) +static inline void i2c_smartbond_pm_prevent_system_sleep(struct i2c_smartbond_data *data) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) { /* * Prevent the SoC from etering the normal sleep state as PDC does not support @@ -50,18 +50,38 @@ static inline void i2c_smartbond_pm_policy_state_lock_get(struct i2c_smartbond_d */ pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); } -#endif } -static inline void i2c_smartbond_pm_policy_state_lock_put(struct i2c_smartbond_data *data) +static inline void i2c_smartbond_pm_allow_system_sleep(struct i2c_smartbond_data *data) { -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) { /* * Allow the SoC to enter the nornmal sleep state once I2C transactions are done. */ pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); } +} +#endif + +static inline void i2c_smartbond_pm_policy_state_lock_get(const struct device *dev) +{ +#ifdef CONFIG_PM_DEVICE +#ifdef CONFIG_PM_DEVICE_RUNTIME + pm_device_runtime_get(dev); +#else + i2c_smartbond_pm_prevent_system_sleep(dev->data); +#endif +#endif +} + +static inline void i2c_smartbond_pm_policy_state_lock_put(const struct device *dev) +{ +#ifdef CONFIG_PM_DEVICE +#ifdef CONFIG_PM_DEVICE_RUNTIME + pm_device_runtime_put(dev); +#else + i2c_smartbond_pm_allow_system_sleep(dev->data); +#endif #endif } @@ -86,7 +106,7 @@ static void i2c_smartbond_disable_when_inactive(const struct device *dev) } } -static int i2c_smartbond_configure(const struct device *dev, uint32_t dev_config) +static int i2c_smartbond_apply_configure(const struct device *dev, uint32_t dev_config) { const struct i2c_smartbond_cfg *config = dev->config; struct i2c_smartbond_data *data = dev->data; @@ -141,6 +161,17 @@ static int i2c_smartbond_configure(const struct device *dev, uint32_t dev_config return 0; } +static int i2c_smartbond_configure(const struct device *dev, uint32_t dev_config) +{ + int ret = 0; + + pm_device_runtime_get(dev); + ret = i2c_smartbond_apply_configure(dev, dev_config); + pm_device_runtime_put(dev); + + return ret; +} + static int i2c_smartbond_get_config(const struct device *dev, uint32_t *dev_config) { const struct i2c_smartbond_cfg *config = dev->config; @@ -148,8 +179,10 @@ static int i2c_smartbond_get_config(const struct device *dev, uint32_t *dev_conf uint32_t reg; k_spinlock_key_t key = k_spin_lock(&data->lock); + pm_device_runtime_get(dev); /* Read the value of the control register */ reg = config->regs->I2C_CON_REG; + pm_device_runtime_put(dev); k_spin_unlock(&data->lock, key); @@ -288,9 +321,6 @@ static inline int i2c_smartbond_tx(const struct i2c_smartbond_cfg *const config, } } - while (!(config->regs->I2C_STATUS_REG & I2C_I2C_STATUS_REG_TFE_Msk)) { - }; - if (config->regs->I2C_TX_ABRT_SOURCE_REG & 0x1FFFF) { ret = -EIO; } @@ -336,16 +366,13 @@ static int i2c_smartbond_transfer(const struct device *dev, struct i2c_msg *msgs struct i2c_smartbond_data *data = dev->data; int ret = 0; - while (!i2c_smartbond_is_idle(dev)) { - }; + i2c_smartbond_pm_policy_state_lock_get(dev); ret = i2c_smartbond_prep_transfer(dev, msgs, num_msgs, addr); if (ret != 0) { - return ret; + goto finish; } - i2c_smartbond_pm_policy_state_lock_get(data); - for (; data->num_msgs > 0; data->num_msgs--, data->msgs++) { data->transmit_cnt = 0; data->receive_cnt = 0; @@ -375,7 +402,9 @@ static int i2c_smartbond_transfer(const struct device *dev, struct i2c_msg *msgs } finish: - i2c_smartbond_pm_policy_state_lock_put(data); + while (!i2c_smartbond_is_idle(dev)) { + }; + i2c_smartbond_pm_policy_state_lock_put(dev); return ret; } @@ -425,13 +454,14 @@ static int i2c_smartbond_transfer_cb(const struct device *dev, struct i2c_msg *m data->cb = cb; data->userdata = userdata; + i2c_smartbond_pm_policy_state_lock_get(dev); + ret = i2c_smartbond_prep_transfer(dev, msgs, num_msgs, addr); if (ret != 0) { + i2c_smartbond_pm_policy_state_lock_put(dev); return ret; } - i2c_smartbond_pm_policy_state_lock_get(data); - i2c_smartbond_enable_msg_interrupts(config, data); LOG_INF("async transfer started"); @@ -496,7 +526,7 @@ static inline void i2c_smartbond_async_msg_done(const struct device *dev) data->cb = NULL; LOG_INF("async transfer finished"); cb(dev, 0, data->userdata); - i2c_smartbond_pm_policy_state_lock_put(data); + i2c_smartbond_pm_policy_state_lock_put(dev); } } @@ -567,11 +597,11 @@ static int i2c_smartbond_resume(const struct device *dev) return err; } - return i2c_smartbond_configure(dev, + return i2c_smartbond_apply_configure(dev, I2C_MODE_CONTROLLER | i2c_map_dt_bitrate(config->bitrate)); } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static int i2c_smartbond_suspend(const struct device *dev) { int ret; @@ -597,6 +627,9 @@ static int i2c_smartbond_pm_action(const struct device *dev, switch (action) { case PM_DEVICE_ACTION_RESUME: +#ifdef CONFIG_PM_DEVICE_RUNTIME + i2c_smartbond_pm_prevent_system_sleep(dev->data); +#endif /* * Although the GPIO driver should already be initialized, make sure PD_COM * is up and running before accessing the I2C block. @@ -611,6 +644,9 @@ static int i2c_smartbond_pm_action(const struct device *dev, * be released, as well. */ da1469x_pd_release(MCU_PD_DOMAIN_COM); +#ifdef CONFIG_PM_DEVICE_RUNTIME + i2c_smartbond_pm_allow_system_sleep(dev->data); +#endif break; default: return -ENOTSUP; diff --git a/drivers/memc/memc_smartbond_nor_psram.c b/drivers/memc/memc_smartbond_nor_psram.c index 37584f99dcc..2d0ae79e5fa 100644 --- a/drivers/memc/memc_smartbond_nor_psram.c +++ b/drivers/memc/memc_smartbond_nor_psram.c @@ -173,23 +173,10 @@ static int memc_smartbond_init(const struct device *dev) /* Should be called prior to switching to auto mode and when the quad bus is selected! */ da1469x_qspi_set_bus_mode(QSPIC2_ID, QSPI_BUS_MODE_QUAD); -#if CONFIG_PM_DEVICE_RUNTIME - /* - * Turn off the controller to minimize power consumption. Application is responsible to - * configure/de-configure the controller before interacting with the memory. - */ - memc_set_status(false, 0); - - /* Make sure device is marked as suspended */ - pm_device_init_suspended(dev); - - return pm_device_runtime_enable(dev); -#else da1469x_pd_acquire(MCU_PD_DOMAIN_SYS); /* From this point onwards memory device should be seen as memory mapped device. */ memc_automode_configure(); -#endif return 0; } diff --git a/drivers/mipi_dbi/mipi_dbi_smartbond.c b/drivers/mipi_dbi/mipi_dbi_smartbond.c index da0e5e154ce..f6f6ce139fa 100644 --- a/drivers/mipi_dbi/mipi_dbi_smartbond.c +++ b/drivers/mipi_dbi/mipi_dbi_smartbond.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -293,7 +292,7 @@ static int mipi_dbi_smartbond_command_write(const struct device *dev, size_t len) { struct mipi_dbi_smartbond_data *data = dev->data; - int ret; + int ret = 0; lcdc_smartbond_mipi_dbi_cfg mipi_dbi_cfg; k_sem_take(&data->device_sem, K_FOREVER); @@ -307,8 +306,7 @@ static int mipi_dbi_smartbond_command_write(const struct device *dev, lcdc_smartbond_mipi_dbi_translation(dbi_config, &mipi_dbi_cfg, PIXEL_FORMAT_RGB_565); ret = da1469x_lcdc_mipi_dbi_interface_configure(&mipi_dbi_cfg); if (ret < 0) { - k_sem_give(&data->device_sem); - return ret; + goto finish; } /* Command and accompanied data should be transmitted via the DBIB interface */ @@ -319,11 +317,12 @@ static int mipi_dbi_smartbond_command_write(const struct device *dev, da1469x_lcdc_send_cmd_data(false, data_buf, len); } +finish: mipi_dbi_smartbond_pm_policy_state_lock_put(); k_sem_give(&data->device_sem); - return 0; + return ret; } static int mipi_dbi_smartbond_write_display(const struct device *dev, @@ -466,7 +465,7 @@ static int mipi_dbi_smartbond_resume(const struct device *dev) return mipi_dbi_smartbond_configure(dev); } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME) +#if defined(CONFIG_PM_DEVICE) static int mipi_dbi_smartbond_suspend(const struct device *dev) { const struct mipi_dbi_smartbond_config *config = dev->config; @@ -532,15 +531,7 @@ static int mipi_dbi_smartbond_init(const struct device *dev) IRQ_CONNECT(SMARTBOND_IRQN, SMARTBOND_IRQ_PRIO, smartbond_mipi_dbi_isr, DEVICE_DT_INST_GET(0), 0); -#ifdef CONFIG_PM_DEVICE_RUNTIME - /* Make sure device state is marked as suspended */ - pm_device_init_suspended(dev); - - ret = pm_device_runtime_enable(dev); -#else - /* Resme if either PM is not used at all or if PM without runtime is used. */ ret = mipi_dbi_smartbond_resume(dev); -#endif return ret; } diff --git a/drivers/serial/uart_smartbond.c b/drivers/serial/uart_smartbond.c index 8656ae8dc43..6aaec5025c8 100644 --- a/drivers/serial/uart_smartbond.c +++ b/drivers/serial/uart_smartbond.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -111,7 +112,7 @@ struct uart_smartbond_data { uint8_t tx_enabled; #if CONFIG_PM_DEVICE struct gpio_callback dtr_wake_cb; - const struct uart_smartbond_cfg *config; + const struct device *dev; struct gpio_callback rx_wake_cb; int rx_wake_timeout; struct k_work_delayable rx_timeout_work; @@ -121,30 +122,48 @@ struct uart_smartbond_data { #endif }; -#if defined(CONFIG_PM_DEVICE) - -static void uart_smartbond_pm_policy_state_lock_get(struct uart_smartbond_data *data, int flag) +#ifdef CONFIG_PM_DEVICE +static inline void uart_smartbond_pm_prevent_system_sleep(struct uart_smartbond_data *data, + int flag) { if (atomic_test_and_set_bit(data->pm_policy_state_flag, flag) == 0) { pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); } } -static void uart_smartbond_pm_policy_state_lock_put(struct uart_smartbond_data *data, int flag) +static inline void uart_smartbond_pm_allow_system_sleep(struct uart_smartbond_data *data, + int flag) { if (atomic_test_and_clear_bit(data->pm_policy_state_flag, flag) == 1) { pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); } } +static void uart_smartbond_pm_policy_state_lock_get(const struct device *dev, int flag) +{ +#ifdef CONFIG_PM_DEVICE_RUNTIME + pm_device_runtime_get(dev); +#else + uart_smartbond_pm_prevent_system_sleep(dev->data, flag); +#endif +} + +static void uart_smartbond_pm_policy_state_lock_put(const struct device *dev, int flag) +{ +#ifdef CONFIG_PM_DEVICE_RUNTIME + pm_device_runtime_put(dev); +#else + uart_smartbond_pm_allow_system_sleep(dev->data, flag); +#endif +} + static void uart_smartbond_rx_refresh_timeout(struct k_work *work) { struct uart_smartbond_data *data = CONTAINER_OF(work, struct uart_smartbond_data, rx_timeout_work.work); - uart_smartbond_pm_policy_state_lock_put(data, UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG); + uart_smartbond_pm_policy_state_lock_put(data->dev, UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG); } - #endif static int uart_smartbond_poll_in(const struct device *dev, unsigned char *p_char) @@ -153,13 +172,17 @@ static int uart_smartbond_poll_in(const struct device *dev, unsigned char *p_cha struct uart_smartbond_data *data = dev->data; k_spinlock_key_t key = k_spin_lock(&data->lock); + pm_device_runtime_get(dev); + if ((config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_RFNE_Msk) == 0) { + pm_device_runtime_put(dev); k_spin_unlock(&data->lock, key); return -1; } *p_char = config->regs->UART2_RBR_THR_DLL_REG; + pm_device_runtime_put(dev); k_spin_unlock(&data->lock, key); return 0; @@ -171,12 +194,16 @@ static void uart_smartbond_poll_out(const struct device *dev, unsigned char out_ struct uart_smartbond_data *data = dev->data; k_spinlock_key_t key = k_spin_lock(&data->lock); + pm_device_runtime_get(dev); + while (!(config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_TFNF_Msk)) { /* Wait until FIFO has free space */ } config->regs->UART2_RBR_THR_DLL_REG = out_char; + pm_device_runtime_put(dev); + k_spin_unlock(&data->lock, key); } @@ -287,7 +314,9 @@ static int uart_smartbond_configure(const struct device *dev, data->runtime_cfg.lcr_reg_val = lcr_reg_val; data->runtime_cfg.mcr_reg_val = cfg->flow_ctrl ? UART2_UART2_MCR_REG_UART_AFCE_Msk : 0; + pm_device_runtime_get(dev); apply_runtime_config(dev); + pm_device_runtime_put(dev); data->current_config = *cfg; @@ -324,8 +353,7 @@ static void uart_smartbond_wake_handler(const struct device *gpio, struct gpio_c GPIO_INT_DISABLE); /* Refresh console expired time */ if (data->rx_wake_timeout) { - - uart_smartbond_pm_policy_state_lock_get(data, + uart_smartbond_pm_policy_state_lock_get(data->dev, UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG); k_work_reschedule(&data->rx_timeout_work, K_MSEC(data->rx_wake_timeout)); } @@ -339,10 +367,10 @@ static void uart_smartbond_dtr_handler(const struct device *gpio, struct gpio_ca int pin = find_lsb_set(pins) - 1; if (gpio_pin_get(gpio, pin) == 1) { - uart_smartbond_pm_policy_state_lock_put(data, + uart_smartbond_pm_policy_state_lock_put(data->dev, UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG); } else { - uart_smartbond_pm_policy_state_lock_get(data, + uart_smartbond_pm_policy_state_lock_get(data->dev, UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG); } } @@ -354,13 +382,21 @@ static int uart_smartbond_init(const struct device *dev) struct uart_smartbond_data *data = dev->data; int ret = 0; +#ifdef CONFIG_PM_DEVICE_RUNTIME + /* Make sure device state is marked as suspended */ + pm_device_init_suspended(dev); + + ret = pm_device_runtime_enable(dev); +#else da1469x_pd_acquire(MCU_PD_DOMAIN_COM); +#endif #ifdef CONFIG_PM_DEVICE int rx_wake_timeout; const struct uart_smartbond_cfg *config = dev->config; const struct device *uart_console_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); + data->dev = dev; /* All uarts can have wake time specified in device tree to keep * device awake after receiving data */ @@ -384,7 +420,7 @@ static int uart_smartbond_init(const struct device *dev) GPIO_INT_TRIG_BOTH); /* Check if DTR is already active (low), if so lock power state */ if (gpio_pin_get(config->dtr_gpio.port, config->dtr_gpio.pin) == 0) { - uart_smartbond_pm_policy_state_lock_get(data, + uart_smartbond_pm_policy_state_lock_get(dev, UART_SMARTBOND_PM_POLICY_STATE_DTR_FLAG); } } @@ -403,9 +439,11 @@ static int uart_smartbond_init(const struct device *dev) #endif ret = uart_smartbond_configure(dev, &data->current_config); +#ifndef CONFIG_PM_DEVICE_RUNTIME if (ret < 0) { da1469x_pd_release(MCU_PD_DOMAIN_COM); } +#endif return ret; } @@ -414,31 +452,39 @@ static int uart_smartbond_init(const struct device *dev) static inline void irq_tx_enable(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; + struct uart_smartbond_data *data = dev->data; config->regs->UART2_IER_DLH_REG |= UART2_UART2_IER_DLH_REG_PTIME_DLH7_Msk | UART2_UART2_IER_DLH_REG_ETBEI_DLH1_Msk; + data->runtime_cfg.ier_reg_val = config->regs->UART2_IER_DLH_REG; } static inline void irq_tx_disable(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; + struct uart_smartbond_data *data = dev->data; config->regs->UART2_IER_DLH_REG &= ~(UART2_UART2_IER_DLH_REG_PTIME_DLH7_Msk | - UART2_UART2_IER_DLH_REG_ETBEI_DLH1_Msk); + UART2_UART2_IER_DLH_REG_ETBEI_DLH1_Msk); + data->runtime_cfg.ier_reg_val = config->regs->UART2_IER_DLH_REG; } static inline void irq_rx_enable(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; + struct uart_smartbond_data *data = dev->data; config->regs->UART2_IER_DLH_REG |= UART2_UART2_IER_DLH_REG_ERBFI_DLH0_Msk; + data->runtime_cfg.ier_reg_val = config->regs->UART2_IER_DLH_REG; } static inline void irq_rx_disable(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; + struct uart_smartbond_data *data = dev->data; config->regs->UART2_IER_DLH_REG &= ~UART2_UART2_IER_DLH_REG_ERBFI_DLH0_Msk; + data->runtime_cfg.ier_reg_val = config->regs->UART2_IER_DLH_REG; } static int uart_smartbond_fifo_fill(const struct device *dev, @@ -450,6 +496,7 @@ static int uart_smartbond_fifo_fill(const struct device *dev, int num_tx = 0; k_spinlock_key_t key = k_spin_lock(&data->lock); + pm_device_runtime_get(dev); while ((len - num_tx > 0) && (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_TFNF_Msk)) { config->regs->UART2_RBR_THR_DLL_REG = tx_data[num_tx++]; @@ -459,6 +506,7 @@ static int uart_smartbond_fifo_fill(const struct device *dev, irq_tx_enable(dev); } + pm_device_runtime_put(dev); k_spin_unlock(&data->lock, key); return num_tx; @@ -472,6 +520,7 @@ static int uart_smartbond_fifo_read(const struct device *dev, uint8_t *rx_data, int num_rx = 0; k_spinlock_key_t key = k_spin_lock(&data->lock); + pm_device_runtime_get(dev); while ((size - num_rx > 0) && (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_RFNE_Msk)) { rx_data[num_rx++] = config->regs->UART2_RBR_THR_DLL_REG; @@ -486,6 +535,8 @@ static int uart_smartbond_fifo_read(const struct device *dev, uint8_t *rx_data, k_work_reschedule(&data->rx_timeout_work, K_MSEC(data->rx_wake_timeout)); } #endif + + pm_device_runtime_put(dev); k_spin_unlock(&data->lock, key); return num_rx; @@ -517,7 +568,9 @@ static int uart_smartbond_irq_tx_ready(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; - return (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_TFNF_Msk) != 0; + bool ret = (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_TFNF_Msk) != 0; + + return ret; } static void uart_smartbond_irq_rx_enable(const struct device *dev) @@ -546,14 +599,18 @@ static int uart_smartbond_irq_tx_complete(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; - return (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_TFE_Msk) != 0; + bool ret = (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_TFE_Msk) != 0; + + return ret; } static int uart_smartbond_irq_rx_ready(const struct device *dev) { const struct uart_smartbond_cfg *config = dev->config; - return (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_RFNE_Msk) != 0; + bool ret = (config->regs->UART2_USR_REG & UART2_UART2_USR_REG_UART_RFNE_Msk) != 0; + + return ret; } static void uart_smartbond_irq_err_enable(const struct device *dev) @@ -659,6 +716,10 @@ static int uart_smartbond_pm_action(const struct device *dev, switch (action) { case PM_DEVICE_ACTION_RESUME: +#ifdef CONFIG_PM_DEVICE_RUNTIME + uart_smartbond_pm_prevent_system_sleep(dev->data, + UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG); +#endif da1469x_pd_acquire(MCU_PD_DOMAIN_COM); apply_runtime_config(dev); break; @@ -670,6 +731,10 @@ static int uart_smartbond_pm_action(const struct device *dev, GPIO_INT_MODE_EDGE | GPIO_INT_TRIG_LOW); } +#ifdef CONFIG_PM_DEVICE_RUNTIME + uart_smartbond_pm_allow_system_sleep(dev->data, + UART_SMARTBOND_PM_POLICY_STATE_RX_FLAG); +#endif break; default: ret = -ENOTSUP; diff --git a/drivers/spi/spi_smartbond.c b/drivers/spi/spi_smartbond.c index f067da9c0a0..2bae051c01a 100644 --- a/drivers/spi/spi_smartbond.c +++ b/drivers/spi/spi_smartbond.c @@ -71,7 +71,6 @@ struct spi_smartbond_data { uint8_t dfs; #if defined(CONFIG_PM_DEVICE) - ATOMIC_DEFINE(pm_policy_state_flag, 1); uint32_t spi_ctrl_reg; #endif @@ -225,28 +224,26 @@ static inline int spi_smartbond_set_word_size(const struct spi_smartbond_cfg *cf return 0; } -static inline void spi_smartbond_pm_policy_state_lock_get(struct spi_smartbond_data *data) +static inline void spi_smartbond_pm_policy_state_lock_get(const struct device *dev) { #if defined(CONFIG_PM_DEVICE) - if (atomic_test_and_set_bit(data->pm_policy_state_flag, 0) == 0) { - /* - * Prevent the SoC from entering the normal sleep state as PDC does not support - * waking up the application core following SPI events. - */ - pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } + /* + * Prevent the SoC from entering the normal sleep state as PDC does not support + * waking up the application core following SPI events. + */ + pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES); + pm_device_runtime_get(dev); #endif } -static inline void spi_smartbond_pm_policy_state_lock_put(struct spi_smartbond_data *data) +static inline void spi_smartbond_pm_policy_state_lock_put(const struct device *dev) { #if defined(CONFIG_PM_DEVICE) - if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0) == 1) { - /* - * Allow the SoC to enter the normal sleep state once SPI transactions are done. - */ - pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); - } + pm_device_runtime_put(dev); + /* + * Allow the SoC to enter the normal sleep state once SPI transactions are done. + */ + pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES); #endif } @@ -604,10 +601,10 @@ static int spi_smartbond_transceive_async(const struct device *dev, int rc; spi_context_lock(ctx, true, cb, userdata, spi_cfg); + spi_smartbond_pm_policy_state_lock_get(dev); rc = spi_smartbond_configure(cfg, data, spi_cfg); if (rc == 0) { - spi_smartbond_pm_policy_state_lock_get(data); spi_context_buffers_setup(ctx, tx_bufs, rx_bufs, data->dfs); spi_context_cs_control(ctx, true); @@ -1054,9 +1051,8 @@ static int spi_smartbond_transceive(const struct device *dev, const struct spi_c struct spi_context *ctx = &data->ctx; int rc; - spi_smartbond_pm_policy_state_lock_get(data); - spi_context_lock(&data->ctx, false, NULL, NULL, spi_cfg); + spi_smartbond_pm_policy_state_lock_get(dev); rc = spi_smartbond_configure(cfg, data, spi_cfg); if (rc == 0) { @@ -1099,7 +1095,7 @@ static int spi_smartbond_transceive(const struct device *dev, const struct spi_c } spi_context_release(&data->ctx, rc); - spi_smartbond_pm_policy_state_lock_put(data); + spi_smartbond_pm_policy_state_lock_put(dev); return rc; } diff --git a/soc/renesas/smartbond/da1469x/Kconfig.defconfig b/soc/renesas/smartbond/da1469x/Kconfig.defconfig index 4d9c062039e..9e8df728e95 100644 --- a/soc/renesas/smartbond/da1469x/Kconfig.defconfig +++ b/soc/renesas/smartbond/da1469x/Kconfig.defconfig @@ -34,4 +34,7 @@ config FLASH_BASE_ADDRESS config FLASH_LOAD_OFFSET default 0x2400 if !USE_DT_CODE_PARTITION +config PM_DEVICE_RUNTIME_EXCLUSIVE + default n if PM_DEVICE_RUNTIME + endif # SOC_SERIES_DA1469X