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