blob: 684f6a586374c21db441849451193adbc7aea833 [file] [log] [blame]
Stefan Roese4745aca2007-02-20 10:57:08 +01001/*
2 * (C) Copyright 2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25#include <common.h>
26#include <command.h>
27#include <i2c.h>
28#include <asm/byteorder.h>
29
30static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
31{
32 uchar chip;
33 ulong data;
34 int nbytes;
35 extern char console_buffer[];
36
37 char sysClock[4];
38 char cpuClock[4];
39 char plbClock[4];
40 char pcixClock[4];
41
42 if (argc < 3) {
43 printf ("Usage:\n%s\n", cmdtp->usage);
44 return 1;
45 }
46
47 if (strcmp(argv[2], "prom0") == 0)
48 chip = IIC0_BOOTPROM_ADDR;
49 else
50 chip = IIC0_ALT_BOOTPROM_ADDR;
51
52 do {
53 printf("enter sys clock frequency 33 or 66 Mhz or quit to abort\n");
54 nbytes = readline (" ? ");
55
56 if (strcmp(console_buffer, "quit") == 0)
57 return 0;
58
59 if ((strcmp(console_buffer, "33") != 0) &
60 (strcmp(console_buffer, "66") != 0))
61 nbytes=0;
62
63 strcpy(sysClock, console_buffer);
64
65 } while (nbytes == 0);
66
67 do {
68 if (strcmp(sysClock, "66") == 0) {
69 printf("enter cpu clock frequency 400, 533 Mhz or quit to abort\n");
70 } else {
71#ifdef CONFIG_STRESS
72 printf("enter cpu clock frequency 400, 500, 533, 667 Mhz or quit to abort\n");
73#else
74 printf("enter cpu clock frequency 400, 500, 533 Mhz or quit to abort\n");
75#endif
76 }
77 nbytes = readline (" ? ");
78
79 if (strcmp(console_buffer, "quit") == 0)
80 return 0;
81
82 if (strcmp(sysClock, "66") == 0) {
83 if ((strcmp(console_buffer, "400") != 0) &
84 (strcmp(console_buffer, "533") != 0)
85#ifdef CONFIG_STRESS
86 & (strcmp(console_buffer, "667") != 0)
87#endif
88 ) {
89 nbytes = 0;
90 }
91 } else {
92 if ((strcmp(console_buffer, "400") != 0) &
93 (strcmp(console_buffer, "500") != 0) &
94 (strcmp(console_buffer, "533") != 0)
95#ifdef CONFIG_STRESS
96 & (strcmp(console_buffer, "667") != 0)
97#endif
98 ) {
99 nbytes = 0;
100 }
101 }
102
103 strcpy(cpuClock, console_buffer);
104
105 } while (nbytes == 0);
106
107 if (strcmp(cpuClock, "500") == 0)
108 strcpy(plbClock, "166");
109 else if (strcmp(cpuClock, "533") == 0)
110 strcpy(plbClock, "133");
111 else {
112 do {
113 if (strcmp(cpuClock, "400") == 0)
114 printf("enter plb clock frequency 100, 133 Mhz or quit to abort\n");
115
116#ifdef CONFIG_STRESS
117 if (strcmp(cpuClock, "667") == 0)
118 printf("enter plb clock frequency 133, 166 Mhz or quit to abort\n");
119
120#endif
121 nbytes = readline (" ? ");
122
123 if (strcmp(console_buffer, "quit") == 0)
124 return 0;
125
126 if (strcmp(cpuClock, "400") == 0) {
127 if ((strcmp(console_buffer, "100") != 0) &
128 (strcmp(console_buffer, "133") != 0))
129 nbytes = 0;
130 }
131#ifdef CONFIG_STRESS
132 if (strcmp(cpuClock, "667") == 0) {
133 if ((strcmp(console_buffer, "133") != 0) &
134 (strcmp(console_buffer, "166") != 0))
135 nbytes = 0;
136 }
137#endif
138 strcpy(plbClock, console_buffer);
139
140 } while (nbytes == 0);
141 }
142
143 do {
144 printf("enter Pci-X clock frequency 33, 66, 100 or 133 Mhz or quit to abort\n");
145 nbytes = readline (" ? ");
146
147 if (strcmp(console_buffer, "quit") == 0)
148 return 0;
149
150 if ((strcmp(console_buffer, "33") != 0) &
151 (strcmp(console_buffer, "66") != 0) &
152 (strcmp(console_buffer, "100") != 0) &
153 (strcmp(console_buffer, "133") != 0)) {
154 nbytes = 0;
155 }
156 strcpy(pcixClock, console_buffer);
157
158 } while (nbytes == 0);
159
160 printf("\nsys clk = %sMhz\n", sysClock);
161 printf("cpu clk = %sMhz\n", cpuClock);
162 printf("plb clk = %sMhz\n", plbClock);
163 printf("Pci-X clk = %sMhz\n", pcixClock);
164
165 do {
166 printf("\npress [y] to write I2C bootstrap \n");
167 printf("or [n] to abort. \n");
168 printf("Don't forget to set board switches \n");
169 printf("according to your choice before re-starting \n");
170 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
171
172 nbytes = readline (" ? ");
173 if (strcmp(console_buffer, "n") == 0)
174 return 0;
175
176 } while (nbytes == 0);
177
178 if (strcmp(sysClock, "33") == 0) {
179 if ((strcmp(cpuClock, "400") == 0) &
180 (strcmp(plbClock, "100") == 0))
181 data = 0x8678c206;
182
183 if ((strcmp(cpuClock, "400") == 0) &
184 (strcmp(plbClock, "133") == 0))
185 data = 0x8678c2c6;
186
187 if ((strcmp(cpuClock, "500") == 0))
188 data = 0x8778f2c6;
189
190 if ((strcmp(cpuClock, "533") == 0))
191 data = 0x87790252;
192
193#ifdef CONFIG_STRESS
194 if ((strcmp(cpuClock, "667") == 0) &
195 (strcmp(plbClock, "133") == 0))
196 data = 0x87794256;
197
198 if ((strcmp(cpuClock, "667") == 0) &
199 (strcmp(plbClock, "166") == 0))
200 data = 0x87794206;
201
202#endif
203 }
204 if (strcmp(sysClock, "66") == 0) {
205 if ((strcmp(cpuClock, "400") == 0) &
206 (strcmp(plbClock, "100") == 0))
207 data = 0x84706206;
208
209 if ((strcmp(cpuClock, "400") == 0) &
210 (strcmp(plbClock, "133") == 0))
211 data = 0x847062c6;
212
213 if ((strcmp(cpuClock, "533") == 0))
214 data = 0x85708206;
215
216#ifdef CONFIG_STRESS
217 if ((strcmp(cpuClock, "667") == 0) &
218 (strcmp(plbClock, "133") == 0))
219 data = 0x8570a256;
220
221 if ((strcmp(cpuClock, "667") == 0) &
222 (strcmp(plbClock, "166") == 0))
223 data = 0x8570a206;
224
225#endif
226 }
227
228#ifdef DEBUG
229 printf(" pin strap0 to write in i2c = %x\n", data);
230#endif /* DEBUG */
231
232 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
233 printf("Error writing strap0 in %s\n", argv[2]);
234
235 if (strcmp(pcixClock, "33") == 0)
236 data = 0x00000701;
237
238 if (strcmp(pcixClock, "66") == 0)
239 data = 0x00000601;
240
241 if (strcmp(pcixClock, "100") == 0)
242 data = 0x00000501;
243
244 if (strcmp(pcixClock, "133") == 0)
245 data = 0x00000401;
246
247 if (strcmp(plbClock, "166") == 0)
248 data |= 0x05950000;
249 else
250 data |= 0x05A50000;
251
252#ifdef DEBUG
253 printf(" pin strap1 to write in i2c = %x\n", data);
254#endif /* DEBUG */
255
256 udelay(1000);
257 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
258 printf("Error writing strap1 in %s\n", argv[2]);
259
260 return 0;
261}
262
263U_BOOT_CMD(
264 bootstrap, 3, 1, do_bootstrap,
265 "bootstrap - program the serial device strap\n",
266 "wrclk [prom0|prom1] - program the serial device strap\n"
267 );