[PATCH 2/2] clocksource: imx-tpm: fix next event not taking effect sometime
Frank Li
Frank.Li at nxp.com
Thu Jul 25 12:33:55 PDT 2024
From: Jacky Bai <ping.bai at nxp.com>
The value written into the TPM CnV can only be updated into the hardware
when the counter increases. Additional writes to the CnV write buffer are
ignored until the register has been updated. Therefore, we need to check
if the CnV has been updated before continuing. This may require waiting for
1 counter cycle in the worst case.
Cc: <stable at vger.kernel.org>
Fixes: 059ab7b82eec ("clocksource/drivers/imx-tpm: Add imx tpm timer support")
Signed-off-by: Jacky Bai <ping.bai at nxp.com>
Reviewed-by: Peng Fan <peng.fan at nxp.com>
Reviewed-by: Ye Li <ye.li at nxp.com>
Reviewed-by: Jason Liu <jason.hui.liu at nxp.com>
Signed-off-by: Frank Li <Frank.Li at nxp.com>
---
drivers/clocksource/timer-imx-tpm.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c
index cd23caf1e5999..92c025b70eb62 100644
--- a/drivers/clocksource/timer-imx-tpm.c
+++ b/drivers/clocksource/timer-imx-tpm.c
@@ -90,6 +90,14 @@ static int tpm_set_next_event(unsigned long delta,
writel(next, timer_base + TPM_C0V);
now = tpm_read_counter();
+ /*
+ * Need to wait CNT increase at least 1 cycle to make sure
+ * the C0V has been updated into HW.
+ */
+ if ((next & 0xffffffff) != readl(timer_base + TPM_C0V))
+ while (now == tpm_read_counter())
+ ;
+
/*
* NOTE: We observed in a very small probability, the bus fabric
* contention between GPU and A7 may results a few cycles delay
--
2.34.1
More information about the linux-arm-kernel
mailing list