sa11x0.c revision 1.11 1 /* $NetBSD: sa11x0.c,v 1.11 2003/04/01 23:19:11 thorpej 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 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/device.h>
61 #include <sys/kernel.h>
62 #include <sys/reboot.h>
63
64 #include <uvm/uvm_extern.h>
65
66 #include <machine/cpu.h>
67 #include <machine/bus.h>
68
69 #include <arm/mainbus/mainbus.h>
70 #include <arm/sa11x0/sa11x0_reg.h>
71 #include <arm/sa11x0/sa11x0_var.h>
72 #include <arm/sa11x0/sa11x0_dmacreg.h>
73 #include <arm/sa11x0/sa11x0_ppcreg.h>
74 #include <arm/sa11x0/sa11x0_gpioreg.h>
75
76 #ifdef hpcarm
77 #include <hpc/include/config_hook.h>
78 #include <hpc/include/platid.h>
79 #include <hpc/include/platid_mask.h>
80 #endif
81
82 #include "locators.h"
83
84 /* prototypes */
85 static int sa11x0_match(struct device *, struct cfdata *, void *);
86 static void sa11x0_attach(struct device *, struct device *, void *);
87 static int sa11x0_search(struct device *, struct cfdata *, void *);
88 static int sa11x0_print(void *, const char *);
89
90 /* attach structures */
91 CFATTACH_DECL(saip, sizeof(struct sa11x0_softc),
92 sa11x0_match, sa11x0_attach, NULL, NULL);
93
94 extern struct bus_space sa11x0_bs_tag;
95 extern vaddr_t saipic_base;
96
97 extern int SetCPSR(int, int);
98
99 /*
100 * int sa11x0_print(void *aux, const char *name)
101 * print configuration info for children
102 */
103
104 static int
105 sa11x0_print(aux, name)
106 void *aux;
107 const char *name;
108 {
109 struct sa11x0_attach_args *sa = (struct sa11x0_attach_args*)aux;
110
111 if (sa->sa_size)
112 aprint_normal(" addr 0x%lx", sa->sa_addr);
113 if (sa->sa_size > 1)
114 aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
115 if (sa->sa_memsize)
116 aprint_normal(" membase 0x%lx", sa->sa_membase);
117 if (sa->sa_memsize > 1)
118 aprint_normal("-0x%lx", sa->sa_membase + sa->sa_memsize - 1);
119 if (sa->sa_intr > 1)
120 aprint_normal(" intr %d", sa->sa_intr);
121 if (sa->sa_gpio != -1)
122 aprint_normal(" gpio %d", sa->sa_gpio);
123
124 return (UNCONF);
125 }
126
127 int
128 sa11x0_match(parent, match, aux)
129 struct device *parent;
130 struct cfdata *match;
131 void *aux;
132 {
133 return 1;
134 }
135
136 void
137 sa11x0_attach(parent, self, aux)
138 struct device *parent;
139 struct device *self;
140 void *aux;
141 {
142 struct sa11x0_softc *sc = (struct sa11x0_softc*)self;
143
144 sc->sc_iot = &sa11x0_bs_tag;
145
146 /* Map the SAIP */
147 if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
148 0, &sc->sc_ioh))
149 panic("%s: Cannot map registers", self->dv_xname);
150 saipic_base = sc->sc_ioh;
151
152 /* Map the GPIO registers */
153 if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
154 0, &sc->sc_gpioh))
155 panic("%s: unable to map GPIO registers", self->dv_xname);
156 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
157
158 /* Map the PPC registers */
159 if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
160 0, &sc->sc_ppch))
161 panic("%s: unable to map PPC registers", self->dv_xname);
162
163 /* Map the DMA controller registers */
164 if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
165 0, &sc->sc_dmach))
166 panic("%s: unable to map DMAC registers", self->dv_xname);
167
168 /* Map the reset controller registers */
169 if (bus_space_map(sc->sc_iot, SARCR_BASE, PAGE_SIZE,
170 0, &sc->sc_reseth))
171 panic("%s: unable to map reset registers", self->dv_xname);
172
173 printf("\n");
174
175 /*
176 * Mask all interrupts.
177 * They are later unmasked at each device's attach routine.
178 */
179 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
180
181 /* Route all bits to IRQ */
182 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
183
184 /* Exit idle mode only when unmasked intr is received */
185 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
186
187 /* disable all DMAC channels */
188 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
189 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
190 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
191 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
192 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
193 bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
194
195 /*
196 * XXX this is probably a bad place, but intr bit shouldn't be
197 * XXX enabled before intr mask is set.
198 * XXX Having sane imask[] suffice??
199 */
200 SetCPSR(I32_bit, 0);
201
202 /*
203 * Attach each devices
204 */
205 config_search(sa11x0_search, self, NULL);
206 }
207
208 int
209 sa11x0_search(parent, cf, aux)
210 struct device *parent;
211 struct cfdata *cf;
212 void *aux;
213 {
214 struct sa11x0_softc *sc = (struct sa11x0_softc *)parent;
215 struct sa11x0_attach_args sa;
216
217 sa.sa_sc = sc;
218 sa.sa_iot = sc->sc_iot;
219 sa.sa_addr = cf->cf_loc[SAIPCF_ADDR];
220 sa.sa_size = cf->cf_loc[SAIPCF_SIZE];
221 sa.sa_membase = cf->cf_loc[SAIPCF_MEMBASE];
222 sa.sa_memsize = cf->cf_loc[SAIPCF_MEMSIZE];
223 sa.sa_intr = cf->cf_loc[SAIPCF_INTR];
224 sa.sa_gpio = cf->cf_loc[SAIPCF_GPIO];
225
226 if (config_match(parent, cf, &sa) > 0)
227 config_attach(parent, cf, &sa, sa11x0_print);
228
229 return 0;
230 }
231