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