|
2 | 2 | #include <linux/clk.h> |
3 | 3 | #include <linux/clocksource.h> |
4 | 4 | #include <linux/clockchips.h> |
| 5 | +#include <linux/cpuhotplug.h> |
5 | 6 | #include <linux/interrupt.h> |
6 | 7 | #include <linux/io.h> |
7 | 8 | #include <linux/iopoll.h> |
@@ -630,6 +631,78 @@ static int __init dmtimer_clockevent_init(struct device_node *np) |
630 | 631 | return error; |
631 | 632 | } |
632 | 633 |
|
| 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 | + |
633 | 706 | /* Clocksource */ |
634 | 707 | static struct dmtimer_clocksource * |
635 | 708 | to_dmtimer_clocksource(struct clocksource *cs) |
@@ -763,6 +836,9 @@ static int __init dmtimer_systimer_init(struct device_node *np) |
763 | 836 | if (clockevent == pa) |
764 | 837 | return dmtimer_clockevent_init(np); |
765 | 838 |
|
| 839 | + if (of_machine_is_compatible("ti,dra7")) |
| 840 | + return dmtimer_percpu_quirk_init(np, pa); |
| 841 | + |
766 | 842 | return 0; |
767 | 843 | } |
768 | 844 |
|
|
0 commit comments