sa11x0.c revision 1.1 1 1.1 rjs /* $NetBSD: sa11x0.c,v 1.1 2001/07/08 23:37:52 rjs Exp $ */
2 1.1 rjs
3 1.1 rjs /*-
4 1.1 rjs * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
5 1.1 rjs *
6 1.1 rjs * This code is derived from software contributed to The NetBSD Foundation
7 1.1 rjs * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
8 1.1 rjs *
9 1.1 rjs * Redistribution and use in source and binary forms, with or without
10 1.1 rjs * modification, are permitted provided that the following conditions
11 1.1 rjs * are met:
12 1.1 rjs * 1. Redistributions of source code must retain the above copyright
13 1.1 rjs * notice, this list of conditions and the following disclaimer.
14 1.1 rjs * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 rjs * notice, this list of conditions and the following disclaimer in the
16 1.1 rjs * documentation and/or other materials provided with the distribution.
17 1.1 rjs * 3. All advertising materials mentioning features or use of this software
18 1.1 rjs * must display the following acknowledgement:
19 1.1 rjs * This product includes software developed by the NetBSD
20 1.1 rjs * Foundation, Inc. and its contributors.
21 1.1 rjs * 4. Neither the name of The NetBSD Foundation nor the names of its
22 1.1 rjs * contributors may be used to endorse or promote products derived
23 1.1 rjs * from this software without specific prior written permission.
24 1.1 rjs */
25 1.1 rjs /*-
26 1.1 rjs * Copyright (c) 1999
27 1.1 rjs * Shin Takemura and PocketBSD Project. All rights reserved.
28 1.1 rjs *
29 1.1 rjs * Redistribution and use in source and binary forms, with or without
30 1.1 rjs * modification, are permitted provided that the following conditions
31 1.1 rjs * are met:
32 1.1 rjs * 1. Redistributions of source code must retain the above copyright
33 1.1 rjs * notice, this list of conditions and the following disclaimer.
34 1.1 rjs * 2. Redistributions in binary form must reproduce the above copyright
35 1.1 rjs * notice, this list of conditions and the following disclaimer in the
36 1.1 rjs * documentation and/or other materials provided with the distribution.
37 1.1 rjs * 3. All advertising materials mentioning features or use of this software
38 1.1 rjs * must display the following acknowledgement:
39 1.1 rjs * This product includes software developed by the PocketBSD project
40 1.1 rjs * and its contributors.
41 1.1 rjs * 4. Neither the name of the project nor the names of its contributors
42 1.1 rjs * may be used to endorse or promote products derived from this software
43 1.1 rjs * without specific prior written permission.
44 1.1 rjs *
45 1.1 rjs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 1.1 rjs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 1.1 rjs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 1.1 rjs * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 1.1 rjs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 1.1 rjs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 1.1 rjs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 1.1 rjs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 1.1 rjs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 1.1 rjs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 1.1 rjs * SUCH DAMAGE.
56 1.1 rjs *
57 1.1 rjs */
58 1.1 rjs #include <sys/param.h>
59 1.1 rjs #include <sys/systm.h>
60 1.1 rjs #include <sys/device.h>
61 1.1 rjs #include <sys/kernel.h>
62 1.1 rjs #include <sys/reboot.h>
63 1.1 rjs
64 1.1 rjs #include <machine/cpu.h>
65 1.1 rjs #include <machine/bus.h>
66 1.1 rjs
67 1.1 rjs #include <arm/mainbus/mainbus.h>
68 1.1 rjs #include <arm/sa11x0/sa11x0_reg.h>
69 1.1 rjs #include <arm/sa11x0/sa11x0_var.h>
70 1.1 rjs #include <arm/sa11x0/sa11x0_dmacreg.h>
71 1.1 rjs #include <arm/sa11x0/sa11x0_ppcreg.h>
72 1.1 rjs #include <arm/sa11x0/sa11x0_gpioreg.h>
73 1.1 rjs
74 1.1 rjs #ifdef hpcarm
75 1.1 rjs #include <hpc/hpc/config_hook.h>
76 1.1 rjs #include <hpc/hpc/platid.h>
77 1.1 rjs #include <hpc/include/platid_mask.h>
78 1.1 rjs #endif
79 1.1 rjs
80 1.1 rjs #include "locators.h"
81 1.1 rjs
82 1.1 rjs /* prototypes */
83 1.1 rjs static int sa11x0_match(struct device *, struct cfdata *, void *);
84 1.1 rjs static void sa11x0_attach(struct device *, struct device *, void *);
85 1.1 rjs static int sa11x0_search(struct device *, struct cfdata *, void *);
86 1.1 rjs static int sa11x0_print(void *, const char *);
87 1.1 rjs
88 1.1 rjs /* attach structures */
89 1.1 rjs struct cfattach saip_ca = {
90 1.1 rjs sizeof(struct sa11x0_softc), sa11x0_match, sa11x0_attach
91 1.1 rjs };
92 1.1 rjs
93 1.1 rjs extern struct bus_space sa11x0_bs_tag;
94 1.1 rjs extern vaddr_t saipic_base;
95 1.1 rjs
96 1.1 rjs extern int SetCPSR(int, int);
97 1.1 rjs
98 1.1 rjs /*
99 1.1 rjs * int sa11x0_print(void *aux, const char *name)
100 1.1 rjs * print configuration info for children
101 1.1 rjs */
102 1.1 rjs
103 1.1 rjs static int
104 1.1 rjs sa11x0_print(aux, name)
105 1.1 rjs void *aux;
106 1.1 rjs const char *name;
107 1.1 rjs {
108 1.1 rjs struct sa11x0_attach_args *sa = (struct sa11x0_attach_args*)aux;
109 1.1 rjs
110 1.1 rjs if (sa->sa_size)
111 1.1 rjs printf(" addr 0x%lx", sa->sa_addr);
112 1.1 rjs if (sa->sa_size > 1)
113 1.1 rjs printf("-0x%lx", sa->sa_addr + sa->sa_size - 1);
114 1.1 rjs if (sa->sa_memsize)
115 1.1 rjs printf(" membase 0x%lx", sa->sa_membase);
116 1.1 rjs if (sa->sa_memsize > 1)
117 1.1 rjs printf("-0x%lx", sa->sa_membase + sa->sa_memsize - 1);
118 1.1 rjs if (sa->sa_intr > 1)
119 1.1 rjs printf(" intr %d", sa->sa_intr);
120 1.1 rjs if (sa->sa_gpio != -1)
121 1.1 rjs printf(" gpio %d", sa->sa_gpio);
122 1.1 rjs
123 1.1 rjs return (UNCONF);
124 1.1 rjs }
125 1.1 rjs
126 1.1 rjs int
127 1.1 rjs sa11x0_match(parent, match, aux)
128 1.1 rjs struct device *parent;
129 1.1 rjs struct cfdata *match;
130 1.1 rjs void *aux;
131 1.1 rjs {
132 1.1 rjs return 1;
133 1.1 rjs }
134 1.1 rjs
135 1.1 rjs void
136 1.1 rjs sa11x0_attach(parent, self, aux)
137 1.1 rjs struct device *parent;
138 1.1 rjs struct device *self;
139 1.1 rjs void *aux;
140 1.1 rjs {
141 1.1 rjs struct sa11x0_softc *sc = (struct sa11x0_softc*)self;
142 1.1 rjs
143 1.1 rjs sc->sc_iot = &sa11x0_bs_tag;
144 1.1 rjs
145 1.1 rjs /* Map the SAIP */
146 1.1 rjs if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
147 1.1 rjs 0, &sc->sc_ioh))
148 1.1 rjs panic("%s: Cannot map registers\n", self->dv_xname);
149 1.1 rjs saipic_base = sc->sc_ioh;
150 1.1 rjs
151 1.1 rjs /* Map the GPIO registers */
152 1.1 rjs if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
153 1.1 rjs 0, &sc->sc_gpioh))
154 1.1 rjs panic("%s: unable to map GPIO registers\n", self->dv_xname);
155 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
156 1.1 rjs
157 1.1 rjs #ifdef SAEGPIO_BASE
158 1.1 rjs /* Map the iPAQ Extended GPIO registers */
159 1.1 rjs if (bus_space_map(sc->sc_iot, SAEGPIO_BASE, 1, 0, &sc->sc_egpioh))
160 1.1 rjs panic("%s: unable to map Extended GPIO registers\n",
161 1.1 rjs self->dv_xname);
162 1.1 rjs # if 0
163 1.1 rjs bus_space_write_2(sc->sc_iot, sc->sc_egpioh, 0, EGPIO_INIT);
164 1.1 rjs # endif
165 1.1 rjs #endif
166 1.1 rjs
167 1.1 rjs /* Map the PPC registers */
168 1.1 rjs if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
169 1.1 rjs 0, &sc->sc_ppch))
170 1.1 rjs panic("%s: unable to map PPC registers\n", self->dv_xname);
171 1.1 rjs
172 1.1 rjs /* Map the DMA controller registers */
173 1.1 rjs if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
174 1.1 rjs 0, &sc->sc_dmach))
175 1.1 rjs panic("%s: unable to map DMAC registers\n", self->dv_xname);
176 1.1 rjs
177 1.1 rjs printf("\n");
178 1.1 rjs
179 1.1 rjs /*
180 1.1 rjs * Mask all interrupts.
181 1.1 rjs * They are later unmasked at each device's attach routine.
182 1.1 rjs */
183 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
184 1.1 rjs
185 1.1 rjs /* Route all bits to IRQ */
186 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
187 1.1 rjs
188 1.1 rjs /* Exit idle mode only when unmasked intr is received */
189 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
190 1.1 rjs
191 1.1 rjs /* disable all DMAC channels */
192 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
193 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
194 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
195 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
196 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
197 1.1 rjs bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
198 1.1 rjs
199 1.1 rjs /*
200 1.1 rjs * XXX this is probably a bad place, but intr bit shouldn't be
201 1.1 rjs * XXX enabled before intr mask is set.
202 1.1 rjs * XXX Having sane imask[] suffice??
203 1.1 rjs */
204 1.1 rjs SetCPSR(I32_bit, 0);
205 1.1 rjs
206 1.1 rjs /*
207 1.1 rjs * Attach each devices
208 1.1 rjs */
209 1.1 rjs config_search(sa11x0_search, self, NULL);
210 1.1 rjs }
211 1.1 rjs
212 1.1 rjs int
213 1.1 rjs sa11x0_search(parent, cf, aux)
214 1.1 rjs struct device *parent;
215 1.1 rjs struct cfdata *cf;
216 1.1 rjs void *aux;
217 1.1 rjs {
218 1.1 rjs struct sa11x0_softc *sc = (struct sa11x0_softc *)parent;
219 1.1 rjs struct sa11x0_attach_args sa;
220 1.1 rjs
221 1.1 rjs sa.sa_sc = sc;
222 1.1 rjs sa.sa_iot = sc->sc_iot;
223 1.1 rjs sa.sa_addr = cf->cf_loc[SAIPCF_ADDR];
224 1.1 rjs sa.sa_size = cf->cf_loc[SAIPCF_SIZE];
225 1.1 rjs sa.sa_membase = cf->cf_loc[SAIPCF_MEMBASE];
226 1.1 rjs sa.sa_memsize = cf->cf_loc[SAIPCF_MEMSIZE];
227 1.1 rjs sa.sa_intr = cf->cf_loc[SAIPCF_INTR];
228 1.1 rjs sa.sa_gpio = cf->cf_loc[SAIPCF_GPIO];
229 1.1 rjs
230 1.1 rjs if ((*cf->cf_attach->ca_match)(parent, cf, &sa) > 0)
231 1.1 rjs config_attach(parent, cf, &sa, sa11x0_print);
232 1.1 rjs
233 1.1 rjs return 0;
234 1.1 rjs }
235