mainbus.c revision 1.1.20.2 1 1.1.20.2 yamt /* $NetBSD: mainbus.c,v 1.1.20.2 2007/09/03 14:24:11 yamt Exp $ */
2 1.1.20.2 yamt
3 1.1.20.2 yamt /*-
4 1.1.20.2 yamt * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
5 1.1.20.2 yamt * All rights reserved.
6 1.1.20.2 yamt *
7 1.1.20.2 yamt * Redistribution and use in source and binary forms, with or
8 1.1.20.2 yamt * without modification, are permitted provided that the following
9 1.1.20.2 yamt * conditions are met:
10 1.1.20.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.1.20.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.1.20.2 yamt * 2. Redistributions in binary form must reproduce the above
13 1.1.20.2 yamt * copyright notice, this list of conditions and the following
14 1.1.20.2 yamt * disclaimer in the documentation and/or other materials provided
15 1.1.20.2 yamt * with the distribution.
16 1.1.20.2 yamt * 3. The names of the authors may not be used to endorse or promote
17 1.1.20.2 yamt * products derived from this software without specific prior
18 1.1.20.2 yamt * written permission.
19 1.1.20.2 yamt *
20 1.1.20.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
21 1.1.20.2 yamt * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 1.1.20.2 yamt * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.1.20.2 yamt * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
24 1.1.20.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25 1.1.20.2 yamt * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.1.20.2 yamt * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 1.1.20.2 yamt * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1.20.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29 1.1.20.2 yamt * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 1.1.20.2 yamt * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 1.1.20.2 yamt * OF SUCH DAMAGE.
32 1.1.20.2 yamt */
33 1.1.20.2 yamt /*
34 1.1.20.2 yamt * Copyright 2002 Wasabi Systems, Inc.
35 1.1.20.2 yamt * All rights reserved.
36 1.1.20.2 yamt *
37 1.1.20.2 yamt * Written by Simon Burge for Wasabi Systems, Inc.
38 1.1.20.2 yamt *
39 1.1.20.2 yamt * Redistribution and use in source and binary forms, with or without
40 1.1.20.2 yamt * modification, are permitted provided that the following conditions
41 1.1.20.2 yamt * are met:
42 1.1.20.2 yamt * 1. Redistributions of source code must retain the above copyright
43 1.1.20.2 yamt * notice, this list of conditions and the following disclaimer.
44 1.1.20.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
45 1.1.20.2 yamt * notice, this list of conditions and the following disclaimer in the
46 1.1.20.2 yamt * documentation and/or other materials provided with the distribution.
47 1.1.20.2 yamt * 3. All advertising materials mentioning features or use of this software
48 1.1.20.2 yamt * must display the following acknowledgement:
49 1.1.20.2 yamt * This product includes software developed for the NetBSD Project by
50 1.1.20.2 yamt * Wasabi Systems, Inc.
51 1.1.20.2 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
52 1.1.20.2 yamt * or promote products derived from this software without specific prior
53 1.1.20.2 yamt * written permission.
54 1.1.20.2 yamt *
55 1.1.20.2 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
56 1.1.20.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 1.1.20.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 1.1.20.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
59 1.1.20.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 1.1.20.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 1.1.20.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 1.1.20.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 1.1.20.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 1.1.20.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 1.1.20.2 yamt * POSSIBILITY OF SUCH DAMAGE.
66 1.1.20.2 yamt */
67 1.1.20.2 yamt
68 1.1.20.2 yamt #include <sys/cdefs.h>
69 1.1.20.2 yamt __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1.20.2 2007/09/03 14:24:11 yamt Exp $");
70 1.1.20.2 yamt
71 1.1.20.2 yamt #include <sys/param.h>
72 1.1.20.2 yamt #include <sys/systm.h>
73 1.1.20.2 yamt #include <sys/device.h>
74 1.1.20.2 yamt
75 1.1.20.2 yamt #include <machine/bus.h>
76 1.1.20.2 yamt
77 1.1.20.2 yamt #include <mips/cache.h>
78 1.1.20.2 yamt #include <mips/cpuregs.h>
79 1.1.20.2 yamt
80 1.1.20.2 yamt #include <mips/adm5120/include/adm5120reg.h>
81 1.1.20.2 yamt #include <mips/adm5120/include/adm5120var.h>
82 1.1.20.2 yamt #include <mips/adm5120/include/adm5120_mainbusvar.h>
83 1.1.20.2 yamt
84 1.1.20.2 yamt #include "locators.h"
85 1.1.20.2 yamt
86 1.1.20.2 yamt static int mainbus_match(struct device *, struct cfdata *, void *);
87 1.1.20.2 yamt static void mainbus_attach(struct device *, struct device *, void *);
88 1.1.20.2 yamt static int mainbus_print(void *, const char *);
89 1.1.20.2 yamt
90 1.1.20.2 yamt CFATTACH_DECL(mainbus, sizeof(struct mainbus_softc),
91 1.1.20.2 yamt mainbus_match, mainbus_attach, NULL, NULL);
92 1.1.20.2 yamt
93 1.1.20.2 yamt /* There can be only one. */
94 1.1.20.2 yamt int mainbus_found;
95 1.1.20.2 yamt
96 1.1.20.2 yamt struct mainbusdev {
97 1.1.20.2 yamt const char *md_name;
98 1.1.20.2 yamt };
99 1.1.20.2 yamt
100 1.1.20.2 yamt struct mainbusdev mainbusdevs[] = {
101 1.1.20.2 yamt {"cpu" },
102 1.1.20.2 yamt {"obio" },
103 1.1.20.2 yamt {"extio" },
104 1.1.20.2 yamt {"admpci" },
105 1.1.20.2 yamt {NULL }
106 1.1.20.2 yamt };
107 1.1.20.2 yamt
108 1.1.20.2 yamt static void
109 1.1.20.2 yamt mainbus_gpio_attach(struct mainbus_softc *sc)
110 1.1.20.2 yamt {
111 1.1.20.2 yamt if (bus_space_map(sc->sc_obiot, ADM5120_BASE_SWITCH, 512, 0,
112 1.1.20.2 yamt &sc->sc_gpioh) != 0){
113 1.1.20.2 yamt printf("%s: unable to map switch\n", device_xname(&sc->sc_dev));
114 1.1.20.2 yamt return;
115 1.1.20.2 yamt }
116 1.1.20.2 yamt #if 0
117 1.1.20.2 yamt printf("%s: memcont 0x%08" PRIx32 "\n", device_xname(&sc->sc_dev),
118 1.1.20.2 yamt bus_space_read_4(sc->sc_obiot, sc->sc_gpioh, 0x1c));
119 1.1.20.2 yamt #endif
120 1.1.20.2 yamt sc->sc_gpio = admgpio_attach(sc);
121 1.1.20.2 yamt }
122 1.1.20.2 yamt
123 1.1.20.2 yamt
124 1.1.20.2 yamt static int
125 1.1.20.2 yamt mainbus_match(struct device *parent, struct cfdata *match, void *aux)
126 1.1.20.2 yamt {
127 1.1.20.2 yamt return !mainbus_found;
128 1.1.20.2 yamt }
129 1.1.20.2 yamt
130 1.1.20.2 yamt static void
131 1.1.20.2 yamt mainbus_attach(struct device *parent, struct device *self, void *aux)
132 1.1.20.2 yamt {
133 1.1.20.2 yamt struct mainbus_softc *sc = (struct mainbus_softc *)self;
134 1.1.20.2 yamt struct mainbus_attach_args ma;
135 1.1.20.2 yamt struct mainbusdev *md;
136 1.1.20.2 yamt struct adm5120_config *admc = &adm5120_configuration;
137 1.1.20.2 yamt
138 1.1.20.2 yamt mainbus_found = 1;
139 1.1.20.2 yamt printf("\n");
140 1.1.20.2 yamt
141 1.1.20.2 yamt sc->sc_obiot = &admc->obio_space;
142 1.1.20.2 yamt
143 1.1.20.2 yamt mainbus_gpio_attach(sc);
144 1.1.20.2 yamt
145 1.1.20.2 yamt ma.ma_dmat = &admc->obio_dmat;
146 1.1.20.2 yamt ma.ma_obiot = sc->sc_obiot;
147 1.1.20.2 yamt ma.ma_gpioh = sc->sc_gpioh;
148 1.1.20.2 yamt ma.ma_gpio = sc->sc_gpio;
149 1.1.20.2 yamt ma.ma_gpio_offset = -1;
150 1.1.20.2 yamt ma.ma_gpio_mask = 0x0;
151 1.1.20.2 yamt
152 1.1.20.2 yamt for (md = mainbusdevs; md->md_name != NULL; md++) {
153 1.1.20.2 yamt ma.ma_name = md->md_name;
154 1.1.20.2 yamt config_found_ia(self, "mainbus", &ma, mainbus_print);
155 1.1.20.2 yamt }
156 1.1.20.2 yamt }
157 1.1.20.2 yamt
158 1.1.20.2 yamt static int
159 1.1.20.2 yamt mainbus_print(void *aux, const char *pnp)
160 1.1.20.2 yamt {
161 1.1.20.2 yamt struct mainbus_attach_args *ma = aux;
162 1.1.20.2 yamt
163 1.1.20.2 yamt if (pnp != NULL)
164 1.1.20.2 yamt aprint_normal("%s at %s", ma->ma_name, pnp);
165 1.1.20.2 yamt
166 1.1.20.2 yamt return UNCONF;
167 1.1.20.2 yamt }
168