• Marek Vasut's avatar
    hwrng: stm32 - repair clock handling · c819d7b8
    Marek Vasut authored
    The clock management in this driver does not seem to be correct. The
    struct hwrng .init callback enables the clock, but there is no matching
    .cleanup callback to disable the clock. The clock get disabled as some
    later point by runtime PM suspend callback.
    
    Furthermore, both runtime PM and sleep suspend callbacks access registers
    first and disable clock which are used for register access second. If the
    IP is already in RPM suspend and the system enters sleep state, the sleep
    callback will attempt to access registers while the register clock are
    already disabled. This bug has been fixed once before already in commit
    9bae5494 ("hwrng: stm32 - fix pm_suspend issue"), and regressed in
    commit ff4e4610 ("hwrng: stm32 - rework power management sequences") .
    
    Fix this slightly differently, disable register clock at the end of .init
    callback, this way the IP is disabled after .init. On every access to the
    IP, which really is only stm32_rng_read(), do pm_runtime_get_sync() which
    is already done in stm32_rng_read() to bring the IP from RPM suspend, and
    pm_runtime_mark_last_busy()/pm_runtime_put_sync_autosuspend() to put it
    back into RPM suspend.
    
    Change sleep suspend/resume callbacks to enable and disable register clock
    around register access, as those cannot use the RPM suspend/resume callbacks
    due to slightly different initialization in those sleep callbacks. This way,
    the register access should always be performed with clock surely enabled.
    
    Fixes: ff4e4610 ("hwrng: stm32 - rework power management sequences")
    Signed-off-by: default avatarMarek Vasut <marex@denx.de>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    c819d7b8
stm32-rng.c 14.8 KB