s3c2800_intr.c revision 1.5 1 /* $NetBSD: s3c2800_intr.c,v 1.5 2003/07/15 00:24:48 lukem Exp $ */
2
3 /*
4 * Copyright (c) 2002 Fujitsu Component Limited
5 * Copyright (c) 2002 Genetec Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 * Genetec corporation may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * IRQ handler for Samsung S3C2800 processor.
37 * It has integrated interrupt controller.
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: s3c2800_intr.c,v 1.5 2003/07/15 00:24:48 lukem Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <uvm/uvm_extern.h>
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 #include <arm/cpufunc.h>
50
51 #include <arm/s3c2xx0/s3c2800reg.h>
52 #include <arm/s3c2xx0/s3c2800var.h>
53
54 /*
55 * interrupt dispatch table.
56 */
57
58 struct s3c2xx0_intr_dispatch handler[ICU_LEN];
59
60 __volatile int softint_pending;
61
62 __volatile int current_spl_level;
63 __volatile int intr_mask;
64
65 /* interrupt masks for each level */
66 int s3c2xx0_imask[NIPL];
67 int s3c2xx0_ilevel[ICU_LEN];
68
69 vaddr_t intctl_base; /* interrupt controller registers */
70 #define icreg(offset) \
71 (*(volatile uint32_t *)(intctl_base+(offset)))
72
73 /*
74 * Map a software interrupt queue to an interrupt priority level.
75 */
76 static const int si_to_ipl[SI_NQUEUES] = {
77 IPL_SOFT, /* SI_SOFT */
78 IPL_SOFTCLOCK, /* SI_SOFTCLOCK */
79 IPL_SOFTNET, /* SI_SOFTNET */
80 IPL_SOFTSERIAL, /* SI_SOFTSERIAL */
81 };
82
83 /*
84 * Clearing interrupt pending bits affects some built-in
85 * peripherals. For example, IIC starts transmitting next data when
86 * its interrupt pending bit is cleared.
87 * We need to leave those bits to peripheral handlers.
88 */
89 #define PENDING_CLEAR_MASK (~((1<<S3C2800_INT_IIC0)|(1<<S3C2800_INT_IIC1)))
90
91 /*
92 * called from irq_entry.
93 */
94 void s3c2800_irq_handler(struct clockframe *);
95 void
96 s3c2800_irq_handler(struct clockframe *frame)
97 {
98 uint32_t irqbits;
99 int irqno;
100 int saved_spl_level;
101
102 saved_spl_level = current_spl_level;
103
104 /* get pending IRQs */
105 irqbits = icreg(INTCTL_IRQPND) & ICU_INT_HWMASK;
106
107 for (irqno = 0; irqbits; ++irqno) {
108 if ((irqbits & (1 << irqno)) == 0)
109 continue;
110 /* raise spl to stop interrupts of lower priorities */
111 if (saved_spl_level < handler[irqno].level)
112 s3c2xx0_setipl(handler[irqno].level);
113
114 /* clear pending bit */
115 icreg(INTCTL_SRCPND) = PENDING_CLEAR_MASK & (1 << irqno);
116 #ifdef notyet
117 /* Enable interrupt */
118 #endif
119 (*handler[irqno].func) (
120 handler[irqno].cookie == 0
121 ? frame : handler[irqno].cookie);
122 #ifdef notyet
123 /* Disable interrupt */
124 #endif
125
126 irqbits &= ~(1 << irqno);
127 }
128
129 /* restore spl to that was when this interrupt happen */
130 s3c2xx0_setipl(saved_spl_level);
131
132 if (softint_pending & intr_mask)
133 s3c2xx0_do_pending();
134 }
135
136 static const u_char s3c2800_ist[] = {
137 EXTINTR_LOW, /* NONE */
138 EXTINTR_FALLING, /* PULSE */
139 EXTINTR_FALLING, /* EDGE */
140 EXTINTR_LOW, /* LEVEL */
141 EXTINTR_HIGH,
142 EXTINTR_RISING,
143 EXTINTR_BOTH,
144 };
145
146 void *
147 s3c2800_intr_establish(int irqno, int level, int type,
148 int (* func) (void *), void *cookie)
149 {
150 int save;
151
152 if (irqno < 0 || irqno >= ICU_LEN ||
153 type < IST_NONE || IST_EDGE_BOTH < type)
154 panic("intr_establish: bogus irq or type");
155
156 save = disable_interrupts(I32_bit);
157
158 handler[irqno].cookie = cookie;
159 handler[irqno].func = func;
160 handler[irqno].level = level;
161
162 s3c2xx0_update_intr_masks(irqno, level);
163
164 if (irqno <= S3C2800_INT_EXT(7)) {
165 /*
166 * Update external interrupt control
167 */
168 uint32_t reg;
169 u_int trig;
170
171 trig = s3c2800_ist[type];
172
173 reg = bus_space_read_4(s3c2xx0_softc->sc_iot,
174 s3c2xx0_softc->sc_gpio_ioh,
175 GPIO_EXTINTR);
176
177 reg = reg & ~(0x0f << (4*irqno));
178 reg |= trig << (4*irqno);
179
180 bus_space_write_4(s3c2xx0_softc->sc_iot, s3c2xx0_softc->sc_gpio_ioh,
181 GPIO_EXTINTR, reg);
182 }
183
184 intr_mask = s3c2xx0_imask[current_spl_level];
185 *s3c2xx0_intr_mask_reg = intr_mask;
186
187 restore_interrupts(save);
188
189 return (&handler[irqno]);
190 }
191
192
193 void
194 s3c2800_intr_init(struct s3c2800_softc *sc)
195 {
196 intctl_base = (vaddr_t) bus_space_vaddr(sc->sc_sx.sc_iot,
197 sc->sc_sx.sc_intctl_ioh);
198
199 s3c2xx0_intr_mask_reg = (uint32_t *)(intctl_base + INTCTL_INTMSK);
200
201 /* clear all pending interrupt */
202 icreg(INTCTL_SRCPND) = 0xffffffff;
203
204 s3c2xx0_intr_init(handler, ICU_LEN);
205
206 }
207