SPARC/LEON: find IRQCTRL and Timer via OF-Tree, instead of hardcoded.
[deliverable/linux.git] / arch / sparc / kernel / leon_kernel.c
CommitLineData
5213a780
KE
1/*
2 * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
3 * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/errno.h>
9#include <linux/mutex.h>
5213a780
KE
10#include <linux/of.h>
11#include <linux/of_platform.h>
12#include <linux/interrupt.h>
13#include <linux/of_device.h>
8401707f 14
5213a780
KE
15#include <asm/oplib.h>
16#include <asm/timer.h>
17#include <asm/prom.h>
18#include <asm/leon.h>
19#include <asm/leon_amba.h>
8401707f
KE
20#include <asm/traps.h>
21#include <asm/cacheflush.h>
5213a780
KE
22
23#include "prom.h"
24#include "irq.h"
25
53aea7ca
DH
26struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address */
27struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address */
5213a780
KE
28struct amba_apb_device leon_percpu_timer_dev[16];
29
30int leondebug_irq_disable;
31int leon_debug_irqout;
32static int dummy_master_l10_counter;
33
53aea7ca 34unsigned long leon3_gptimer_irq; /* interrupt controller irq number */
5213a780
KE
35unsigned int sparc_leon_eirq;
36#define LEON_IMASK ((&leon3_irqctrl_regs->mask[0]))
37
38/* Return the IRQ of the pending IRQ on the extended IRQ controller */
39int sparc_leon_eirq_get(int eirq, int cpu)
40{
41 return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
42}
43
44irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id)
45{
46 printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n");
47 return IRQ_HANDLED;
48}
49
50/* The extended IRQ controller has been found, this function registers it */
51void sparc_leon_eirq_register(int eirq)
52{
53 int irq;
54
55 /* Register a "BAD" handler for this interrupt, it should never happen */
56 irq = request_irq(eirq, sparc_leon_eirq_isr,
57 (IRQF_DISABLED | SA_STATIC_ALLOC), "extirq", NULL);
58
59 if (irq) {
60 printk(KERN_ERR
61 "sparc_leon_eirq_register: unable to attach IRQ%d\n",
62 eirq);
63 } else {
64 sparc_leon_eirq = eirq;
65 }
66
67}
68
69static inline unsigned long get_irqmask(unsigned int irq)
70{
71 unsigned long mask;
72
73 if (!irq || ((irq > 0xf) && !sparc_leon_eirq)
74 || ((irq > 0x1f) && sparc_leon_eirq)) {
75 printk(KERN_ERR
76 "leon_get_irqmask: false irq number: %d\n", irq);
77 mask = 0;
78 } else {
79 mask = LEON_HARD_INT(irq);
80 }
81 return mask;
82}
83
84static void leon_enable_irq(unsigned int irq_nr)
85{
86 unsigned long mask, flags;
87 mask = get_irqmask(irq_nr);
88 local_irq_save(flags);
89 LEON3_BYPASS_STORE_PA(LEON_IMASK,
90 (LEON3_BYPASS_LOAD_PA(LEON_IMASK) | (mask)));
91 local_irq_restore(flags);
92}
93
94static void leon_disable_irq(unsigned int irq_nr)
95{
96 unsigned long mask, flags;
97 mask = get_irqmask(irq_nr);
98 local_irq_save(flags);
99 LEON3_BYPASS_STORE_PA(LEON_IMASK,
100 (LEON3_BYPASS_LOAD_PA(LEON_IMASK) & ~(mask)));
101 local_irq_restore(flags);
102
103}
104
105void __init leon_init_timers(irq_handler_t counter_fn)
106{
107 int irq;
53aea7ca
DH
108 struct device_node *rootnp, *np;
109 struct property *pp;
110 int len;
5213a780
KE
111
112 leondebug_irq_disable = 0;
113 leon_debug_irqout = 0;
114 master_l10_counter = (unsigned int *)&dummy_master_l10_counter;
115 dummy_master_l10_counter = 0;
116
53aea7ca
DH
117 /*Find IRQMP IRQ Controller Registers base address otherwise bail out.*/
118 rootnp = of_find_node_by_path("/ambapp0");
119 if (!rootnp)
120 goto bad;
121 np = of_find_node_by_name(rootnp, "GAISLER_IRQMP");
122 if (!np)
123 goto bad;
124 pp = of_find_property(np, "reg", &len);
125 if (!pp)
126 goto bad;
127 leon3_irqctrl_regs = *(struct leon3_irqctrl_regs_map **)pp->value;
128
129 /* Find GPTIMER Timer Registers base address otherwise bail out. */
130 np = of_find_node_by_name(rootnp, "GAISLER_GPTIMER");
131 if (!np)
132 goto bad;
133 pp = of_find_property(np, "reg", &len);
134 if (!pp)
135 goto bad;
136 leon3_gptimer_regs = *(struct leon3_gptimer_regs_map **)pp->value;
137 pp = of_find_property(np, "interrupts", &len);
138 if (!pp)
139 goto bad;
140 leon3_gptimer_irq = *(unsigned int *)pp->value;
141
142 if (leon3_gptimer_regs && leon3_irqctrl_regs && leon3_gptimer_irq) {
5213a780
KE
143 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0);
144 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld,
b690c425 145 (((1000000 / HZ) - 1)));
5213a780
KE
146 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0);
147
8401707f
KE
148#ifdef CONFIG_SMP
149 leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs;
150 leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1;
151
152 if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) &
153 (1<<LEON3_GPTIMER_SEPIRQ))) {
0da2b300 154 prom_printf("irq timer not configured with separate irqs\n");
8401707f
KE
155 BUG();
156 }
157
158 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0);
b690c425 159 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/HZ) - 1)));
8401707f
KE
160 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0);
161# endif
162
5213a780 163 } else {
53aea7ca 164 goto bad;
5213a780
KE
165 }
166
167 irq = request_irq(leon3_gptimer_irq,
168 counter_fn,
169 (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
170
171 if (irq) {
172 printk(KERN_ERR "leon_time_init: unable to attach IRQ%d\n",
173 LEON_INTERRUPT_TIMER1);
174 prom_halt();
175 }
176
8401707f
KE
177# ifdef CONFIG_SMP
178 {
179 unsigned long flags;
180 struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (leon_percpu_timer_dev[0].irq - 1)];
181
182 /* For SMP we use the level 14 ticker, however the bootup code
183 * has copied the firmwares level 14 vector into boot cpu's
184 * trap table, we must fix this now or we get squashed.
185 */
186 local_irq_save(flags);
187
188 patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
189
190 /* Adjust so that we jump directly to smpleon_ticker */
191 trap_table->inst_three += smpleon_ticker - real_irq_entry;
192
193 local_flush_cache_all();
194 local_irq_restore(flags);
195 }
196# endif
197
5213a780
KE
198 if (leon3_gptimer_regs) {
199 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl,
200 LEON3_GPTIMER_EN |
201 LEON3_GPTIMER_RL |
202 LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
8401707f
KE
203
204#ifdef CONFIG_SMP
205 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl,
206 LEON3_GPTIMER_EN |
207 LEON3_GPTIMER_RL |
208 LEON3_GPTIMER_LD |
209 LEON3_GPTIMER_IRQEN);
210#endif
211
5213a780 212 }
53aea7ca
DH
213 return;
214bad:
215 printk(KERN_ERR "No Timer/irqctrl found\n");
216 BUG();
217 return;
5213a780
KE
218}
219
220void leon_clear_clock_irq(void)
221{
222}
223
224void leon_load_profile_irq(int cpu, unsigned int limit)
225{
226 BUG();
227}
228
229
230
231
232void __init leon_trans_init(struct device_node *dp)
233{
234 if (strcmp(dp->type, "cpu") == 0 && strcmp(dp->name, "<NULL>") == 0) {
235 struct property *p;
236 p = of_find_property(dp, "mid", (void *)0);
237 if (p) {
238 int mid;
239 dp->name = prom_early_alloc(5 + 1);
240 memcpy(&mid, p->value, p->length);
241 sprintf((char *)dp->name, "cpu%.2d", mid);
242 }
243 }
244}
245
246void __initdata (*prom_amba_init)(struct device_node *dp, struct device_node ***nextp) = 0;
247
248void __init leon_node_init(struct device_node *dp, struct device_node ***nextp)
249{
250 if (prom_amba_init &&
251 strcmp(dp->type, "ambapp") == 0 &&
252 strcmp(dp->name, "ambapp0") == 0) {
253 prom_amba_init(dp, nextp);
254 }
255}
256
8401707f
KE
257#ifdef CONFIG_SMP
258
259void leon_set_cpu_int(int cpu, int level)
260{
261 unsigned long mask;
262 mask = get_irqmask(level);
263 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask);
264}
265
266static void leon_clear_ipi(int cpu, int level)
267{
268 unsigned long mask;
269 mask = get_irqmask(level);
270 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask<<16);
271}
272
273static void leon_set_udt(int cpu)
274{
275}
276
277void leon_clear_profile_irq(int cpu)
278{
279}
280
281void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
282{
283 unsigned long mask, flags, *addr;
284 mask = get_irqmask(irq_nr);
285 local_irq_save(flags);
286 addr = (unsigned long *)&(leon3_irqctrl_regs->mask[cpu]);
287 LEON3_BYPASS_STORE_PA(addr, (LEON3_BYPASS_LOAD_PA(addr) | (mask)));
288 local_irq_restore(flags);
289}
290
291#endif
292
5213a780
KE
293void __init leon_init_IRQ(void)
294{
295 sparc_init_timers = leon_init_timers;
296
297 BTFIXUPSET_CALL(enable_irq, leon_enable_irq, BTFIXUPCALL_NORM);
298 BTFIXUPSET_CALL(disable_irq, leon_disable_irq, BTFIXUPCALL_NORM);
299 BTFIXUPSET_CALL(enable_pil_irq, leon_enable_irq, BTFIXUPCALL_NORM);
300 BTFIXUPSET_CALL(disable_pil_irq, leon_disable_irq, BTFIXUPCALL_NORM);
301
302 BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq,
303 BTFIXUPCALL_NORM);
304 BTFIXUPSET_CALL(load_profile_irq, leon_load_profile_irq,
305 BTFIXUPCALL_NOP);
306
307#ifdef CONFIG_SMP
308 BTFIXUPSET_CALL(set_cpu_int, leon_set_cpu_int, BTFIXUPCALL_NORM);
309 BTFIXUPSET_CALL(clear_cpu_int, leon_clear_ipi, BTFIXUPCALL_NORM);
310 BTFIXUPSET_CALL(set_irq_udt, leon_set_udt, BTFIXUPCALL_NORM);
311#endif
312
313}
314
315void __init leon_init(void)
316{
ed418502 317 of_pdt_build_more = &leon_node_init;
5213a780 318}
This page took 0.097898 seconds and 5 git commands to generate.