Skip to content

Commit 5aff88a

Browse files
gautierg-stcarlescufi
authored andcommitted
drivers: entropy: stm32: reinit rng when exiting suspend to ram
With PM, when resuming from low power mode, reenable the RNG register clocks and check the health register. If it is not set to the desired value, it means we exit Suspend to RAM mode, and that the RNG needs to be reinitialized. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent b8fdcbb commit 5aff88a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

drivers/entropy/entropy_stm32.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,16 +701,37 @@ static int entropy_stm32_rng_init(const struct device *dev)
701701
static int entropy_stm32_rng_pm_action(const struct device *dev,
702702
enum pm_device_action action)
703703
{
704+
struct entropy_stm32_rng_dev_data *dev_data = dev->data;
705+
704706
int res = 0;
705707

708+
/* Remove warning on some platforms */
709+
ARG_UNUSED(dev_data);
710+
706711
switch (action) {
707712
case PM_DEVICE_ACTION_SUSPEND:
708713
res = entropy_stm32_suspend();
709714
break;
710715
case PM_DEVICE_ACTION_RESUME:
711-
/* Resume RNG only if it was suspended during filling pool */
712-
if (entropy_stm32_rng_data.filling_pools) {
713-
res = entropy_stm32_resume();
716+
if (IS_ENABLED(CONFIG_PM_S2RAM)) {
717+
#if DT_INST_NODE_HAS_PROP(0, health_test_config)
718+
entropy_stm32_resume();
719+
#if DT_INST_NODE_HAS_PROP(0, health_test_magic)
720+
LL_RNG_SetHealthConfig(rng, DT_INST_PROP(0, health_test_magic));
721+
#endif /* health_test_magic */
722+
if (LL_RNG_GetHealthConfig(dev_data->rng) !=
723+
DT_INST_PROP_OR(0, health_test_config, 0U)) {
724+
entropy_stm32_rng_init(dev);
725+
} else if (!entropy_stm32_rng_data.filling_pools) {
726+
/* Resume RNG only if it was suspended during filling pool */
727+
entropy_stm32_suspend();
728+
}
729+
#endif /* health_test_config */
730+
} else {
731+
/* Resume RNG only if it was suspended during filling pool */
732+
if (entropy_stm32_rng_data.filling_pools) {
733+
res = entropy_stm32_resume();
734+
}
714735
}
715736
break;
716737
default:

0 commit comments

Comments
 (0)