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.
20 * Shin Takemura and PocketBSD Project. All rights reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * This product includes software developed by the PocketBSD project
33 * and its contributors.
34 * 4. Neither the name of the project nor the names of its contributors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
38 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 #include <sys/cdefs.h>
53 __FBSDID("$FreeBSD$");
55 #include <sys/param.h>
56 #include <sys/systm.h>
58 #include <sys/kernel.h>
59 #include <sys/reboot.h>
60 #include <sys/malloc.h>
61 #include <sys/interrupt.h>
62 #include <sys/module.h>
66 #include <vm/vm_extern.h>
68 #include <machine/cpu.h>
69 #include <machine/bus.h>
70 #include <machine/intr.h>
71 #include <arm/sa11x0/sa11x0_reg.h>
72 #include <arm/sa11x0/sa11x0_var.h>
73 #include <arm/sa11x0/sa11x0_dmacreg.h>
74 #include <arm/sa11x0/sa11x0_ppcreg.h>
75 #include <arm/sa11x0/sa11x0_gpioreg.h>
77 extern void sa11x0_activateirqs(void);
79 static struct resource *sa1110_alloc_resource(device_t, device_t, int, int *,
80 u_long, u_long, u_long, u_int);
82 static int sa1110_activate_resource(device_t, device_t, int, int,
84 static int sa1110_setup_intr(device_t, device_t, struct resource *, int,
85 driver_filter_t *, driver_intr_t *, void *, void **);
87 struct sa11x0_softc *sa11x0_softc; /* There can be only one. */
90 sa1110_setup_intr(device_t dev, device_t child,
91 struct resource *ires, int flags, driver_filter_t *filt,
92 driver_intr_t *intr, void *arg, void **cookiep)
96 if (flags & INTR_TYPE_TTY)
97 rman_set_start(ires, 15);
98 else if (flags & INTR_TYPE_CLK) {
99 if (rman_get_start(ires) == 0)
100 rman_set_start(ires, 26);
102 rman_set_start(ires, 27);
104 saved_cpsr = SetCPSR(I32_bit, I32_bit);
106 SetCPSR(I32_bit, saved_cpsr & I32_bit);
107 BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, filt,
112 static struct resource *
113 sa1110_alloc_resource(device_t bus, device_t child, int type, int *rid,
114 u_long start, u_long end, u_long count, u_int flags)
116 struct resource *res;
118 res = rman_reserve_resource(&sa11x0_softc->sa11x0_rman, *rid, *rid,
119 count, flags, child);
121 rman_set_rid(res, *rid);
126 sa1110_activate_resource(device_t bus, device_t child, int type, int rid,
132 static int sa11x0_probe(device_t);
133 static int sa11x0_attach(device_t);
134 static void sa11x0_identify(driver_t *, device_t);
136 extern vm_offset_t saipic_base;
140 sa11x0_probe(device_t dev)
146 sa11x0_identify(driver_t *driver, device_t parent)
149 BUS_ADD_CHILD(parent, 0, "saip", 0);
153 sa11x0_attach(device_t dev)
155 struct sa11x0_softc *sc = device_get_softc(dev);
156 int unit = device_get_unit(dev);
157 sc->sc_iot = &sa11x0_bs_tag;
163 if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
165 panic("saip%d: Cannot map registers", unit);
166 saipic_base = sc->sc_ioh;
168 /* Map the GPIO registers */
169 if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
171 panic("saip%d: unable to map GPIO registers", unit);
172 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
174 /* Map the PPC registers */
175 if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
177 panic("saip%d: unable to map PPC registers", unit);
180 /* Map the DMA controller registers */
181 if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
183 panic("saip%d: unable to map DMAC registers", unit);
185 /* Map the reset controller registers */
186 if (bus_space_map(sc->sc_iot, SARCR_BASE, PAGE_SIZE,
188 panic("saip%d: unable to map reset registers", unit);
193 * Mask all interrupts.
194 * They are later unmasked at each device's attach routine.
196 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
198 /* Route all bits to IRQ */
199 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
201 /* Exit idle mode only when unmasked intr is received */
202 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
204 /* disable all DMAC channels */
205 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
206 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
207 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
208 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
209 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
210 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
213 * XXX this is probably a bad place, but intr bit shouldn't be
214 * XXX enabled before intr mask is set.
215 * XXX Having sane imask[] suffice??
221 * Attach each devices
223 sc->sa11x0_rman.rm_type = RMAN_ARRAY;
224 sc->sa11x0_rman.rm_descr = "SA11x0 IRQs";
225 if (rman_init(&sc->sa11x0_rman) != 0 ||
226 rman_manage_region(&sc->sa11x0_rman, 0, 32) != 0)
227 panic("sa11x0_attach: failed to set up rman");
228 device_add_child(dev, "uart", 0);
229 device_add_child(dev, "saost", 0);
230 bus_generic_probe(dev);
231 bus_generic_attach(dev);
232 sa11x0_activateirqs();
236 static device_method_t saip_methods[] = {
237 DEVMETHOD(device_probe, sa11x0_probe),
238 DEVMETHOD(device_attach, sa11x0_attach),
239 DEVMETHOD(device_identify, sa11x0_identify),
240 DEVMETHOD(bus_alloc_resource, sa1110_alloc_resource),
241 DEVMETHOD(bus_activate_resource, sa1110_activate_resource),
242 DEVMETHOD(bus_setup_intr, sa1110_setup_intr),
246 static driver_t saip_driver = {
249 sizeof(struct sa11x0_softc),
251 static devclass_t saip_devclass;
253 DRIVER_MODULE(saip, nexus, saip_driver, saip_devclass, 0, 0);