AT91: Added a generic way to setup AT91 serial ports in Kconfig
[linux-2.6/pdupreez.git] / arch / h8300 / kernel / irq.c
blobef4f0047067d309663f116cd537a5f04d635786a
1 /*
2 * linux/arch/h8300/kernel/irq.c
4 * Copyright 2007 Yoshinori Sato <ysato@users.sourceforge.jp>
5 */
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/kernel_stat.h>
12 #include <linux/seq_file.h>
13 #include <linux/init.h>
14 #include <linux/random.h>
15 #include <linux/bootmem.h>
16 #include <linux/irq.h>
17 #include <linux/interrupt.h>
19 #include <asm/system.h>
20 #include <asm/traps.h>
21 #include <asm/io.h>
22 #include <asm/setup.h>
23 #include <asm/errno.h>
25 /*#define DEBUG*/
27 extern unsigned long *interrupt_redirect_table;
28 extern const int h8300_saved_vectors[];
29 extern const h8300_vector h8300_trap_table[];
30 int h8300_enable_irq_pin(unsigned int irq);
31 void h8300_disable_irq_pin(unsigned int irq);
33 #define CPU_VECTOR ((unsigned long *)0x000000)
34 #define ADDR_MASK (0xffffff)
36 static inline int is_ext_irq(unsigned int irq)
38 return (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS));
41 static void h8300_enable_irq(unsigned int irq)
43 if (is_ext_irq(irq))
44 IER_REGS |= 1 << (irq - EXT_IRQ0);
47 static void h8300_disable_irq(unsigned int irq)
49 if (is_ext_irq(irq))
50 IER_REGS &= ~(1 << (irq - EXT_IRQ0));
53 static void h8300_end_irq(unsigned int irq)
57 static unsigned int h8300_startup_irq(unsigned int irq)
59 if (is_ext_irq(irq))
60 return h8300_enable_irq_pin(irq);
61 else
62 return 0;
65 static void h8300_shutdown_irq(unsigned int irq)
67 if (is_ext_irq(irq))
68 h8300_disable_irq_pin(irq);
72 * h8300 interrupt controller implementation
74 struct irq_chip h8300irq_chip = {
75 .name = "H8300-INTC",
76 .startup = h8300_startup_irq,
77 .shutdown = h8300_shutdown_irq,
78 .enable = h8300_enable_irq,
79 .disable = h8300_disable_irq,
80 .ack = NULL,
81 .end = h8300_end_irq,
84 void ack_bad_irq(unsigned int irq)
86 printk("unexpected IRQ trap at vector %02x\n", irq);
89 #if defined(CONFIG_RAMKERNEL)
90 static unsigned long __init *get_vector_address(void)
92 unsigned long *rom_vector = CPU_VECTOR;
93 unsigned long base,tmp;
94 int vec_no;
96 base = rom_vector[EXT_IRQ0] & ADDR_MASK;
98 /* check romvector format */
99 for (vec_no = EXT_IRQ1; vec_no <= EXT_IRQ0+EXT_IRQS; vec_no++) {
100 if ((base+(vec_no - EXT_IRQ0)*4) != (rom_vector[vec_no] & ADDR_MASK))
101 return NULL;
104 /* ramvector base address */
105 base -= EXT_IRQ0*4;
107 /* writerble check */
108 tmp = ~(*(volatile unsigned long *)base);
109 (*(volatile unsigned long *)base) = tmp;
110 if ((*(volatile unsigned long *)base) != tmp)
111 return NULL;
112 return (unsigned long *)base;
115 static void __init setup_vector(void)
117 int i;
118 unsigned long *ramvec,*ramvec_p;
119 const h8300_vector *trap_entry;
120 const int *saved_vector;
122 ramvec = get_vector_address();
123 if (ramvec == NULL)
124 panic("interrupt vector serup failed.");
125 else
126 printk(KERN_INFO "virtual vector at 0x%08lx\n",(unsigned long)ramvec);
128 /* create redirect table */
129 ramvec_p = ramvec;
130 trap_entry = h8300_trap_table;
131 saved_vector = h8300_saved_vectors;
132 for ( i = 0; i < NR_IRQS; i++) {
133 if (i == *saved_vector) {
134 ramvec_p++;
135 saved_vector++;
136 } else {
137 if ( i < NR_TRAPS ) {
138 if (*trap_entry)
139 *ramvec_p = VECTOR(*trap_entry);
140 ramvec_p++;
141 trap_entry++;
142 } else
143 *ramvec_p++ = REDIRECT(interrupt_entry);
146 interrupt_redirect_table = ramvec;
147 #ifdef DEBUG
148 ramvec_p = ramvec;
149 for (i = 0; i < NR_IRQS; i++) {
150 if ((i % 8) == 0)
151 printk(KERN_DEBUG "\n%p: ",ramvec_p);
152 printk(KERN_DEBUG "%p ",*ramvec_p);
153 ramvec_p++;
155 printk(KERN_DEBUG "\n");
156 #endif
158 #else
159 #define setup_vector() do { } while(0)
160 #endif
162 void __init init_IRQ(void)
164 int c;
166 setup_vector();
168 for (c = 0; c < NR_IRQS; c++) {
169 irq_desc[c].status = IRQ_DISABLED;
170 irq_desc[c].action = NULL;
171 irq_desc[c].depth = 1;
172 irq_desc[c].chip = &h8300irq_chip;
176 asmlinkage void do_IRQ(int irq)
178 irq_enter();
179 __do_IRQ(irq);
180 irq_exit();
183 #if defined(CONFIG_PROC_FS)
184 int show_interrupts(struct seq_file *p, void *v)
186 int i = *(loff_t *) v, j;
187 struct irqaction * action;
188 unsigned long flags;
190 if (i == 0)
191 seq_puts(p, " CPU0");
193 if (i < NR_IRQS) {
194 spin_lock_irqsave(&irq_desc[i].lock, flags);
195 action = irq_desc[i].action;
196 if (!action)
197 goto unlock;
198 seq_printf(p, "%3d: ",i);
199 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
200 seq_printf(p, " %14s", irq_desc[i].chip->name);
201 seq_printf(p, "-%-8s", irq_desc[i].name);
202 seq_printf(p, " %s", action->name);
204 for (action=action->next; action; action = action->next)
205 seq_printf(p, ", %s", action->name);
206 seq_putc(p, '\n');
207 unlock:
208 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
210 return 0;
212 #endif