]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/amcc/yucca/cmd_yucca.c
Merge branch 'u-boot/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 <command.h>
12 #include "yucca.h"
13 #include <i2c.h>
14 #include <asm/byteorder.h>
15
16 extern void print_evb440spe_info(void);
17 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
18                 int flag, int argc, char * const argv[]);
19
20 /* ------------------------------------------------------------------------- */
21 int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
22 {
23         return setBootStrapClock (cmdtp, 1, flag, argc, argv);
24 }
25
26 /* ------------------------------------------------------------------------- */
27 /* Modify memory.
28  *
29  * Syntax:
30  *      evb440spe wrclk prom0,prom1
31  */
32 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
33                 int argc, char * const argv[])
34 {
35         uchar   chip;
36         ulong   data;
37         int     nbytes;
38
39         char sysClock[4];
40         char cpuClock[4];
41         char plbClock[4];
42         char pcixClock[4];
43
44         if (argc < 3)
45                 return cmd_usage(cmdtp);
46
47         if (strcmp(argv[2], "prom0") == 0)
48                 chip = IIC0_BOOTPROM_ADDR;
49         else
50                 chip = IIC0_ALT_BOOTPROM_ADDR;
51
52         do {
53                 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
54                 nbytes = readline (" ? ");
55
56                 if (strcmp(console_buffer, "quit") == 0)
57                         return 0;
58
59                 if ((strcmp(console_buffer, "33") != 0) &
60                                 (strcmp(console_buffer, "66") != 0))
61                         nbytes=0;
62
63                 strcpy(sysClock, console_buffer);
64
65         } while (nbytes == 0);
66
67         do {
68                 if (strcmp(sysClock, "66") == 0) {
69                         printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
70                 } else {
71 #ifdef  CONFIG_STRESS
72                         printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
73 #else
74                         printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
75 #endif
76                 }
77                 nbytes = readline (" ? ");
78
79                 if (strcmp(console_buffer, "quit") == 0)
80                         return 0;
81
82                 if (strcmp(sysClock, "66") == 0) {
83                         if ((strcmp(console_buffer, "400") != 0) &
84                                         (strcmp(console_buffer, "533") != 0)
85 #ifdef  CONFIG_STRESS
86                                         & (strcmp(console_buffer, "667") != 0)
87 #endif
88                            ) {
89                                 nbytes = 0;
90                         }
91                 } else {
92                         if ((strcmp(console_buffer, "400") != 0) &
93                                         (strcmp(console_buffer, "500") != 0) &
94                                         (strcmp(console_buffer, "533") != 0)
95 #ifdef  CONFIG_STRESS
96                                         & (strcmp(console_buffer, "667") != 0)
97 #endif
98                            ) {
99                                 nbytes = 0;
100                         }
101                 }
102
103                 strcpy(cpuClock, console_buffer);
104
105         } while (nbytes == 0);
106
107         if (strcmp(cpuClock, "500") == 0){
108                 strcpy(plbClock, "166");
109         } else if (strcmp(cpuClock, "533") == 0){
110                 strcpy(plbClock, "133");
111         } else {
112                 do {
113                         if (strcmp(cpuClock, "400") == 0)
114                                 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
115
116 #ifdef  CONFIG_STRESS
117                         if (strcmp(cpuClock, "667") == 0)
118                                 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
119
120 #endif
121                         nbytes = readline (" ? ");
122
123                         if (strcmp(console_buffer, "quit") == 0)
124                                 return 0;
125
126                         if (strcmp(cpuClock, "400") == 0) {
127                                 if ((strcmp(console_buffer, "100") != 0) &
128                                                 (strcmp(console_buffer, "133") != 0))
129                                         nbytes = 0;
130                         }
131 #ifdef  CONFIG_STRESS
132                         if (strcmp(cpuClock, "667") == 0) {
133                                 if ((strcmp(console_buffer, "133") != 0) &
134                                                 (strcmp(console_buffer, "166") != 0))
135                                         nbytes = 0;
136                         }
137 #endif
138                         strcpy(plbClock, console_buffer);
139
140                 } while (nbytes == 0);
141         }
142
143         do {
144                 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
145                 nbytes = readline (" ? ");
146
147                 if (strcmp(console_buffer, "quit") == 0)
148                         return 0;
149
150                 if ((strcmp(console_buffer, "33") != 0) &
151                                 (strcmp(console_buffer, "66") != 0) &
152                                 (strcmp(console_buffer, "100") != 0) &
153                                 (strcmp(console_buffer, "133") != 0)) {
154                         nbytes = 0;
155                 }
156                 strcpy(pcixClock, console_buffer);
157
158         } while (nbytes == 0);
159
160         printf("\nsys clk   = %s MHz\n", sysClock);
161         printf("cpu clk   = %s MHz\n", cpuClock);
162         printf("plb clk   = %s MHz\n", plbClock);
163         printf("Pci-X clk = %s MHz\n", pcixClock);
164
165         do {
166                 printf("\npress [y] to write I2C bootstrap \n");
167                 printf("or [n] to abort.  \n");
168                 printf("Don't forget to set board switches \n");
169                 printf("according to your choice before re-starting \n");
170                 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
171
172                 nbytes = readline (" ? ");
173                 if (strcmp(console_buffer, "n") == 0)
174                         return 0;
175
176         } while (nbytes == 0);
177
178         if (strcmp(sysClock, "33") == 0) {
179                 if ((strcmp(cpuClock, "400") == 0) &
180                                 (strcmp(plbClock, "100") == 0))
181                         data = 0x8678c206;
182
183                 if ((strcmp(cpuClock, "400") == 0) &
184                                 (strcmp(plbClock, "133") == 0))
185                         data = 0x8678c2c6;
186
187                 if ((strcmp(cpuClock, "500") == 0))
188                         data = 0x8778f2c6;
189
190                 if ((strcmp(cpuClock, "533") == 0))
191                         data = 0x87790252;
192
193 #ifdef  CONFIG_STRESS
194                 if ((strcmp(cpuClock, "667") == 0) &
195                                 (strcmp(plbClock, "133") == 0))
196                         data = 0x87794256;
197
198                 if ((strcmp(cpuClock, "667") == 0) &
199                                 (strcmp(plbClock, "166") == 0))
200                         data = 0x87794206;
201
202 #endif
203         }
204         if (strcmp(sysClock, "66") == 0) {
205                 if ((strcmp(cpuClock, "400") == 0) &
206                                 (strcmp(plbClock, "100") == 0))
207                         data = 0x84706206;
208
209                 if ((strcmp(cpuClock, "400") == 0) &
210                                 (strcmp(plbClock, "133") == 0))
211                         data = 0x847062c6;
212
213                 if ((strcmp(cpuClock, "533") == 0))
214                         data = 0x85708206;
215
216 #ifdef  CONFIG_STRESS
217                 if ((strcmp(cpuClock, "667") == 0) &
218                                 (strcmp(plbClock, "133") == 0))
219                         data = 0x8570a256;
220
221                 if ((strcmp(cpuClock, "667") == 0) &
222                                 (strcmp(plbClock, "166") == 0))
223                         data = 0x8570a206;
224
225 #endif
226         }
227
228 #ifdef  DEBUG
229         printf(" pin strap0 to write in i2c  = %x\n", data);
230 #endif  /* DEBUG */
231
232         if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
233                 printf("Error writing strap0 in %s\n", argv[2]);
234
235         if (strcmp(pcixClock, "33") == 0)
236                 data = 0x00000701;
237
238         if (strcmp(pcixClock, "66") == 0)
239                 data = 0x00000601;
240
241         if (strcmp(pcixClock, "100") == 0)
242                 data = 0x00000501;
243
244         if (strcmp(pcixClock, "133") == 0)
245                 data = 0x00000401;
246
247         if (strcmp(plbClock, "166") == 0)
248                 data = data | 0x05950000;
249         else
250                 data = data | 0x05A50000;
251
252 #ifdef  DEBUG
253         printf(" pin strap1 to write in i2c  = %x\n", data);
254 #endif  /* DEBUG */
255
256         udelay(1000);
257         if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
258                 printf("Error writing strap1 in %s\n", argv[2]);
259
260         return 0;
261 }
262
263 U_BOOT_CMD(
264         evb440spe,      3,      1,      do_evb440spe,
265         "program the serial device strap",
266         "wrclk [prom0|prom1] - program the serial device strap"
267 );