Skip to content

Commit 2791c1a

Browse files
daniel-hellstromdavem330
authored andcommitted
SPARC/LEON: added support for selecting Timer Core and Timer within core
The ability to select Timer Core and Timer instance for system clock makes it possible for multiple AMP systems to coexist. Signed-off-by: Daniel Hellstrom <daniel@gaisler.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9742e72 commit 2791c1a

1 file changed

Lines changed: 54 additions & 26 deletions

File tree

‎arch/sparc/kernel/leon_kernel.c‎

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int leon_debug_irqout;
3232
static int dummy_master_l10_counter;
3333

3434
unsigned long leon3_gptimer_irq; /* interrupt controller irq number */
35+
unsigned long leon3_gptimer_idx; /* Timer Index (0..6) within Timer Core */
3536
unsigned int sparc_leon_eirq;
3637
#define LEON_IMASK ((&leon3_irqctrl_regs->mask[0]))
3738

@@ -105,10 +106,11 @@ static void leon_disable_irq(unsigned int irq_nr)
105106
void __init leon_init_timers(irq_handler_t counter_fn)
106107
{
107108
int irq;
108-
struct device_node *rootnp, *np;
109+
struct device_node *rootnp, *np, *nnp;
109110
struct property *pp;
110111
int len;
111112
int cpu, icsel;
113+
int ampopts;
112114

113115
leondebug_irq_disable = 0;
114116
leon_debug_irqout = 0;
@@ -131,40 +133,66 @@ void __init leon_init_timers(irq_handler_t counter_fn)
131133
leon3_irqctrl_regs = *(struct leon3_irqctrl_regs_map **)pp->value;
132134

133135
/* Find GPTIMER Timer Registers base address otherwise bail out. */
134-
np = of_find_node_by_name(rootnp, "GAISLER_GPTIMER");
135-
if (!np) {
136-
np = of_find_node_by_name(np, "01_011");
137-
if (!np)
138-
goto bad;
139-
}
140-
pp = of_find_property(np, "reg", &len);
141-
if (!pp)
142-
goto bad;
143-
leon3_gptimer_regs = *(struct leon3_gptimer_regs_map **)pp->value;
144-
pp = of_find_property(np, "interrupts", &len);
145-
if (!pp)
146-
goto bad;
147-
leon3_gptimer_irq = *(unsigned int *)pp->value;
136+
nnp = rootnp;
137+
do {
138+
np = of_find_node_by_name(nnp, "GAISLER_GPTIMER");
139+
if (!np) {
140+
np = of_find_node_by_name(nnp, "01_011");
141+
if (!np)
142+
goto bad;
143+
}
144+
145+
ampopts = 0;
146+
pp = of_find_property(np, "ampopts", &len);
147+
if (pp) {
148+
ampopts = *(int *)pp->value;
149+
if (ampopts == 0) {
150+
/* Skip this instance, resource already
151+
* allocated by other OS */
152+
nnp = np;
153+
continue;
154+
}
155+
}
156+
157+
/* Select Timer-Instance on Timer Core. Default is zero */
158+
leon3_gptimer_idx = ampopts & 0x7;
159+
160+
pp = of_find_property(np, "reg", &len);
161+
if (pp)
162+
leon3_gptimer_regs = *(struct leon3_gptimer_regs_map **)
163+
pp->value;
164+
pp = of_find_property(np, "interrupts", &len);
165+
if (pp)
166+
leon3_gptimer_irq = *(unsigned int *)pp->value;
167+
} while (0);
148168

149169
if (leon3_gptimer_regs && leon3_irqctrl_regs && leon3_gptimer_irq) {
150-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0);
151-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld,
152-
(((1000000 / HZ) - 1)));
153-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0);
170+
LEON3_BYPASS_STORE_PA(
171+
&leon3_gptimer_regs->e[leon3_gptimer_idx].val, 0);
172+
LEON3_BYPASS_STORE_PA(
173+
&leon3_gptimer_regs->e[leon3_gptimer_idx].rld,
174+
(((1000000 / HZ) - 1)));
175+
LEON3_BYPASS_STORE_PA(
176+
&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl, 0);
154177

155178
#ifdef CONFIG_SMP
156179
leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs;
157-
leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1;
180+
leon_percpu_timer_dev[0].irq = leon3_gptimer_irq + 1 +
181+
leon3_gptimer_idx;
158182

159183
if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) &
160184
(1<<LEON3_GPTIMER_SEPIRQ))) {
161185
prom_printf("irq timer not configured with separate irqs\n");
162186
BUG();
163187
}
164188

165-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0);
166-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/HZ) - 1)));
167-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0);
189+
LEON3_BYPASS_STORE_PA(
190+
&leon3_gptimer_regs->e[leon3_gptimer_idx+1].val, 0);
191+
LEON3_BYPASS_STORE_PA(
192+
&leon3_gptimer_regs->e[leon3_gptimer_idx+1].rld,
193+
(((1000000/HZ) - 1)));
194+
LEON3_BYPASS_STORE_PA(
195+
&leon3_gptimer_regs->e[leon3_gptimer_idx+1].ctrl, 0);
168196
# endif
169197

170198
/*
@@ -184,7 +212,7 @@ void __init leon_init_timers(irq_handler_t counter_fn)
184212
goto bad;
185213
}
186214

187-
irq = request_irq(leon3_gptimer_irq,
215+
irq = request_irq(leon3_gptimer_irq+leon3_gptimer_idx,
188216
counter_fn,
189217
(IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
190218

@@ -216,13 +244,13 @@ void __init leon_init_timers(irq_handler_t counter_fn)
216244
# endif
217245

218246
if (leon3_gptimer_regs) {
219-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl,
247+
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx].ctrl,
220248
LEON3_GPTIMER_EN |
221249
LEON3_GPTIMER_RL |
222250
LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
223251

224252
#ifdef CONFIG_SMP
225-
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl,
253+
LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[leon3_gptimer_idx+1].ctrl,
226254
LEON3_GPTIMER_EN |
227255
LEON3_GPTIMER_RL |
228256
LEON3_GPTIMER_LD |

0 commit comments

Comments
 (0)