No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / omap / omap_tipb.c
bloba135007cdb0c8a4952191b287cba7247ac8dc946
1 /* $NetBSD: omap_tipb.c,v 1.3 2008/11/21 17:13:07 matt Exp $ */
3 /*
4 * Autoconfiguration support for the Texas Instruments OMAP TIPB.
5 * Based on arm/xscale/pxa2x0.c which in turn was derived from
6 * arm/sa11x0/sa11x0.c. The code to do the early attach was initially derived
7 * from arch/sparc/dev/obio.c.
9 * Copyright (c) 2002, 2005 Genetec Corporation. All rights reserved.
10 * Written by Hiroyuki Bessho for Genetec Corporation.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed for the NetBSD Project by
23 * Genetec Corporation.
24 * 4. The name of Genetec Corporation may not be used to endorse or
25 * promote products derived from this software without specific prior
26 * written permission.
28 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 * Copyright (c) 1997, 1998, 2001, The NetBSD Foundation, Inc.
41 * All rights reserved.
43 * This code is derived from software contributed to The NetBSD Foundation
44 * by IWAMOTO Toshihiro, Ichiro FUKUHARA and Paul Kranenburg.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
55 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
56 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
59 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 * POSSIBILITY OF SUCH DAMAGE.
67 * Copyright (c) 1999
68 * Shin Takemura and PocketBSD Project. All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
72 * are met:
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 * must display the following acknowledgement:
80 * This product includes software developed by the PocketBSD project
81 * and its contributors.
82 * 4. Neither the name of the project nor the names of its contributors
83 * may be used to endorse or promote products derived from this software
84 * without specific prior written permission.
86 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
87 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
92 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 * SUCH DAMAGE.
99 #include <sys/cdefs.h>
100 __KERNEL_RCSID(0, "$NetBSD: omap_tipb.c,v 1.3 2008/11/21 17:13:07 matt Exp $");
102 #include "locators.h"
104 #include <sys/param.h>
105 #include <sys/systm.h>
106 #include <sys/device.h>
107 #include <sys/kernel.h>
108 #include <sys/reboot.h>
110 #include <machine/cpu.h>
111 #include <machine/bus.h>
113 #include <arm/cpufunc.h>
114 #include <arm/mainbus/mainbus.h>
115 #include <arm/omap/omap_reg.h>
116 #include <arm/omap/omap_tipb.h>
118 struct tipb_softc {
119 device_t sc_dev;
120 bus_dma_tag_t sc_dmac;
123 /* prototypes */
124 static int tipb_match(device_t, cfdata_t, void *);
125 static void tipb_attach(device_t, device_t, void *);
126 static int tipb_search(device_t, cfdata_t, const int *, void *);
127 static int tipb_print(void *, const char *);
129 /* attach structures */
130 CFATTACH_DECL_NEW(tipb, sizeof(struct tipb_softc),
131 tipb_match, tipb_attach, NULL, NULL);
133 static int tipb_attached;
136 * There are some devices that need to be set up before all the others. The
137 * earlies array contains their names. tipb_attach() and tipb_search() work
138 * together to attach these devices in the order they appear in this array
139 * before any other TIPB devices are attached.
141 static const char * const earlies[] = {
142 OMAP_INTC_DEVICE,
143 "omapmputmr",
144 NULL
147 static int
148 tipb_match(device_t parent, cfdata_t match, void *aux)
150 if (tipb_attached)
151 return 0;
152 return 1;
155 static void
156 tipb_attach(device_t parent, device_t self, void *aux)
158 struct tipb_softc *sc = device_private(self);
160 tipb_attached = 1;
162 #if NOMAPDMAC > 0
163 #error DMA not implemented
164 sc->sc_dmac = &omap_bus_dma_tag;
165 #else
166 sc->sc_dmac = NULL;
167 #endif
169 aprint_normal(": Texas Instruments Peripheral Bus\n");
170 aprint_naive("\n");
173 * There are some devices that need to be set up before all the
174 * others. The earlies array contains their names. Find them and
175 * attach them in the order they appear in the array.
177 const char *const *earlyp;
178 for (earlyp = earlies; *earlyp != NULL; earlyp++)
180 * The bus search function is passed an aux argument that
181 * "describes the device that has been found". The type of it
182 * is void *. However, I want to pass a constant string, so
183 * use __UNCONST to convince the compiler that this is ok.
185 config_search_ia(tipb_search, self, "tipb",
186 __UNCONST(*earlyp));
189 * Attach all other devices
191 config_search_ia(tipb_search, self, "tipb", NULL);
194 static int
195 tipb_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
197 struct tipb_softc *sc = device_private(parent);
198 struct tipb_attach_args aa;
199 const char *const name = (const char *const)aux;
201 /* Check whether we're looking for a specifically named device */
202 if (name != NULL && strcmp(name, cf->cf_name) != 0)
203 return (0);
205 switch (cf->cf_loc[TIPBCF_MULT]) {
206 case 1:
207 aa.tipb_iot = &omap_bs_tag;
208 break;
209 case 2:
210 aa.tipb_iot = &omap_a2x_bs_tag;
211 break;
212 case 4:
213 aa.tipb_iot = &omap_a4x_bs_tag;
214 break;
215 default:
216 panic("Unsupported TIPB multiplier.");
217 break;
219 aa.tipb_dmac = sc->sc_dmac;
220 aa.tipb_addr = cf->cf_loc[TIPBCF_ADDR];
221 aa.tipb_size = cf->cf_loc[TIPBCF_SIZE];
222 aa.tipb_intr = cf->cf_loc[TIPBCF_INTR];
223 aa.tipb_mult = cf->cf_loc[TIPBCF_MULT];
225 if (config_match(parent, cf, &aa))
226 config_attach(parent, cf, &aa, tipb_print);
228 return 0;
231 static int
232 tipb_print(void *aux, const char *name)
234 struct tipb_attach_args *sa = (struct tipb_attach_args*)aux;
236 if (sa->tipb_addr != TIPBCF_ADDR_DEFAULT) {
237 aprint_normal(" addr 0x%08lx", sa->tipb_addr);
238 if (sa->tipb_size > TIPBCF_SIZE_DEFAULT)
239 aprint_normal("-0x%08lx", sa->tipb_addr + sa->tipb_size-1);
241 if (sa->tipb_intr != TIPBCF_INTR_DEFAULT)
242 aprint_normal(" intr %d", sa->tipb_intr);
244 return (UNCONF);