Pull acpi_os_free into release branch
[pandora-kernel.git] / arch / sh / boards / superh / microdev / irq.c
1 /*
2  * arch/sh/boards/superh/microdev/irq.c
3  *
4  * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
5  *
6  * SuperH SH4-202 MicroDev board support.
7  *
8  * May be copied or modified under the terms of the GNU General Public
9  * License.  See linux/COPYING for more information.
10  */
11
12 #include <linux/init.h>
13 #include <linux/irq.h>
14
15 #include <asm/system.h>
16 #include <asm/io.h>
17 #include <asm/microdev.h>
18
19 #define NUM_EXTERNAL_IRQS 16    /* IRL0 .. IRL15 */
20
21
22 static const struct {
23         unsigned char fpgaIrq;
24         unsigned char mapped;
25         const char *name;
26 } fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
27         { 0,                            0,      "unused"   },           /* IRQ #0       IRL=15  0x200  */
28         { MICRODEV_FPGA_IRQ_KEYBOARD,   1,      "keyboard" },           /* IRQ #1       IRL=14  0x220  */
29         { MICRODEV_FPGA_IRQ_SERIAL1,    1,      "Serial #1"},           /* IRQ #2       IRL=13  0x240  */
30         { MICRODEV_FPGA_IRQ_ETHERNET,   1,      "Ethernet" },           /* IRQ #3       IRL=12  0x260  */
31         { MICRODEV_FPGA_IRQ_SERIAL2,    0,      "Serial #2"},           /* IRQ #4       IRL=11  0x280  */
32         { 0,                            0,      "unused"   },           /* IRQ #5       IRL=10  0x2a0  */
33         { 0,                            0,      "unused"   },           /* IRQ #6       IRL=9   0x2c0  */
34         { MICRODEV_FPGA_IRQ_USB_HC,     1,      "USB"      },           /* IRQ #7       IRL=8   0x2e0  */
35         { MICRODEV_IRQ_PCI_INTA,        1,      "PCI INTA" },           /* IRQ #8       IRL=7   0x300  */
36         { MICRODEV_IRQ_PCI_INTB,        1,      "PCI INTB" },           /* IRQ #9       IRL=6   0x320  */
37         { MICRODEV_IRQ_PCI_INTC,        1,      "PCI INTC" },           /* IRQ #10      IRL=5   0x340  */
38         { MICRODEV_IRQ_PCI_INTD,        1,      "PCI INTD" },           /* IRQ #11      IRL=4   0x360  */
39         { MICRODEV_FPGA_IRQ_MOUSE,      1,      "mouse"    },           /* IRQ #12      IRL=3   0x380  */
40         { MICRODEV_FPGA_IRQ_IDE2,       1,      "IDE #2"   },           /* IRQ #13      IRL=2   0x3a0  */
41         { MICRODEV_FPGA_IRQ_IDE1,       1,      "IDE #1"   },           /* IRQ #14      IRL=1   0x3c0  */
42         { 0,                            0,      "unused"   },           /* IRQ #15      IRL=0   0x3e0  */
43 };
44
45 #if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
46 #  error Inconsistancy in defining the IRQ# for Keyboard!
47 #endif
48
49 #if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
50 #  error Inconsistancy in defining the IRQ# for Ethernet!
51 #endif
52
53 #if (MICRODEV_LINUX_IRQ_USB_HC != 7)
54 #  error Inconsistancy in defining the IRQ# for USB!
55 #endif
56
57 #if (MICRODEV_LINUX_IRQ_MOUSE != 12)
58 #  error Inconsistancy in defining the IRQ# for PS/2 Mouse!
59 #endif
60
61 #if (MICRODEV_LINUX_IRQ_IDE2 != 13)
62 #  error Inconsistancy in defining the IRQ# for secondary IDE!
63 #endif
64
65 #if (MICRODEV_LINUX_IRQ_IDE1 != 14)
66 #  error Inconsistancy in defining the IRQ# for primary IDE!
67 #endif
68
69 static void enable_microdev_irq(unsigned int irq);
70 static void disable_microdev_irq(unsigned int irq);
71
72         /* shutdown is same as "disable" */
73 #define shutdown_microdev_irq disable_microdev_irq
74
75 static void mask_and_ack_microdev(unsigned int);
76 static void end_microdev_irq(unsigned int irq);
77
78 static unsigned int startup_microdev_irq(unsigned int irq)
79 {
80         enable_microdev_irq(irq);
81         return 0;               /* never anything pending */
82 }
83
84 static struct hw_interrupt_type microdev_irq_type = {
85         .typename = "MicroDev-IRQ",
86         .startup = startup_microdev_irq,
87         .shutdown = shutdown_microdev_irq,
88         .enable = enable_microdev_irq,
89         .disable = disable_microdev_irq,
90         .ack = mask_and_ack_microdev,
91         .end = end_microdev_irq
92 };
93
94 static void disable_microdev_irq(unsigned int irq)
95 {
96         unsigned int flags;
97         unsigned int fpgaIrq;
98
99         if (irq >= NUM_EXTERNAL_IRQS) return;
100         if (!fpgaIrqTable[irq].mapped) return;
101
102         fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
103
104                 /* disable interrupts */
105         local_irq_save(flags);
106
107                 /* disable interupts on the FPGA INTC register */
108         ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
109
110                 /* restore interrupts */
111         local_irq_restore(flags);
112 }
113
114 static void enable_microdev_irq(unsigned int irq)
115 {
116         unsigned long priorityReg, priorities, pri;
117         unsigned int flags;
118         unsigned int fpgaIrq;
119
120
121         if (irq >= NUM_EXTERNAL_IRQS) return;
122         if (!fpgaIrqTable[irq].mapped) return;
123
124         pri = 15 - irq;
125
126         fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
127         priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
128
129                 /* disable interrupts */
130         local_irq_save(flags);
131
132                 /* set priority for the interrupt */
133         priorities = ctrl_inl(priorityReg);
134         priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
135         priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
136         ctrl_outl(priorities, priorityReg);
137
138                 /* enable interupts on the FPGA INTC register */
139         ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
140
141                 /* restore interrupts */
142         local_irq_restore(flags);
143 }
144
145         /* This functions sets the desired irq handler to be a MicroDev type */
146 static void __init make_microdev_irq(unsigned int irq)
147 {
148         disable_irq_nosync(irq);
149         irq_desc[irq].chip = &microdev_irq_type;
150         disable_microdev_irq(irq);
151 }
152
153 static void mask_and_ack_microdev(unsigned int irq)
154 {
155         disable_microdev_irq(irq);
156 }
157
158 static void end_microdev_irq(unsigned int irq)
159 {
160         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
161         {
162                 enable_microdev_irq(irq);
163         }
164 }
165
166 extern void __init init_microdev_irq(void)
167 {
168         int i;
169
170                 /* disable interupts on the FPGA INTC register */
171         ctrl_outl(~0ul, MICRODEV_FPGA_INTDSB_REG);
172
173         for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
174         {
175                 make_microdev_irq(i);
176         }
177 }
178
179 extern void microdev_print_fpga_intc_status(void)
180 {
181         volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
182         volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
183         volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
184         volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
185         volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
186         volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
187         volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
188         volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
189
190         printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
191         printk("FPGA_INTENB = 0x%08x\n", *intenb);
192         printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
193         printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
194         printk("FPGA_INTREQ = 0x%08x\n", *intreq);
195         printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
196         printk("-------------------------------------------------------------------------------\n");
197 }
198
199