1 /*
2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/reboot.h>
22 #include <linux/string.h>
23
24 #include <asm/bootinfo.h>
25 #include <asm/cpu.h>
26 #include <asm/mipsregs.h>
27 #include <asm/io.h>
28 #include <asm/sibyte/sb1250.h>
29 #include <asm/sibyte/sb1250_regs.h>
30 #include <asm/sibyte/sb1250_scd.h>
31
32 unsigned int sb1_pass;
33 unsigned int soc_pass;
34 unsigned int soc_type;
35 EXPORT_SYMBOL(soc_type);
36 unsigned int periph_rev;
37 unsigned int zbbus_mhz;
38 EXPORT_SYMBOL(zbbus_mhz);
39
40 static char *soc_str;
41 static char *pass_str;
42 static unsigned int war_pass; /* XXXKW don't overload PASS defines? */
43
setup_bcm1250(void)44 static int __init setup_bcm1250(void)
45 {
46 int ret = 0;
47
48 switch (soc_pass) {
49 case K_SYS_REVISION_BCM1250_PASS1:
50 periph_rev = 1;
51 pass_str = "Pass 1";
52 break;
53 case K_SYS_REVISION_BCM1250_A10:
54 periph_rev = 2;
55 pass_str = "A8/A10";
56 /* XXXKW different war_pass? */
57 war_pass = K_SYS_REVISION_BCM1250_PASS2;
58 break;
59 case K_SYS_REVISION_BCM1250_PASS2_2:
60 periph_rev = 2;
61 pass_str = "B1";
62 break;
63 case K_SYS_REVISION_BCM1250_B2:
64 periph_rev = 2;
65 pass_str = "B2";
66 war_pass = K_SYS_REVISION_BCM1250_PASS2_2;
67 break;
68 case K_SYS_REVISION_BCM1250_PASS3:
69 periph_rev = 3;
70 pass_str = "C0";
71 break;
72 case K_SYS_REVISION_BCM1250_C1:
73 periph_rev = 3;
74 pass_str = "C1";
75 break;
76 default:
77 if (soc_pass < K_SYS_REVISION_BCM1250_PASS2_2) {
78 periph_rev = 2;
79 pass_str = "A0-A6";
80 war_pass = K_SYS_REVISION_BCM1250_PASS2;
81 } else {
82 printk("Unknown BCM1250 rev %x\n", soc_pass);
83 ret = 1;
84 }
85 break;
86 }
87
88 return ret;
89 }
90
sb1250_m3_workaround_needed(void)91 int sb1250_m3_workaround_needed(void)
92 {
93 switch (soc_type) {
94 case K_SYS_SOC_TYPE_BCM1250:
95 case K_SYS_SOC_TYPE_BCM1250_ALT:
96 case K_SYS_SOC_TYPE_BCM1250_ALT2:
97 case K_SYS_SOC_TYPE_BCM1125:
98 case K_SYS_SOC_TYPE_BCM1125H:
99 return soc_pass < K_SYS_REVISION_BCM1250_C0;
100
101 default:
102 return 0;
103 }
104 }
105
setup_bcm112x(void)106 static int __init setup_bcm112x(void)
107 {
108 int ret = 0;
109
110 switch (soc_pass) {
111 case 0:
112 /* Early build didn't have revid set */
113 periph_rev = 3;
114 pass_str = "A1";
115 war_pass = K_SYS_REVISION_BCM112x_A1;
116 break;
117 case K_SYS_REVISION_BCM112x_A1:
118 periph_rev = 3;
119 pass_str = "A1";
120 break;
121 case K_SYS_REVISION_BCM112x_A2:
122 periph_rev = 3;
123 pass_str = "A2";
124 break;
125 case K_SYS_REVISION_BCM112x_A3:
126 periph_rev = 3;
127 pass_str = "A3";
128 break;
129 case K_SYS_REVISION_BCM112x_A4:
130 periph_rev = 3;
131 pass_str = "A4";
132 break;
133 case K_SYS_REVISION_BCM112x_B0:
134 periph_rev = 3;
135 pass_str = "B0";
136 break;
137 default:
138 printk("Unknown %s rev %x\n", soc_str, soc_pass);
139 ret = 1;
140 }
141
142 return ret;
143 }
144
145 /* Setup code likely to be common to all SiByte platforms */
146
sys_rev_decode(void)147 static int __init sys_rev_decode(void)
148 {
149 int ret = 0;
150
151 war_pass = soc_pass;
152 switch (soc_type) {
153 case K_SYS_SOC_TYPE_BCM1250:
154 case K_SYS_SOC_TYPE_BCM1250_ALT:
155 case K_SYS_SOC_TYPE_BCM1250_ALT2:
156 soc_str = "BCM1250";
157 ret = setup_bcm1250();
158 break;
159 case K_SYS_SOC_TYPE_BCM1120:
160 soc_str = "BCM1120";
161 ret = setup_bcm112x();
162 break;
163 case K_SYS_SOC_TYPE_BCM1125:
164 soc_str = "BCM1125";
165 ret = setup_bcm112x();
166 break;
167 case K_SYS_SOC_TYPE_BCM1125H:
168 soc_str = "BCM1125H";
169 ret = setup_bcm112x();
170 break;
171 default:
172 printk("Unknown SOC type %x\n", soc_type);
173 ret = 1;
174 break;
175 }
176
177 return ret;
178 }
179
sb1250_setup(void)180 void __init sb1250_setup(void)
181 {
182 uint64_t sys_rev;
183 int plldiv;
184 int bad_config = 0;
185
186 sb1_pass = read_c0_prid() & PRID_REV_MASK;
187 sys_rev = __raw_readq(IOADDR(A_SCD_SYSTEM_REVISION));
188 soc_type = SYS_SOC_TYPE(sys_rev);
189 soc_pass = G_SYS_REVISION(sys_rev);
190
191 if (sys_rev_decode()) {
192 printk("Restart after failure to identify SiByte chip\n");
193 machine_restart(NULL);
194 }
195
196 plldiv = G_SYS_PLL_DIV(__raw_readq(IOADDR(A_SCD_SYSTEM_CFG)));
197 zbbus_mhz = ((plldiv >> 1) * 50) + ((plldiv & 1) * 25);
198
199 printk("Broadcom SiByte %s %s @ %d MHz (SB1 rev %d)\n",
200 soc_str, pass_str, zbbus_mhz * 2, sb1_pass);
201 printk("Board type: %s\n", get_system_type());
202
203 switch (war_pass) {
204 case K_SYS_REVISION_BCM1250_PASS1:
205 #ifndef CONFIG_SB1_PASS_1_WORKAROUNDS
206 printk("@@@@ This is a BCM1250 A0-A2 (Pass 1) board, "
207 "and the kernel doesn't have the proper "
208 "workarounds compiled in. @@@@\n");
209 bad_config = 1;
210 #endif
211 break;
212 case K_SYS_REVISION_BCM1250_PASS2:
213 /* Pass 2 - easiest as default for now - so many numbers */
214 #if !defined(CONFIG_SB1_PASS_2_WORKAROUNDS) || \
215 !defined(CONFIG_SB1_PASS_2_1_WORKAROUNDS)
216 printk("@@@@ This is a BCM1250 A3-A10 board, and the "
217 "kernel doesn't have the proper workarounds "
218 "compiled in. @@@@\n");
219 bad_config = 1;
220 #endif
221 #ifdef CONFIG_CPU_HAS_PREFETCH
222 printk("@@@@ Prefetches may be enabled in this kernel, "
223 "but are buggy on this board. @@@@\n");
224 bad_config = 1;
225 #endif
226 break;
227 case K_SYS_REVISION_BCM1250_PASS2_2:
228 #ifndef CONFIG_SB1_PASS_2_WORKAROUNDS
229 printk("@@@@ This is a BCM1250 B1/B2. board, and the "
230 "kernel doesn't have the proper workarounds "
231 "compiled in. @@@@\n");
232 bad_config = 1;
233 #endif
234 #if defined(CONFIG_SB1_PASS_2_1_WORKAROUNDS) || \
235 !defined(CONFIG_CPU_HAS_PREFETCH)
236 printk("@@@@ This is a BCM1250 B1/B2, but the kernel is "
237 "conservatively configured for an 'A' stepping. "
238 "@@@@\n");
239 #endif
240 break;
241 default:
242 break;
243 }
244 if (bad_config) {
245 printk("Invalid configuration for this chip.\n");
246 machine_restart(NULL);
247 }
248 }
249