1 /* $NetBSD: sa11x0.c,v 1.14 2003/07/15 00:24:50 lukem Exp $ */
4 * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
27 * Shin Takemura and PocketBSD Project. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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.
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
59 #include <sys/cdefs.h>
60 __FBSDID("$FreeBSD$");
62 #include <sys/param.h>
63 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/reboot.h>
67 #include <sys/malloc.h>
69 #include <sys/interrupt.h>
70 #include <sys/module.h>
74 #include <vm/vm_extern.h>
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>
86 extern void sa11x0_activateirqs(void);
88 static struct resource *sa1110_alloc_resource(device_t, device_t, int, int *,
89 u_long, u_long, u_long, u_int);
91 static int sa1110_activate_resource(device_t, device_t, int, int,
93 static int sa1110_setup_intr(device_t, device_t, struct resource *, int,
94 driver_filter_t *, driver_intr_t *, void *, void **);
96 struct sa11x0_softc *sa11x0_softc; /* There can be only one. */
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)
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);
111 rman_set_start(ires, 27);
113 saved_cpsr = SetCPSR(I32_bit, I32_bit);
115 SetCPSR(I32_bit, saved_cpsr & I32_bit);
116 BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, filt,
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)
125 struct resource *res;
127 res = rman_reserve_resource(&sa11x0_softc->sa11x0_rman, *rid, *rid,
128 count, flags, child);
130 rman_set_rid(res, *rid);
135 sa1110_activate_resource(device_t bus, device_t child, int type, int rid,
141 static int sa11x0_probe(device_t);
142 static int sa11x0_attach(device_t);
143 static void sa11x0_identify(driver_t *, device_t);
145 extern vm_offset_t saipic_base;
149 sa11x0_probe(device_t dev)
155 sa11x0_identify(driver_t *driver, device_t parent)
158 BUS_ADD_CHILD(parent, 0, "saip", 0);
162 sa11x0_attach(device_t dev)
164 struct sa11x0_softc *sc = device_get_softc(dev);
165 int unit = device_get_unit(dev);
166 sc->sc_iot = &sa11x0_bs_tag;
172 if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
174 panic("saip%d: Cannot map registers", unit);
175 saipic_base = sc->sc_ioh;
177 /* Map the GPIO registers */
178 if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
180 panic("saip%d: unable to map GPIO registers", unit);
181 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
183 /* Map the PPC registers */
184 if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
186 panic("saip%d: unable to map PPC registers", unit);
189 /* Map the DMA controller registers */
190 if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
192 panic("saip%d: unable to map DMAC registers", unit);
194 /* Map the reset controller registers */
195 if (bus_space_map(sc->sc_iot, SARCR_BASE, PAGE_SIZE,
197 panic("saip%d: unable to map reset registers", unit);
202 * Mask all interrupts.
203 * They are later unmasked at each device's attach routine.
205 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
207 /* Route all bits to IRQ */
208 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
210 /* Exit idle mode only when unmasked intr is received */
211 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
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);
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??
230 * Attach each devices
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();
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),
255 static driver_t saip_driver = {
258 sizeof(struct sa11x0_softc),
260 static devclass_t saip_devclass;
262 DRIVER_MODULE(saip, nexus, saip_driver, saip_devclass, 0, 0);