blob: e9cd333f3a5452cf36bfa817bba5ad854dcda889 [file] [log] [blame]
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02001/*
2 * (C) Copyright 2001
3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
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 * hacked for evb440spe
24 */
25
26#include <common.h>
27#include <command.h>
28#include "yucca.h"
29#include <i2c.h>
30#include <asm/byteorder.h>
31
32extern void print_evb440spe_info(void);
Wolfgang Denkba940932006-07-19 13:50:38 +020033static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
Wolfgang Denk6262d0212010-06-28 22:00:46 +020034 int flag, int argc, char * const argv[]);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020035
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020036/* ------------------------------------------------------------------------- */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020037int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020038{
39 return setBootStrapClock (cmdtp, 1, flag, argc, argv);
40}
41
42/* ------------------------------------------------------------------------- */
43/* Modify memory.
44 *
45 * Syntax:
46 * evb440spe wrclk prom0,prom1
47 */
48static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
Wolfgang Denk6262d0212010-06-28 22:00:46 +020049 int argc, char * const argv[])
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020050{
51 uchar chip;
52 ulong data;
53 int nbytes;
54 extern char console_buffer[];
55
56 char sysClock[4];
57 char cpuClock[4];
58 char plbClock[4];
59 char pcixClock[4];
60
Wolfgang Denk3b683112010-07-17 01:06:04 +020061 if (argc < 3)
62 return cmd_usage(cmdtp);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020063
64 if (strcmp(argv[2], "prom0") == 0)
65 chip = IIC0_BOOTPROM_ADDR;
66 else
67 chip = IIC0_ALT_BOOTPROM_ADDR;
68
69 do {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020070 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020071 nbytes = readline (" ? ");
72
73 if (strcmp(console_buffer, "quit") == 0)
74 return 0;
75
76 if ((strcmp(console_buffer, "33") != 0) &
77 (strcmp(console_buffer, "66") != 0))
78 nbytes=0;
79
80 strcpy(sysClock, console_buffer);
81
82 } while (nbytes == 0);
83
84 do {
85 if (strcmp(sysClock, "66") == 0) {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020086 printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020087 } else {
88#ifdef CONFIG_STRESS
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020089 printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020090#else
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020091 printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020092#endif
93 }
94 nbytes = readline (" ? ");
95
96 if (strcmp(console_buffer, "quit") == 0)
97 return 0;
98
99 if (strcmp(sysClock, "66") == 0) {
100 if ((strcmp(console_buffer, "400") != 0) &
101 (strcmp(console_buffer, "533") != 0)
102#ifdef CONFIG_STRESS
103 & (strcmp(console_buffer, "667") != 0)
104#endif
105 ) {
106 nbytes = 0;
107 }
108 } else {
109 if ((strcmp(console_buffer, "400") != 0) &
110 (strcmp(console_buffer, "500") != 0) &
111 (strcmp(console_buffer, "533") != 0)
112#ifdef CONFIG_STRESS
113 & (strcmp(console_buffer, "667") != 0)
114#endif
115 ) {
116 nbytes = 0;
117 }
118 }
119
120 strcpy(cpuClock, console_buffer);
121
122 } while (nbytes == 0);
123
124 if (strcmp(cpuClock, "500") == 0){
125 strcpy(plbClock, "166");
126 } else if (strcmp(cpuClock, "533") == 0){
127 strcpy(plbClock, "133");
128 } else {
129 do {
130 if (strcmp(cpuClock, "400") == 0)
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200131 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200132
133#ifdef CONFIG_STRESS
134 if (strcmp(cpuClock, "667") == 0)
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200135 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200136
137#endif
138 nbytes = readline (" ? ");
139
140 if (strcmp(console_buffer, "quit") == 0)
141 return 0;
142
143 if (strcmp(cpuClock, "400") == 0) {
144 if ((strcmp(console_buffer, "100") != 0) &
145 (strcmp(console_buffer, "133") != 0))
146 nbytes = 0;
147 }
148#ifdef CONFIG_STRESS
149 if (strcmp(cpuClock, "667") == 0) {
150 if ((strcmp(console_buffer, "133") != 0) &
151 (strcmp(console_buffer, "166") != 0))
152 nbytes = 0;
153 }
154#endif
155 strcpy(plbClock, console_buffer);
156
157 } while (nbytes == 0);
158 }
159
160 do {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200161 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200162 nbytes = readline (" ? ");
163
164 if (strcmp(console_buffer, "quit") == 0)
165 return 0;
166
167 if ((strcmp(console_buffer, "33") != 0) &
168 (strcmp(console_buffer, "66") != 0) &
169 (strcmp(console_buffer, "100") != 0) &
170 (strcmp(console_buffer, "133") != 0)) {
171 nbytes = 0;
172 }
173 strcpy(pcixClock, console_buffer);
174
175 } while (nbytes == 0);
176
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200177 printf("\nsys clk = %s MHz\n", sysClock);
178 printf("cpu clk = %s MHz\n", cpuClock);
179 printf("plb clk = %s MHz\n", plbClock);
180 printf("Pci-X clk = %s MHz\n", pcixClock);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200181
182 do {
183 printf("\npress [y] to write I2C bootstrap \n");
184 printf("or [n] to abort. \n");
185 printf("Don't forget to set board switches \n");
186 printf("according to your choice before re-starting \n");
187 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
188
189 nbytes = readline (" ? ");
190 if (strcmp(console_buffer, "n") == 0)
191 return 0;
192
193 } while (nbytes == 0);
194
195 if (strcmp(sysClock, "33") == 0) {
196 if ((strcmp(cpuClock, "400") == 0) &
197 (strcmp(plbClock, "100") == 0))
198 data = 0x8678c206;
199
200 if ((strcmp(cpuClock, "400") == 0) &
201 (strcmp(plbClock, "133") == 0))
202 data = 0x8678c2c6;
203
204 if ((strcmp(cpuClock, "500") == 0))
205 data = 0x8778f2c6;
206
207 if ((strcmp(cpuClock, "533") == 0))
208 data = 0x87790252;
209
210#ifdef CONFIG_STRESS
211 if ((strcmp(cpuClock, "667") == 0) &
212 (strcmp(plbClock, "133") == 0))
213 data = 0x87794256;
214
215 if ((strcmp(cpuClock, "667") == 0) &
216 (strcmp(plbClock, "166") == 0))
217 data = 0x87794206;
218
219#endif
220 }
221 if (strcmp(sysClock, "66") == 0) {
222 if ((strcmp(cpuClock, "400") == 0) &
223 (strcmp(plbClock, "100") == 0))
224 data = 0x84706206;
225
226 if ((strcmp(cpuClock, "400") == 0) &
227 (strcmp(plbClock, "133") == 0))
228 data = 0x847062c6;
229
230 if ((strcmp(cpuClock, "533") == 0))
231 data = 0x85708206;
232
233#ifdef CONFIG_STRESS
234 if ((strcmp(cpuClock, "667") == 0) &
235 (strcmp(plbClock, "133") == 0))
236 data = 0x8570a256;
237
238 if ((strcmp(cpuClock, "667") == 0) &
239 (strcmp(plbClock, "166") == 0))
240 data = 0x8570a206;
241
242#endif
243 }
244
245#ifdef DEBUG
246 printf(" pin strap0 to write in i2c = %x\n", data);
247#endif /* DEBUG */
248
249 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
250 printf("Error writing strap0 in %s\n", argv[2]);
251
252 if (strcmp(pcixClock, "33") == 0)
253 data = 0x00000701;
254
255 if (strcmp(pcixClock, "66") == 0)
256 data = 0x00000601;
257
258 if (strcmp(pcixClock, "100") == 0)
259 data = 0x00000501;
260
261 if (strcmp(pcixClock, "133") == 0)
262 data = 0x00000401;
263
264 if (strcmp(plbClock, "166") == 0)
265 data = data | 0x05950000;
266 else
267 data = data | 0x05A50000;
268
269#ifdef DEBUG
270 printf(" pin strap1 to write in i2c = %x\n", data);
271#endif /* DEBUG */
272
273 udelay(1000);
274 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
275 printf("Error writing strap1 in %s\n", argv[2]);
276
277 return 0;
278}
279
280U_BOOT_CMD(
281 evb440spe, 3, 1, do_evb440spe,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600282 "program the serial device strap",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200283 "wrclk [prom0|prom1] - program the serial device strap"
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200284);