Skip to content

Commit 6d5fda4

Browse files
tmlindgregkh
authored andcommitted
clocksource/drivers/timer-ti-dm: Handle dra7 timer wrap errata i940
commit 25de4ce upstream. There is a timer wrap issue on dra7 for the ARM architected timer. In a typical clock configuration the timer fails to wrap after 388 days. To work around the issue, we need to use timer-ti-dm percpu timers instead. Let's configure dmtimer3 and 4 as percpu timers by default, and warn about the issue if the dtb is not configured properly. Let's do this as a single patch so it can be backported to v5.8 and later kernels easily. Note that this patch depends on earlier timer-ti-dm systimer posted mode fixes, and a preparatory clockevent patch "clocksource/drivers/timer-ti-dm: Prepare to handle dra7 timer wrap issue". For more information, please see the errata for "AM572x Sitara Processors Silicon Revisions 1.1, 2.0": https://www.ti.com/lit/er/sprz429m/sprz429m.pdf The concept is based on earlier reference patches done by Tero Kristo and Keerthy. Cc: Keerthy <j-keerthy@ti.com> Cc: Tero Kristo <kristo@kernel.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20210323074326.28302-3-tony@atomide.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 06470de commit 6d5fda4

4 files changed

Lines changed: 99 additions & 2 deletions

File tree

‎arch/arm/boot/dts/dra7-l4.dtsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@
11681168
};
11691169
};
11701170

1171-
target-module@34000 { /* 0x48034000, ap 7 46.0 */
1171+
timer3_target: target-module@34000 { /* 0x48034000, ap 7 46.0 */
11721172
compatible = "ti,sysc-omap4-timer", "ti,sysc";
11731173
reg = <0x34000 0x4>,
11741174
<0x34010 0x4>;
@@ -1195,7 +1195,7 @@
11951195
};
11961196
};
11971197

1198-
target-module@36000 { /* 0x48036000, ap 9 4e.0 */
1198+
timer4_target: target-module@36000 { /* 0x48036000, ap 9 4e.0 */
11991199
compatible = "ti,sysc-omap4-timer", "ti,sysc";
12001200
reg = <0x36000 0x4>,
12011201
<0x36010 0x4>;

‎arch/arm/boot/dts/dra7.dtsi‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
timer {
4848
compatible = "arm,armv7-timer";
49+
status = "disabled"; /* See ARM architected timer wrap erratum i940 */
4950
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>,
5051
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>,
5152
<GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>,
@@ -1090,3 +1091,22 @@
10901091
assigned-clock-parents = <&sys_32k_ck>;
10911092
};
10921093
};
1094+
1095+
/* Local timers, see ARM architected timer wrap erratum i940 */
1096+
&timer3_target {
1097+
ti,no-reset-on-init;
1098+
ti,no-idle;
1099+
timer@0 {
1100+
assigned-clocks = <&l4per_clkctrl DRA7_L4PER_TIMER3_CLKCTRL 24>;
1101+
assigned-clock-parents = <&timer_sys_clk_div>;
1102+
};
1103+
};
1104+
1105+
&timer4_target {
1106+
ti,no-reset-on-init;
1107+
ti,no-idle;
1108+
timer@0 {
1109+
assigned-clocks = <&l4per_clkctrl DRA7_L4PER_TIMER4_CLKCTRL 24>;
1110+
assigned-clock-parents = <&timer_sys_clk_div>;
1111+
};
1112+
};

‎drivers/clocksource/timer-ti-dm-systimer.c‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/clk.h>
33
#include <linux/clocksource.h>
44
#include <linux/clockchips.h>
5+
#include <linux/cpuhotplug.h>
56
#include <linux/interrupt.h>
67
#include <linux/io.h>
78
#include <linux/iopoll.h>
@@ -630,6 +631,78 @@ static int __init dmtimer_clockevent_init(struct device_node *np)
630631
return error;
631632
}
632633

634+
/* Dmtimer as percpu timer. See dra7 ARM architected timer wrap erratum i940 */
635+
static DEFINE_PER_CPU(struct dmtimer_clockevent, dmtimer_percpu_timer);
636+
637+
static int __init dmtimer_percpu_timer_init(struct device_node *np, int cpu)
638+
{
639+
struct dmtimer_clockevent *clkevt;
640+
int error;
641+
642+
if (!cpu_possible(cpu))
643+
return -EINVAL;
644+
645+
if (!of_property_read_bool(np->parent, "ti,no-reset-on-init") ||
646+
!of_property_read_bool(np->parent, "ti,no-idle"))
647+
pr_warn("Incomplete dtb for percpu dmtimer %pOF\n", np->parent);
648+
649+
clkevt = per_cpu_ptr(&dmtimer_percpu_timer, cpu);
650+
651+
error = dmtimer_clkevt_init_common(clkevt, np, CLOCK_EVT_FEAT_ONESHOT,
652+
cpumask_of(cpu), "percpu-dmtimer",
653+
500);
654+
if (error)
655+
return error;
656+
657+
return 0;
658+
}
659+
660+
/* See TRM for timer internal resynch latency */
661+
static int omap_dmtimer_starting_cpu(unsigned int cpu)
662+
{
663+
struct dmtimer_clockevent *clkevt = per_cpu_ptr(&dmtimer_percpu_timer, cpu);
664+
struct clock_event_device *dev = &clkevt->dev;
665+
struct dmtimer_systimer *t = &clkevt->t;
666+
667+
clockevents_config_and_register(dev, t->rate, 3, ULONG_MAX);
668+
irq_force_affinity(dev->irq, cpumask_of(cpu));
669+
670+
return 0;
671+
}
672+
673+
static int __init dmtimer_percpu_timer_startup(void)
674+
{
675+
struct dmtimer_clockevent *clkevt = per_cpu_ptr(&dmtimer_percpu_timer, 0);
676+
struct dmtimer_systimer *t = &clkevt->t;
677+
678+
if (t->sysc) {
679+
cpuhp_setup_state(CPUHP_AP_TI_GP_TIMER_STARTING,
680+
"clockevents/omap/gptimer:starting",
681+
omap_dmtimer_starting_cpu, NULL);
682+
}
683+
684+
return 0;
685+
}
686+
subsys_initcall(dmtimer_percpu_timer_startup);
687+
688+
static int __init dmtimer_percpu_quirk_init(struct device_node *np, u32 pa)
689+
{
690+
struct device_node *arm_timer;
691+
692+
arm_timer = of_find_compatible_node(NULL, NULL, "arm,armv7-timer");
693+
if (of_device_is_available(arm_timer)) {
694+
pr_warn_once("ARM architected timer wrap issue i940 detected\n");
695+
return 0;
696+
}
697+
698+
if (pa == 0x48034000) /* dra7 dmtimer3 */
699+
return dmtimer_percpu_timer_init(np, 0);
700+
else if (pa == 0x48036000) /* dra7 dmtimer4 */
701+
return dmtimer_percpu_timer_init(np, 1);
702+
703+
return 0;
704+
}
705+
633706
/* Clocksource */
634707
static struct dmtimer_clocksource *
635708
to_dmtimer_clocksource(struct clocksource *cs)
@@ -763,6 +836,9 @@ static int __init dmtimer_systimer_init(struct device_node *np)
763836
if (clockevent == pa)
764837
return dmtimer_clockevent_init(np);
765838

839+
if (of_machine_is_compatible("ti,dra7"))
840+
return dmtimer_percpu_quirk_init(np, pa);
841+
766842
return 0;
767843
}
768844

‎include/linux/cpuhotplug.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum cpuhp_state {
135135
CPUHP_AP_RISCV_TIMER_STARTING,
136136
CPUHP_AP_CLINT_TIMER_STARTING,
137137
CPUHP_AP_CSKY_TIMER_STARTING,
138+
CPUHP_AP_TI_GP_TIMER_STARTING,
138139
CPUHP_AP_HYPERV_TIMER_STARTING,
139140
CPUHP_AP_KVM_STARTING,
140141
CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING,

0 commit comments

Comments
 (0)