blob: c1724bf03480819f256f3c7003a6d864c1be887a [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Marian Balakowicz6c5879f2006-06-30 16:30:46 +02006 *
7 * hacked for evb440spe
8 */
9
10#include <common.h>
Simon Glass18d66532014-04-10 20:01:25 -060011#include <cli.h>
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020012#include <command.h>
13#include "yucca.h"
14#include <i2c.h>
15#include <asm/byteorder.h>
16
17extern void print_evb440spe_info(void);
Wolfgang Denkb87dfd22006-07-19 13:50:38 +020018static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
Wolfgang Denk54841ab2010-06-28 22:00:46 +020019 int flag, int argc, char * const argv[]);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020020
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020021/* ------------------------------------------------------------------------- */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020022int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020023{
24 return setBootStrapClock (cmdtp, 1, flag, argc, argv);
25}
26
27/* ------------------------------------------------------------------------- */
28/* Modify memory.
29 *
30 * Syntax:
31 * evb440spe wrclk prom0,prom1
32 */
33static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
Wolfgang Denk54841ab2010-06-28 22:00:46 +020034 int argc, char * const argv[])
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020035{
36 uchar chip;
37 ulong data;
38 int nbytes;
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020039
40 char sysClock[4];
41 char cpuClock[4];
42 char plbClock[4];
43 char pcixClock[4];
44
Wolfgang Denk47e26b12010-07-17 01:06:04 +020045 if (argc < 3)
46 return cmd_usage(cmdtp);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020047
48 if (strcmp(argv[2], "prom0") == 0)
49 chip = IIC0_BOOTPROM_ADDR;
50 else
51 chip = IIC0_ALT_BOOTPROM_ADDR;
52
53 do {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020054 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
Simon Glasse1bf8242014-04-10 20:01:27 -060055 nbytes = cli_readline(" ? ");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020056
57 if (strcmp(console_buffer, "quit") == 0)
58 return 0;
59
60 if ((strcmp(console_buffer, "33") != 0) &
61 (strcmp(console_buffer, "66") != 0))
62 nbytes=0;
63
64 strcpy(sysClock, console_buffer);
65
66 } while (nbytes == 0);
67
68 do {
69 if (strcmp(sysClock, "66") == 0) {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020070 printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020071 } else {
72#ifdef CONFIG_STRESS
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020073 printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020074#else
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020075 printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020076#endif
77 }
Simon Glasse1bf8242014-04-10 20:01:27 -060078 nbytes = cli_readline(" ? ");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020079
80 if (strcmp(console_buffer, "quit") == 0)
81 return 0;
82
83 if (strcmp(sysClock, "66") == 0) {
84 if ((strcmp(console_buffer, "400") != 0) &
85 (strcmp(console_buffer, "533") != 0)
86#ifdef CONFIG_STRESS
87 & (strcmp(console_buffer, "667") != 0)
88#endif
89 ) {
90 nbytes = 0;
91 }
92 } else {
93 if ((strcmp(console_buffer, "400") != 0) &
94 (strcmp(console_buffer, "500") != 0) &
95 (strcmp(console_buffer, "533") != 0)
96#ifdef CONFIG_STRESS
97 & (strcmp(console_buffer, "667") != 0)
98#endif
99 ) {
100 nbytes = 0;
101 }
102 }
103
104 strcpy(cpuClock, console_buffer);
105
106 } while (nbytes == 0);
107
108 if (strcmp(cpuClock, "500") == 0){
109 strcpy(plbClock, "166");
110 } else if (strcmp(cpuClock, "533") == 0){
111 strcpy(plbClock, "133");
112 } else {
113 do {
114 if (strcmp(cpuClock, "400") == 0)
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200115 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200116
117#ifdef CONFIG_STRESS
118 if (strcmp(cpuClock, "667") == 0)
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200119 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200120
121#endif
Simon Glasse1bf8242014-04-10 20:01:27 -0600122 nbytes = cli_readline(" ? ");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200123
124 if (strcmp(console_buffer, "quit") == 0)
125 return 0;
126
127 if (strcmp(cpuClock, "400") == 0) {
128 if ((strcmp(console_buffer, "100") != 0) &
129 (strcmp(console_buffer, "133") != 0))
130 nbytes = 0;
131 }
132#ifdef CONFIG_STRESS
133 if (strcmp(cpuClock, "667") == 0) {
134 if ((strcmp(console_buffer, "133") != 0) &
135 (strcmp(console_buffer, "166") != 0))
136 nbytes = 0;
137 }
138#endif
139 strcpy(plbClock, console_buffer);
140
141 } while (nbytes == 0);
142 }
143
144 do {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200145 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
Simon Glasse1bf8242014-04-10 20:01:27 -0600146 nbytes = cli_readline(" ? ");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200147
148 if (strcmp(console_buffer, "quit") == 0)
149 return 0;
150
151 if ((strcmp(console_buffer, "33") != 0) &
152 (strcmp(console_buffer, "66") != 0) &
153 (strcmp(console_buffer, "100") != 0) &
154 (strcmp(console_buffer, "133") != 0)) {
155 nbytes = 0;
156 }
157 strcpy(pcixClock, console_buffer);
158
159 } while (nbytes == 0);
160
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200161 printf("\nsys clk = %s MHz\n", sysClock);
162 printf("cpu clk = %s MHz\n", cpuClock);
163 printf("plb clk = %s MHz\n", plbClock);
164 printf("Pci-X clk = %s MHz\n", pcixClock);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200165
166 do {
Simon Glasse1bf8242014-04-10 20:01:27 -0600167 printf("\npress [y] to write I2C bootstrap\n");
168 printf("or [n] to abort.\n");
169 printf("Don't forget to set board switches\n");
170 printf("according to your choice before re-starting\n");
171 printf("(refer to 440spe_uboot_kit_um_1_01.pdf)\n");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200172
Simon Glasse1bf8242014-04-10 20:01:27 -0600173 nbytes = cli_readline(" ? ");
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200174 if (strcmp(console_buffer, "n") == 0)
175 return 0;
176
177 } while (nbytes == 0);
178
179 if (strcmp(sysClock, "33") == 0) {
180 if ((strcmp(cpuClock, "400") == 0) &
181 (strcmp(plbClock, "100") == 0))
182 data = 0x8678c206;
183
184 if ((strcmp(cpuClock, "400") == 0) &
185 (strcmp(plbClock, "133") == 0))
186 data = 0x8678c2c6;
187
188 if ((strcmp(cpuClock, "500") == 0))
189 data = 0x8778f2c6;
190
191 if ((strcmp(cpuClock, "533") == 0))
192 data = 0x87790252;
193
194#ifdef CONFIG_STRESS
195 if ((strcmp(cpuClock, "667") == 0) &
196 (strcmp(plbClock, "133") == 0))
197 data = 0x87794256;
198
199 if ((strcmp(cpuClock, "667") == 0) &
200 (strcmp(plbClock, "166") == 0))
201 data = 0x87794206;
202
203#endif
204 }
205 if (strcmp(sysClock, "66") == 0) {
206 if ((strcmp(cpuClock, "400") == 0) &
207 (strcmp(plbClock, "100") == 0))
208 data = 0x84706206;
209
210 if ((strcmp(cpuClock, "400") == 0) &
211 (strcmp(plbClock, "133") == 0))
212 data = 0x847062c6;
213
214 if ((strcmp(cpuClock, "533") == 0))
215 data = 0x85708206;
216
217#ifdef CONFIG_STRESS
218 if ((strcmp(cpuClock, "667") == 0) &
219 (strcmp(plbClock, "133") == 0))
220 data = 0x8570a256;
221
222 if ((strcmp(cpuClock, "667") == 0) &
223 (strcmp(plbClock, "166") == 0))
224 data = 0x8570a206;
225
226#endif
227 }
228
229#ifdef DEBUG
230 printf(" pin strap0 to write in i2c = %x\n", data);
231#endif /* DEBUG */
232
233 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
234 printf("Error writing strap0 in %s\n", argv[2]);
235
236 if (strcmp(pcixClock, "33") == 0)
237 data = 0x00000701;
238
239 if (strcmp(pcixClock, "66") == 0)
240 data = 0x00000601;
241
242 if (strcmp(pcixClock, "100") == 0)
243 data = 0x00000501;
244
245 if (strcmp(pcixClock, "133") == 0)
246 data = 0x00000401;
247
248 if (strcmp(plbClock, "166") == 0)
249 data = data | 0x05950000;
250 else
251 data = data | 0x05A50000;
252
253#ifdef DEBUG
254 printf(" pin strap1 to write in i2c = %x\n", data);
255#endif /* DEBUG */
256
257 udelay(1000);
258 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
259 printf("Error writing strap1 in %s\n", argv[2]);
260
261 return 0;
262}
263
264U_BOOT_CMD(
265 evb440spe, 3, 1, do_evb440spe,
Peter Tyser2fb26042009-01-27 18:03:12 -0600266 "program the serial device strap",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200267 "wrclk [prom0|prom1] - program the serial device strap"
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200268);