opb.c revision 1.23.92.1 1 /* $NetBSD: opb.c,v 1.23.92.1 2011/01/07 02:12:18 matt Exp $ */
2
3 /*
4 * Copyright 2001,2002 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
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 for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * 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 WASABI SYSTEMS, INC
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 /*
39 * Copyright (c) 1996 Christopher G. Demetriou. 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 Christopher G. Demetriou
52 * for the NetBSD Project.
53 * 4. The name of the author may not be used to endorse or promote products
54 * derived from this software without specific prior written permission
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: opb.c,v 1.23.92.1 2011/01/07 02:12:18 matt Exp $");
70
71 #include "locators.h"
72
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/device.h>
76 #include <sys/extent.h>
77
78 #include <powerpc/spr.h>
79 #include <powerpc/ibm4xx/spr.h>
80 #include <powerpc/ibm4xx/dev/opbvar.h>
81 #include <powerpc/ibm4xx/dev/plbvar.h>
82 #include <powerpc/ibm4xx/ibm405gp.h>
83
84 /*
85 * The devices on the On-chip Peripheral Bus to the 405GP CPU.
86 */
87 const struct opb_dev {
88 int pvr;
89 const char *name;
90 bus_addr_t addr;
91 int instance;
92 int irq;
93 } opb_devs [] = {
94 /* IBM405GP */
95 { IBM405GP, "com", IBM405GP_UART0_BASE, 0, 0 },
96 { IBM405GP, "com", IBM405GP_UART1_BASE, 1, 1 },
97 { IBM405GP, "emac", IBM405GP_EMAC0_BASE, 0, 9 }, /* XXX: really irq 9..15 */
98 { IBM405GP, "opbgpio", IBM405GP_GPIO0_BASE, 0, -1 },
99 { IBM405GP, "gpiic",IBM405GP_IIC0_BASE, 0, 2 },
100 { IBM405GP, "wdog", -1, 0, -1 },
101
102 /* IBM405GPR */
103 { IBM405GPR, "com", IBM405GP_UART0_BASE, 0, 0 },
104 { IBM405GPR, "com", IBM405GP_UART1_BASE, 1, 1 },
105 { IBM405GPR, "emac", IBM405GP_EMAC0_BASE, 0, 9 }, /* XXX: really irq 9..15 */
106 { IBM405GPR, "opbgpio", IBM405GP_GPIO0_BASE, 0, -1 },
107 { IBM405GPR, "gpiic",IBM405GP_IIC0_BASE, 0, 2 },
108 { IBM405GPR, "wdog", -1, 0, -1 },
109 { 0, NULL }
110 };
111
112 const struct opb_limit {
113 int pvr;
114 bus_addr_t base;
115 bus_addr_t limit;
116 } opb_limits[] = {
117 { IBM405GP, IBM405GP_UART0_BASE, IBM405GP_UART0_BASE + 0xfff },
118 { IBM405GPR, IBM405GP_UART0_BASE, IBM405GP_UART0_BASE + 0xfff },
119 { 0, 0, 0 }
120 };
121
122 static int opb_match(struct device *, struct cfdata *, void *);
123 static void opb_attach(struct device *, struct device *, void *);
124 static int opb_submatch(struct device *, struct cfdata *,
125 const int *, void *);
126 static int opb_print(void *, const char *);
127
128 CFATTACH_DECL(opb, sizeof(struct device),
129 opb_match, opb_attach, NULL, NULL);
130
131 static struct powerpc_bus_space opb_tag = {
132 _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE,
133 0x0, IBM405GP_UART0_BASE, 0x1000
134 };
135 static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
136 __attribute__((aligned(8)));
137 static int opb_tag_init_done;
138
139 /*
140 * Probe for the opb; always succeeds.
141 */
142 static int
143 opb_match(struct device *parent, struct cfdata *cf, void *aux)
144 {
145 struct opb_attach_args *oaa = aux;
146
147 /* match only opb devices */
148 if (strcmp(oaa->opb_name, cf->cf_name) != 0)
149 return (0);
150
151 return (1);
152 }
153
154 static int
155 opb_submatch(struct device *parent, struct cfdata *cf,
156 const int *ldesc, void *aux)
157 {
158 struct opb_attach_args *oaa = aux;
159
160 if (cf->cf_loc[OPBCF_ADDR] != OPBCF_ADDR_DEFAULT &&
161 cf->cf_loc[OPBCF_ADDR] != oaa->opb_addr)
162 return (0);
163
164 return (config_match(parent, cf, aux));
165 }
166
167 /*
168 * Attach the on-chip peripheral bus.
169 */
170 static void
171 opb_attach(struct device *parent, struct device *self, void *aux)
172 {
173 struct plb_attach_args *paa = aux;
174 struct opb_attach_args oaa;
175 bus_space_tag_t tag;
176 int i, pvr;
177
178 printf("\n");
179 pvr = mfpvr() >> 16;
180
181 tag = opb_get_bus_space_tag();
182
183 for (i = 0; opb_devs[i].name != NULL; i++) {
184 if (opb_devs[i].pvr != pvr)
185 continue;
186 oaa.opb_name = opb_devs[i].name;
187 oaa.opb_addr = opb_devs[i].addr;
188 oaa.opb_instance = opb_devs[i].instance;
189 oaa.opb_irq = opb_devs[i].irq;
190 oaa.opb_bt = tag;
191 oaa.opb_dmat = paa->plb_dmat;
192
193 (void) config_found_sm_loc(self, "opb", NULL, &oaa, opb_print,
194 opb_submatch);
195 }
196 }
197
198 static int
199 opb_print(void *aux, const char *pnp)
200 {
201 struct opb_attach_args *oaa = aux;
202
203 if (pnp)
204 aprint_normal("%s at %s", oaa->opb_name, pnp);
205
206 if (oaa->opb_addr != OPBCF_ADDR_DEFAULT)
207 aprint_normal(" addr 0x%08lx", oaa->opb_addr);
208 if (oaa->opb_irq != OPBCF_IRQ_DEFAULT)
209 aprint_normal(" irq %d", oaa->opb_irq);
210
211 return (UNCONF);
212 }
213
214 bus_space_tag_t
215 opb_get_bus_space_tag(void)
216 {
217 int i, pvr;
218
219 if (!opb_tag_init_done) {
220 pvr = mfpvr() >> 16;
221
222 for (i = 0; opb_limits[i].pvr && opb_limits[i].pvr != pvr; i++)
223 ;
224 if (opb_limits[i].pvr == 0)
225 panic("opb_get_bus_space_tag: no limits for this CPU!");
226
227 opb_tag.pbs_base = opb_limits[i].base;
228 opb_tag.pbs_limit = opb_limits[i].limit;
229
230 if (bus_space_init(&opb_tag, "opbtag",
231 ex_storage, sizeof(ex_storage)))
232 panic("opb_attach: Failed to initialise opb_tag");
233 opb_tag_init_done = 1;
234 }
235
236 return (&opb_tag);
237 }
238