]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/amcc/yucca/cmd_yucca.c
socfpga: Move board/socfpga_cyclone5 to board/socfpga
[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  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  *
23  * hacked for evb440spe
24  */
25
26 #include <common.h>
27 #include <command.h>
28 #include "yucca.h"
29 #include <i2c.h>
30 #include <asm/byteorder.h>
31
32 extern void print_evb440spe_info(void);
33 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag,
34                 int flag, int argc, char * const argv[]);
35
36 /* ------------------------------------------------------------------------- */
37 int do_evb440spe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
38 {
39         return setBootStrapClock (cmdtp, 1, flag, argc, argv);
40 }
41
42 /* ------------------------------------------------------------------------- */
43 /* Modify memory.
44  *
45  * Syntax:
46  *      evb440spe wrclk prom0,prom1
47  */
48 static int setBootStrapClock(cmd_tbl_t *cmdtp, int incrflag, int flag,
49                 int argc, char * const argv[])
50 {
51         uchar   chip;
52         ulong   data;
53         int     nbytes;
54
55         char sysClock[4];
56         char cpuClock[4];
57         char plbClock[4];
58         char pcixClock[4];
59
60         if (argc < 3)
61                 return cmd_usage(cmdtp);
62
63         if (strcmp(argv[2], "prom0") == 0)
64                 chip = IIC0_BOOTPROM_ADDR;
65         else
66                 chip = IIC0_ALT_BOOTPROM_ADDR;
67
68         do {
69                 printf("enter sys clock frequency 33 or 66 MHz or quit to abort\n");
70                 nbytes = readline (" ? ");
71
72                 if (strcmp(console_buffer, "quit") == 0)
73                         return 0;
74
75                 if ((strcmp(console_buffer, "33") != 0) &
76                                 (strcmp(console_buffer, "66") != 0))
77                         nbytes=0;
78
79                 strcpy(sysClock, console_buffer);
80
81         } while (nbytes == 0);
82
83         do {
84                 if (strcmp(sysClock, "66") == 0) {
85                         printf("enter cpu clock frequency 400, 533 MHz or quit to abort\n");
86                 } else {
87 #ifdef  CONFIG_STRESS
88                         printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n");
89 #else
90                         printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n");
91 #endif
92                 }
93                 nbytes = readline (" ? ");
94
95                 if (strcmp(console_buffer, "quit") == 0)
96                         return 0;
97
98                 if (strcmp(sysClock, "66") == 0) {
99                         if ((strcmp(console_buffer, "400") != 0) &
100                                         (strcmp(console_buffer, "533") != 0)
101 #ifdef  CONFIG_STRESS
102                                         & (strcmp(console_buffer, "667") != 0)
103 #endif
104                            ) {
105                                 nbytes = 0;
106                         }
107                 } else {
108                         if ((strcmp(console_buffer, "400") != 0) &
109                                         (strcmp(console_buffer, "500") != 0) &
110                                         (strcmp(console_buffer, "533") != 0)
111 #ifdef  CONFIG_STRESS
112                                         & (strcmp(console_buffer, "667") != 0)
113 #endif
114                            ) {
115                                 nbytes = 0;
116                         }
117                 }
118
119                 strcpy(cpuClock, console_buffer);
120
121         } while (nbytes == 0);
122
123         if (strcmp(cpuClock, "500") == 0){
124                 strcpy(plbClock, "166");
125         } else if (strcmp(cpuClock, "533") == 0){
126                 strcpy(plbClock, "133");
127         } else {
128                 do {
129                         if (strcmp(cpuClock, "400") == 0)
130                                 printf("enter plb clock frequency 100, 133 MHz or quit to abort\n");
131
132 #ifdef  CONFIG_STRESS
133                         if (strcmp(cpuClock, "667") == 0)
134                                 printf("enter plb clock frequency 133, 166 MHz or quit to abort\n");
135
136 #endif
137                         nbytes = readline (" ? ");
138
139                         if (strcmp(console_buffer, "quit") == 0)
140                                 return 0;
141
142                         if (strcmp(cpuClock, "400") == 0) {
143                                 if ((strcmp(console_buffer, "100") != 0) &
144                                                 (strcmp(console_buffer, "133") != 0))
145                                         nbytes = 0;
146                         }
147 #ifdef  CONFIG_STRESS
148                         if (strcmp(cpuClock, "667") == 0) {
149                                 if ((strcmp(console_buffer, "133") != 0) &
150                                                 (strcmp(console_buffer, "166") != 0))
151                                         nbytes = 0;
152                         }
153 #endif
154                         strcpy(plbClock, console_buffer);
155
156                 } while (nbytes == 0);
157         }
158
159         do {
160                 printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n");
161                 nbytes = readline (" ? ");
162
163                 if (strcmp(console_buffer, "quit") == 0)
164                         return 0;
165
166                 if ((strcmp(console_buffer, "33") != 0) &
167                                 (strcmp(console_buffer, "66") != 0) &
168                                 (strcmp(console_buffer, "100") != 0) &
169                                 (strcmp(console_buffer, "133") != 0)) {
170                         nbytes = 0;
171                 }
172                 strcpy(pcixClock, console_buffer);
173
174         } while (nbytes == 0);
175
176         printf("\nsys clk   = %s MHz\n", sysClock);
177         printf("cpu clk   = %s MHz\n", cpuClock);
178         printf("plb clk   = %s MHz\n", plbClock);
179         printf("Pci-X clk = %s MHz\n", pcixClock);
180
181         do {
182                 printf("\npress [y] to write I2C bootstrap \n");
183                 printf("or [n] to abort.  \n");
184                 printf("Don't forget to set board switches \n");
185                 printf("according to your choice before re-starting \n");
186                 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
187
188                 nbytes = readline (" ? ");
189                 if (strcmp(console_buffer, "n") == 0)
190                         return 0;
191
192         } while (nbytes == 0);
193
194         if (strcmp(sysClock, "33") == 0) {
195                 if ((strcmp(cpuClock, "400") == 0) &
196                                 (strcmp(plbClock, "100") == 0))
197                         data = 0x8678c206;
198
199                 if ((strcmp(cpuClock, "400") == 0) &
200                                 (strcmp(plbClock, "133") == 0))
201                         data = 0x8678c2c6;
202
203                 if ((strcmp(cpuClock, "500") == 0))
204                         data = 0x8778f2c6;
205
206                 if ((strcmp(cpuClock, "533") == 0))
207                         data = 0x87790252;
208
209 #ifdef  CONFIG_STRESS
210                 if ((strcmp(cpuClock, "667") == 0) &
211                                 (strcmp(plbClock, "133") == 0))
212                         data = 0x87794256;
213
214                 if ((strcmp(cpuClock, "667") == 0) &
215                                 (strcmp(plbClock, "166") == 0))
216                         data = 0x87794206;
217
218 #endif
219         }
220         if (strcmp(sysClock, "66") == 0) {
221                 if ((strcmp(cpuClock, "400") == 0) &
222                                 (strcmp(plbClock, "100") == 0))
223                         data = 0x84706206;
224
225                 if ((strcmp(cpuClock, "400") == 0) &
226                                 (strcmp(plbClock, "133") == 0))
227                         data = 0x847062c6;
228
229                 if ((strcmp(cpuClock, "533") == 0))
230                         data = 0x85708206;
231
232 #ifdef  CONFIG_STRESS
233                 if ((strcmp(cpuClock, "667") == 0) &
234                                 (strcmp(plbClock, "133") == 0))
235                         data = 0x8570a256;
236
237                 if ((strcmp(cpuClock, "667") == 0) &
238                                 (strcmp(plbClock, "166") == 0))
239                         data = 0x8570a206;
240
241 #endif
242         }
243
244 #ifdef  DEBUG
245         printf(" pin strap0 to write in i2c  = %x\n", data);
246 #endif  /* DEBUG */
247
248         if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
249                 printf("Error writing strap0 in %s\n", argv[2]);
250
251         if (strcmp(pcixClock, "33") == 0)
252                 data = 0x00000701;
253
254         if (strcmp(pcixClock, "66") == 0)
255                 data = 0x00000601;
256
257         if (strcmp(pcixClock, "100") == 0)
258                 data = 0x00000501;
259
260         if (strcmp(pcixClock, "133") == 0)
261                 data = 0x00000401;
262
263         if (strcmp(plbClock, "166") == 0)
264                 data = data | 0x05950000;
265         else
266                 data = data | 0x05A50000;
267
268 #ifdef  DEBUG
269         printf(" pin strap1 to write in i2c  = %x\n", data);
270 #endif  /* DEBUG */
271
272         udelay(1000);
273         if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
274                 printf("Error writing strap1 in %s\n", argv[2]);
275
276         return 0;
277 }
278
279 U_BOOT_CMD(
280         evb440spe,      3,      1,      do_evb440spe,
281         "program the serial device strap",
282         "wrclk [prom0|prom1] - program the serial device strap"
283 );