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