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