sbobio.c revision 1.13.10.1 1 /* $NetBSD: sbobio.c,v 1.13.10.1 2005/11/21 20:25:02 tron Exp $ */
2
3 /*
4 * Copyright 2000, 2001
5 * Broadcom Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions. Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce and
14 * retain this copyright notice and list of conditions as they appear in
15 * the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Broadcom Corporation. The "Broadcom Corporation" name may not be
19 * used to endorse or promote products derived from this software
20 * without the prior written permission of Broadcom Corporation.
21 *
22 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
25 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
26 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
27 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: sbobio.c,v 1.13.10.1 2005/11/21 20:25:02 tron Exp $");
37
38 #include <sys/param.h>
39 #include <sys/device.h>
40 #include <sys/systm.h>
41
42 #include <machine/locore.h>
43 #include <mips/sibyte/include/sb1250_regs.h>
44 #include <mips/sibyte/include/sb1250_scd.h>
45 #include <mips/sibyte/include/zbbusvar.h>
46 #include <mips/sibyte/dev/sbobiovar.h>
47
48 #include "locators.h"
49
50 static int sbobio_match(struct device *, struct cfdata *, void *);
51 static void sbobio_attach(struct device *, struct device *, void *);
52
53 CFATTACH_DECL(sbobio, sizeof(struct device),
54 sbobio_match, sbobio_attach, NULL, NULL);
55
56 static int sbobio_print(void *, const char *);
57 static int sbobio_submatch(struct device *, struct cfdata *,
58 const locdesc_t *, void *);
59 static const char *sbobio_device_type_name(enum sbobio_device_type type);
60
61 static const struct sbobio_attach_locs sb1250_rev1_sbobio_devs[] = {
62 { 0x0000, {6,-1}, SBOBIO_DEVTYPE_SMBUS },
63 { 0x0008, {7,-1}, SBOBIO_DEVTYPE_SMBUS },
64 { 0x0100, {8,9}, SBOBIO_DEVTYPE_DUART },
65 { 0x0400, {10,-1}, SBOBIO_DEVTYPE_SYNCSERIAL },
66 { 0x0800, {11,-1}, SBOBIO_DEVTYPE_SYNCSERIAL },
67 #if 0
68 { 0x1000, {-1,-1}, SBOBIO_DEVTYPE_GBUS, }, /* XXXCGD ??? */
69 #endif
70 { 0x4000, {19,-1}, SBOBIO_DEVTYPE_MAC, },
71 { 0x5000, {20,-1}, SBOBIO_DEVTYPE_MAC, },
72 { 0x6000, {21,-1}, SBOBIO_DEVTYPE_MAC, },
73 };
74 static const int sb1250_rev1_sbobio_dev_count =
75 sizeof sb1250_rev1_sbobio_devs / sizeof sb1250_rev1_sbobio_devs[0];
76
77 static const struct sbobio_attach_locs sb1250_sbobio_devs[] = {
78 { 0x0000, {6,-1}, SBOBIO_DEVTYPE_SMBUS },
79 { 0x0008, {7,-1}, SBOBIO_DEVTYPE_SMBUS },
80 { 0x0100, {8,9}, SBOBIO_DEVTYPE_DUART },
81 { 0x0400, {10,-1}, SBOBIO_DEVTYPE_SYNCSERIAL },
82 { 0x0800, {11,-1}, SBOBIO_DEVTYPE_SYNCSERIAL },
83 #if 0
84 { 0x1000, {-1,-1}, SBOBIO_DEVTYPE_GBUS, }, /* XXXCGD ??? */
85 #endif
86 { 0x4000, {19,61}, SBOBIO_DEVTYPE_MAC, },
87 { 0x5000, {20,62}, SBOBIO_DEVTYPE_MAC, },
88 { 0x6000, {21,63}, SBOBIO_DEVTYPE_MAC, },
89 };
90 static const int sb1250_sbobio_dev_count =
91 sizeof sb1250_sbobio_devs / sizeof sb1250_sbobio_devs[0];
92
93 static const struct sbobio_attach_locs sb112x_sbobio_devs[] = {
94 { 0x0000, {6,-1}, SBOBIO_DEVTYPE_SMBUS },
95 { 0x0008, {7,-1}, SBOBIO_DEVTYPE_SMBUS },
96 { 0x0100, {8,9}, SBOBIO_DEVTYPE_DUART },
97 { 0x0400, {10,-1}, SBOBIO_DEVTYPE_SYNCSERIAL },
98 { 0x0800, {11,-1}, SBOBIO_DEVTYPE_SYNCSERIAL },
99 #if 0
100 { 0x1000, {-1,-1}, SBOBIO_DEVTYPE_GBUS, }, /* XXXCGD ??? */
101 #endif
102 { 0x4000, {19,61}, SBOBIO_DEVTYPE_MAC, },
103 { 0x5000, {20,62}, SBOBIO_DEVTYPE_MAC, },
104 };
105 static const int sb112x_sbobio_dev_count =
106 sizeof sb112x_sbobio_devs / sizeof sb112x_sbobio_devs[0];
107
108 static int
109 sbobio_match(struct device *parent, struct cfdata *match, void *aux)
110 {
111 struct zbbus_attach_args *zap = aux;
112 uint64_t sysrev;
113
114 if (zap->za_locs.za_type != ZBBUS_ENTTYPE_OBIO)
115 return (0);
116
117 sysrev = mips3_ld((u_int64_t *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_REVISION));
118 switch (SYS_SOC_TYPE(sysrev)) {
119 case K_SYS_SOC_TYPE_BCM1120:
120 case K_SYS_SOC_TYPE_BCM1125:
121 case K_SYS_SOC_TYPE_BCM1125H:
122 case K_SYS_SOC_TYPE_BCM1250:
123 break;
124
125 default:
126 return (0);
127 }
128
129 return (1);
130 }
131
132 static void
133 sbobio_attach(struct device *parent, struct device *self, void *aux)
134 {
135 struct sbobio_attach_args sa;
136 const char *dscr;
137 const struct sbobio_attach_locs *devs;
138 uint64_t sysrev;
139 int i, devcount;
140 int help[4];
141 locdesc_t *ldesc = (void *)help; /* XXX */
142
143 sysrev = mips3_ld((u_int64_t *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_REVISION));
144 switch (SYS_SOC_TYPE(sysrev)) {
145 case K_SYS_SOC_TYPE_BCM1120:
146 case K_SYS_SOC_TYPE_BCM1125:
147 case K_SYS_SOC_TYPE_BCM1125H:
148 dscr = "BCM112x";
149 devs = sb112x_sbobio_devs;
150 devcount = sb112x_sbobio_dev_count;
151 break;
152
153 case K_SYS_SOC_TYPE_BCM1250:
154 if (G_SYS_REVISION(sysrev) >= K_SYS_REVISION_BCM1250_PASS2) {
155 dscr = "BCM1250 (rev2 and later)";
156 devs = sb1250_sbobio_devs;
157 devcount = sb1250_sbobio_dev_count;
158 } else {
159 dscr = "BCM1250 rev1";
160 devs = sb1250_rev1_sbobio_devs;
161 devcount = sb1250_rev1_sbobio_dev_count;
162 }
163 break;
164 default:
165 panic("un-matched in sbobio_attach");
166 break;
167 }
168
169 printf(": %s peripherals\n", dscr);
170
171 for (i = 0; i < devcount; i++) {
172 memset(&sa, 0, sizeof sa);
173 sa.sa_base = A_PHYS_IO_SYSTEM;
174 sa.sa_locs = devs[i];
175
176 ldesc->len = 3;
177 ldesc->locs[SBOBIOCF_OFFSET] = devs[i].sa_offset;
178 ldesc->locs[SBOBIOCF_INTR + 0] = devs[i].sa_intr[0];
179 ldesc->locs[SBOBIOCF_INTR + 1] = devs[i].sa_intr[1];
180
181 config_found_sm_loc(self, "sbobio", ldesc, &sa,
182 sbobio_print, sbobio_submatch);
183 }
184 return;
185 }
186
187 int
188 sbobio_print(void *aux, const char *pnp)
189 {
190 struct sbobio_attach_args *sap = aux;
191 int i;
192
193 if (pnp)
194 aprint_normal("%s at %s",
195 sbobio_device_type_name(sap->sa_locs.sa_type), pnp);
196 aprint_normal(" offset 0x%lx", (long)sap->sa_locs.sa_offset);
197 for (i = 0; i < 2; i++) {
198 if (sap->sa_locs.sa_intr[i] != SBOBIOCF_INTR_DEFAULT)
199 aprint_normal("%s%ld", i == 0 ? " intr " : ",",
200 (long)sap->sa_locs.sa_intr[i]);
201 }
202 return (UNCONF);
203 }
204
205 static int
206 sbobio_submatch(struct device *parent, struct cfdata *cf,
207 const locdesc_t *ldesc, void *aux)
208 {
209 int i;
210
211 if (cf->cf_loc[SBOBIOCF_OFFSET] != SBOBIOCF_OFFSET_DEFAULT &&
212 cf->cf_loc[SBOBIOCF_OFFSET] != ldesc->locs[SBOBIOCF_OFFSET])
213 return (0);
214
215 for (i = 0; i < 2; i++) {
216 if (cf->cf_loc[SBOBIOCF_INTR + i] != SBOBIOCF_INTR_DEFAULT &&
217 cf->cf_loc[SBOBIOCF_INTR + i]
218 != ldesc->locs[SBOBIOCF_INTR + i])
219 return (0);
220 }
221
222 return (config_match(parent, cf, aux));
223 }
224
225 static const char *
226 sbobio_device_type_name(enum sbobio_device_type type)
227 {
228
229 switch (type) {
230 case SBOBIO_DEVTYPE_SMBUS:
231 return ("sbsmbus");
232 case SBOBIO_DEVTYPE_DUART:
233 return ("sbscn");
234 case SBOBIO_DEVTYPE_SYNCSERIAL:
235 return ("sbsync");
236 case SBOBIO_DEVTYPE_GBUS:
237 return ("sbgbus");
238 case SBOBIO_DEVTYPE_MAC:
239 return ("sbmac");
240 }
241 panic("sbobio_device_type_name");
242 return ("panic");
243 }
244