Merge branch 'master' of /home/sam/kernel/linux-2.6/
[pandora-kernel.git] / arch / arm / mach-at91rm9200 / irq.c
1 /*
2  * linux/arch/arm/mach-at91rm9200/irq.c
3  *
4  *  Copyright (C) 2004 SAN People
5  *  Copyright (C) 2004 ATMEL
6  *  Copyright (C) Rick Bronson
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/mm.h>
26 #include <linux/types.h>
27
28 #include <asm/hardware.h>
29 #include <asm/irq.h>
30 #include <asm/mach-types.h>
31 #include <asm/setup.h>
32
33 #include <asm/mach/arch.h>
34 #include <asm/mach/irq.h>
35 #include <asm/mach/map.h>
36
37 #include "generic.h"
38
39 /*
40  * The default interrupt priority levels (0 = lowest, 7 = highest).
41  */
42 static unsigned int at91rm9200_default_irq_priority[NR_AIC_IRQS] __initdata = {
43         7,      /* Advanced Interrupt Controller */
44         7,      /* System Peripheral */
45         0,      /* Parallel IO Controller A */
46         0,      /* Parallel IO Controller B */
47         0,      /* Parallel IO Controller C */
48         0,      /* Parallel IO Controller D */
49         6,      /* USART 0 */
50         6,      /* USART 1 */
51         6,      /* USART 2 */
52         6,      /* USART 3 */
53         0,      /* Multimedia Card Interface */
54         4,      /* USB Device Port */
55         0,      /* Two-Wire Interface */
56         6,      /* Serial Peripheral Interface */
57         5,      /* Serial Synchronous Controller */
58         5,      /* Serial Synchronous Controller */
59         5,      /* Serial Synchronous Controller */
60         0,      /* Timer Counter 0 */
61         0,      /* Timer Counter 1 */
62         0,      /* Timer Counter 2 */
63         0,      /* Timer Counter 3 */
64         0,      /* Timer Counter 4 */
65         0,      /* Timer Counter 5 */
66         3,      /* USB Host port */
67         3,      /* Ethernet MAC */
68         0,      /* Advanced Interrupt Controller */
69         0,      /* Advanced Interrupt Controller */
70         0,      /* Advanced Interrupt Controller */
71         0,      /* Advanced Interrupt Controller */
72         0,      /* Advanced Interrupt Controller */
73         0,      /* Advanced Interrupt Controller */
74         0       /* Advanced Interrupt Controller */
75 };
76
77
78 static void at91rm9200_mask_irq(unsigned int irq)
79 {
80         /* Disable interrupt on AIC */
81         at91_sys_write(AT91_AIC_IDCR, 1 << irq);
82 }
83
84 static void at91rm9200_unmask_irq(unsigned int irq)
85 {
86         /* Enable interrupt on AIC */
87         at91_sys_write(AT91_AIC_IECR, 1 << irq);
88 }
89
90 static int at91rm9200_irq_type(unsigned irq, unsigned type)
91 {
92         unsigned int smr, srctype;
93
94         switch (type) {
95         case IRQT_HIGH:
96                 srctype = AT91_AIC_SRCTYPE_HIGH;
97                 break;
98         case IRQT_RISING:
99                 srctype = AT91_AIC_SRCTYPE_RISING;
100                 break;
101         case IRQT_LOW:
102                 if ((irq > AT91_ID_FIQ) && (irq < AT91_ID_IRQ0))        /* only supported on external interrupts */
103                         return -EINVAL;
104                 srctype = AT91_AIC_SRCTYPE_LOW;
105                 break;
106         case IRQT_FALLING:
107                 if ((irq > AT91_ID_FIQ) && (irq < AT91_ID_IRQ0))        /* only supported on external interrupts */
108                         return -EINVAL;
109                 srctype = AT91_AIC_SRCTYPE_FALLING;
110                 break;
111         default:
112                 return -EINVAL;
113         }
114
115         smr = at91_sys_read(AT91_AIC_SMR(irq)) & ~AT91_AIC_SRCTYPE;
116         at91_sys_write(AT91_AIC_SMR(irq), smr | srctype);
117         return 0;
118 }
119
120 #ifdef CONFIG_PM
121
122 static u32 wakeups;
123 static u32 backups;
124
125 static int at91rm9200_irq_set_wake(unsigned irq, unsigned value)
126 {
127         if (unlikely(irq >= 32))
128                 return -EINVAL;
129
130         if (value)
131                 wakeups |= (1 << irq);
132         else
133                 wakeups &= ~(1 << irq);
134
135         return 0;
136 }
137
138 void at91_irq_suspend(void)
139 {
140         backups = at91_sys_read(AT91_AIC_IMR);
141         at91_sys_write(AT91_AIC_IDCR, backups);
142         at91_sys_write(AT91_AIC_IECR, wakeups);
143 }
144
145 void at91_irq_resume(void)
146 {
147         at91_sys_write(AT91_AIC_IDCR, wakeups);
148         at91_sys_write(AT91_AIC_IECR, backups);
149 }
150
151 #else
152 #define at91rm9200_irq_set_wake NULL
153 #endif
154
155 static struct irqchip at91rm9200_irq_chip = {
156         .ack            = at91rm9200_mask_irq,
157         .mask           = at91rm9200_mask_irq,
158         .unmask         = at91rm9200_unmask_irq,
159         .set_type       = at91rm9200_irq_type,
160         .set_wake       = at91rm9200_irq_set_wake,
161 };
162
163 /*
164  * Initialize the AIC interrupt controller.
165  */
166 void __init at91rm9200_init_irq(unsigned int priority[NR_AIC_IRQS])
167 {
168         unsigned int i;
169
170         /* No priority list specified for this board -> use defaults */
171         if (priority == NULL)
172                 priority = at91rm9200_default_irq_priority;
173
174         /*
175          * The IVR is used by macro get_irqnr_and_base to read and verify.
176          * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
177          */
178         for (i = 0; i < NR_AIC_IRQS; i++) {
179                 /* Put irq number in Source Vector Register: */
180                 at91_sys_write(AT91_AIC_SVR(i), i);
181                 /* Store the Source Mode Register as defined in table above */
182                 at91_sys_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
183
184                 set_irq_chip(i, &at91rm9200_irq_chip);
185                 set_irq_handler(i, do_level_IRQ);
186                 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
187
188                 /* Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ */
189                 if (i < 8)
190                         at91_sys_write(AT91_AIC_EOICR, 0);
191         }
192
193         /*
194          * Spurious Interrupt ID in Spurious Vector Register is NR_AIC_IRQS
195          * When there is no current interrupt, the IRQ Vector Register reads the value stored in AIC_SPU
196          */
197         at91_sys_write(AT91_AIC_SPU, NR_AIC_IRQS);
198
199         /* No debugging in AIC: Debug (Protect) Control Register */
200         at91_sys_write(AT91_AIC_DCR, 0);
201
202         /* Disable and clear all interrupts initially */
203         at91_sys_write(AT91_AIC_IDCR, 0xFFFFFFFF);
204         at91_sys_write(AT91_AIC_ICCR, 0xFFFFFFFF);
205 }