blob: cde13e424b5e30ebabbeeaff3e88b2a569f30b7a [file] [log] [blame]
Marian Balakowicz6c5879f2006-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 Denkb87dfd22006-07-19 13:50:38 +020033static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
Wolfgang Denk54841ab2010-06-28 22:00:46 +020034 int flag, int argc, char * const argv[]);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020035
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020036/* ------------------------------------------------------------------------- */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020037int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Marian Balakowicz6c5879f2006-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 Denk54841ab2010-06-28 22:00:46 +020049 int argc, char * const argv[])
Marian Balakowicz6c5879f2006-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
61 if (argc < 3) {
Peter Tyser62c3ae72009-01-27 18:03:10 -060062 cmd_usage(cmdtp);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020063 return 1;
64 }
65
66 if (strcmp(argv[2], "prom0") == 0)
67 chip = IIC0_BOOTPROM_ADDR;
68 else
69 chip = IIC0_ALT_BOOTPROM_ADDR;
70
71 do {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020072 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020073 nbytes = readline (" ? ");
74
75 if (strcmp(console_buffer, "quit") == 0)
76 return 0;
77
78 if ((strcmp(console_buffer, "33") != 0) &
79 (strcmp(console_buffer, "66") != 0))
80 nbytes=0;
81
82 strcpy(sysClock, console_buffer);
83
84 } while (nbytes == 0);
85
86 do {
87 if (strcmp(sysClock, "66") == 0) {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020088 printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020089 } else {
90#ifdef CONFIG_STRESS
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020091 printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020092#else
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020093 printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020094#endif
95 }
96 nbytes = readline (" ? ");
97
98 if (strcmp(console_buffer, "quit") == 0)
99 return 0;
100
101 if (strcmp(sysClock, "66") == 0) {
102 if ((strcmp(console_buffer, "400") != 0) &
103 (strcmp(console_buffer, "533") != 0)
104#ifdef CONFIG_STRESS
105 & (strcmp(console_buffer, "667") != 0)
106#endif
107 ) {
108 nbytes = 0;
109 }
110 } else {
111 if ((strcmp(console_buffer, "400") != 0) &
112 (strcmp(console_buffer, "500") != 0) &
113 (strcmp(console_buffer, "533") != 0)
114#ifdef CONFIG_STRESS
115 & (strcmp(console_buffer, "667") != 0)
116#endif
117 ) {
118 nbytes = 0;
119 }
120 }
121
122 strcpy(cpuClock, console_buffer);
123
124 } while (nbytes == 0);
125
126 if (strcmp(cpuClock, "500") == 0){
127 strcpy(plbClock, "166");
128 } else if (strcmp(cpuClock, "533") == 0){
129 strcpy(plbClock, "133");
130 } else {
131 do {
132 if (strcmp(cpuClock, "400") == 0)
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200133 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200134
135#ifdef CONFIG_STRESS
136 if (strcmp(cpuClock, "667") == 0)
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200137 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200138
139#endif
140 nbytes = readline (" ? ");
141
142 if (strcmp(console_buffer, "quit") == 0)
143 return 0;
144
145 if (strcmp(cpuClock, "400") == 0) {
146 if ((strcmp(console_buffer, "100") != 0) &
147 (strcmp(console_buffer, "133") != 0))
148 nbytes = 0;
149 }
150#ifdef CONFIG_STRESS
151 if (strcmp(cpuClock, "667") == 0) {
152 if ((strcmp(console_buffer, "133") != 0) &
153 (strcmp(console_buffer, "166") != 0))
154 nbytes = 0;
155 }
156#endif
157 strcpy(plbClock, console_buffer);
158
159 } while (nbytes == 0);
160 }
161
162 do {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200163 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200164 nbytes = readline (" ? ");
165
166 if (strcmp(console_buffer, "quit") == 0)
167 return 0;
168
169 if ((strcmp(console_buffer, "33") != 0) &
170 (strcmp(console_buffer, "66") != 0) &
171 (strcmp(console_buffer, "100") != 0) &
172 (strcmp(console_buffer, "133") != 0)) {
173 nbytes = 0;
174 }
175 strcpy(pcixClock, console_buffer);
176
177 } while (nbytes == 0);
178
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200179 printf("\nsys clk = %s MHz\n", sysClock);
180 printf("cpu clk = %s MHz\n", cpuClock);
181 printf("plb clk = %s MHz\n", plbClock);
182 printf("Pci-X clk = %s MHz\n", pcixClock);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200183
184 do {
185 printf("\npress [y] to write I2C bootstrap \n");
186 printf("or [n] to abort. \n");
187 printf("Don't forget to set board switches \n");
188 printf("according to your choice before re-starting \n");
189 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
190
191 nbytes = readline (" ? ");
192 if (strcmp(console_buffer, "n") == 0)
193 return 0;
194
195 } while (nbytes == 0);
196
197 if (strcmp(sysClock, "33") == 0) {
198 if ((strcmp(cpuClock, "400") == 0) &
199 (strcmp(plbClock, "100") == 0))
200 data = 0x8678c206;
201
202 if ((strcmp(cpuClock, "400") == 0) &
203 (strcmp(plbClock, "133") == 0))
204 data = 0x8678c2c6;
205
206 if ((strcmp(cpuClock, "500") == 0))
207 data = 0x8778f2c6;
208
209 if ((strcmp(cpuClock, "533") == 0))
210 data = 0x87790252;
211
212#ifdef CONFIG_STRESS
213 if ((strcmp(cpuClock, "667") == 0) &
214 (strcmp(plbClock, "133") == 0))
215 data = 0x87794256;
216
217 if ((strcmp(cpuClock, "667") == 0) &
218 (strcmp(plbClock, "166") == 0))
219 data = 0x87794206;
220
221#endif
222 }
223 if (strcmp(sysClock, "66") == 0) {
224 if ((strcmp(cpuClock, "400") == 0) &
225 (strcmp(plbClock, "100") == 0))
226 data = 0x84706206;
227
228 if ((strcmp(cpuClock, "400") == 0) &
229 (strcmp(plbClock, "133") == 0))
230 data = 0x847062c6;
231
232 if ((strcmp(cpuClock, "533") == 0))
233 data = 0x85708206;
234
235#ifdef CONFIG_STRESS
236 if ((strcmp(cpuClock, "667") == 0) &
237 (strcmp(plbClock, "133") == 0))
238 data = 0x8570a256;
239
240 if ((strcmp(cpuClock, "667") == 0) &
241 (strcmp(plbClock, "166") == 0))
242 data = 0x8570a206;
243
244#endif
245 }
246
247#ifdef DEBUG
248 printf(" pin strap0 to write in i2c = %x\n", data);
249#endif /* DEBUG */
250
251 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
252 printf("Error writing strap0 in %s\n", argv[2]);
253
254 if (strcmp(pcixClock, "33") == 0)
255 data = 0x00000701;
256
257 if (strcmp(pcixClock, "66") == 0)
258 data = 0x00000601;
259
260 if (strcmp(pcixClock, "100") == 0)
261 data = 0x00000501;
262
263 if (strcmp(pcixClock, "133") == 0)
264 data = 0x00000401;
265
266 if (strcmp(plbClock, "166") == 0)
267 data = data | 0x05950000;
268 else
269 data = data | 0x05A50000;
270
271#ifdef DEBUG
272 printf(" pin strap1 to write in i2c = %x\n", data);
273#endif /* DEBUG */
274
275 udelay(1000);
276 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
277 printf("Error writing strap1 in %s\n", argv[2]);
278
279 return 0;
280}
281
282U_BOOT_CMD(
283 evb440spe, 3, 1, do_evb440spe,
Peter Tyser2fb26042009-01-27 18:03:12 -0600284 "program the serial device strap",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200285 "wrclk [prom0|prom1] - program the serial device strap"
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200286);