2 * linux/arch/arm/mach-imx/irq.c
4 * Copyright (C) 1999 ARM Limited
5 * Copyright (C) 2002 Shane Nay (shane@minirl.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * 03/03/2004 Sascha Hauer <sascha@saschahauer.de>
22 * Copied from the motorola bsp package and added gpio demux
26 #include <linux/init.h>
27 #include <linux/list.h>
28 #include <linux/timer.h>
30 #include <mach/hardware.h>
34 #include <asm/mach/irq.h>
38 * We simply use the ENABLE DISABLE registers inside of the IMX
39 * to turn on/off specific interrupts. FIXME- We should
40 * also add support for the accelerated interrupt controller
41 * by putting offets to irq jump code in the appropriate
46 #define INTCNTL_OFF 0x00
47 #define NIMASK_OFF 0x04
48 #define INTENNUM_OFF 0x08
49 #define INTDISNUM_OFF 0x0C
50 #define INTENABLEH_OFF 0x10
51 #define INTENABLEL_OFF 0x14
52 #define INTTYPEH_OFF 0x18
53 #define INTTYPEL_OFF 0x1C
54 #define NIPRIORITY_OFF(x) (0x20+4*(7-(x)))
55 #define NIVECSR_OFF 0x40
56 #define FIVECSR_OFF 0x44
57 #define INTSRCH_OFF 0x48
58 #define INTSRCL_OFF 0x4C
59 #define INTFRCH_OFF 0x50
60 #define INTFRCL_OFF 0x54
61 #define NIPNDH_OFF 0x58
62 #define NIPNDL_OFF 0x5C
63 #define FIPNDH_OFF 0x60
64 #define FIPNDL_OFF 0x64
66 #define VA_AITC_BASE IO_ADDRESS(IMX_AITC_BASE)
67 #define IMX_AITC_INTCNTL (VA_AITC_BASE + INTCNTL_OFF)
68 #define IMX_AITC_NIMASK (VA_AITC_BASE + NIMASK_OFF)
69 #define IMX_AITC_INTENNUM (VA_AITC_BASE + INTENNUM_OFF)
70 #define IMX_AITC_INTDISNUM (VA_AITC_BASE + INTDISNUM_OFF)
71 #define IMX_AITC_INTENABLEH (VA_AITC_BASE + INTENABLEH_OFF)
72 #define IMX_AITC_INTENABLEL (VA_AITC_BASE + INTENABLEL_OFF)
73 #define IMX_AITC_INTTYPEH (VA_AITC_BASE + INTTYPEH_OFF)
74 #define IMX_AITC_INTTYPEL (VA_AITC_BASE + INTTYPEL_OFF)
75 #define IMX_AITC_NIPRIORITY(x) (VA_AITC_BASE + NIPRIORITY_OFF(x))
76 #define IMX_AITC_NIVECSR (VA_AITC_BASE + NIVECSR_OFF)
77 #define IMX_AITC_FIVECSR (VA_AITC_BASE + FIVECSR_OFF)
78 #define IMX_AITC_INTSRCH (VA_AITC_BASE + INTSRCH_OFF)
79 #define IMX_AITC_INTSRCL (VA_AITC_BASE + INTSRCL_OFF)
80 #define IMX_AITC_INTFRCH (VA_AITC_BASE + INTFRCH_OFF)
81 #define IMX_AITC_INTFRCL (VA_AITC_BASE + INTFRCL_OFF)
82 #define IMX_AITC_NIPNDH (VA_AITC_BASE + NIPNDH_OFF)
83 #define IMX_AITC_NIPNDL (VA_AITC_BASE + NIPNDL_OFF)
84 #define IMX_AITC_FIPNDH (VA_AITC_BASE + FIPNDH_OFF)
85 #define IMX_AITC_FIPNDL (VA_AITC_BASE + FIPNDL_OFF)
88 #define DEBUG_IRQ(fmt...) printk(fmt)
90 #define DEBUG_IRQ(fmt...) do { } while (0)
94 imx_mask_irq(unsigned int irq)
96 __raw_writel(irq, IMX_AITC_INTDISNUM);
100 imx_unmask_irq(unsigned int irq)
102 __raw_writel(irq, IMX_AITC_INTENNUM);
106 imx_gpio_irq_type(unsigned int _irq, unsigned int type)
108 unsigned int irq_type = 0, irq, reg, bit;
110 irq = _irq - IRQ_GPIOA(0);
112 bit = 1 << (irq % 32);
114 if (type == IRQ_TYPE_PROBE) {
115 /* Don't mess with enabled GPIOs using preconfigured edges or
116 GPIOs set to alternate function during probe */
117 /* TODO: support probe */
118 // if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx]) &
121 // if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
123 // type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
129 DEBUG_IRQ("setting type of irq %d to ", _irq);
131 if (type & IRQ_TYPE_EDGE_RISING) {
132 DEBUG_IRQ("rising edges\n");
135 if (type & IRQ_TYPE_EDGE_FALLING) {
136 DEBUG_IRQ("falling edges\n");
139 if (type & IRQ_TYPE_LEVEL_LOW) {
140 DEBUG_IRQ("low level\n");
143 if (type & IRQ_TYPE_LEVEL_HIGH) {
144 DEBUG_IRQ("high level\n");
149 ICR1(reg) = (ICR1(reg) & ~(0x3 << ((irq % 16) * 2))) |
150 (irq_type << ((irq % 16) * 2));
152 ICR2(reg) = (ICR2(reg) & ~(0x3 << ((irq % 16) * 2))) |
153 (irq_type << ((irq % 16) * 2));
161 imx_gpio_ack_irq(unsigned int irq)
163 DEBUG_IRQ("%s: irq %d\n", __func__, irq);
164 ISR(IRQ_TO_REG(irq)) = 1 << ((irq - IRQ_GPIOA(0)) % 32);
168 imx_gpio_mask_irq(unsigned int irq)
170 DEBUG_IRQ("%s: irq %d\n", __func__, irq);
171 IMR(IRQ_TO_REG(irq)) &= ~( 1 << ((irq - IRQ_GPIOA(0)) % 32));
175 imx_gpio_unmask_irq(unsigned int irq)
177 DEBUG_IRQ("%s: irq %d\n", __func__, irq);
178 IMR(IRQ_TO_REG(irq)) |= 1 << ((irq - IRQ_GPIOA(0)) % 32);
182 imx_gpio_handler(unsigned int mask, unsigned int irq,
183 struct irq_desc *desc)
185 desc = irq_desc + irq;
188 DEBUG_IRQ("handling irq %d\n", irq);
189 desc_handle_irq(irq, desc);
198 imx_gpioa_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
200 unsigned int mask, irq;
204 imx_gpio_handler(mask, irq, desc);
208 imx_gpiob_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
210 unsigned int mask, irq;
214 imx_gpio_handler(mask, irq, desc);
218 imx_gpioc_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
220 unsigned int mask, irq;
224 imx_gpio_handler(mask, irq, desc);
228 imx_gpiod_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
230 unsigned int mask, irq;
234 imx_gpio_handler(mask, irq, desc);
237 static struct irq_chip imx_internal_chip = {
240 .mask = imx_mask_irq,
241 .unmask = imx_unmask_irq,
244 static struct irq_chip imx_gpio_chip = {
246 .ack = imx_gpio_ack_irq,
247 .mask = imx_gpio_mask_irq,
248 .unmask = imx_gpio_unmask_irq,
249 .set_type = imx_gpio_irq_type,
257 DEBUG_IRQ("Initializing imx interrupts\n");
259 /* Disable all interrupts initially. */
260 /* Do not rely on the bootloader. */
261 __raw_writel(0, IMX_AITC_INTENABLEH);
262 __raw_writel(0, IMX_AITC_INTENABLEL);
264 /* Mask all GPIO interrupts as well */
270 for (irq = 0; irq < IMX_IRQS; irq++) {
271 set_irq_chip(irq, &imx_internal_chip);
272 set_irq_handler(irq, handle_level_irq);
273 set_irq_flags(irq, IRQF_VALID);
276 for (irq = IRQ_GPIOA(0); irq < IRQ_GPIOD(32); irq++) {
277 set_irq_chip(irq, &imx_gpio_chip);
278 set_irq_handler(irq, handle_edge_irq);
279 set_irq_flags(irq, IRQF_VALID);
282 set_irq_chained_handler(GPIO_INT_PORTA, imx_gpioa_demux_handler);
283 set_irq_chained_handler(GPIO_INT_PORTB, imx_gpiob_demux_handler);
284 set_irq_chained_handler(GPIO_INT_PORTC, imx_gpioc_demux_handler);
285 set_irq_chained_handler(GPIO_INT_PORTD, imx_gpiod_demux_handler);
287 /* Release masking of interrupts according to priority */
288 __raw_writel(-1, IMX_AITC_NIMASK);