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