cc78284e2bf21c85735ea4ddeedf0977f4967483
[platform/kernel/u-boot.git] / board / amcc / yucca / cmd_yucca.c
1 /*
2  * (C) Copyright 2001
3  * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  *
7  * hacked for evb440spe
8  */
9
10 #include <common.h>
11 #include <cli.h>
12 #include <command.h>
13 #include <console.h>
14 #include "yucca.h"
15 #include <i2c.h>
16 #include <asm/byteorder.h>
17
18 extern void print_evb440spe_info(void);
19 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
20                 int flag, int argc, char * const argv[]);
21
22 /* ------------------------------------------------------------------------- */
23 int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
24 {
25         return setBootStrapClock (cmdtp, 1, flag, argc, argv);
26 }
27
28 /* ------------------------------------------------------------------------- */
29 /* Modify memory.
30  *
31  * Syntax:
32  *      evb440spe wrclk prom0,prom1
33  */
34 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
35                 int argc, char * const argv[])
36 {
37         uchar   chip;
38         ulong   data;
39         int     nbytes;
40
41         char sysClock[4];
42         char cpuClock[4];
43         char plbClock[4];
44         char pcixClock[4];
45
46         if (argc < 3)
47                 return cmd_usage(cmdtp);
48
49         if (strcmp(argv[2], "prom0") == 0)
50                 chip = IIC0_BOOTPROM_ADDR;
51         else
52                 chip = IIC0_ALT_BOOTPROM_ADDR;
53
54         do {
55                 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
56                 nbytes = cli_readline(" ? ");
57
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) {
71                         printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
72                 } else {
73 #ifdef  CONFIG_STRESS
74                         printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
75 #else
76                         printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
77 #endif
78                 }
79                 nbytes = cli_readline(" ? ");
80
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)
116                                 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
117
118 #ifdef  CONFIG_STRESS
119                         if (strcmp(cpuClock, "667") == 0)
120                                 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
121
122 #endif
123                         nbytes = cli_readline(" ? ");
124
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 {
146                 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
147                 nbytes = cli_readline(" ? ");
148
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
162         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);
166
167         do {
168                 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");
173
174                 nbytes = cli_readline(" ? ");
175                 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
265 U_BOOT_CMD(
266         evb440spe,      3,      1,      do_evb440spe,
267         "program the serial device strap",
268         "wrclk [prom0|prom1] - program the serial device strap"
269 );