1 /* 2 * linux/arch/arm/mach-pxa/irq.c 3 * 4 * Generic PXA IRQ handling 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> 18 #include <linux/syscore_ops.h> 19 #include <linux/io.h> 20 #include <linux/irq.h> 21 22 #include <asm/exception.h> 23 24 #include <mach/hardware.h> 25 #include <mach/irqs.h> 26 #include <mach/gpio.h> 27 28 #include "generic.h" 29 30 #define IRQ_BASE (void __iomem *)io_p2v(0x40d00000) 31 32 #define ICIP (0x000) 33 #define ICMR (0x004) 34 #define ICLR (0x008) 35 #define ICFR (0x00c) 36 #define ICPR (0x010) 37 #define ICCR (0x014) 38 #define ICHP (0x018) 39 #define IPR(i) (((i) < 32) ? (0x01c + ((i) << 2)) : \ 40 ((i) < 64) ? (0x0b0 + (((i) - 32) << 2)) : \ 41 (0x144 + (((i) - 64) << 2))) 42 #define ICHP_VAL_IRQ (1 << 31) 43 #define ICHP_IRQ(i) (((i) >> 16) & 0x7fff) 44 #define IPR_VALID (1 << 31) 45 #define IRQ_BIT(n) (((n) - PXA_IRQ(0)) & 0x1f) 46 47 #define MAX_INTERNAL_IRQS 128 48 49 /* 50 * This is for peripheral IRQs internal to the PXA chip. 51 */ 52 53 static int pxa_internal_irq_nr; 54 55 static inline int cpu_has_ipr(void) 56 { 57 return !cpu_is_pxa25x(); 58 } 59 60 static inline void __iomem *irq_base(int i) 61 { 62 static unsigned long phys_base[] = { 63 0x40d00000, 64 0x40d0009c, 65 0x40d00130, 66 }; 67 68 return (void __iomem *)io_p2v(phys_base[i]); 69 } 70 71 void pxa_mask_irq(struct irq_data *d) 72 { 73 void __iomem *base = irq_data_get_irq_chip_data(d); 74 uint32_t icmr = __raw_readl(base + ICMR); 75 76 icmr &= ~(1 << IRQ_BIT(d->irq)); 77 __raw_writel(icmr, base + ICMR); 78 } 79 80 void pxa_unmask_irq(struct irq_data *d) 81 { 82 void __iomem *base = irq_data_get_irq_chip_data(d); 83 uint32_t icmr = __raw_readl(base + ICMR); 84 85 icmr |= 1 << IRQ_BIT(d->irq); 86 __raw_writel(icmr, base + ICMR); 87 } 88 89 static struct irq_chip pxa_internal_irq_chip = { 90 .name = "SC", 91 .irq_ack = pxa_mask_irq, 92 .irq_mask = pxa_mask_irq, 93 .irq_unmask = pxa_unmask_irq, 94 }; 95 96 /* 97 * GPIO IRQs for GPIO 0 and 1 98 */ 99 static int pxa_set_low_gpio_type(struct irq_data *d, unsigned int type) 100 { 101 int gpio = d->irq - IRQ_GPIO0; 102 103 if (__gpio_is_occupied(gpio)) { 104 pr_err("%s failed: GPIO is configured\n", __func__); 105 return -EINVAL; 106 } 107 108 if (type & IRQ_TYPE_EDGE_RISING) 109 GRER0 |= GPIO_bit(gpio); 110 else 111 GRER0 &= ~GPIO_bit(gpio); 112 113 if (type & IRQ_TYPE_EDGE_FALLING) 114 GFER0 |= GPIO_bit(gpio); 115 else 116 GFER0 &= ~GPIO_bit(gpio); 117 118 return 0; 119 } 120 121 static void pxa_ack_low_gpio(struct irq_data *d) 122 { 123 GEDR0 = (1 << (d->irq - IRQ_GPIO0)); 124 } 125 126 static struct irq_chip pxa_low_gpio_chip = { 127 .name = "GPIO-l", 128 .irq_ack = pxa_ack_low_gpio, 129 .irq_mask = pxa_mask_irq, 130 .irq_unmask = pxa_unmask_irq, 131 .irq_set_type = pxa_set_low_gpio_type, 132 }; 133 134 asmlinkage void __exception_irq_entry icip_handle_irq(struct pt_regs *regs) 135 { 136 uint32_t icip, icmr, mask; 137 138 do { 139 icip = __raw_readl(IRQ_BASE + ICIP); 140 icmr = __raw_readl(IRQ_BASE + ICMR); 141 mask = icip & icmr; 142 143 if (mask == 0) 144 break; 145 146 handle_IRQ(PXA_IRQ(fls(mask) - 1), regs); 147 } while (1); 148 } 149 150 asmlinkage void __exception_irq_entry ichp_handle_irq(struct pt_regs *regs) 151 { 152 uint32_t ichp; 153 154 do { 155 __asm__ __volatile__("mrc p6, 0, %0, c5, c0, 0\n": "=r"(ichp)); 156 157 if ((ichp & ICHP_VAL_IRQ) == 0) 158 break; 159 160 handle_IRQ(PXA_IRQ(ICHP_IRQ(ichp)), regs); 161 } while (1); 162 } 163 164 static void __init pxa_init_low_gpio_irq(set_wake_t fn) 165 { 166 int irq; 167 168 /* clear edge detection on GPIO 0 and 1 */ 169 GFER0 &= ~0x3; 170 GRER0 &= ~0x3; 171 GEDR0 = 0x3; 172 173 for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) { 174 irq_set_chip_and_handler(irq, &pxa_low_gpio_chip, 175 handle_edge_irq); 176 irq_set_chip_data(irq, irq_base(0)); 177 set_irq_flags(irq, IRQF_VALID); 178 } 179 180 pxa_low_gpio_chip.irq_set_wake = fn; 181 } 182 183 void __init pxa_init_irq(int irq_nr, set_wake_t fn) 184 { 185 int irq, i, n; 186 187 BUG_ON(irq_nr > MAX_INTERNAL_IRQS); 188 189 pxa_internal_irq_nr = irq_nr; 190 191 for (n = 0; n < irq_nr; n += 32) { 192 void __iomem *base = irq_base(n >> 5); 193 194 __raw_writel(0, base + ICMR); /* disable all IRQs */ 195 __raw_writel(0, base + ICLR); /* all IRQs are IRQ, not FIQ */ 196 for (i = n; (i < (n + 32)) && (i < irq_nr); i++) { 197 /* initialize interrupt priority */ 198 if (cpu_has_ipr()) 199 __raw_writel(i | IPR_VALID, IRQ_BASE + IPR(i)); 200 201 irq = PXA_IRQ(i); 202 irq_set_chip_and_handler(irq, &pxa_internal_irq_chip, 203 handle_level_irq); 204 irq_set_chip_data(irq, base); 205 set_irq_flags(irq, IRQF_VALID); 206 } 207 } 208 209 /* only unmasked interrupts kick us out of idle */ 210 __raw_writel(1, irq_base(0) + ICCR); 211 212 pxa_internal_irq_chip.irq_set_wake = fn; 213 pxa_init_low_gpio_irq(fn); 214 } 215 216 #ifdef CONFIG_PM 217 static unsigned long saved_icmr[MAX_INTERNAL_IRQS/32]; 218 static unsigned long saved_ipr[MAX_INTERNAL_IRQS]; 219 220 static int pxa_irq_suspend(void) 221 { 222 int i; 223 224 for (i = 0; i < pxa_internal_irq_nr / 32; i++) { 225 void __iomem *base = irq_base(i); 226 227 saved_icmr[i] = __raw_readl(base + ICMR); 228 __raw_writel(0, base + ICMR); 229 } 230 231 if (cpu_has_ipr()) { 232 for (i = 0; i < pxa_internal_irq_nr; i++) 233 saved_ipr[i] = __raw_readl(IRQ_BASE + IPR(i)); 234 } 235 236 return 0; 237 } 238 239 static void pxa_irq_resume(void) 240 { 241 int i; 242 243 for (i = 0; i < pxa_internal_irq_nr / 32; i++) { 244 void __iomem *base = irq_base(i); 245 246 __raw_writel(saved_icmr[i], base + ICMR); 247 __raw_writel(0, base + ICLR); 248 } 249 250 if (cpu_has_ipr()) 251 for (i = 0; i < pxa_internal_irq_nr; i++) 252 __raw_writel(saved_ipr[i], IRQ_BASE + IPR(i)); 253 254 __raw_writel(1, IRQ_BASE + ICCR); 255 } 256 #else 257 #define pxa_irq_suspend NULL 258 #define pxa_irq_resume NULL 259 #endif 260 261 struct syscore_ops pxa_irq_syscore_ops = { 262 .suspend = pxa_irq_suspend, 263 .resume = pxa_irq_resume, 264 }; 265