hwrng: rockchip: fixed bugs on rk_trng_v1_init timeout for 50ms sometimes

TRNG_V1_STAT_GENERATING is generated abnormally, but the
 corresponding TRNG_V1_ISTAT_RAND_RDY flag cannot be triggered
 in sometimes.

Signed-off-by: Lin Jinhan <troy.lin@rock-chips.com>
Change-Id: I446b8d521075057d07f842041f790075aec402a1
This commit is contained in:
Lin Jinhan
2021-12-02 17:52:48 +08:00
committed by Tao Huang
parent b58babc2d3
commit 11ff5084f9

View File

@@ -274,8 +274,15 @@ static int rk_trng_v1_init(struct hwrng *rng)
if (!(status & TRNG_V1_STAT_SEEDED) ||
(status & TRNG_V1_STAT_GENERATING) ||
(status & TRNG_V1_STAT_RESEEDING)) {
readl_poll_timeout(rk_rng->mem + TRNG_V1_ISTAT, reg_ctrl,
(reg_ctrl & TRNG_V1_ISTAT_RAND_RDY),
uint32_t mask = TRNG_V1_STAT_SEEDED |
TRNG_V1_STAT_GENERATING |
TRNG_V1_STAT_RESEEDING;
udelay(10);
/* wait for GENERATING and RESEEDING flag to clear */
readl_poll_timeout(rk_rng->mem + TRNG_V1_STAT, reg_ctrl,
(reg_ctrl & mask) == TRNG_V1_STAT_SEEDED,
ROCKCHIP_POLL_PERIOD_US,
ROCKCHIP_POLL_TIMEOUT_US);
}