]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/amcc/yucca/cmd_yucca.c
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.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 "yucca.h"
14 #include <i2c.h>
15 #include <asm/byteorder.h>
16
17 extern void print_evb440spe_info(void);
18 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
19                 int flag, int argc, char * const argv[]);
20
21 /* ------------------------------------------------------------------------- */
22 int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23 {
24         return setBootStrapClock (cmdtp, 1, flag, argc, argv);
25 }
26
27 /* ------------------------------------------------------------------------- */
28 /* Modify memory.
29  *
30  * Syntax:
31  *      evb440spe wrclk prom0,prom1
32  */
33 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
34                 int argc, char * const argv[])
35 {
36         uchar   chip;
37         ulong   data;
38         int     nbytes;
39
40         char sysClock[4];
41         char cpuClock[4];
42         char plbClock[4];
43         char pcixClock[4];
44
45         if (argc < 3)
46                 return cmd_usage(cmdtp);
47
48         if (strcmp(argv[2], "prom0") == 0)
49                 chip = IIC0_BOOTPROM_ADDR;
50         else
51                 chip = IIC0_ALT_BOOTPROM_ADDR;
52
53         do {
54                 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
55                 nbytes = cli_readline(" ? ");
56
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) {
70                         printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
71                 } else {
72 #ifdef  CONFIG_STRESS
73                         printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
74 #else
75                         printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
76 #endif
77                 }
78                 nbytes = cli_readline(" ? ");
79
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)
115                                 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
116
117 #ifdef  CONFIG_STRESS
118                         if (strcmp(cpuClock, "667") == 0)
119                                 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
120
121 #endif
122                         nbytes = cli_readline(" ? ");
123
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 {
145                 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
146                 nbytes = cli_readline(" ? ");
147
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
161         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);
165
166         do {
167                 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");
172
173                 nbytes = cli_readline(" ? ");
174                 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
264 U_BOOT_CMD(
265         evb440spe,      3,      1,      do_evb440spe,
266         "program the serial device strap",
267         "wrclk [prom0|prom1] - program the serial device strap"
268 );