opb.c revision 1.5 1 /* $NetBSD: opb.c,v 1.5 2002/08/13 06:15:15 simonb 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 "locators.h"
69
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/device.h>
73
74 #include <powerpc/spr.h>
75 #include <powerpc/ibm4xx/dev/opbvar.h>
76 #include <powerpc/ibm4xx/dev/plbvar.h>
77 #include <powerpc/ibm4xx/ibm405gp.h>
78
79 /*
80 * The devices on the On-chip Peripheral Bus to the 405GP cpu.
81 */
82 const struct opb_dev {
83 int pvr;
84 const char *name;
85 bus_addr_t addr;
86 int irq;
87 } opb_devs [] = {
88 { IBM405GP, "com", IBM405GP_UART0_BASE, 0 },
89 { IBM405GP, "com", IBM405GP_UART1_BASE, 1 },
90 { IBM405GP, "emac", IBM405GP_EMAC0_BASE, 9 }, /* XXX: really irq 9..15 */
91 { IBM405GP, "gpio", IBM405GP_GPIO0_BASE, -1 },
92 { IBM405GP, "iic", IBM405GP_IIC0_BASE, 2 },
93 { IBM405GP, "wdog", -1, -1 },
94 { 0, NULL }
95 };
96
97 static int opb_match(struct device *, struct cfdata *, void *);
98 static void opb_attach(struct device *, struct device *, void *);
99 static int opb_submatch(struct device *, struct cfdata *, void *);
100 static int opb_print(void *, const char *);
101
102 struct cfattach opb_ca = {
103 sizeof(struct device), opb_match, opb_attach
104 };
105
106
107 /*
108 * Probe for the opb; always succeeds.
109 */
110 static int
111 opb_match(struct device *parent, struct cfdata *cf, void *aux)
112 {
113 struct opb_attach_args *oaa = aux;
114
115 /* match only opb devices */
116 if (strcmp(oaa->opb_name, cf->cf_driver->cd_name) != 0)
117 return (0);
118
119 return (1);
120 }
121
122 static int
123 opb_submatch(struct device *parent, struct cfdata *cf, void *aux)
124 {
125 struct opb_attach_args *oaa = aux;
126
127 if (cf->cf_loc[OPBCF_ADDR] != OPBCF_ADDR_DEFAULT &&
128 cf->cf_loc[OPBCF_ADDR] != oaa->opb_addr)
129 return (0);
130
131 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
132 }
133
134 /*
135 * Attach the on-chip peripheral bus.
136 */
137 static void
138 opb_attach(struct device *parent, struct device *self, void *aux)
139 {
140 struct plb_attach_args *paa = aux;
141 struct opb_attach_args oaa;
142 int i, pvr;
143
144 printf("\n");
145 pvr = mfpvr() >> 16;
146
147 for (i = 0; opb_devs[i].name != NULL; i++) {
148 if (opb_devs[i].pvr != pvr)
149 continue;
150 oaa.opb_name = opb_devs[i].name;
151 oaa.opb_addr = opb_devs[i].addr;
152 oaa.opb_irq = opb_devs[i].irq;
153 oaa.opb_bt = paa->plb_bt;
154 oaa.opb_dmat = paa->plb_dmat;
155
156 (void) config_found_sm(self, &oaa, opb_print, opb_submatch);
157 }
158 }
159
160 static int
161 opb_print(void *aux, const char *pnp)
162 {
163 struct opb_attach_args *oaa = aux;
164
165 if (pnp)
166 printf("%s at %s", oaa->opb_name, pnp);
167
168 if (oaa->opb_addr != OPBCF_ADDR_DEFAULT)
169 printf(" addr 0x%08lx", oaa->opb_addr);
170 if (oaa->opb_irq != OPBCF_IRQ_DEFAULT)
171 printf(" irq %d", oaa->opb_irq);
172
173 return (UNCONF);
174 }
175