Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-pxa/irq.c |
| 3 | * |
eric miao | e3630db | 2008-03-04 11:42:26 +0800 | [diff] [blame] | 4 | * Generic PXA IRQ handling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Author: Nicolas Pitre |
| 7 | * Created: Jun 15, 2001 |
| 8 | * Copyright: MontaVista Software Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/interrupt.h> |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 18 | #include <linux/sysdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 20 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/irq.h> |
| 22 | #include <asm/mach/irq.h> |
Eric Miao | a58fbcd | 2009-01-06 17:37:37 +0800 | [diff] [blame] | 23 | #include <mach/gpio.h> |
Eric Miao | 5bf3df3 | 2009-01-20 11:04:16 +0800 | [diff] [blame] | 24 | #include <mach/regs-intc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "generic.h" |
| 27 | |
Haojian Zhuang | c482ae4 | 2009-11-02 14:02:21 -0500 | [diff] [blame] | 28 | #define MAX_INTERNAL_IRQS 128 |
| 29 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 30 | #define IRQ_BIT(n) (((n) - PXA_IRQ(0)) & 0x1f) |
| 31 | #define _ICMR(n) (*((((n) - PXA_IRQ(0)) & ~0x1f) ? &ICMR2 : &ICMR)) |
| 32 | #define _ICLR(n) (*((((n) - PXA_IRQ(0)) & ~0x1f) ? &ICLR2 : &ICLR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * This is for peripheral IRQs internal to the PXA chip. |
| 36 | */ |
| 37 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 38 | static int pxa_internal_irq_nr; |
| 39 | |
Haojian Zhuang | bb71bdd | 2010-11-17 19:03:36 +0800 | [diff] [blame^] | 40 | static inline int cpu_has_ipr(void) |
| 41 | { |
| 42 | return !cpu_is_pxa25x(); |
| 43 | } |
| 44 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 45 | static void pxa_mask_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 47 | _ICMR(irq) &= ~(1 << IRQ_BIT(irq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 50 | static void pxa_unmask_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 52 | _ICMR(irq) |= 1 << IRQ_BIT(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 55 | static struct irq_chip pxa_internal_irq_chip = { |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 56 | .name = "SC", |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 57 | .ack = pxa_mask_irq, |
| 58 | .mask = pxa_mask_irq, |
| 59 | .unmask = pxa_unmask_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Eric Miao | a58fbcd | 2009-01-06 17:37:37 +0800 | [diff] [blame] | 62 | /* |
| 63 | * GPIO IRQs for GPIO 0 and 1 |
| 64 | */ |
| 65 | static int pxa_set_low_gpio_type(unsigned int irq, unsigned int type) |
| 66 | { |
| 67 | int gpio = irq - IRQ_GPIO0; |
| 68 | |
| 69 | if (__gpio_is_occupied(gpio)) { |
| 70 | pr_err("%s failed: GPIO is configured\n", __func__); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | |
| 74 | if (type & IRQ_TYPE_EDGE_RISING) |
| 75 | GRER0 |= GPIO_bit(gpio); |
| 76 | else |
| 77 | GRER0 &= ~GPIO_bit(gpio); |
| 78 | |
| 79 | if (type & IRQ_TYPE_EDGE_FALLING) |
| 80 | GFER0 |= GPIO_bit(gpio); |
| 81 | else |
| 82 | GFER0 &= ~GPIO_bit(gpio); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static void pxa_ack_low_gpio(unsigned int irq) |
| 88 | { |
| 89 | GEDR0 = (1 << (irq - IRQ_GPIO0)); |
| 90 | } |
| 91 | |
| 92 | static void pxa_mask_low_gpio(unsigned int irq) |
| 93 | { |
| 94 | ICMR &= ~(1 << (irq - PXA_IRQ(0))); |
| 95 | } |
| 96 | |
| 97 | static void pxa_unmask_low_gpio(unsigned int irq) |
| 98 | { |
| 99 | ICMR |= 1 << (irq - PXA_IRQ(0)); |
| 100 | } |
| 101 | |
| 102 | static struct irq_chip pxa_low_gpio_chip = { |
| 103 | .name = "GPIO-l", |
| 104 | .ack = pxa_ack_low_gpio, |
| 105 | .mask = pxa_mask_low_gpio, |
| 106 | .unmask = pxa_unmask_low_gpio, |
| 107 | .set_type = pxa_set_low_gpio_type, |
| 108 | }; |
| 109 | |
| 110 | static void __init pxa_init_low_gpio_irq(set_wake_t fn) |
| 111 | { |
| 112 | int irq; |
| 113 | |
| 114 | /* clear edge detection on GPIO 0 and 1 */ |
| 115 | GFER0 &= ~0x3; |
| 116 | GRER0 &= ~0x3; |
| 117 | GEDR0 = 0x3; |
| 118 | |
| 119 | for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) { |
| 120 | set_irq_chip(irq, &pxa_low_gpio_chip); |
| 121 | set_irq_handler(irq, handle_edge_irq); |
| 122 | set_irq_flags(irq, IRQF_VALID); |
| 123 | } |
| 124 | |
| 125 | pxa_low_gpio_chip.set_wake = fn; |
| 126 | } |
| 127 | |
eric miao | b9e25ac | 2008-03-04 14:19:58 +0800 | [diff] [blame] | 128 | void __init pxa_init_irq(int irq_nr, set_wake_t fn) |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 129 | { |
Haojian Zhuang | d2c3706 | 2009-08-19 19:49:31 +0800 | [diff] [blame] | 130 | int irq, i; |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 131 | |
Haojian Zhuang | c482ae4 | 2009-11-02 14:02:21 -0500 | [diff] [blame] | 132 | BUG_ON(irq_nr > MAX_INTERNAL_IRQS); |
| 133 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 134 | pxa_internal_irq_nr = irq_nr; |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 135 | |
Marc Zyngier | 57a7a62 | 2008-09-01 13:03:32 +0100 | [diff] [blame] | 136 | for (irq = PXA_IRQ(0); irq < PXA_IRQ(irq_nr); irq += 32) { |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 137 | _ICMR(irq) = 0; /* disable all IRQs */ |
| 138 | _ICLR(irq) = 0; /* all IRQs are IRQ, not FIQ */ |
| 139 | } |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 140 | |
Haojian Zhuang | d2c3706 | 2009-08-19 19:49:31 +0800 | [diff] [blame] | 141 | /* initialize interrupt priority */ |
Haojian Zhuang | bb71bdd | 2010-11-17 19:03:36 +0800 | [diff] [blame^] | 142 | if (cpu_has_ipr()) { |
Haojian Zhuang | d2c3706 | 2009-08-19 19:49:31 +0800 | [diff] [blame] | 143 | for (i = 0; i < irq_nr; i++) |
| 144 | IPR(i) = i | (1 << 31); |
| 145 | } |
| 146 | |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 147 | /* only unmasked interrupts kick us out of idle */ |
| 148 | ICCR = 1; |
| 149 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 150 | for (irq = PXA_IRQ(0); irq < PXA_IRQ(irq_nr); irq++) { |
| 151 | set_irq_chip(irq, &pxa_internal_irq_chip); |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 152 | set_irq_handler(irq, handle_level_irq); |
| 153 | set_irq_flags(irq, IRQF_VALID); |
| 154 | } |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 155 | |
eric miao | b9e25ac | 2008-03-04 14:19:58 +0800 | [diff] [blame] | 156 | pxa_internal_irq_chip.set_wake = fn; |
Eric Miao | a58fbcd | 2009-01-06 17:37:37 +0800 | [diff] [blame] | 157 | pxa_init_low_gpio_irq(fn); |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame] | 158 | } |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 159 | |
| 160 | #ifdef CONFIG_PM |
Haojian Zhuang | c482ae4 | 2009-11-02 14:02:21 -0500 | [diff] [blame] | 161 | static unsigned long saved_icmr[MAX_INTERNAL_IRQS/32]; |
| 162 | static unsigned long saved_ipr[MAX_INTERNAL_IRQS]; |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 163 | |
| 164 | static int pxa_irq_suspend(struct sys_device *dev, pm_message_t state) |
| 165 | { |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 166 | int i, irq = PXA_IRQ(0); |
| 167 | |
| 168 | for (i = 0; irq < PXA_IRQ(pxa_internal_irq_nr); i++, irq += 32) { |
| 169 | saved_icmr[i] = _ICMR(irq); |
| 170 | _ICMR(irq) = 0; |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 171 | } |
Eric Miao | c70f5a6 | 2010-01-11 20:39:37 +0800 | [diff] [blame] | 172 | |
Haojian Zhuang | bb71bdd | 2010-11-17 19:03:36 +0800 | [diff] [blame^] | 173 | if (cpu_has_ipr()) { |
Eric Miao | c70f5a6 | 2010-01-11 20:39:37 +0800 | [diff] [blame] | 174 | for (i = 0; i < pxa_internal_irq_nr; i++) |
| 175 | saved_ipr[i] = IPR(i); |
| 176 | } |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static int pxa_irq_resume(struct sys_device *dev) |
| 182 | { |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 183 | int i, irq = PXA_IRQ(0); |
| 184 | |
Haojian Zhuang | bb71bdd | 2010-11-17 19:03:36 +0800 | [diff] [blame^] | 185 | if (cpu_has_ipr()) { |
Eric Miao | c70f5a6 | 2010-01-11 20:39:37 +0800 | [diff] [blame] | 186 | for (i = 0; i < pxa_internal_irq_nr; i++) |
| 187 | IPR(i) = saved_ipr[i]; |
| 188 | } |
| 189 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 190 | for (i = 0; irq < PXA_IRQ(pxa_internal_irq_nr); i++, irq += 32) { |
| 191 | _ICMR(irq) = saved_icmr[i]; |
| 192 | _ICLR(irq) = 0; |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 193 | } |
| 194 | |
eric miao | f6fb7af | 2008-03-04 13:53:05 +0800 | [diff] [blame] | 195 | ICCR = 1; |
eric miao | c0165504 | 2008-01-28 23:00:02 +0000 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | #else |
| 199 | #define pxa_irq_suspend NULL |
| 200 | #define pxa_irq_resume NULL |
| 201 | #endif |
| 202 | |
| 203 | struct sysdev_class pxa_irq_sysclass = { |
| 204 | .name = "irq", |
| 205 | .suspend = pxa_irq_suspend, |
| 206 | .resume = pxa_irq_resume, |
| 207 | }; |
| 208 | |
| 209 | static int __init pxa_irq_init(void) |
| 210 | { |
| 211 | return sysdev_class_register(&pxa_irq_sysclass); |
| 212 | } |
| 213 | |
| 214 | core_initcall(pxa_irq_init); |