blob: cc78284e2bf21c85735ea4ddeedf0977f4967483 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Marian Balakowicz49d0eee2006-06-30 16:30:46 +02006 *
7 * hacked for evb440spe
8 */
9
10#include <common.h>
Simon Glassdec3c012014-04-10 20:01:25 -060011#include <cli.h>
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020012#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070013#include <console.h>
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020014#include "yucca.h"
15#include <i2c.h>
16#include <asm/byteorder.h>
17
18extern void print_evb440spe_info(void);
Wolfgang Denkba940932006-07-19 13:50:38 +020019static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
Wolfgang Denk6262d0212010-06-28 22:00:46 +020020 int flag, int argc, char * const argv[]);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020021
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020022/* ------------------------------------------------------------------------- */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020023int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020024{
25 return setBootStrapClock (cmdtp, 1, flag, argc, argv);
26}
27
28/* ------------------------------------------------------------------------- */
29/* Modify memory.
30 *
31 * Syntax:
32 * evb440spe wrclk prom0,prom1
33 */
34static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
Wolfgang Denk6262d0212010-06-28 22:00:46 +020035 int argc, char * const argv[])
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020036{
37 uchar chip;
38 ulong data;
39 int nbytes;
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020040
41 char sysClock[4];
42 char cpuClock[4];
43 char plbClock[4];
44 char pcixClock[4];
45
Wolfgang Denk3b683112010-07-17 01:06:04 +020046 if (argc < 3)
47 return cmd_usage(cmdtp);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020048
49 if (strcmp(argv[2], "prom0") == 0)
50 chip = IIC0_BOOTPROM_ADDR;
51 else
52 chip = IIC0_ALT_BOOTPROM_ADDR;
53
54 do {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020055 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
Simon Glassbe6aafc2014-04-10 20:01:27 -060056 nbytes = cli_readline(" ? ");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020057
58 if (strcmp(console_buffer, "quit") == 0)
59 return 0;
60
61 if ((strcmp(console_buffer, "33") != 0) &
62 (strcmp(console_buffer, "66") != 0))
63 nbytes=0;
64
65 strcpy(sysClock, console_buffer);
66
67 } while (nbytes == 0);
68
69 do {
70 if (strcmp(sysClock, "66") == 0) {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020071 printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020072 } else {
73#ifdef CONFIG_STRESS
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020074 printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020075#else
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020076 printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020077#endif
78 }
Simon Glassbe6aafc2014-04-10 20:01:27 -060079 nbytes = cli_readline(" ? ");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +020080
81 if (strcmp(console_buffer, "quit") == 0)
82 return 0;
83
84 if (strcmp(sysClock, "66") == 0) {
85 if ((strcmp(console_buffer, "400") != 0) &
86 (strcmp(console_buffer, "533") != 0)
87#ifdef CONFIG_STRESS
88 & (strcmp(console_buffer, "667") != 0)
89#endif
90 ) {
91 nbytes = 0;
92 }
93 } else {
94 if ((strcmp(console_buffer, "400") != 0) &
95 (strcmp(console_buffer, "500") != 0) &
96 (strcmp(console_buffer, "533") != 0)
97#ifdef CONFIG_STRESS
98 & (strcmp(console_buffer, "667") != 0)
99#endif
100 ) {
101 nbytes = 0;
102 }
103 }
104
105 strcpy(cpuClock, console_buffer);
106
107 } while (nbytes == 0);
108
109 if (strcmp(cpuClock, "500") == 0){
110 strcpy(plbClock, "166");
111 } else if (strcmp(cpuClock, "533") == 0){
112 strcpy(plbClock, "133");
113 } else {
114 do {
115 if (strcmp(cpuClock, "400") == 0)
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200116 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200117
118#ifdef CONFIG_STRESS
119 if (strcmp(cpuClock, "667") == 0)
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200120 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200121
122#endif
Simon Glassbe6aafc2014-04-10 20:01:27 -0600123 nbytes = cli_readline(" ? ");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200124
125 if (strcmp(console_buffer, "quit") == 0)
126 return 0;
127
128 if (strcmp(cpuClock, "400") == 0) {
129 if ((strcmp(console_buffer, "100") != 0) &
130 (strcmp(console_buffer, "133") != 0))
131 nbytes = 0;
132 }
133#ifdef CONFIG_STRESS
134 if (strcmp(cpuClock, "667") == 0) {
135 if ((strcmp(console_buffer, "133") != 0) &
136 (strcmp(console_buffer, "166") != 0))
137 nbytes = 0;
138 }
139#endif
140 strcpy(plbClock, console_buffer);
141
142 } while (nbytes == 0);
143 }
144
145 do {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200146 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
Simon Glassbe6aafc2014-04-10 20:01:27 -0600147 nbytes = cli_readline(" ? ");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200148
149 if (strcmp(console_buffer, "quit") == 0)
150 return 0;
151
152 if ((strcmp(console_buffer, "33") != 0) &
153 (strcmp(console_buffer, "66") != 0) &
154 (strcmp(console_buffer, "100") != 0) &
155 (strcmp(console_buffer, "133") != 0)) {
156 nbytes = 0;
157 }
158 strcpy(pcixClock, console_buffer);
159
160 } while (nbytes == 0);
161
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200162 printf("\nsys clk = %s MHz\n", sysClock);
163 printf("cpu clk = %s MHz\n", cpuClock);
164 printf("plb clk = %s MHz\n", plbClock);
165 printf("Pci-X clk = %s MHz\n", pcixClock);
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200166
167 do {
Simon Glassbe6aafc2014-04-10 20:01:27 -0600168 printf("\npress [y] to write I2C bootstrap\n");
169 printf("or [n] to abort.\n");
170 printf("Don't forget to set board switches\n");
171 printf("according to your choice before re-starting\n");
172 printf("(refer to 440spe_uboot_kit_um_1_01.pdf)\n");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200173
Simon Glassbe6aafc2014-04-10 20:01:27 -0600174 nbytes = cli_readline(" ? ");
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200175 if (strcmp(console_buffer, "n") == 0)
176 return 0;
177
178 } while (nbytes == 0);
179
180 if (strcmp(sysClock, "33") == 0) {
181 if ((strcmp(cpuClock, "400") == 0) &
182 (strcmp(plbClock, "100") == 0))
183 data = 0x8678c206;
184
185 if ((strcmp(cpuClock, "400") == 0) &
186 (strcmp(plbClock, "133") == 0))
187 data = 0x8678c2c6;
188
189 if ((strcmp(cpuClock, "500") == 0))
190 data = 0x8778f2c6;
191
192 if ((strcmp(cpuClock, "533") == 0))
193 data = 0x87790252;
194
195#ifdef CONFIG_STRESS
196 if ((strcmp(cpuClock, "667") == 0) &
197 (strcmp(plbClock, "133") == 0))
198 data = 0x87794256;
199
200 if ((strcmp(cpuClock, "667") == 0) &
201 (strcmp(plbClock, "166") == 0))
202 data = 0x87794206;
203
204#endif
205 }
206 if (strcmp(sysClock, "66") == 0) {
207 if ((strcmp(cpuClock, "400") == 0) &
208 (strcmp(plbClock, "100") == 0))
209 data = 0x84706206;
210
211 if ((strcmp(cpuClock, "400") == 0) &
212 (strcmp(plbClock, "133") == 0))
213 data = 0x847062c6;
214
215 if ((strcmp(cpuClock, "533") == 0))
216 data = 0x85708206;
217
218#ifdef CONFIG_STRESS
219 if ((strcmp(cpuClock, "667") == 0) &
220 (strcmp(plbClock, "133") == 0))
221 data = 0x8570a256;
222
223 if ((strcmp(cpuClock, "667") == 0) &
224 (strcmp(plbClock, "166") == 0))
225 data = 0x8570a206;
226
227#endif
228 }
229
230#ifdef DEBUG
231 printf(" pin strap0 to write in i2c = %x\n", data);
232#endif /* DEBUG */
233
234 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
235 printf("Error writing strap0 in %s\n", argv[2]);
236
237 if (strcmp(pcixClock, "33") == 0)
238 data = 0x00000701;
239
240 if (strcmp(pcixClock, "66") == 0)
241 data = 0x00000601;
242
243 if (strcmp(pcixClock, "100") == 0)
244 data = 0x00000501;
245
246 if (strcmp(pcixClock, "133") == 0)
247 data = 0x00000401;
248
249 if (strcmp(plbClock, "166") == 0)
250 data = data | 0x05950000;
251 else
252 data = data | 0x05A50000;
253
254#ifdef DEBUG
255 printf(" pin strap1 to write in i2c = %x\n", data);
256#endif /* DEBUG */
257
258 udelay(1000);
259 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
260 printf("Error writing strap1 in %s\n", argv[2]);
261
262 return 0;
263}
264
265U_BOOT_CMD(
266 evb440spe, 3, 1, do_evb440spe,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600267 "program the serial device strap",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200268 "wrclk [prom0|prom1] - program the serial device strap"
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200269);