MLK-14748 clocksource: imx-tpm: Increase the min_delta
authorShenwei Wang <shenwei.wang@nxp.com>
Mon, 24 Apr 2017 18:24:32 +0000 (13:24 -0500)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:22:34 +0000 (15:22 -0500)
The current min_delta for TPM clock event is 2 ticks which
is too small. As the TPM is running at 3MHz, 2 ticks equal
2/3 us. According to our testing, the interrupt latency will
be longer than this min_delta, especially when GPU is running.

This patch changed the min_delta to 300 which give the system
around 100us for interrupt handling in case the "set_next_event"
call is interrupted by other signals.

Also a simple validation code is added before the function returns.

Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
Signed-off-by: Bai Ping <ping.bai@nxp.com>
(cherry picked from commit 4f882165cc31672f3c98de74ab02b757cb96ad26)

drivers/clocksource/timer-imx-tpm.c

index 608dca1..f7d0d68 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2016 Freescale Semiconductor, Inc.
+ * Copyright 2017 NXP
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -81,12 +82,15 @@ static int __init tpm_clocksource_init(unsigned long rate)
 static int tpm_set_next_event(unsigned long delta,
                                struct clock_event_device *evt)
 {
-       unsigned long tmp;
+       unsigned long next, now, ret;
 
-       tmp = __raw_readl(timer_base + TPM_CNT) + delta;
-       __raw_writel(tmp, timer_base + TPM_C0V);
+       now = __raw_readl(timer_base + TPM_CNT);
+       next = now + delta;
+       __raw_writel(next, timer_base + TPM_C0V);
+       now = __raw_readl(timer_base + TPM_CNT);
 
-       return 0;
+       ret = next - now;
+       return (ret > delta) ? -ETIME : 0;
 }
 
 static int tpm_set_state_oneshot(struct clock_event_device *evt)
@@ -140,7 +144,7 @@ static int __init tpm_clockevent_init(unsigned long rate, int irq)
        clockevent_tpm.cpumask = cpumask_of(0);
        clockevent_tpm.irq = irq;
        clockevents_config_and_register(&clockevent_tpm,
-               rate, 2, 0xfffffffe);
+               rate, 300, 0xfffffffe);
 
        return 0;
 }