davinci: gpio bugfixes
[linux-2.6] / arch / arm / mach-davinci / irq.c
1 /*
2  * Interrupt handler for DaVinci boards.
3  *
4  * Copyright (C) 2006 Texas Instruments.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/io.h>
26
27 #include <mach/hardware.h>
28 #include <asm/mach/irq.h>
29
30 #define IRQ_BIT(irq)            ((irq) & 0x1f)
31
32 #define FIQ_REG0_OFFSET         0x0000
33 #define FIQ_REG1_OFFSET         0x0004
34 #define IRQ_REG0_OFFSET         0x0008
35 #define IRQ_REG1_OFFSET         0x000C
36 #define IRQ_ENT_REG0_OFFSET     0x0018
37 #define IRQ_ENT_REG1_OFFSET     0x001C
38 #define IRQ_INCTL_REG_OFFSET    0x0020
39 #define IRQ_EABASE_REG_OFFSET   0x0024
40 #define IRQ_INTPRI0_REG_OFFSET  0x0030
41 #define IRQ_INTPRI7_REG_OFFSET  0x004C
42
43 #define INTC_BASE IO_ADDRESS(DAVINCI_ARM_INTC_BASE)
44
45 static inline unsigned int davinci_irq_readl(int offset)
46 {
47         return __raw_readl(INTC_BASE + offset);
48 }
49
50 static inline void davinci_irq_writel(unsigned long value, int offset)
51 {
52         __raw_writel(value, INTC_BASE + offset);
53 }
54
55 /* Disable interrupt */
56 static void davinci_mask_irq(unsigned int irq)
57 {
58         unsigned int mask;
59         u32 l;
60
61         mask = 1 << IRQ_BIT(irq);
62
63         if (irq > 31) {
64                 l = davinci_irq_readl(IRQ_ENT_REG1_OFFSET);
65                 l &= ~mask;
66                 davinci_irq_writel(l, IRQ_ENT_REG1_OFFSET);
67         } else {
68                 l = davinci_irq_readl(IRQ_ENT_REG0_OFFSET);
69                 l &= ~mask;
70                 davinci_irq_writel(l, IRQ_ENT_REG0_OFFSET);
71         }
72 }
73
74 /* Enable interrupt */
75 static void davinci_unmask_irq(unsigned int irq)
76 {
77         unsigned int mask;
78         u32 l;
79
80         mask = 1 << IRQ_BIT(irq);
81
82         if (irq > 31) {
83                 l = davinci_irq_readl(IRQ_ENT_REG1_OFFSET);
84                 l |= mask;
85                 davinci_irq_writel(l, IRQ_ENT_REG1_OFFSET);
86         } else {
87                 l = davinci_irq_readl(IRQ_ENT_REG0_OFFSET);
88                 l |= mask;
89                 davinci_irq_writel(l, IRQ_ENT_REG0_OFFSET);
90         }
91 }
92
93 /* EOI interrupt */
94 static void davinci_ack_irq(unsigned int irq)
95 {
96         unsigned int mask;
97
98         mask = 1 << IRQ_BIT(irq);
99
100         if (irq > 31)
101                 davinci_irq_writel(mask, IRQ_REG1_OFFSET);
102         else
103                 davinci_irq_writel(mask, IRQ_REG0_OFFSET);
104 }
105
106 static struct irq_chip davinci_irq_chip_0 = {
107         .name   = "AINTC",
108         .ack    = davinci_ack_irq,
109         .mask   = davinci_mask_irq,
110         .unmask = davinci_unmask_irq,
111 };
112
113
114 /* FIQ are pri 0-1; otherwise 2-7, with 7 lowest priority */
115 static const u8 default_priorities[DAVINCI_N_AINTC_IRQ] __initdata = {
116         [IRQ_VDINT0]            = 2,
117         [IRQ_VDINT1]            = 6,
118         [IRQ_VDINT2]            = 6,
119         [IRQ_HISTINT]           = 6,
120         [IRQ_H3AINT]            = 6,
121         [IRQ_PRVUINT]           = 6,
122         [IRQ_RSZINT]            = 6,
123         [7]                     = 7,
124         [IRQ_VENCINT]           = 6,
125         [IRQ_ASQINT]            = 6,
126         [IRQ_IMXINT]            = 6,
127         [IRQ_VLCDINT]           = 6,
128         [IRQ_USBINT]            = 4,
129         [IRQ_EMACINT]           = 4,
130         [14]                    = 7,
131         [15]                    = 7,
132         [IRQ_CCINT0]            = 5,    /* dma */
133         [IRQ_CCERRINT]          = 5,    /* dma */
134         [IRQ_TCERRINT0]         = 5,    /* dma */
135         [IRQ_TCERRINT]          = 5,    /* dma */
136         [IRQ_PSCIN]             = 7,
137         [21]                    = 7,
138         [IRQ_IDE]               = 4,
139         [23]                    = 7,
140         [IRQ_MBXINT]            = 7,
141         [IRQ_MBRINT]            = 7,
142         [IRQ_MMCINT]            = 7,
143         [IRQ_SDIOINT]           = 7,
144         [28]                    = 7,
145         [IRQ_DDRINT]            = 7,
146         [IRQ_AEMIFINT]          = 7,
147         [IRQ_VLQINT]            = 4,
148         [IRQ_TINT0_TINT12]      = 2,    /* clockevent */
149         [IRQ_TINT0_TINT34]      = 2,    /* clocksource */
150         [IRQ_TINT1_TINT12]      = 7,    /* DSP timer */
151         [IRQ_TINT1_TINT34]      = 7,    /* system tick */
152         [IRQ_PWMINT0]           = 7,
153         [IRQ_PWMINT1]           = 7,
154         [IRQ_PWMINT2]           = 7,
155         [IRQ_I2C]               = 3,
156         [IRQ_UARTINT0]          = 3,
157         [IRQ_UARTINT1]          = 3,
158         [IRQ_UARTINT2]          = 3,
159         [IRQ_SPINT0]            = 3,
160         [IRQ_SPINT1]            = 3,
161         [45]                    = 7,
162         [IRQ_DSP2ARM0]          = 4,
163         [IRQ_DSP2ARM1]          = 4,
164         [IRQ_GPIO0]             = 7,
165         [IRQ_GPIO1]             = 7,
166         [IRQ_GPIO2]             = 7,
167         [IRQ_GPIO3]             = 7,
168         [IRQ_GPIO4]             = 7,
169         [IRQ_GPIO5]             = 7,
170         [IRQ_GPIO6]             = 7,
171         [IRQ_GPIO7]             = 7,
172         [IRQ_GPIOBNK0]          = 7,
173         [IRQ_GPIOBNK1]          = 7,
174         [IRQ_GPIOBNK2]          = 7,
175         [IRQ_GPIOBNK3]          = 7,
176         [IRQ_GPIOBNK4]          = 7,
177         [IRQ_COMMTX]            = 7,
178         [IRQ_COMMRX]            = 7,
179         [IRQ_EMUINT]            = 7,
180 };
181
182 /* ARM Interrupt Controller Initialization */
183 void __init davinci_irq_init(void)
184 {
185         unsigned i;
186         const u8 *priority = default_priorities;
187
188         /* Clear all interrupt requests */
189         davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
190         davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
191         davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
192         davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
193
194         /* Disable all interrupts */
195         davinci_irq_writel(0x0, IRQ_ENT_REG0_OFFSET);
196         davinci_irq_writel(0x0, IRQ_ENT_REG1_OFFSET);
197
198         /* Interrupts disabled immediately, IRQ entry reflects all */
199         davinci_irq_writel(0x0, IRQ_INCTL_REG_OFFSET);
200
201         /* we don't use the hardware vector table, just its entry addresses */
202         davinci_irq_writel(0, IRQ_EABASE_REG_OFFSET);
203
204         /* Clear all interrupt requests */
205         davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
206         davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
207         davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
208         davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
209
210         for (i = IRQ_INTPRI0_REG_OFFSET; i <= IRQ_INTPRI7_REG_OFFSET; i += 4) {
211                 unsigned        j;
212                 u32             pri;
213
214                 for (j = 0, pri = 0; j < 32; j += 4, priority++)
215                         pri |= (*priority & 0x07) << j;
216                 davinci_irq_writel(pri, i);
217         }
218
219         /* set up genirq dispatch for ARM INTC */
220         for (i = 0; i < DAVINCI_N_AINTC_IRQ; i++) {
221                 set_irq_chip(i, &davinci_irq_chip_0);
222                 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
223                 if (i != IRQ_TINT1_TINT34)
224                         set_irq_handler(i, handle_edge_irq);
225                 else
226                         set_irq_handler(i, handle_level_irq);
227         }
228 }