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/6.1/sys/arm/sa11x0/sa11x0.c 135667 2004-09-23 22:33:38Z cognet $");
61
62 #define __RMAN_RESOURCE_VISIBLE
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/bus.h>
66 #include <sys/kernel.h>
67 #include <sys/reboot.h>
68 #include <sys/types.h>
69 #include <sys/malloc.h>
70 #include <sys/bus.h>
71 #include <sys/interrupt.h>
72 #include <sys/module.h>
73
74 #include <vm/vm.h>
75 #include <vm/vm_extern.h>
76
77 #include <machine/cpu.h>
78 #include <machine/bus.h>
79 #include <machine/intr.h>
80 #include <arm/sa11x0/sa11x0_reg.h>
81 #include <arm/sa11x0/sa11x0_var.h>
82 #include <arm/sa11x0/sa11x0_dmacreg.h>
83 #include <arm/sa11x0/sa11x0_ppcreg.h>
84 #include <arm/sa11x0/sa11x0_gpioreg.h>
85 #include <machine/bus.h>
86 #include <sys/rman.h>
87
88 extern void sa11x0_activateirqs(void);
89
90 static struct resource *sa1110_alloc_resource(device_t, device_t, int, int *,
91 u_long, u_long, u_long, u_int);
92
93 static int sa1110_activate_resource(device_t, device_t, int, int,
94 struct resource *);
95 static int sa1110_setup_intr(device_t, device_t, struct resource *, int,
96 driver_intr_t *, void *, void **);
97
98 struct sa11x0_softc *sa11x0_softc; /* There can be only one. */
99
100 static int
101 sa1110_setup_intr(device_t dev, device_t child,
102 struct resource *ires, int flags, driver_intr_t *intr, void *arg,
103 void **cookiep)
104 {
105 int saved_cpsr;
106
107 if (flags & INTR_TYPE_TTY)
108 ires->r_start = 15;
109 else if (flags & INTR_TYPE_CLK) {
110 if (ires->r_start == 0)
111 ires->r_start = 26;
112 else
113 ires->r_start = 27;
114 }
115 saved_cpsr = SetCPSR(I32_bit, I32_bit);
116
117 SetCPSR(I32_bit, saved_cpsr & I32_bit);
118 BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, intr, arg,
119 cookiep);
120 return (0);
121 }
122
123 static struct resource *
124 sa1110_alloc_resource(device_t bus, device_t child, int type, int *rid,
125 u_long start, u_long end, u_long count, u_int flags)
126 {
127 struct resource *res = malloc(sizeof(*res), M_DEVBUF, M_WAITOK);
128 /* XXX */
129 res->r_start = *rid;
130 return (res);
131 }
132 static int
133 sa1110_activate_resource(device_t bus, device_t child, int type, int rid,
134 struct resource *r)
135 {
136 return (0);
137 }
138 /* prototypes */
139 static int sa11x0_probe(device_t);
140 static int sa11x0_attach(device_t);
141 static void sa11x0_identify(driver_t *, device_t);
142
143 extern vm_offset_t saipic_base;
144
145
146 int
147 sa11x0_probe(device_t dev)
148 {
149 return 0;
150 }
151
152 void
153 sa11x0_identify(driver_t *driver, device_t parent)
154 {
155
156 BUS_ADD_CHILD(parent, 0, "saip", 0);
157 }
158
159 int
160 sa11x0_attach(device_t dev)
161 {
162 struct sa11x0_softc *sc = device_get_softc(dev);
163 int unit = device_get_unit(dev);
164 sc->sc_iot = &sa11x0_bs_tag;
165
166 sa11x0_softc = sc;
167
168 /* Map the SAIP */
169
170 if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
171 0, &sc->sc_ioh))
172 panic("saip%d: Cannot map registers", unit);
173 saipic_base = sc->sc_ioh;
174
175 /* Map the GPIO registers */
176 if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
177 0, &sc->sc_gpioh))
178 panic("saip%d: unable to map GPIO registers", unit);
179 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
180
181 /* Map the PPC registers */
182 if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
183 0, &sc->sc_ppch))
184 panic("saip%d: unable to map PPC registers", unit);
185
186 #if 0
187 /* Map the DMA controller registers */
188 if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
189 0, &sc->sc_dmach))
190 panic("saip%d: unable to map DMAC registers", unit);
191 #endif
192 /* Map the reset controller registers */
193 if (bus_space_map(sc->sc_iot, SARCR_BASE, PAGE_SIZE,
194 0, &sc->sc_reseth))
195 panic("saip%d: unable to map reset registers", unit);
196 printf("\n");
197
198
199 /*
200 * Mask all interrupts.
201 * They are later unmasked at each device's attach routine.
202 */
203 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
204
205 /* Route all bits to IRQ */
206 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
207
208 /* Exit idle mode only when unmasked intr is received */
209 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
210 #if 0
211 /* disable all DMAC channels */
212 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
213 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
214 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
215 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
216 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
217 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
218 #endif
219 /*
220 * XXX this is probably a bad place, but intr bit shouldn't be
221 * XXX enabled before intr mask is set.
222 * XXX Having sane imask[] suffice??
223 */
224 #if 0
225 SetCPSR(I32_bit, 0);
226 #endif
227 /*
228 * Attach each devices
229 */
230 device_add_child(dev, "uart", 0);
231 device_add_child(dev, "saost", 0);
232 bus_generic_probe(dev);
233 bus_generic_attach(dev);
234 sa11x0_activateirqs();
235 return (0);
236 }
237
238 static device_method_t saip_methods[] = {
239 DEVMETHOD(device_probe, sa11x0_probe),
240 DEVMETHOD(device_attach, sa11x0_attach),
241 DEVMETHOD(device_identify, sa11x0_identify),
242 DEVMETHOD(bus_alloc_resource, sa1110_alloc_resource),
243 DEVMETHOD(bus_activate_resource, sa1110_activate_resource),
244 DEVMETHOD(bus_setup_intr, sa1110_setup_intr),
245 {0, 0},
246 };
247
248 static driver_t saip_driver = {
249 "saip",
250 saip_methods,
251 sizeof(struct sa11x0_softc),
252 };
253 static devclass_t saip_devclass;
254
255 DRIVER_MODULE(saip, nexus, saip_driver, saip_devclass, 0, 0);
Cache object: 1a5d637e298e6af08d1ee96cb9b62ec0
|