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