1 /* $NetBSD: sa11x0.c,v 1.14 2003/07/15 00:24:50 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 */
25 /*-
26 * Copyright (c) 1999
27 * Shin Takemura and PocketBSD Project. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the PocketBSD project
40 * and its contributors.
41 * 4. Neither the name of the project nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 *
57 */
58
59 #include <sys/cdefs.h>
60 __FBSDID("$FreeBSD: releng/7.3/sys/arm/sa11x0/sa11x0.c 167262 2007-03-06 10:56:54Z piso $");
61
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/bus.h>
65 #include <sys/kernel.h>
66 #include <sys/reboot.h>
67 #include <sys/malloc.h>
68 #include <sys/bus.h>
69 #include <sys/interrupt.h>
70 #include <sys/module.h>
71 #include <sys/rman.h>
72
73 #include <vm/vm.h>
74 #include <vm/vm_extern.h>
75
76 #include <machine/cpu.h>
77 #include <machine/bus.h>
78 #include <machine/intr.h>
79 #include <arm/sa11x0/sa11x0_reg.h>
80 #include <arm/sa11x0/sa11x0_var.h>
81 #include <arm/sa11x0/sa11x0_dmacreg.h>
82 #include <arm/sa11x0/sa11x0_ppcreg.h>
83 #include <arm/sa11x0/sa11x0_gpioreg.h>
84 #include <machine/bus.h>
85
86 extern void sa11x0_activateirqs(void);
87
88 static struct resource *sa1110_alloc_resource(device_t, device_t, int, int *,
89 u_long, u_long, u_long, u_int);
90
91 static int sa1110_activate_resource(device_t, device_t, int, int,
92 struct resource *);
93 static int sa1110_setup_intr(device_t, device_t, struct resource *, int,
94 driver_filter_t *, driver_intr_t *, void *, void **);
95
96 struct sa11x0_softc *sa11x0_softc; /* There can be only one. */
97
98 static int
99 sa1110_setup_intr(device_t dev, device_t child,
100 struct resource *ires, int flags, driver_filter_t *filt,
101 driver_intr_t *intr, void *arg, void **cookiep)
102 {
103 int saved_cpsr;
104
105 if (flags & INTR_TYPE_TTY)
106 rman_set_start(ires, 15);
107 else if (flags & INTR_TYPE_CLK) {
108 if (rman_get_start(ires) == 0)
109 rman_set_start(ires, 26);
110 else
111 rman_set_start(ires, 27);
112 }
113 saved_cpsr = SetCPSR(I32_bit, I32_bit);
114
115 SetCPSR(I32_bit, saved_cpsr & I32_bit);
116 BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, filt,
117 intr, arg, cookiep);
118 return (0);
119 }
120
121 static struct resource *
122 sa1110_alloc_resource(device_t bus, device_t child, int type, int *rid,
123 u_long start, u_long end, u_long count, u_int flags)
124 {
125 struct resource *res;
126
127 res = rman_reserve_resource(&sa11x0_softc->sa11x0_rman, *rid, *rid,
128 count, flags, child);
129 if (res != NULL)
130 rman_set_rid(res, *rid);
131
132 return (res);
133 }
134 static int
135 sa1110_activate_resource(device_t bus, device_t child, int type, int rid,
136 struct resource *r)
137 {
138 return (0);
139 }
140 /* prototypes */
141 static int sa11x0_probe(device_t);
142 static int sa11x0_attach(device_t);
143 static void sa11x0_identify(driver_t *, device_t);
144
145 extern vm_offset_t saipic_base;
146
147
148 int
149 sa11x0_probe(device_t dev)
150 {
151 return 0;
152 }
153
154 void
155 sa11x0_identify(driver_t *driver, device_t parent)
156 {
157
158 BUS_ADD_CHILD(parent, 0, "saip", 0);
159 }
160
161 int
162 sa11x0_attach(device_t dev)
163 {
164 struct sa11x0_softc *sc = device_get_softc(dev);
165 int unit = device_get_unit(dev);
166 sc->sc_iot = &sa11x0_bs_tag;
167
168 sa11x0_softc = sc;
169
170 /* Map the SAIP */
171
172 if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
173 0, &sc->sc_ioh))
174 panic("saip%d: Cannot map registers", unit);
175 saipic_base = sc->sc_ioh;
176
177 /* Map the GPIO registers */
178 if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
179 0, &sc->sc_gpioh))
180 panic("saip%d: unable to map GPIO registers", unit);
181 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
182
183 /* Map the PPC registers */
184 if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
185 0, &sc->sc_ppch))
186 panic("saip%d: unable to map PPC registers", unit);
187
188 #if 0
189 /* Map the DMA controller registers */
190 if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
191 0, &sc->sc_dmach))
192 panic("saip%d: unable to map DMAC registers", unit);
193 #endif
194 /* Map the reset controller registers */
195 if (bus_space_map(sc->sc_iot, SARCR_BASE, PAGE_SIZE,
196 0, &sc->sc_reseth))
197 panic("saip%d: unable to map reset registers", unit);
198 printf("\n");
199
200
201 /*
202 * Mask all interrupts.
203 * They are later unmasked at each device's attach routine.
204 */
205 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
206
207 /* Route all bits to IRQ */
208 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
209
210 /* Exit idle mode only when unmasked intr is received */
211 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
212 #if 0
213 /* disable all DMAC channels */
214 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
215 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
216 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
217 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
218 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
219 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
220 #endif
221 /*
222 * XXX this is probably a bad place, but intr bit shouldn't be
223 * XXX enabled before intr mask is set.
224 * XXX Having sane imask[] suffice??
225 */
226 #if 0
227 SetCPSR(I32_bit, 0);
228 #endif
229 /*
230 * Attach each devices
231 */
232 sc->sa11x0_rman.rm_type = RMAN_ARRAY;
233 sc->sa11x0_rman.rm_descr = "SA11x0 IRQs";
234 if (rman_init(&sc->sa11x0_rman) != 0 ||
235 rman_manage_region(&sc->sa11x0_rman, 0, 32) != 0)
236 panic("sa11x0_attach: failed to set up rman");
237 device_add_child(dev, "uart", 0);
238 device_add_child(dev, "saost", 0);
239 bus_generic_probe(dev);
240 bus_generic_attach(dev);
241 sa11x0_activateirqs();
242 return (0);
243 }
244
245 static device_method_t saip_methods[] = {
246 DEVMETHOD(device_probe, sa11x0_probe),
247 DEVMETHOD(device_attach, sa11x0_attach),
248 DEVMETHOD(device_identify, sa11x0_identify),
249 DEVMETHOD(bus_alloc_resource, sa1110_alloc_resource),
250 DEVMETHOD(bus_activate_resource, sa1110_activate_resource),
251 DEVMETHOD(bus_setup_intr, sa1110_setup_intr),
252 {0, 0},
253 };
254
255 static driver_t saip_driver = {
256 "saip",
257 saip_methods,
258 sizeof(struct sa11x0_softc),
259 };
260 static devclass_t saip_devclass;
261
262 DRIVER_MODULE(saip, nexus, saip_driver, saip_devclass, 0, 0);
Cache object: 7d981c54e92b803c1083c39ea147fcfe
|