drivers: entropy: stm32 entropy driver add semaphore protection
Add a semaphore to protect the disable access to the RNG peripheral when the PM is going to suspend mode. The change does not affect other stm32 than CONFIG_SOC_SERIES_STM32WBX or CONFIG_STM32H7_DUAL_CORE Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit is contained in:
parent
c9c9c9797f
commit
447bdea7ff
1 changed files with 23 additions and 2 deletions
|
@ -112,6 +112,10 @@ static int entropy_stm32_suspend(void)
|
||||||
RNG_TypeDef *rng = dev_data->rng;
|
RNG_TypeDef *rng = dev_data->rng;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_STM32H7_DUAL_CORE)
|
||||||
|
/* Prevent concurrent access with PM */
|
||||||
|
z_stm32_hsem_lock(CFG_HW_RNG_SEMID, HSEM_LOCK_WAIT_FOREVER);
|
||||||
|
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE */
|
||||||
LL_RNG_Disable(rng);
|
LL_RNG_Disable(rng);
|
||||||
|
|
||||||
#ifdef CONFIG_SOC_SERIES_STM32WBAX
|
#ifdef CONFIG_SOC_SERIES_STM32WBAX
|
||||||
|
@ -136,6 +140,10 @@ static int entropy_stm32_suspend(void)
|
||||||
res = clock_control_off(dev_data->clock,
|
res = clock_control_off(dev_data->clock,
|
||||||
(clock_control_subsys_t)&dev_cfg->pclken[0]);
|
(clock_control_subsys_t)&dev_cfg->pclken[0]);
|
||||||
|
|
||||||
|
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_STM32H7_DUAL_CORE)
|
||||||
|
z_stm32_hsem_unlock(CFG_HW_RNG_SEMID);
|
||||||
|
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE */
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +718,12 @@ static int entropy_stm32_rng_pm_action(const struct device *dev,
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case PM_DEVICE_ACTION_SUSPEND:
|
case PM_DEVICE_ACTION_SUSPEND:
|
||||||
res = entropy_stm32_suspend();
|
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_STM32H7_DUAL_CORE)
|
||||||
|
/* Lock to Prevent concurrent access with PM */
|
||||||
|
z_stm32_hsem_lock(CFG_HW_RNG_SEMID, HSEM_LOCK_WAIT_FOREVER);
|
||||||
|
/* Call release_rng instead of entropy_stm32_suspend to avoid double hsem_unlock */
|
||||||
|
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE */
|
||||||
|
release_rng();
|
||||||
break;
|
break;
|
||||||
case PM_DEVICE_ACTION_RESUME:
|
case PM_DEVICE_ACTION_RESUME:
|
||||||
if (IS_ENABLED(CONFIG_PM_S2RAM)) {
|
if (IS_ENABLED(CONFIG_PM_S2RAM)) {
|
||||||
|
@ -724,7 +737,15 @@ static int entropy_stm32_rng_pm_action(const struct device *dev,
|
||||||
entropy_stm32_rng_init(dev);
|
entropy_stm32_rng_init(dev);
|
||||||
} else if (!entropy_stm32_rng_data.filling_pools) {
|
} else if (!entropy_stm32_rng_data.filling_pools) {
|
||||||
/* Resume RNG only if it was suspended during filling pool */
|
/* Resume RNG only if it was suspended during filling pool */
|
||||||
entropy_stm32_suspend();
|
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_STM32H7_DUAL_CORE)
|
||||||
|
/* Lock to Prevent concurrent access with PM */
|
||||||
|
z_stm32_hsem_lock(CFG_HW_RNG_SEMID, HSEM_LOCK_WAIT_FOREVER);
|
||||||
|
/*
|
||||||
|
* Call release_rng instead of entropy_stm32_suspend
|
||||||
|
* to avoid double hsem_unlock
|
||||||
|
*/
|
||||||
|
#endif /* CONFIG_SOC_SERIES_STM32WBX || CONFIG_STM32H7_DUAL_CORE */
|
||||||
|
release_rng();
|
||||||
}
|
}
|
||||||
#endif /* health_test_config */
|
#endif /* health_test_config */
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue