Skip to content

Commit 06470de

Browse files
tmlindgregkh
authored andcommitted
clocksource/drivers/timer-ti-dm: Prepare to handle dra7 timer wrap issue
commit 3efe7a8 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 timers instead. Let's prepare for adding support for percpu timers by adding a common dmtimer_clkevt_init_common() and call it from dmtimer_clockevent_init(). This patch makes no intentional functional changes. 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-2-tony@atomide.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 462049c commit 06470de

1 file changed

Lines changed: 44 additions & 24 deletions

File tree

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

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -530,43 +530,41 @@ static void omap_clockevent_unidle(struct clock_event_device *evt)
530530
writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->wakeup);
531531
}
532532

533-
static int __init dmtimer_clockevent_init(struct device_node *np)
533+
static int __init dmtimer_clkevt_init_common(struct dmtimer_clockevent *clkevt,
534+
struct device_node *np,
535+
unsigned int features,
536+
const struct cpumask *cpumask,
537+
const char *name,
538+
int rating)
534539
{
535-
struct dmtimer_clockevent *clkevt;
536540
struct clock_event_device *dev;
537541
struct dmtimer_systimer *t;
538542
int error;
539543

540-
clkevt = kzalloc(sizeof(*clkevt), GFP_KERNEL);
541-
if (!clkevt)
542-
return -ENOMEM;
543-
544544
t = &clkevt->t;
545545
dev = &clkevt->dev;
546546

547547
/*
548548
* We mostly use cpuidle_coupled with ARM local timers for runtime,
549549
* so there's probably no use for CLOCK_EVT_FEAT_DYNIRQ here.
550550
*/
551-
dev->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
552-
dev->rating = 300;
551+
dev->features = features;
552+
dev->rating = rating;
553553
dev->set_next_event = dmtimer_set_next_event;
554554
dev->set_state_shutdown = dmtimer_clockevent_shutdown;
555555
dev->set_state_periodic = dmtimer_set_periodic;
556556
dev->set_state_oneshot = dmtimer_clockevent_shutdown;
557557
dev->set_state_oneshot_stopped = dmtimer_clockevent_shutdown;
558558
dev->tick_resume = dmtimer_clockevent_shutdown;
559-
dev->cpumask = cpu_possible_mask;
559+
dev->cpumask = cpumask;
560560

561561
dev->irq = irq_of_parse_and_map(np, 0);
562-
if (!dev->irq) {
563-
error = -ENXIO;
564-
goto err_out_free;
565-
}
562+
if (!dev->irq)
563+
return -ENXIO;
566564

567565
error = dmtimer_systimer_setup(np, &clkevt->t);
568566
if (error)
569-
goto err_out_free;
567+
return error;
570568

571569
clkevt->period = 0xffffffff - DIV_ROUND_CLOSEST(t->rate, HZ);
572570

@@ -578,32 +576,54 @@ static int __init dmtimer_clockevent_init(struct device_node *np)
578576
writel_relaxed(OMAP_TIMER_CTRL_POSTED, t->base + t->ifctrl);
579577

580578
error = request_irq(dev->irq, dmtimer_clockevent_interrupt,
581-
IRQF_TIMER, "clockevent", clkevt);
579+
IRQF_TIMER, name, clkevt);
582580
if (error)
583581
goto err_out_unmap;
584582

585583
writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->irq_ena);
586584
writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->wakeup);
587585

588-
pr_info("TI gptimer clockevent: %s%lu Hz at %pOF\n",
589-
of_find_property(np, "ti,timer-alwon", NULL) ?
586+
pr_info("TI gptimer %s: %s%lu Hz at %pOF\n",
587+
name, of_find_property(np, "ti,timer-alwon", NULL) ?
590588
"always-on " : "", t->rate, np->parent);
591589

592-
clockevents_config_and_register(dev, t->rate,
593-
3, /* Timer internal resynch latency */
590+
return 0;
591+
592+
err_out_unmap:
593+
iounmap(t->base);
594+
595+
return error;
596+
}
597+
598+
static int __init dmtimer_clockevent_init(struct device_node *np)
599+
{
600+
struct dmtimer_clockevent *clkevt;
601+
int error;
602+
603+
clkevt = kzalloc(sizeof(*clkevt), GFP_KERNEL);
604+
if (!clkevt)
605+
return -ENOMEM;
606+
607+
error = dmtimer_clkevt_init_common(clkevt, np,
608+
CLOCK_EVT_FEAT_PERIODIC |
609+
CLOCK_EVT_FEAT_ONESHOT,
610+
cpu_possible_mask, "clockevent",
611+
300);
612+
if (error)
613+
goto err_out_free;
614+
615+
clockevents_config_and_register(&clkevt->dev, clkevt->t.rate,
616+
3, /* Timer internal resync latency */
594617
0xffffffff);
595618

596619
if (of_machine_is_compatible("ti,am33xx") ||
597620
of_machine_is_compatible("ti,am43")) {
598-
dev->suspend = omap_clockevent_idle;
599-
dev->resume = omap_clockevent_unidle;
621+
clkevt->dev.suspend = omap_clockevent_idle;
622+
clkevt->dev.resume = omap_clockevent_unidle;
600623
}
601624

602625
return 0;
603626

604-
err_out_unmap:
605-
iounmap(t->base);
606-
607627
err_out_free:
608628
kfree(clkevt);
609629

0 commit comments

Comments
 (0)