blob: 9071677590ecce919e60a530f272a4f27cf7c597 [file] [log] [blame]
Brian Swetlanddfdb4612009-01-01 11:44:36 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google, Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <debug.h>
33#include <arch/arm.h>
34#include <reg.h>
35#include <kernel/thread.h>
36#include <platform/interrupts.h>
37
38#include <platform/irqs.h>
39#include <platform/iomap.h>
40
41#define VIC_REG(off) (MSM_VIC_BASE + (off))
42
43#define VIC_INT_SELECT0 VIC_REG(0x0000) /* 1: FIQ, 0: IRQ */
44#define VIC_INT_SELECT1 VIC_REG(0x0004) /* 1: FIQ, 0: IRQ */
45#define VIC_INT_EN0 VIC_REG(0x0010)
46#define VIC_INT_EN1 VIC_REG(0x0014)
47#define VIC_INT_ENCLEAR0 VIC_REG(0x0020)
48#define VIC_INT_ENCLEAR1 VIC_REG(0x0024)
49#define VIC_INT_ENSET0 VIC_REG(0x0030)
50#define VIC_INT_ENSET1 VIC_REG(0x0034)
51#define VIC_INT_TYPE0 VIC_REG(0x0040) /* 1: EDGE, 0: LEVEL */
52#define VIC_INT_TYPE1 VIC_REG(0x0044) /* 1: EDGE, 0: LEVEL */
53#define VIC_INT_POLARITY0 VIC_REG(0x0050) /* 1: NEG, 0: POS */
54#define VIC_INT_POLARITY1 VIC_REG(0x0054) /* 1: NEG, 0: POS */
55#define VIC_NO_PEND_VAL VIC_REG(0x0060)
56#define VIC_INT_MASTEREN VIC_REG(0x0068) /* 1: IRQ, 2: FIQ */
57#define VIC_CONFIG VIC_REG(0x006C) /* 1: USE ARM1136 VIC */
58#define VIC_SECURITY0 VIC_REG(0x0070)
59#define VIC_SECURITY1 VIC_REG(0x0074)
60#define VIC_IRQ_STATUS0 VIC_REG(0x0080)
61#define VIC_IRQ_STATUS1 VIC_REG(0x0084)
62#define VIC_FIQ_STATUS0 VIC_REG(0x0090)
63#define VIC_FIQ_STATUS1 VIC_REG(0x0094)
64#define VIC_RAW_STATUS0 VIC_REG(0x00A0)
65#define VIC_RAW_STATUS1 VIC_REG(0x00A4)
66#define VIC_INT_CLEAR0 VIC_REG(0x00B0)
67#define VIC_INT_CLEAR1 VIC_REG(0x00B4)
68#define VIC_SOFTINT0 VIC_REG(0x00C0)
69#define VIC_SOFTINT1 VIC_REG(0x00C4)
70#define VIC_IRQ_VEC_RD VIC_REG(0x00D0) /* pending int # */
71#define VIC_IRQ_VEC_PEND_RD VIC_REG(0x00D4) /* pending vector addr */
72#define VIC_IRQ_VEC_WR VIC_REG(0x00D8)
73#define VIC_FIQ_VEC_RD VIC_REG(0x00DC) /* pending int # */
74#define VIC_FIQ_VEC_PEND_RD VIC_REG(0x00E0) /* pending vector addr */
75#define VIC_FIQ_VEC_WR VIC_REG(0x00E4)
76#define VIC_IRQ_IN_SERVICE VIC_REG(0x00E8)
77#define VIC_IRQ_IN_STACK VIC_REG(0x00EC)
78#define VIC_FIQ_IN_SERVICE VIC_REG(0x00F0)
79#define VIC_FIQ_IN_STACK VIC_REG(0x00F4)
80#define VIC_TEST_BUS_SEL VIC_REG(0x00F8)
81
82#define SIRC_REG(off) (MSM_SIRC_BASE + (off))
83
84#define SIRC_INT_SELECT SIRC_REG(0x0000) /* 0: IRQ0 1: IRQ1 */
85#define SIRC_INT_ENABLE SIRC_REG(0x0004)
86#define SIRC_INT_ENCLEAR SIRC_REG(0x0008)
87#define SIRC_INT_ENSET SIRC_REG(0x000C)
88#define SIRC_INT_TYPE SIRC_REG(0x0010) /* 1: EDGE, 0: LEVEL */
89#define SIRC_INT_POLARITY SIRC_REG(0x0014) /* 1: NEG, 0: POS */
90#define SIRC_SECURITY SIRC_REG(0x0018) /* 0: SEC, 1: NSEC */
91#define SIRC_IRQ0_STATUS SIRC_REG(0x001C)
92#define SIRC_IRQ1_STATUS SIRC_REG(0x0020)
93#define SIRC_RAW_STATUS SIRC_REG(0x0024)
94
95struct ihandler {
96 int_handler func;
97 void *arg;
98};
99
100static struct ihandler handler[NR_IRQS];
101
102void platform_init_interrupts(void)
103{
104 writel(0xffffffff, VIC_INT_CLEAR0);
105 writel(0xffffffff, VIC_INT_CLEAR1);
106 writel(0, VIC_INT_SELECT0);
107 writel(0, VIC_INT_SELECT1);
108 writel(0xffffffff, VIC_INT_TYPE0);
109 writel(0xffffffff, VIC_INT_TYPE1);
110 writel(0, VIC_CONFIG);
111 writel(1, VIC_INT_MASTEREN);
112}
113
114enum handler_return platform_irq(struct arm_iframe *frame)
115{
116 unsigned num;
117 enum handler_return ret;
118 num = readl(VIC_IRQ_VEC_RD);
119 num = readl(VIC_IRQ_VEC_PEND_RD);
120 if (num > NR_IRQS)
121 return 0;
122 writel(1 << (num & 31), (num > 31) ? VIC_INT_CLEAR1 : VIC_INT_CLEAR0);
123 ret = handler[num].func(handler[num].arg);
124 writel(0, VIC_IRQ_VEC_WR);
125 return ret;
126}
127
128void platform_fiq(struct arm_iframe *frame)
129{
130 PANIC_UNIMPLEMENTED;
131}
132
133status_t mask_interrupt(unsigned int vector)
134{
135 unsigned reg = (vector > 31) ? VIC_INT_ENCLEAR1 : VIC_INT_ENCLEAR0;
136 unsigned bit = 1 << (vector & 31);
137 writel(bit, reg);
138 return 0;
139}
140
141status_t unmask_interrupt(unsigned int vector)
142{
143 unsigned reg = (vector > 31) ? VIC_INT_ENSET1 : VIC_INT_ENSET0;
144 unsigned bit = 1 << (vector & 31);
145 writel(bit, reg);
146 return 0;
147}
148
149void register_int_handler(unsigned int vector, int_handler func, void *arg)
150{
151 if (vector >= NR_IRQS)
152 return;
153
154 enter_critical_section();
155 handler[vector].func = func;
156 handler[vector].arg = arg;
157 exit_critical_section();
158}
159