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