blob: 152eefda3ce65e85e43b81134035c0ce6d51cc71 [file] [log] [blame]
Gregory Beanec4d7922010-04-30 21:59:38 -07001/* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 *
17 */
18
19#include <linux/io.h>
20#include <linux/irq.h>
21#include <linux/interrupt.h>
22#include <asm/irq.h>
23
24static unsigned int int_enable;
25static unsigned int wake_enable;
26
27static struct sirc_regs_t sirc_regs = {
28 .int_enable = SPSS_SIRC_INT_ENABLE,
29 .int_enable_clear = SPSS_SIRC_INT_ENABLE_CLEAR,
30 .int_enable_set = SPSS_SIRC_INT_ENABLE_SET,
31 .int_type = SPSS_SIRC_INT_TYPE,
32 .int_polarity = SPSS_SIRC_INT_POLARITY,
33 .int_clear = SPSS_SIRC_INT_CLEAR,
34};
35
36static struct sirc_cascade_regs sirc_reg_table[] = {
37 {
38 .int_status = SPSS_SIRC_IRQ_STATUS,
39 .cascade_irq = INT_SIRC_0,
40 }
41};
42
Gregory Beanec4d7922010-04-30 21:59:38 -070043/* Mask off the given interrupt. Keep the int_enable mask in sync with
44 the enable reg, so it can be restored after power collapse. */
45static void sirc_irq_mask(unsigned int irq)
46{
47 unsigned int mask;
48
49
50 mask = 1 << (irq - FIRST_SIRC_IRQ);
51 writel(mask, sirc_regs.int_enable_clear);
52 int_enable &= ~mask;
53 return;
54}
55
56/* Unmask the given interrupt. Keep the int_enable mask in sync with
57 the enable reg, so it can be restored after power collapse. */
58static void sirc_irq_unmask(unsigned int irq)
59{
60 unsigned int mask;
61
62 mask = 1 << (irq - FIRST_SIRC_IRQ);
63 writel(mask, sirc_regs.int_enable_set);
64 int_enable |= mask;
65 return;
66}
67
68static void sirc_irq_ack(unsigned int irq)
69{
70 unsigned int mask;
71
72 mask = 1 << (irq - FIRST_SIRC_IRQ);
73 writel(mask, sirc_regs.int_clear);
74 return;
75}
76
77static int sirc_irq_set_wake(unsigned int irq, unsigned int on)
78{
79 unsigned int mask;
80
81 /* Used to set the interrupt enable mask during power collapse. */
82 mask = 1 << (irq - FIRST_SIRC_IRQ);
83 if (on)
84 wake_enable |= mask;
85 else
86 wake_enable &= ~mask;
87
88 return 0;
89}
90
91static int sirc_irq_set_type(unsigned int irq, unsigned int flow_type)
92{
93 unsigned int mask;
94 unsigned int val;
95
96 mask = 1 << (irq - FIRST_SIRC_IRQ);
97 val = readl(sirc_regs.int_polarity);
98
99 if (flow_type & (IRQF_TRIGGER_LOW | IRQF_TRIGGER_FALLING))
100 val |= mask;
101 else
102 val &= ~mask;
103
104 writel(val, sirc_regs.int_polarity);
105
106 val = readl(sirc_regs.int_type);
107 if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
108 val |= mask;
109 irq_desc[irq].handle_irq = handle_edge_irq;
110 } else {
111 val &= ~mask;
112 irq_desc[irq].handle_irq = handle_level_irq;
113 }
114
115 writel(val, sirc_regs.int_type);
116
117 return 0;
118}
119
120/* Finds the pending interrupt on the passed cascade irq and redrives it */
121static void sirc_irq_handler(unsigned int irq, struct irq_desc *desc)
122{
123 unsigned int reg = 0;
124 unsigned int sirq;
125 unsigned int status;
126
127 while ((reg < ARRAY_SIZE(sirc_reg_table)) &&
128 (sirc_reg_table[reg].cascade_irq != irq))
129 reg++;
130
131 status = readl(sirc_reg_table[reg].int_status);
132 status &= SIRC_MASK;
133 if (status == 0)
134 return;
135
136 for (sirq = 0;
137 (sirq < NR_SIRC_IRQS) && ((status & (1U << sirq)) == 0);
138 sirq++)
139 ;
140 generic_handle_irq(sirq+FIRST_SIRC_IRQ);
141
142 desc->chip->ack(irq);
143}
144
145static struct irq_chip sirc_irq_chip = {
146 .name = "sirc",
147 .ack = sirc_irq_ack,
148 .mask = sirc_irq_mask,
149 .unmask = sirc_irq_unmask,
150 .set_wake = sirc_irq_set_wake,
151 .set_type = sirc_irq_set_type,
152};
153
154void __init msm_init_sirc(void)
155{
156 int i;
157
158 int_enable = 0;
159 wake_enable = 0;
160
161 for (i = FIRST_SIRC_IRQ; i < LAST_SIRC_IRQ; i++) {
162 set_irq_chip(i, &sirc_irq_chip);
163 set_irq_handler(i, handle_edge_irq);
164 set_irq_flags(i, IRQF_VALID);
165 }
166
167 for (i = 0; i < ARRAY_SIZE(sirc_reg_table); i++) {
168 set_irq_chained_handler(sirc_reg_table[i].cascade_irq,
169 sirc_irq_handler);
170 set_irq_wake(sirc_reg_table[i].cascade_irq, 1);
171 }
172 return;
173}
174