blob: 0c42c394d6b6439206c4228f9a1cbf3685b4f3ab [file] [log] [blame]
Stefan Roese4745aca2007-02-20 10:57:08 +01001/*
2 * (C) Copyright 2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
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 */
24
25#include <common.h>
26#include <command.h>
27#include <i2c.h>
28#include <asm/byteorder.h>
29
Stefan Roese490e5732007-03-31 08:47:34 +020030#define CONFIG_STRESS /* enable 667 MHz CPU freq selection */
31
Stefan Roese4745aca2007-02-20 10:57:08 +010032static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
33{
34 uchar chip;
35 ulong data;
36 int nbytes;
37 extern char console_buffer[];
38
39 char sysClock[4];
40 char cpuClock[4];
41 char plbClock[4];
42 char pcixClock[4];
43
44 if (argc < 3) {
45 printf ("Usage:\n%s\n", cmdtp->usage);
46 return 1;
47 }
48
49 if (strcmp(argv[2], "prom0") == 0)
50 chip = IIC0_BOOTPROM_ADDR;
51 else
52 chip = IIC0_ALT_BOOTPROM_ADDR;
53
Stefan Roese490e5732007-03-31 08:47:34 +020054 /* on Katmai SysClk is always 33MHz */
55 strcpy(sysClock, "33");
Stefan Roese4745aca2007-02-20 10:57:08 +010056
57 do {
Stefan Roese4745aca2007-02-20 10:57:08 +010058#ifdef CONFIG_STRESS
Stefan Roese490e5732007-03-31 08:47:34 +020059 printf("enter cpu clock frequency 400, 500, 533, 667 Mhz or quit to abort\n");
Stefan Roese4745aca2007-02-20 10:57:08 +010060#else
Stefan Roese490e5732007-03-31 08:47:34 +020061 printf("enter cpu clock frequency 400, 500, 533 Mhz or quit to abort\n");
Stefan Roese4745aca2007-02-20 10:57:08 +010062#endif
Stefan Roese4745aca2007-02-20 10:57:08 +010063 nbytes = readline (" ? ");
64
65 if (strcmp(console_buffer, "quit") == 0)
66 return 0;
67
Stefan Roese490e5732007-03-31 08:47:34 +020068 if ((strcmp(console_buffer, "400") != 0) &&
69 (strcmp(console_buffer, "500") != 0) &&
70 (strcmp(console_buffer, "533") != 0)
Stefan Roese4745aca2007-02-20 10:57:08 +010071#ifdef CONFIG_STRESS
Stefan Roese490e5732007-03-31 08:47:34 +020072 && (strcmp(console_buffer, "667") != 0)
Stefan Roese4745aca2007-02-20 10:57:08 +010073#endif
Stefan Roese490e5732007-03-31 08:47:34 +020074 ) {
75 nbytes = 0;
Stefan Roese4745aca2007-02-20 10:57:08 +010076 }
77
78 strcpy(cpuClock, console_buffer);
79
80 } while (nbytes == 0);
81
82 if (strcmp(cpuClock, "500") == 0)
83 strcpy(plbClock, "166");
84 else if (strcmp(cpuClock, "533") == 0)
85 strcpy(plbClock, "133");
86 else {
87 do {
88 if (strcmp(cpuClock, "400") == 0)
89 printf("enter plb clock frequency 100, 133 Mhz or quit to abort\n");
90
91#ifdef CONFIG_STRESS
92 if (strcmp(cpuClock, "667") == 0)
93 printf("enter plb clock frequency 133, 166 Mhz or quit to abort\n");
94
95#endif
96 nbytes = readline (" ? ");
97
98 if (strcmp(console_buffer, "quit") == 0)
99 return 0;
100
101 if (strcmp(cpuClock, "400") == 0) {
Stefan Roese490e5732007-03-31 08:47:34 +0200102 if ((strcmp(console_buffer, "100") != 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100103 (strcmp(console_buffer, "133") != 0))
104 nbytes = 0;
105 }
106#ifdef CONFIG_STRESS
107 if (strcmp(cpuClock, "667") == 0) {
Stefan Roese490e5732007-03-31 08:47:34 +0200108 if ((strcmp(console_buffer, "133") != 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100109 (strcmp(console_buffer, "166") != 0))
110 nbytes = 0;
111 }
112#endif
113 strcpy(plbClock, console_buffer);
114
115 } while (nbytes == 0);
116 }
117
118 do {
119 printf("enter Pci-X clock frequency 33, 66, 100 or 133 Mhz or quit to abort\n");
120 nbytes = readline (" ? ");
121
122 if (strcmp(console_buffer, "quit") == 0)
123 return 0;
124
Stefan Roese490e5732007-03-31 08:47:34 +0200125 if ((strcmp(console_buffer, "33") != 0) &&
126 (strcmp(console_buffer, "66") != 0) &&
127 (strcmp(console_buffer, "100") != 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100128 (strcmp(console_buffer, "133") != 0)) {
129 nbytes = 0;
130 }
131 strcpy(pcixClock, console_buffer);
132
133 } while (nbytes == 0);
134
135 printf("\nsys clk = %sMhz\n", sysClock);
136 printf("cpu clk = %sMhz\n", cpuClock);
137 printf("plb clk = %sMhz\n", plbClock);
138 printf("Pci-X clk = %sMhz\n", pcixClock);
139
140 do {
141 printf("\npress [y] to write I2C bootstrap \n");
142 printf("or [n] to abort. \n");
143 printf("Don't forget to set board switches \n");
144 printf("according to your choice before re-starting \n");
145 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
146
147 nbytes = readline (" ? ");
148 if (strcmp(console_buffer, "n") == 0)
149 return 0;
150
151 } while (nbytes == 0);
152
153 if (strcmp(sysClock, "33") == 0) {
Stefan Roese490e5732007-03-31 08:47:34 +0200154 if ((strcmp(cpuClock, "400") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100155 (strcmp(plbClock, "100") == 0))
156 data = 0x8678c206;
157
Stefan Roese490e5732007-03-31 08:47:34 +0200158 if ((strcmp(cpuClock, "400") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100159 (strcmp(plbClock, "133") == 0))
160 data = 0x8678c2c6;
161
162 if ((strcmp(cpuClock, "500") == 0))
163 data = 0x8778f2c6;
164
165 if ((strcmp(cpuClock, "533") == 0))
166 data = 0x87790252;
Stefan Roese4745aca2007-02-20 10:57:08 +0100167#ifdef CONFIG_STRESS
Stefan Roese490e5732007-03-31 08:47:34 +0200168 if ((strcmp(cpuClock, "667") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100169 (strcmp(plbClock, "133") == 0))
170 data = 0x87794256;
171
Stefan Roese490e5732007-03-31 08:47:34 +0200172 if ((strcmp(cpuClock, "667") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100173 (strcmp(plbClock, "166") == 0))
174 data = 0x87794206;
Stefan Roese4745aca2007-02-20 10:57:08 +0100175#endif
176 }
Stefan Roese4745aca2007-02-20 10:57:08 +0100177#ifdef DEBUG
178 printf(" pin strap0 to write in i2c = %x\n", data);
179#endif /* DEBUG */
180
181 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
182 printf("Error writing strap0 in %s\n", argv[2]);
183
184 if (strcmp(pcixClock, "33") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200185 data = 0x000007E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100186
187 if (strcmp(pcixClock, "66") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200188 data = 0x000006E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100189
190 if (strcmp(pcixClock, "100") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200191 data = 0x000005E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100192
193 if (strcmp(pcixClock, "133") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200194 data = 0x000004E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100195
196 if (strcmp(plbClock, "166") == 0)
197 data |= 0x05950000;
198 else
199 data |= 0x05A50000;
200
201#ifdef DEBUG
202 printf(" pin strap1 to write in i2c = %x\n", data);
203#endif /* DEBUG */
204
205 udelay(1000);
206 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
207 printf("Error writing strap1 in %s\n", argv[2]);
208
209 return 0;
210}
211
212U_BOOT_CMD(
213 bootstrap, 3, 1, do_bootstrap,
214 "bootstrap - program the serial device strap\n",
215 "wrclk [prom0|prom1] - program the serial device strap\n"
216 );