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