Skip to content

Commit

Permalink
drivers: entropy: stm32: reinit rng when exiting suspend to ram
Browse files Browse the repository at this point in the history
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 <guillaume.gautier-ext@st.com>
  • Loading branch information
gautierg-st committed Jan 17, 2024
1 parent 1d43e70 commit 8db2081
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drivers/entropy/entropy_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,17 +701,35 @@ static int entropy_stm32_rng_init(const struct device *dev)
static int entropy_stm32_rng_pm_action(const struct device *dev,
enum pm_device_action action)
{
struct entropy_stm32_rng_dev_data *dev_data = dev->data;
uint32_t desired_htcr = DT_INST_PROP_OR(0, health_test_config, 0U);

int res = 0;

switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
res = entropy_stm32_suspend();
break;
case PM_DEVICE_ACTION_RESUME:
#ifdef CONFIG_PM_S2RAM
#if DT_INST_NODE_HAS_PROP(0, health_test_config)
entropy_stm32_resume();
#if DT_INST_NODE_HAS_PROP(0, health_test_magic)
LL_RNG_SetHealthConfig(rng, DT_INST_PROP(0, health_test_magic));
#endif /* health_test_magic */
if (LL_RNG_GetHealthConfig(dev_data->rng) != desired_htcr) {
entropy_stm32_rng_init(dev);
} else if (!entropy_stm32_rng_data.filling_pools) {
/* Resume RNG only if it was suspended during filling pool */
entropy_stm32_suspend();
}
#endif /* health_test_config */
#else
/* Resume RNG only if it was suspended during filling pool */
if (entropy_stm32_rng_data.filling_pools) {
res = entropy_stm32_resume();
}
#endif
break;
default:
return -ENOTSUP;
Expand Down

0 comments on commit 8db2081

Please sign in to comment.