| 1 | From 1dffe06838c26b7c3fc99f9ddb7db78e378f6908 Mon Sep 17 00:00:00 2001 |
| 2 | From: Daniel Hellstrom <daniel@gaisler.com> |
| 3 | Date: Wed, 22 Sep 2010 13:21:13 +0200 |
| 4 | Subject: [PATCH] SPARC/LEON: added support for selecting Timer Core and Timer within core, useful for AMP systems. |
| 5 | |
| 6 | Signed-off-by: Daniel Hellstrom <daniel@gaisler.com> |
| 7 | --- |
| 8 | arch/sparc/kernel/leon_kernel.c | 41 +++++++++++++++++++++++++------------- |
| 9 | 1 files changed, 27 insertions(+), 14 deletions(-) |
| 10 | |
| 11 | --- a/arch/sparc/kernel/leon_kernel.c |
| 12 | +++ b/arch/sparc/kernel/leon_kernel.c |
| 13 | @@ -23,15 +23,16 @@ |
| 14 | #include "prom.h" |
| 15 | #include "irq.h" |
| 16 | |
| 17 | -struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address, initialized by amba_init() */ |
| 18 | -struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address, initialized by amba_init() */ |
| 19 | +struct leon3_irqctrl_regs_map *leon3_irqctrl_regs = NULL; /* interrupt controller base address, initialized by amba_init() */ |
| 20 | +struct leon3_gptimer_regs_map *leon3_gptimer_regs = NULL; /* timer controller base address, initialized by amba_init() */ |
| 21 | struct amba_apb_device leon_percpu_timer_dev[16]; |
| 22 | |
| 23 | int leondebug_irq_disable; |
| 24 | int leon_debug_irqout; |
| 25 | static int dummy_master_l10_counter; |
| 26 | |
| 27 | -unsigned long leon3_gptimer_irq; /* interrupt controller irq number, initialized by amba_init() */ |
| 28 | +unsigned long leon3_gptimer_irq = 0; /* interrupt controller irq number, initialized by amba_init() */ |
| 29 | +unsigned long leon3_gptimer_idx = 0; /* Timer Index (starting at 0) with Timer Core */ |
| 30 | unsigned int sparc_leon_eirq; |
| 31 | #define LEON_IMASK ((&leon3_irqctrl_regs->mask[0])) |
| 32 | |
| 33 | @@ -109,6 +110,7 @@ void __init leon_init_timers(irq_handler |
| 34 | struct property *pp; |
| 35 | int len; |
| 36 | int cpu, icsel; |
| 37 | + int ampopts; |
| 38 | |
| 39 | leondebug_irq_disable = 0; |
| 40 | leon_debug_irqout = 0; |
| 41 | @@ -124,24 +126,35 @@ void __init leon_init_timers(irq_handler |
| 42 | } |
| 43 | |
| 44 | /* Find GPTIMER Timer Registers base address otherwise bail out. */ |
| 45 | - if (rootnp && (np=of_find_node_by_name(rootnp, "GAISLER_GPTIMER"))) { |
| 46 | + np = rootnp; |
| 47 | + while (np && (np=of_find_node_by_name(np, "GAISLER_GPTIMER"))) { |
| 48 | + ampopts = 0; |
| 49 | + pp = of_find_property(np, "ampopts", &len); |
| 50 | + if ( pp && ((ampopts = *(int *)pp->value) == 0) ) { |
| 51 | + /* Skip this instance, resource already allocated by other OS */ |
| 52 | + continue; |
| 53 | + } |
| 54 | + /* Select Timer-Instance on Timer Core. Default is zero */ |
| 55 | + leon3_gptimer_idx = ampopts & 0x7; |
| 56 | + |
| 57 | pp = of_find_property(np, "reg", &len); |
| 58 | if (pp) |
| 59 | leon3_gptimer_regs = *(struct leon3_gptimer_regs_map **)pp->value; |
| 60 | pp = of_find_property(np, "interrupts", &len); |
| 61 | if (pp) |
| 62 | leon3_gptimer_irq = *(unsigned int *)pp->value; |
| 63 | + break; |
| 64 | } |
| 65 | |
| 66 | if (leon3_gptimer_regs && leon3_irqctrl_regs && leon3_gptimer_irq) { |
| 67 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0); |
| 68 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld, |
| 69 | - (((1000000 / HZ) - 1))); |
| 70 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0); |
| 71 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].val, 0); |
| 72 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].rld, |
| 73 | + (((1000000 / 100) - 1))); |
| 74 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl, 0); |
| 75 | |
| 76 | #ifdef CONFIG_SMP |
| 77 | leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs; |
| 78 | - leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1; |
| 79 | + leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1+leon3_gptimer_idx; |
| 80 | |
| 81 | if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) & |
| 82 | (1<<LEON3_GPTIMER_SEPIRQ))) { |
| 83 | @@ -149,9 +162,9 @@ void __init leon_init_timers(irq_handler |
| 84 | BUG(); |
| 85 | } |
| 86 | |
| 87 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0); |
| 88 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/HZ) - 1))); |
| 89 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0); |
| 90 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx+1].val, 0); |
| 91 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx+1].rld, (((1000000/100) - 1))); |
| 92 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx+1].ctrl, 0); |
| 93 | # endif |
| 94 | |
| 95 | /* The IRQ controller may (if implemented) consist of multiple |
| 96 | @@ -178,7 +191,7 @@ void __init leon_init_timers(irq_handler |
| 97 | BUG(); |
| 98 | } |
| 99 | |
| 100 | - irq = request_irq(leon3_gptimer_irq, |
| 101 | + irq = request_irq(leon3_gptimer_irq+leon3_gptimer_idx, |
| 102 | counter_fn, |
| 103 | (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL); |
| 104 | |
| 105 | @@ -210,13 +223,13 @@ void __init leon_init_timers(irq_handler |
| 106 | # endif |
| 107 | |
| 108 | if (leon3_gptimer_regs) { |
| 109 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, |
| 110 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl, |
| 111 | LEON3_GPTIMER_EN | |
| 112 | LEON3_GPTIMER_RL | |
| 113 | LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN); |
| 114 | |
| 115 | #ifdef CONFIG_SMP |
| 116 | - LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, |
| 117 | + LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx+1].ctrl, |
| 118 | LEON3_GPTIMER_EN | |
| 119 | LEON3_GPTIMER_RL | |
| 120 | LEON3_GPTIMER_LD | |
| 121 | |