Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google, Inc. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | * Copyright (c) 2009, 2011 Code Aurora Forum. All rights reserved. |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/ptrace.h> |
| 21 | #include <linux/timer.h> |
| 22 | #include <linux/irq.h> |
| 23 | #include <linux/io.h> |
| 24 | |
| 25 | #include <asm/cacheflush.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | #include <asm/io.h> |
Jamie Iles | 0fd8629 | 2011-10-08 11:20:42 +0100 | [diff] [blame] | 27 | #include <asm/exception.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 28 | #include <asm/cp15.h> |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 29 | |
| 30 | #include <mach/hardware.h> |
| 31 | |
| 32 | #include <mach/msm_iomap.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | #include <mach/fiq.h> |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 34 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | #include "fiq.h" |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 36 | #include "smd_private.h" |
| 37 | |
| 38 | enum { |
| 39 | IRQ_DEBUG_SLEEP_INT_TRIGGER = 1U << 0, |
| 40 | IRQ_DEBUG_SLEEP_INT = 1U << 1, |
| 41 | IRQ_DEBUG_SLEEP_ABORT = 1U << 2, |
| 42 | IRQ_DEBUG_SLEEP = 1U << 3, |
| 43 | IRQ_DEBUG_SLEEP_REQUEST = 1U << 4, |
| 44 | }; |
| 45 | static int msm_irq_debug_mask; |
| 46 | module_param_named(debug_mask, msm_irq_debug_mask, int, |
| 47 | S_IRUGO | S_IWUSR | S_IWGRP); |
| 48 | |
| 49 | #define VIC_REG(off) (MSM_VIC_BASE + (off)) |
| 50 | #define VIC_INT_TO_REG_ADDR(base, irq) (base + (irq / 32) * 4) |
| 51 | #define VIC_INT_TO_REG_INDEX(irq) ((irq >> 5) & 3) |
| 52 | |
| 53 | #define VIC_INT_SELECT0 VIC_REG(0x0000) /* 1: FIQ, 0: IRQ */ |
| 54 | #define VIC_INT_SELECT1 VIC_REG(0x0004) /* 1: FIQ, 0: IRQ */ |
| 55 | #define VIC_INT_SELECT2 VIC_REG(0x0008) /* 1: FIQ, 0: IRQ */ |
| 56 | #define VIC_INT_SELECT3 VIC_REG(0x000C) /* 1: FIQ, 0: IRQ */ |
| 57 | #define VIC_INT_EN0 VIC_REG(0x0010) |
| 58 | #define VIC_INT_EN1 VIC_REG(0x0014) |
| 59 | #define VIC_INT_EN2 VIC_REG(0x0018) |
| 60 | #define VIC_INT_EN3 VIC_REG(0x001C) |
| 61 | #define VIC_INT_ENCLEAR0 VIC_REG(0x0020) |
| 62 | #define VIC_INT_ENCLEAR1 VIC_REG(0x0024) |
| 63 | #define VIC_INT_ENCLEAR2 VIC_REG(0x0028) |
| 64 | #define VIC_INT_ENCLEAR3 VIC_REG(0x002C) |
| 65 | #define VIC_INT_ENSET0 VIC_REG(0x0030) |
| 66 | #define VIC_INT_ENSET1 VIC_REG(0x0034) |
| 67 | #define VIC_INT_ENSET2 VIC_REG(0x0038) |
| 68 | #define VIC_INT_ENSET3 VIC_REG(0x003C) |
| 69 | #define VIC_INT_TYPE0 VIC_REG(0x0040) /* 1: EDGE, 0: LEVEL */ |
| 70 | #define VIC_INT_TYPE1 VIC_REG(0x0044) /* 1: EDGE, 0: LEVEL */ |
| 71 | #define VIC_INT_TYPE2 VIC_REG(0x0048) /* 1: EDGE, 0: LEVEL */ |
| 72 | #define VIC_INT_TYPE3 VIC_REG(0x004C) /* 1: EDGE, 0: LEVEL */ |
| 73 | #define VIC_INT_POLARITY0 VIC_REG(0x0050) /* 1: NEG, 0: POS */ |
| 74 | #define VIC_INT_POLARITY1 VIC_REG(0x0054) /* 1: NEG, 0: POS */ |
| 75 | #define VIC_INT_POLARITY2 VIC_REG(0x0058) /* 1: NEG, 0: POS */ |
| 76 | #define VIC_INT_POLARITY3 VIC_REG(0x005C) /* 1: NEG, 0: POS */ |
| 77 | #define VIC_NO_PEND_VAL VIC_REG(0x0060) |
| 78 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | #if defined(CONFIG_ARCH_MSM_SCORPION) && !defined(CONFIG_MSM_SMP) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 80 | #define VIC_NO_PEND_VAL_FIQ VIC_REG(0x0064) |
| 81 | #define VIC_INT_MASTEREN VIC_REG(0x0068) /* 1: IRQ, 2: FIQ */ |
| 82 | #define VIC_CONFIG VIC_REG(0x006C) /* 1: USE SC VIC */ |
| 83 | #else |
| 84 | #define VIC_INT_MASTEREN VIC_REG(0x0064) /* 1: IRQ, 2: FIQ */ |
| 85 | #define VIC_PROTECTION VIC_REG(0x006C) /* 1: ENABLE */ |
| 86 | #define VIC_CONFIG VIC_REG(0x0068) /* 1: USE ARM1136 VIC */ |
| 87 | #endif |
| 88 | |
| 89 | #define VIC_IRQ_STATUS0 VIC_REG(0x0080) |
| 90 | #define VIC_IRQ_STATUS1 VIC_REG(0x0084) |
| 91 | #define VIC_IRQ_STATUS2 VIC_REG(0x0088) |
| 92 | #define VIC_IRQ_STATUS3 VIC_REG(0x008C) |
| 93 | #define VIC_FIQ_STATUS0 VIC_REG(0x0090) |
| 94 | #define VIC_FIQ_STATUS1 VIC_REG(0x0094) |
| 95 | #define VIC_FIQ_STATUS2 VIC_REG(0x0098) |
| 96 | #define VIC_FIQ_STATUS3 VIC_REG(0x009C) |
| 97 | #define VIC_RAW_STATUS0 VIC_REG(0x00A0) |
| 98 | #define VIC_RAW_STATUS1 VIC_REG(0x00A4) |
| 99 | #define VIC_RAW_STATUS2 VIC_REG(0x00A8) |
| 100 | #define VIC_RAW_STATUS3 VIC_REG(0x00AC) |
| 101 | #define VIC_INT_CLEAR0 VIC_REG(0x00B0) |
| 102 | #define VIC_INT_CLEAR1 VIC_REG(0x00B4) |
| 103 | #define VIC_INT_CLEAR2 VIC_REG(0x00B8) |
| 104 | #define VIC_INT_CLEAR3 VIC_REG(0x00BC) |
| 105 | #define VIC_SOFTINT0 VIC_REG(0x00C0) |
| 106 | #define VIC_SOFTINT1 VIC_REG(0x00C4) |
| 107 | #define VIC_SOFTINT2 VIC_REG(0x00C8) |
| 108 | #define VIC_SOFTINT3 VIC_REG(0x00CC) |
| 109 | #define VIC_IRQ_VEC_RD VIC_REG(0x00D0) /* pending int # */ |
| 110 | #define VIC_IRQ_VEC_PEND_RD VIC_REG(0x00D4) /* pending vector addr */ |
| 111 | #define VIC_IRQ_VEC_WR VIC_REG(0x00D8) |
| 112 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 113 | #if defined(CONFIG_ARCH_MSM_SCORPION) && !defined(CONFIG_MSM_SMP) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 114 | #define VIC_FIQ_VEC_RD VIC_REG(0x00DC) |
| 115 | #define VIC_FIQ_VEC_PEND_RD VIC_REG(0x00E0) |
| 116 | #define VIC_FIQ_VEC_WR VIC_REG(0x00E4) |
| 117 | #define VIC_IRQ_IN_SERVICE VIC_REG(0x00E8) |
| 118 | #define VIC_IRQ_IN_STACK VIC_REG(0x00EC) |
| 119 | #define VIC_FIQ_IN_SERVICE VIC_REG(0x00F0) |
| 120 | #define VIC_FIQ_IN_STACK VIC_REG(0x00F4) |
| 121 | #define VIC_TEST_BUS_SEL VIC_REG(0x00F8) |
| 122 | #define VIC_IRQ_CTRL_CONFIG VIC_REG(0x00FC) |
| 123 | #else |
| 124 | #define VIC_IRQ_IN_SERVICE VIC_REG(0x00E0) |
| 125 | #define VIC_IRQ_IN_STACK VIC_REG(0x00E4) |
| 126 | #define VIC_TEST_BUS_SEL VIC_REG(0x00E8) |
| 127 | #endif |
| 128 | |
| 129 | #define VIC_VECTPRIORITY(n) VIC_REG(0x0200+((n) * 4)) |
| 130 | #define VIC_VECTADDR(n) VIC_REG(0x0400+((n) * 4)) |
| 131 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | #if defined(CONFIG_ARCH_MSM7X30) || defined(CONFIG_ARCH_FSM9XXX) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 133 | #define VIC_NUM_REGS 4 |
| 134 | #else |
| 135 | #define VIC_NUM_REGS 2 |
| 136 | #endif |
| 137 | |
| 138 | #if VIC_NUM_REGS == 2 |
| 139 | #define DPRINT_REGS(base_reg, format, ...) \ |
| 140 | printk(KERN_INFO format " %x %x\n", ##__VA_ARGS__, \ |
| 141 | readl(base_reg ## 0), readl(base_reg ## 1)) |
| 142 | #define DPRINT_ARRAY(array, format, ...) \ |
| 143 | printk(KERN_INFO format " %x %x\n", ##__VA_ARGS__, \ |
| 144 | array[0], array[1]) |
| 145 | #elif VIC_NUM_REGS == 4 |
| 146 | #define DPRINT_REGS(base_reg, format, ...) \ |
| 147 | printk(KERN_INFO format " %x %x %x %x\n", ##__VA_ARGS__, \ |
| 148 | readl(base_reg ## 0), readl(base_reg ## 1), \ |
| 149 | readl(base_reg ## 2), readl(base_reg ## 3)) |
| 150 | #define DPRINT_ARRAY(array, format, ...) \ |
| 151 | printk(KERN_INFO format " %x %x %x %x\n", ##__VA_ARGS__, \ |
| 152 | array[0], array[1], \ |
| 153 | array[2], array[3]) |
| 154 | #else |
| 155 | #error "VIC_NUM_REGS set to illegal value" |
| 156 | #endif |
| 157 | |
| 158 | static uint32_t msm_irq_smsm_wake_enable[2]; |
| 159 | static struct { |
| 160 | uint32_t int_en[2]; |
| 161 | uint32_t int_type; |
| 162 | uint32_t int_polarity; |
| 163 | uint32_t int_select; |
| 164 | } msm_irq_shadow_reg[VIC_NUM_REGS]; |
| 165 | static uint32_t msm_irq_idle_disable[VIC_NUM_REGS]; |
| 166 | |
| 167 | #define SMSM_FAKE_IRQ (0xff) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 168 | #if !defined(CONFIG_ARCH_FSM9XXX) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 169 | static uint8_t msm_irq_to_smsm[NR_IRQS] = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 170 | #if !defined(CONFIG_ARCH_MSM7X27A) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 171 | [INT_MDDI_EXT] = 1, |
| 172 | [INT_MDDI_PRI] = 2, |
| 173 | [INT_MDDI_CLIENT] = 3, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | #endif |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 175 | [INT_USB_OTG] = 4, |
| 176 | |
| 177 | [INT_PWB_I2C] = 5, |
| 178 | [INT_SDC1_0] = 6, |
| 179 | [INT_SDC1_1] = 7, |
| 180 | [INT_SDC2_0] = 8, |
| 181 | |
| 182 | [INT_SDC2_1] = 9, |
| 183 | [INT_ADSP_A9_A11] = 10, |
| 184 | [INT_UART1] = 11, |
| 185 | [INT_UART2] = 12, |
| 186 | |
| 187 | [INT_UART3] = 13, |
| 188 | [INT_UART1_RX] = 14, |
| 189 | [INT_UART2_RX] = 15, |
| 190 | [INT_UART3_RX] = 16, |
| 191 | |
| 192 | [INT_UART1DM_IRQ] = 17, |
| 193 | [INT_UART1DM_RX] = 18, |
| 194 | [INT_KEYSENSE] = 19, |
| 195 | #if !defined(CONFIG_ARCH_MSM7X30) |
| 196 | [INT_AD_HSSD] = 20, |
| 197 | #endif |
| 198 | |
| 199 | [INT_NAND_WR_ER_DONE] = 21, |
| 200 | [INT_NAND_OP_DONE] = 22, |
| 201 | [INT_TCHSCRN1] = 23, |
| 202 | [INT_TCHSCRN2] = 24, |
| 203 | |
| 204 | [INT_TCHSCRN_SSBI] = 25, |
| 205 | [INT_USB_HS] = 26, |
| 206 | [INT_UART2DM_RX] = 27, |
| 207 | [INT_UART2DM_IRQ] = 28, |
| 208 | |
| 209 | [INT_SDC4_1] = 29, |
| 210 | [INT_SDC4_0] = 30, |
| 211 | [INT_SDC3_1] = 31, |
| 212 | [INT_SDC3_0] = 32, |
| 213 | |
| 214 | /* fake wakeup interrupts */ |
| 215 | [INT_GPIO_GROUP1] = SMSM_FAKE_IRQ, |
| 216 | [INT_GPIO_GROUP2] = SMSM_FAKE_IRQ, |
| 217 | [INT_A9_M2A_0] = SMSM_FAKE_IRQ, |
| 218 | [INT_A9_M2A_1] = SMSM_FAKE_IRQ, |
| 219 | [INT_A9_M2A_5] = SMSM_FAKE_IRQ, |
| 220 | [INT_GP_TIMER_EXP] = SMSM_FAKE_IRQ, |
| 221 | [INT_DEBUG_TIMER_EXP] = SMSM_FAKE_IRQ, |
| 222 | [INT_ADSP_A11] = SMSM_FAKE_IRQ, |
| 223 | #ifdef CONFIG_ARCH_QSD8X50 |
| 224 | [INT_SIRC_0] = SMSM_FAKE_IRQ, |
| 225 | [INT_SIRC_1] = SMSM_FAKE_IRQ, |
| 226 | #endif |
| 227 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | # else /* CONFIG_ARCH_FSM9XXX */ |
| 229 | static uint8_t msm_irq_to_smsm[NR_IRQS] = { |
| 230 | [INT_UART1] = 11, |
| 231 | [INT_A9_M2A_0] = SMSM_FAKE_IRQ, |
| 232 | [INT_A9_M2A_1] = SMSM_FAKE_IRQ, |
| 233 | [INT_A9_M2A_5] = SMSM_FAKE_IRQ, |
| 234 | [INT_GP_TIMER_EXP] = SMSM_FAKE_IRQ, |
| 235 | [INT_DEBUG_TIMER_EXP] = SMSM_FAKE_IRQ, |
| 236 | [INT_SIRC_0] = 10, |
Rohit Vaswani | e35585d | 2011-08-17 20:04:08 -0700 | [diff] [blame] | 237 | [INT_ADSP_A11] = SMSM_FAKE_IRQ, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 238 | }; |
| 239 | #endif /* CONFIG_ARCH_FSM9XXX */ |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 240 | |
| 241 | static inline void msm_irq_write_all_regs(void __iomem *base, unsigned int val) |
| 242 | { |
| 243 | int i; |
| 244 | |
| 245 | for (i = 0; i < VIC_NUM_REGS; i++) |
| 246 | writel(val, base + (i * 4)); |
| 247 | } |
| 248 | |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 249 | static void msm_irq_ack(struct irq_data *d) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 250 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | uint32_t mask; |
| 252 | |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 253 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_CLEAR0, d->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 254 | mask = 1 << (d->irq & 31); |
| 255 | writel(mask, reg); |
| 256 | mb(); |
| 257 | } |
| 258 | |
| 259 | static void msm_irq_disable(struct irq_data *d) |
| 260 | { |
| 261 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENCLEAR0, d->irq); |
| 262 | unsigned index = VIC_INT_TO_REG_INDEX(d->irq); |
| 263 | uint32_t mask = 1UL << (d->irq & 31); |
| 264 | int smsm_irq = msm_irq_to_smsm[d->irq]; |
| 265 | |
| 266 | if (!(msm_irq_shadow_reg[index].int_en[1] & mask)) { |
| 267 | msm_irq_shadow_reg[index].int_en[0] &= ~mask; |
| 268 | writel(mask, reg); |
| 269 | mb(); |
| 270 | if (smsm_irq == 0) |
| 271 | msm_irq_idle_disable[index] &= ~mask; |
| 272 | else { |
| 273 | mask = 1UL << (smsm_irq - 1); |
| 274 | msm_irq_smsm_wake_enable[0] &= ~mask; |
| 275 | } |
| 276 | } |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 279 | static void msm_irq_mask(struct irq_data *d) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 280 | { |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 281 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENCLEAR0, d->irq); |
| 282 | unsigned index = VIC_INT_TO_REG_INDEX(d->irq); |
| 283 | uint32_t mask = 1UL << (d->irq & 31); |
| 284 | int smsm_irq = msm_irq_to_smsm[d->irq]; |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 285 | |
| 286 | msm_irq_shadow_reg[index].int_en[0] &= ~mask; |
| 287 | writel(mask, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 288 | mb(); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 289 | if (smsm_irq == 0) |
| 290 | msm_irq_idle_disable[index] &= ~mask; |
| 291 | else { |
| 292 | mask = 1UL << (smsm_irq - 1); |
| 293 | msm_irq_smsm_wake_enable[0] &= ~mask; |
| 294 | } |
| 295 | } |
| 296 | |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 297 | static void msm_irq_unmask(struct irq_data *d) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 298 | { |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 299 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENSET0, d->irq); |
| 300 | unsigned index = VIC_INT_TO_REG_INDEX(d->irq); |
| 301 | uint32_t mask = 1UL << (d->irq & 31); |
| 302 | int smsm_irq = msm_irq_to_smsm[d->irq]; |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 303 | |
| 304 | msm_irq_shadow_reg[index].int_en[0] |= mask; |
| 305 | writel(mask, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 306 | mb(); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 307 | |
| 308 | if (smsm_irq == 0) |
| 309 | msm_irq_idle_disable[index] |= mask; |
| 310 | else { |
| 311 | mask = 1UL << (smsm_irq - 1); |
| 312 | msm_irq_smsm_wake_enable[0] |= mask; |
| 313 | } |
| 314 | } |
| 315 | |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 316 | static int msm_irq_set_wake(struct irq_data *d, unsigned int on) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 317 | { |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 318 | unsigned index = VIC_INT_TO_REG_INDEX(d->irq); |
| 319 | uint32_t mask = 1UL << (d->irq & 31); |
| 320 | int smsm_irq = msm_irq_to_smsm[d->irq]; |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 321 | |
| 322 | if (smsm_irq == 0) { |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 323 | printk(KERN_ERR "msm_irq_set_wake: bad wakeup irq %d\n", d->irq); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 324 | return -EINVAL; |
| 325 | } |
| 326 | if (on) |
| 327 | msm_irq_shadow_reg[index].int_en[1] |= mask; |
| 328 | else |
| 329 | msm_irq_shadow_reg[index].int_en[1] &= ~mask; |
| 330 | |
| 331 | if (smsm_irq == SMSM_FAKE_IRQ) |
| 332 | return 0; |
| 333 | |
| 334 | mask = 1UL << (smsm_irq - 1); |
| 335 | if (on) |
| 336 | msm_irq_smsm_wake_enable[1] |= mask; |
| 337 | else |
| 338 | msm_irq_smsm_wake_enable[1] &= ~mask; |
| 339 | return 0; |
| 340 | } |
| 341 | |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 342 | static int msm_irq_set_type(struct irq_data *d, unsigned int flow_type) |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 343 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 344 | void __iomem *treg = VIC_INT_TO_REG_ADDR(VIC_INT_TYPE0, d->irq); |
Lennert Buytenhek | 0f86ee0 | 2010-11-29 10:37:34 +0100 | [diff] [blame] | 345 | void __iomem *preg = VIC_INT_TO_REG_ADDR(VIC_INT_POLARITY0, d->irq); |
| 346 | unsigned index = VIC_INT_TO_REG_INDEX(d->irq); |
| 347 | int b = 1 << (d->irq & 31); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 348 | uint32_t polarity; |
| 349 | uint32_t type; |
| 350 | |
| 351 | polarity = msm_irq_shadow_reg[index].int_polarity; |
| 352 | if (flow_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW)) |
| 353 | polarity |= b; |
| 354 | if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_HIGH)) |
| 355 | polarity &= ~b; |
| 356 | writel(polarity, preg); |
| 357 | msm_irq_shadow_reg[index].int_polarity = polarity; |
| 358 | |
| 359 | type = msm_irq_shadow_reg[index].int_type; |
| 360 | if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) { |
| 361 | type |= b; |
Thomas Gleixner | 70c4fa2 | 2011-03-24 12:41:27 +0100 | [diff] [blame] | 362 | __irq_set_handler_locked(d->irq, handle_edge_irq); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 363 | } |
| 364 | if (flow_type & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW)) { |
| 365 | type &= ~b; |
Thomas Gleixner | 70c4fa2 | 2011-03-24 12:41:27 +0100 | [diff] [blame] | 366 | __irq_set_handler_locked(d->irq, handle_level_irq); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 367 | } |
| 368 | writel(type, treg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 369 | mb(); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 370 | msm_irq_shadow_reg[index].int_type = type; |
| 371 | return 0; |
| 372 | } |
| 373 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 374 | unsigned int msm_irq_pending(void) |
| 375 | { |
| 376 | unsigned int i, pending = 0; |
| 377 | |
| 378 | for (i = 0; (i < VIC_NUM_REGS) && !pending; i++) |
| 379 | pending |= readl(VIC_IRQ_STATUS0 + (i * 4)); |
| 380 | |
| 381 | return pending; |
| 382 | } |
| 383 | |
| 384 | int msm_irq_idle_sleep_allowed(void) |
| 385 | { |
| 386 | uint32_t i, disable = 0; |
| 387 | |
| 388 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP_REQUEST) |
| 389 | DPRINT_ARRAY(msm_irq_idle_disable, |
| 390 | "msm_irq_idle_sleep_allowed: disable"); |
| 391 | |
| 392 | for (i = 0; i < VIC_NUM_REGS; i++) |
| 393 | disable |= msm_irq_idle_disable[i]; |
| 394 | |
| 395 | return !disable; |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Prepare interrupt subsystem for entering sleep -- phase 1. |
| 400 | * If modem_wake is true, return currently enabled interrupts in *irq_mask. |
| 401 | */ |
| 402 | void msm_irq_enter_sleep1(bool modem_wake, int from_idle, uint32_t *irq_mask) |
| 403 | { |
| 404 | if (modem_wake) { |
| 405 | *irq_mask = msm_irq_smsm_wake_enable[!from_idle]; |
| 406 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP) |
| 407 | printk(KERN_INFO |
| 408 | "%s irq_mask %x\n", __func__, *irq_mask); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Prepare interrupt subsystem for entering sleep -- phase 2. |
| 414 | * Detect any pending interrupts and configure interrupt hardware. |
| 415 | * |
| 416 | * Return value: |
| 417 | * -EAGAIN: there are pending interrupt(s); interrupt configuration |
| 418 | * is not changed. |
| 419 | * 0: success |
| 420 | */ |
| 421 | int msm_irq_enter_sleep2(bool modem_wake, int from_idle) |
| 422 | { |
| 423 | int i, limit = 10; |
| 424 | uint32_t pending[VIC_NUM_REGS]; |
| 425 | |
| 426 | if (from_idle && !modem_wake) |
| 427 | return 0; |
| 428 | |
| 429 | /* edge triggered interrupt may get lost if this mode is used */ |
| 430 | WARN_ON_ONCE(!modem_wake && !from_idle); |
| 431 | |
| 432 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP) |
| 433 | DPRINT_REGS(VIC_IRQ_STATUS, "%s change irq, pend", __func__); |
| 434 | |
| 435 | for (i = 0; i < VIC_NUM_REGS; i++) { |
| 436 | pending[i] = readl(VIC_IRQ_STATUS0 + (i * 4)); |
| 437 | pending[i] &= msm_irq_shadow_reg[i].int_en[!from_idle]; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Clear INT_A9_M2A_5 since requesting sleep triggers it. |
| 442 | * In some arch e.g. FSM9XXX, INT_A9_M2A_5 may not be in the first set. |
| 443 | */ |
| 444 | pending[INT_A9_M2A_5 / 32] &= ~(1U << (INT_A9_M2A_5 % 32)); |
| 445 | |
| 446 | for (i = 0; i < VIC_NUM_REGS; i++) { |
| 447 | if (pending[i]) { |
| 448 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP_ABORT) |
| 449 | DPRINT_ARRAY(pending, "%s abort", |
| 450 | __func__); |
| 451 | return -EAGAIN; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | msm_irq_write_all_regs(VIC_INT_EN0, 0); |
| 456 | |
| 457 | while (limit-- > 0) { |
| 458 | int pend_irq; |
| 459 | int irq = readl(VIC_IRQ_VEC_RD); |
| 460 | if (irq == -1) |
| 461 | break; |
| 462 | pend_irq = readl(VIC_IRQ_VEC_PEND_RD); |
| 463 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP_INT) |
| 464 | printk(KERN_INFO "%s cleared int %d (%d)\n", |
| 465 | __func__, irq, pend_irq); |
| 466 | } |
| 467 | |
| 468 | if (modem_wake) { |
| 469 | struct irq_data d = { .irq = INT_A9_M2A_6 }; |
| 470 | msm_irq_set_type(&d, IRQF_TRIGGER_RISING); |
| 471 | __raw_writel(1U << (INT_A9_M2A_6 % 32), |
| 472 | VIC_INT_TO_REG_ADDR(VIC_INT_ENSET0, INT_A9_M2A_6)); |
| 473 | } else { |
| 474 | for (i = 0; i < VIC_NUM_REGS; i++) |
| 475 | writel(msm_irq_shadow_reg[i].int_en[1], |
| 476 | VIC_INT_ENSET0 + (i * 4)); |
| 477 | } |
| 478 | mb(); |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * Restore interrupt subsystem from sleep -- phase 1. |
| 485 | * Configure interrupt hardware. |
| 486 | */ |
| 487 | void msm_irq_exit_sleep1(uint32_t irq_mask, uint32_t wakeup_reason, |
| 488 | uint32_t pending_irqs) |
| 489 | { |
| 490 | int i; |
| 491 | struct irq_data d = { .irq = INT_A9_M2A_6 }; |
| 492 | |
| 493 | msm_irq_ack(&d); |
| 494 | |
| 495 | for (i = 0; i < VIC_NUM_REGS; i++) { |
| 496 | writel(msm_irq_shadow_reg[i].int_type, |
| 497 | VIC_INT_TYPE0 + i * 4); |
| 498 | writel(msm_irq_shadow_reg[i].int_polarity, |
| 499 | VIC_INT_POLARITY0 + i * 4); |
| 500 | writel(msm_irq_shadow_reg[i].int_en[0], |
| 501 | VIC_INT_EN0 + i * 4); |
| 502 | writel(msm_irq_shadow_reg[i].int_select, |
| 503 | VIC_INT_SELECT0 + i * 4); |
| 504 | } |
| 505 | |
| 506 | writel(3, VIC_INT_MASTEREN); |
| 507 | mb(); |
| 508 | |
| 509 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP) |
| 510 | DPRINT_REGS(VIC_IRQ_STATUS, "%s %x %x %x now", |
| 511 | __func__, irq_mask, pending_irqs, wakeup_reason); |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Restore interrupt subsystem from sleep -- phase 2. |
| 516 | * Poke the specified pending interrupts into interrupt hardware. |
| 517 | */ |
| 518 | void msm_irq_exit_sleep2(uint32_t irq_mask, uint32_t wakeup_reason, |
| 519 | uint32_t pending) |
| 520 | { |
| 521 | int i; |
| 522 | |
| 523 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP) |
| 524 | DPRINT_REGS(VIC_IRQ_STATUS, "%s %x %x %x now", |
| 525 | __func__, irq_mask, pending, wakeup_reason); |
| 526 | |
| 527 | for (i = 0; pending && i < ARRAY_SIZE(msm_irq_to_smsm); i++) { |
| 528 | unsigned reg_offset = VIC_INT_TO_REG_ADDR(0, i); |
| 529 | uint32_t reg_mask = 1UL << (i & 31); |
| 530 | int smsm_irq = msm_irq_to_smsm[i]; |
| 531 | uint32_t smsm_mask; |
| 532 | |
| 533 | if (smsm_irq == 0) |
| 534 | continue; |
| 535 | |
| 536 | smsm_mask = 1U << (smsm_irq - 1); |
| 537 | if (!(pending & smsm_mask)) |
| 538 | continue; |
| 539 | |
| 540 | pending &= ~smsm_mask; |
| 541 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP_INT) |
| 542 | DPRINT_REGS(VIC_IRQ_STATUS, |
| 543 | "%s: irq %d still pending %x now", |
| 544 | __func__, i, pending); |
| 545 | #ifdef DEBUG_INTERRUPT_TRIGGER |
| 546 | if (readl(VIC_IRQ_STATUS0 + reg_offset) & reg_mask) |
| 547 | writel(reg_mask, VIC_INT_CLEAR0 + reg_offset); |
| 548 | #endif |
| 549 | if (readl(VIC_IRQ_STATUS0 + reg_offset) & reg_mask) |
| 550 | continue; |
| 551 | |
| 552 | writel(reg_mask, VIC_SOFTINT0 + reg_offset); |
| 553 | |
| 554 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP_INT_TRIGGER) |
| 555 | DPRINT_REGS(VIC_IRQ_STATUS, |
| 556 | "%s: irq %d need trigger, now", |
| 557 | __func__, i); |
| 558 | } |
| 559 | mb(); |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * Restore interrupt subsystem from sleep -- phase 3. |
| 564 | * Print debug information. |
| 565 | */ |
| 566 | void msm_irq_exit_sleep3(uint32_t irq_mask, uint32_t wakeup_reason, |
| 567 | uint32_t pending_irqs) |
| 568 | { |
| 569 | if (msm_irq_debug_mask & IRQ_DEBUG_SLEEP) |
| 570 | DPRINT_REGS(VIC_IRQ_STATUS, "%s %x %x %x state %x now", |
| 571 | __func__, irq_mask, pending_irqs, wakeup_reason, |
| 572 | smsm_get_state(SMSM_MODEM_STATE)); |
| 573 | } |
| 574 | |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 575 | static struct irq_chip msm_irq_chip = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 576 | .name = "msm", |
| 577 | .irq_disable = msm_irq_disable, |
| 578 | .irq_ack = msm_irq_ack, |
| 579 | .irq_mask = msm_irq_mask, |
| 580 | .irq_unmask = msm_irq_unmask, |
| 581 | .irq_set_wake = msm_irq_set_wake, |
| 582 | .irq_set_type = msm_irq_set_type, |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | void __init msm_init_irq(void) |
| 586 | { |
| 587 | unsigned n; |
| 588 | |
| 589 | /* select level interrupts */ |
| 590 | msm_irq_write_all_regs(VIC_INT_TYPE0, 0); |
| 591 | |
| 592 | /* select highlevel interrupts */ |
| 593 | msm_irq_write_all_regs(VIC_INT_POLARITY0, 0); |
| 594 | |
| 595 | /* select IRQ for all INTs */ |
| 596 | msm_irq_write_all_regs(VIC_INT_SELECT0, 0); |
| 597 | |
| 598 | /* disable all INTs */ |
| 599 | msm_irq_write_all_regs(VIC_INT_EN0, 0); |
| 600 | |
| 601 | /* don't use vic */ |
| 602 | writel(0, VIC_CONFIG); |
| 603 | |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 604 | |
| 605 | for (n = 0; n < NR_MSM_IRQS; n++) { |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 606 | irq_set_chip_and_handler(n, &msm_irq_chip, handle_level_irq); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 607 | set_irq_flags(n, IRQF_VALID); |
| 608 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 609 | |
| 610 | /* enable interrupt controller */ |
| 611 | writel(3, VIC_INT_MASTEREN); |
| 612 | mb(); |
Gregory Bean | f9f3d31 | 2010-04-30 22:06:50 -0700 | [diff] [blame] | 613 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 614 | |
Taniya Das | 86e0e13 | 2011-10-19 11:32:00 +0530 | [diff] [blame] | 615 | static inline void msm_vic_handle_irq(void __iomem *base_addr, struct pt_regs |
| 616 | *regs) |
| 617 | { |
| 618 | u32 irqnr; |
| 619 | |
| 620 | do { |
| 621 | /* 0xD0 has irq# or old irq# if the irq has been handled |
| 622 | * 0xD4 has irq# or -1 if none pending *but* if you just |
| 623 | * read 0xD4 you never get the first irq for some reason |
| 624 | */ |
| 625 | irqnr = readl_relaxed(base_addr + 0xD0); |
| 626 | irqnr = readl_relaxed(base_addr + 0xD4); |
| 627 | if (irqnr == -1) |
| 628 | break; |
| 629 | handle_IRQ(irqnr, regs); |
| 630 | } while (1); |
| 631 | } |
| 632 | |
| 633 | /* enable imprecise aborts */ |
| 634 | #define local_cpsie_enable() __asm__ __volatile__("cpsie a @ enable") |
| 635 | |
| 636 | asmlinkage void __exception_irq_entry vic_handle_irq(struct pt_regs *regs) |
| 637 | { |
| 638 | local_cpsie_enable(); |
| 639 | msm_vic_handle_irq((void __iomem *)MSM_VIC_BASE, regs); |
| 640 | } |
| 641 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 642 | #if defined(CONFIG_MSM_FIQ_SUPPORT) |
| 643 | void msm_trigger_irq(int irq) |
| 644 | { |
| 645 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_SOFTINT0, irq); |
| 646 | uint32_t mask = 1UL << (irq & 31); |
| 647 | writel(mask, reg); |
| 648 | mb(); |
| 649 | } |
| 650 | |
| 651 | void msm_fiq_enable(int irq) |
| 652 | { |
| 653 | struct irq_data d = { .irq = irq }; |
| 654 | unsigned long flags; |
| 655 | local_irq_save(flags); |
| 656 | msm_irq_unmask(&d); |
| 657 | local_irq_restore(flags); |
| 658 | } |
| 659 | |
| 660 | void msm_fiq_disable(int irq) |
| 661 | { |
| 662 | struct irq_data d = { .irq = irq }; |
| 663 | unsigned long flags; |
| 664 | local_irq_save(flags); |
| 665 | msm_irq_mask(&d); |
| 666 | local_irq_restore(flags); |
| 667 | } |
| 668 | |
| 669 | void msm_fiq_select(int irq) |
| 670 | { |
| 671 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_SELECT0, irq); |
| 672 | unsigned index = VIC_INT_TO_REG_INDEX(irq); |
| 673 | uint32_t mask = 1UL << (irq & 31); |
| 674 | unsigned long flags; |
| 675 | |
| 676 | local_irq_save(flags); |
| 677 | msm_irq_shadow_reg[index].int_select |= mask; |
| 678 | writel(msm_irq_shadow_reg[index].int_select, reg); |
| 679 | mb(); |
| 680 | local_irq_restore(flags); |
| 681 | } |
| 682 | |
| 683 | void msm_fiq_unselect(int irq) |
| 684 | { |
| 685 | void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_SELECT0, irq); |
| 686 | unsigned index = VIC_INT_TO_REG_INDEX(irq); |
| 687 | uint32_t mask = 1UL << (irq & 31); |
| 688 | unsigned long flags; |
| 689 | |
| 690 | local_irq_save(flags); |
| 691 | msm_irq_shadow_reg[index].int_select &= (!mask); |
| 692 | writel(msm_irq_shadow_reg[index].int_select, reg); |
| 693 | mb(); |
| 694 | local_irq_restore(flags); |
| 695 | } |
| 696 | /* set_fiq_handler originally from arch/arm/kernel/fiq.c */ |
| 697 | static void set_fiq_handler(void *start, unsigned int length) |
| 698 | { |
| 699 | memcpy((void *)0xffff001c, start, length); |
| 700 | flush_icache_range(0xffff001c, 0xffff001c + length); |
| 701 | if (!vectors_high()) |
| 702 | flush_icache_range(0x1c, 0x1c + length); |
| 703 | } |
| 704 | |
| 705 | static void (*fiq_func)(void *data, void *regs); |
| 706 | static unsigned long long fiq_stack[256]; |
| 707 | |
| 708 | int msm_fiq_set_handler(void (*func)(void *data, void *regs), void *data) |
| 709 | { |
| 710 | unsigned long flags; |
| 711 | int ret = -ENOMEM; |
| 712 | |
| 713 | local_irq_save(flags); |
| 714 | if (fiq_func == 0) { |
| 715 | fiq_func = func; |
| 716 | fiq_glue_setup(func, data, fiq_stack + 255); |
| 717 | set_fiq_handler(&fiq_glue, (&fiq_glue_end - &fiq_glue)); |
| 718 | ret = 0; |
| 719 | } |
| 720 | local_irq_restore(flags); |
| 721 | return ret; |
| 722 | } |
| 723 | #endif |