@@ -32,6 +32,7 @@ int leon_debug_irqout;
3232static int dummy_master_l10_counter ;
3333
3434unsigned long leon3_gptimer_irq ; /* interrupt controller irq number */
35+ unsigned long leon3_gptimer_idx ; /* Timer Index (0..6) within Timer Core */
3536unsigned 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)
105106void __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