blob: 2bd347a530a9e8586bd33d7ac527308038dc799d [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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
13#include <linux/io.h>
14#include <linux/irq.h>
15#include <linux/interrupt.h>
16#include <asm/irq.h>
17
18#include "sirc.h"
19
20static unsigned int sirc_int_enable[2];
21
22static struct sirc_regs_t sirc_regs = {
23 .int_enable = SPSS_SIRC_INT_ENABLE,
24 .int_type = SPSS_SIRC_INT_TYPE,
25 .int_polarity = SPSS_SIRC_INT_POLARITY,
26 .int_clear = SPSS_SIRC_INT_CLEAR,
27};
28
29static inline void sirc_get_group_offset_mask(unsigned int irq,
30 unsigned int *group, unsigned int *offset, unsigned int *mask)
31{
32 *group = 0;
33 *offset = irq - FIRST_SIRC_IRQ;
34 if (*offset >= NR_SIRC_IRQS_GROUPA) {
35 *group = 1;
36 *offset -= NR_SIRC_IRQS_GROUPA;
37 }
38 *mask = 1 << *offset;
39}
40
41static void sirc_irq_mask(struct irq_data *d)
42{
43 void *reg_enable;
44 unsigned int group, offset, mask;
45 unsigned int val;
46
47 sirc_get_group_offset_mask(d->irq, &group, &offset, &mask);
48
49 reg_enable = sirc_regs.int_enable + group * 4;
50 val = __raw_readl(reg_enable);
51 __raw_writel(val & ~mask, reg_enable);
52 sirc_int_enable[group] &= ~mask;
53 mb();
54}
55
56static void sirc_irq_unmask(struct irq_data *d)
57{
58 void *reg_enable;
59 void *reg_clear;
60 unsigned int group, offset, mask;
61 unsigned int val;
62
63 sirc_get_group_offset_mask(d->irq, &group, &offset, &mask);
64
65 if (irq_desc[d->irq].handle_irq == handle_level_irq) {
66 reg_clear = sirc_regs.int_clear + group * 4;
67 __raw_writel(mask, reg_clear);
68 }
69
70 reg_enable = sirc_regs.int_enable + group * 4;
71 val = __raw_readl(reg_enable);
72 __raw_writel(val | mask, reg_enable);
73 sirc_int_enable[group] |= mask;
74 mb();
75}
76
77static void sirc_irq_ack(struct irq_data *d)
78{
79 void *reg_clear;
80 unsigned int group, offset, mask;
81
82 sirc_get_group_offset_mask(d->irq, &group, &offset, &mask);
83
84 reg_clear = sirc_regs.int_clear + group * 4;
85 __raw_writel(mask, reg_clear);
86}
87
88static int sirc_irq_set_wake(struct irq_data *d, unsigned int on)
89{
90 return 0;
91}
92
93static int sirc_irq_set_type(struct irq_data *d, unsigned int flow_type)
94{
95 void *reg_polarity, *reg_type;
96 unsigned int group, offset, mask;
97 unsigned int val;
98
99 sirc_get_group_offset_mask(d->irq, &group, &offset, &mask);
100
101 reg_polarity = sirc_regs.int_polarity + group * 4;
102 val = __raw_readl(reg_polarity);
103
104 if (flow_type & (IRQF_TRIGGER_LOW | IRQF_TRIGGER_FALLING))
105 val &= ~mask;
106 else
107 val |= mask;
108
109 __raw_writel(val, reg_polarity);
110
111 reg_type = sirc_regs.int_type + group * 4;
112 val = __raw_readl(reg_type);
113
114 if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
115 val |= mask;
116 irq_desc[d->irq].handle_irq = handle_edge_irq;
117 } else {
118 val &= ~mask;
119 irq_desc[d->irq].handle_irq = handle_level_irq;
120 }
121
122 __raw_writel(val, reg_type);
123
124 return 0;
125}
126
127/* Finds the pending interrupt on the passed cascade irq and redrives it */
128static void sirc_irq_handler(unsigned int irq, struct irq_desc *desc)
129{
130 unsigned int sirq;
131
132 for (;;) {
133 sirq = __raw_readl(SPSS_SIRC_VEC_INDEX_RD);
134 if (sirq >= NR_SIRC_IRQS)
135 break;
136
137 generic_handle_irq(sirq + FIRST_SIRC_IRQ);
138 }
139
140 irq_desc_get_chip(desc)->irq_ack(irq_get_irq_data(irq));
141}
142
143static struct irq_chip sirc_irq_chip = {
144 .name = "sirc",
145 .irq_ack = sirc_irq_ack,
146 .irq_mask = sirc_irq_mask,
147 .irq_unmask = sirc_irq_unmask,
148 .irq_set_wake = sirc_irq_set_wake,
149 .irq_set_type = sirc_irq_set_type,
150};
151
152void __init msm_init_sirc(void)
153{
154 int i;
155
156 sirc_int_enable[0] = 0;
157 sirc_int_enable[1] = 0;
158
159 for (i = FIRST_SIRC_IRQ; i <= LAST_SIRC_IRQ; i++) {
160 irq_set_chip_and_handler(i, &sirc_irq_chip, handle_edge_irq);
161 set_irq_flags(i, IRQF_VALID);
162 }
163
164 irq_set_chained_handler(INT_SIRC_0, sirc_irq_handler);
165 irq_set_irq_wake(INT_SIRC_0, 1);
166}