MIPS: Alchemy: prom_putchar is board dependent
[linux-2.6/linux-mips.git] / arch / sparc / kernel / leon_kernel.c
blob87f1760c0aa21aa87e9e11ce454c106f5501f311
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 */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/errno.h>
9 #include <linux/mutex.h>
10 #include <linux/slab.h>
11 #include <linux/of.h>
12 #include <linux/of_platform.h>
13 #include <linux/interrupt.h>
14 #include <linux/of_device.h>
16 #include <asm/oplib.h>
17 #include <asm/timer.h>
18 #include <asm/prom.h>
19 #include <asm/leon.h>
20 #include <asm/leon_amba.h>
21 #include <asm/traps.h>
22 #include <asm/cacheflush.h>
24 #include "prom.h"
25 #include "irq.h"
27 struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address, initialized by amba_init() */
28 struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address, initialized by amba_init() */
29 struct amba_apb_device leon_percpu_timer_dev[16];
31 int leondebug_irq_disable;
32 int leon_debug_irqout;
33 static int dummy_master_l10_counter;
35 unsigned long leon3_gptimer_irq; /* interrupt controller irq number, initialized by amba_init() */
36 unsigned int sparc_leon_eirq;
37 #define LEON_IMASK ((&leon3_irqctrl_regs->mask[0]))
39 /* Return the IRQ of the pending IRQ on the extended IRQ controller */
40 int sparc_leon_eirq_get(int eirq, int cpu)
42 return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
45 irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id)
47 printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n");
48 return IRQ_HANDLED;
51 /* The extended IRQ controller has been found, this function registers it */
52 void sparc_leon_eirq_register(int eirq)
54 int irq;
56 /* Register a "BAD" handler for this interrupt, it should never happen */
57 irq = request_irq(eirq, sparc_leon_eirq_isr,
58 (IRQF_DISABLED | SA_STATIC_ALLOC), "extirq", NULL);
60 if (irq) {
61 printk(KERN_ERR
62 "sparc_leon_eirq_register: unable to attach IRQ%d\n",
63 eirq);
64 } else {
65 sparc_leon_eirq = eirq;
70 static inline unsigned long get_irqmask(unsigned int irq)
72 unsigned long mask;
74 if (!irq || ((irq > 0xf) && !sparc_leon_eirq)
75 || ((irq > 0x1f) && sparc_leon_eirq)) {
76 printk(KERN_ERR
77 "leon_get_irqmask: false irq number: %d\n", irq);
78 mask = 0;
79 } else {
80 mask = LEON_HARD_INT(irq);
82 return mask;
85 static void leon_enable_irq(unsigned int irq_nr)
87 unsigned long mask, flags;
88 mask = get_irqmask(irq_nr);
89 local_irq_save(flags);
90 LEON3_BYPASS_STORE_PA(LEON_IMASK,
91 (LEON3_BYPASS_LOAD_PA(LEON_IMASK) | (mask)));
92 local_irq_restore(flags);
95 static void leon_disable_irq(unsigned int irq_nr)
97 unsigned long mask, flags;
98 mask = get_irqmask(irq_nr);
99 local_irq_save(flags);
100 LEON3_BYPASS_STORE_PA(LEON_IMASK,
101 (LEON3_BYPASS_LOAD_PA(LEON_IMASK) & ~(mask)));
102 local_irq_restore(flags);
106 void __init leon_init_timers(irq_handler_t counter_fn)
108 int irq;
110 leondebug_irq_disable = 0;
111 leon_debug_irqout = 0;
112 master_l10_counter = (unsigned int *)&dummy_master_l10_counter;
113 dummy_master_l10_counter = 0;
115 if (leon3_gptimer_regs && leon3_irqctrl_regs) {
116 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0);
117 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld,
118 (((1000000 / 100) - 1)));
119 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0);
121 #ifdef CONFIG_SMP
122 leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs;
123 leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1;
125 if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) &
126 (1<<LEON3_GPTIMER_SEPIRQ))) {
127 prom_printf("irq timer not configured with seperate irqs \n");
128 BUG();
131 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0);
132 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/100) - 1)));
133 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0);
134 # endif
136 } else {
137 printk(KERN_ERR "No Timer/irqctrl found\n");
138 BUG();
141 irq = request_irq(leon3_gptimer_irq,
142 counter_fn,
143 (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
145 if (irq) {
146 printk(KERN_ERR "leon_time_init: unable to attach IRQ%d\n",
147 LEON_INTERRUPT_TIMER1);
148 prom_halt();
151 # ifdef CONFIG_SMP
153 unsigned long flags;
154 struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (leon_percpu_timer_dev[0].irq - 1)];
156 /* For SMP we use the level 14 ticker, however the bootup code
157 * has copied the firmwares level 14 vector into boot cpu's
158 * trap table, we must fix this now or we get squashed.
160 local_irq_save(flags);
162 patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
164 /* Adjust so that we jump directly to smpleon_ticker */
165 trap_table->inst_three += smpleon_ticker - real_irq_entry;
167 local_flush_cache_all();
168 local_irq_restore(flags);
170 # endif
172 if (leon3_gptimer_regs) {
173 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl,
174 LEON3_GPTIMER_EN |
175 LEON3_GPTIMER_RL |
176 LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
178 #ifdef CONFIG_SMP
179 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl,
180 LEON3_GPTIMER_EN |
181 LEON3_GPTIMER_RL |
182 LEON3_GPTIMER_LD |
183 LEON3_GPTIMER_IRQEN);
184 #endif
189 void leon_clear_clock_irq(void)
193 void leon_load_profile_irq(int cpu, unsigned int limit)
195 BUG();
201 void __init leon_trans_init(struct device_node *dp)
203 if (strcmp(dp->type, "cpu") == 0 && strcmp(dp->name, "<NULL>") == 0) {
204 struct property *p;
205 p = of_find_property(dp, "mid", (void *)0);
206 if (p) {
207 int mid;
208 dp->name = prom_early_alloc(5 + 1);
209 memcpy(&mid, p->value, p->length);
210 sprintf((char *)dp->name, "cpu%.2d", mid);
215 void __initdata (*prom_amba_init)(struct device_node *dp, struct device_node ***nextp) = 0;
217 void __init leon_node_init(struct device_node *dp, struct device_node ***nextp)
219 if (prom_amba_init &&
220 strcmp(dp->type, "ambapp") == 0 &&
221 strcmp(dp->name, "ambapp0") == 0) {
222 prom_amba_init(dp, nextp);
226 #ifdef CONFIG_SMP
228 void leon_set_cpu_int(int cpu, int level)
230 unsigned long mask;
231 mask = get_irqmask(level);
232 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask);
235 static void leon_clear_ipi(int cpu, int level)
237 unsigned long mask;
238 mask = get_irqmask(level);
239 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask<<16);
242 static void leon_set_udt(int cpu)
246 void leon_clear_profile_irq(int cpu)
250 void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
252 unsigned long mask, flags, *addr;
253 mask = get_irqmask(irq_nr);
254 local_irq_save(flags);
255 addr = (unsigned long *)&(leon3_irqctrl_regs->mask[cpu]);
256 LEON3_BYPASS_STORE_PA(addr, (LEON3_BYPASS_LOAD_PA(addr) | (mask)));
257 local_irq_restore(flags);
260 #endif
262 void __init leon_init_IRQ(void)
264 sparc_init_timers = leon_init_timers;
266 BTFIXUPSET_CALL(enable_irq, leon_enable_irq, BTFIXUPCALL_NORM);
267 BTFIXUPSET_CALL(disable_irq, leon_disable_irq, BTFIXUPCALL_NORM);
268 BTFIXUPSET_CALL(enable_pil_irq, leon_enable_irq, BTFIXUPCALL_NORM);
269 BTFIXUPSET_CALL(disable_pil_irq, leon_disable_irq, BTFIXUPCALL_NORM);
271 BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq,
272 BTFIXUPCALL_NORM);
273 BTFIXUPSET_CALL(load_profile_irq, leon_load_profile_irq,
274 BTFIXUPCALL_NOP);
276 #ifdef CONFIG_SMP
277 BTFIXUPSET_CALL(set_cpu_int, leon_set_cpu_int, BTFIXUPCALL_NORM);
278 BTFIXUPSET_CALL(clear_cpu_int, leon_clear_ipi, BTFIXUPCALL_NORM);
279 BTFIXUPSET_CALL(set_irq_udt, leon_set_udt, BTFIXUPCALL_NORM);
280 #endif
284 void __init leon_init(void)
286 prom_build_more = &leon_node_init;