Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[linux-2.6] / arch / h8300 / kernel / irq.c
1 /*
2  * linux/arch/h8300/kernel/irq.c
3  *
4  * Copyright 2007 Yoshinori Sato <ysato@users.sourceforge.jp>
5  */
6
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>
18
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>
24
25 /*#define DEBUG*/
26
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);
32
33 #define CPU_VECTOR ((unsigned long *)0x000000)
34 #define ADDR_MASK (0xffffff)
35
36 static inline int is_ext_irq(unsigned int irq)
37 {
38         return (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS));
39 }
40
41 static void h8300_enable_irq(unsigned int irq)
42 {
43         if (is_ext_irq(irq))
44                 IER_REGS |= 1 << (irq - EXT_IRQ0);
45 }
46
47 static void h8300_disable_irq(unsigned int irq)
48 {
49         if (is_ext_irq(irq))
50                 IER_REGS &= ~(1 << (irq - EXT_IRQ0));
51 }
52
53 static void h8300_end_irq(unsigned int irq)
54 {
55 }
56
57 static unsigned int h8300_startup_irq(unsigned int irq)
58 {
59         if (is_ext_irq(irq))
60                 return h8300_enable_irq_pin(irq);
61         else
62                 return 0;
63 }
64
65 static void h8300_shutdown_irq(unsigned int irq)
66 {
67         if (is_ext_irq(irq))
68                 h8300_disable_irq_pin(irq);
69 }
70
71 /*
72  * h8300 interrupt controller implementation
73  */
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,
82 };
83
84 void ack_bad_irq(unsigned int irq)
85 {
86         printk("unexpected IRQ trap at vector %02x\n", irq);
87 }
88
89 #if defined(CONFIG_RAMKERNEL)
90 static unsigned long __init *get_vector_address(void)
91 {
92         unsigned long *rom_vector = CPU_VECTOR;
93         unsigned long base,tmp;
94         int vec_no;
95
96         base = rom_vector[EXT_IRQ0] & ADDR_MASK;
97
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;
102         }
103
104         /* ramvector base address */
105         base -= EXT_IRQ0*4;
106
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;
113 }
114
115 static void __init setup_vector(void)
116 {
117         int i;
118         unsigned long *ramvec,*ramvec_p;
119         const h8300_vector *trap_entry;
120         const int *saved_vector;
121
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);
127
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);
144                 }
145         }
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++;
154         }
155         printk(KERN_DEBUG "\n");
156 #endif
157 }
158 #else
159 #define setup_vector() do { } while(0)
160 #endif
161
162 void __init init_IRQ(void)
163 {
164         int c;
165
166         setup_vector();
167
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;
173         }
174 }
175
176 asmlinkage void do_IRQ(int irq)
177 {
178         irq_enter();
179         __do_IRQ(irq);
180         irq_exit();
181 }
182
183 #if defined(CONFIG_PROC_FS)
184 int show_interrupts(struct seq_file *p, void *v)
185 {
186         int i = *(loff_t *) v;
187         struct irqaction * action;
188         unsigned long flags;
189
190         if (i == 0)
191                 seq_puts(p, "           CPU0");
192
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_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);
203
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);
209         }
210         return 0;
211 }
212 #endif