Skip to content

Commit 04b05c5

Browse files
JackyBaiJason Liu
authored andcommitted
LF-9952 clocksource: imx-tpm: Wait for CnV write to take effect
The value write into the TPM CnV can only be updated into the HW when CNT increase. Additional writes to the CnV write buffer are ignored until the register has been updated. So we need to check if the CnV has been updated before continue. Wait for 1 CNT cycle in worst case. Additionally, current return check is not correct, if a max_delta need be set, it will return '-ETIME' wrongly due to the 'int' type cast, so refine the check logic to fix it. Signed-off-by: Jacky Bai <ping.bai@nxp.com> Reviewed-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Ye Li <ye.li@nxp.com> Reviewed-by: Jason Liu <jason.hui.liu@nxp.com>
1 parent 5a6b16b commit 04b05c5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/clocksource/timer-imx-tpm.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,28 @@ static u64 notrace tpm_read_sched_clock(void)
8383
static int tpm_set_next_event(unsigned long delta,
8484
struct clock_event_device *evt)
8585
{
86-
unsigned long next, now;
86+
unsigned long next, prev, now;
8787

88-
next = tpm_read_counter();
89-
next += delta;
88+
prev = tpm_read_counter();
89+
next = prev + delta;
9090
writel(next, timer_base + TPM_C0V);
9191
now = tpm_read_counter();
9292

93+
/*
94+
* Need to wait CNT increase at least 1 cycle to make sure
95+
* the C0V has been updated into HW.
96+
*/
97+
if ((next & 0xffffffff) != readl(timer_base + TPM_C0V))
98+
while (now == tpm_read_counter())
99+
;
100+
93101
/*
94102
* NOTE: We observed in a very small probability, the bus fabric
95103
* contention between GPU and A7 may results a few cycles delay
96104
* of writing CNT registers which may cause the min_delta event got
97105
* missed, so we need add a ETIME check here in case it happened.
98106
*/
99-
return (int)(next - now) <= 0 ? -ETIME : 0;
107+
return (now - prev) >= delta ? -ETIME : 0;
100108
}
101109

102110
static int tpm_set_state_oneshot(struct clock_event_device *evt)

0 commit comments

Comments
 (0)