blob: 703d225606959d352cc3b10a6ef3665eec40c01c [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 */
Stefan Roeseda6ebc12007-03-31 13:16:23 +020031#define DEBUG
Stefan Roese490e5732007-03-31 08:47:34 +020032
Stefan Roese4745aca2007-02-20 10:57:08 +010033static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
34{
35 uchar chip;
36 ulong data;
37 int nbytes;
38 extern char console_buffer[];
39
40 char sysClock[4];
41 char cpuClock[4];
42 char plbClock[4];
43 char pcixClock[4];
44
45 if (argc < 3) {
46 printf ("Usage:\n%s\n", cmdtp->usage);
47 return 1;
48 }
49
50 if (strcmp(argv[2], "prom0") == 0)
51 chip = IIC0_BOOTPROM_ADDR;
52 else
53 chip = IIC0_ALT_BOOTPROM_ADDR;
54
Stefan Roese490e5732007-03-31 08:47:34 +020055 /* on Katmai SysClk is always 33MHz */
56 strcpy(sysClock, "33");
Stefan Roese4745aca2007-02-20 10:57:08 +010057
58 do {
Stefan Roese4745aca2007-02-20 10:57:08 +010059#ifdef CONFIG_STRESS
Stefan Roese490e5732007-03-31 08:47:34 +020060 printf("enter cpu clock frequency 400, 500, 533, 667 Mhz or quit to abort\n");
Stefan Roese4745aca2007-02-20 10:57:08 +010061#else
Stefan Roese490e5732007-03-31 08:47:34 +020062 printf("enter cpu clock frequency 400, 500, 533 Mhz or quit to abort\n");
Stefan Roese4745aca2007-02-20 10:57:08 +010063#endif
Stefan Roese4745aca2007-02-20 10:57:08 +010064 nbytes = readline (" ? ");
65
66 if (strcmp(console_buffer, "quit") == 0)
67 return 0;
68
Stefan Roese490e5732007-03-31 08:47:34 +020069 if ((strcmp(console_buffer, "400") != 0) &&
70 (strcmp(console_buffer, "500") != 0) &&
71 (strcmp(console_buffer, "533") != 0)
Stefan Roese4745aca2007-02-20 10:57:08 +010072#ifdef CONFIG_STRESS
Stefan Roese490e5732007-03-31 08:47:34 +020073 && (strcmp(console_buffer, "667") != 0)
Stefan Roese4745aca2007-02-20 10:57:08 +010074#endif
Stefan Roese490e5732007-03-31 08:47:34 +020075 ) {
76 nbytes = 0;
Stefan Roese4745aca2007-02-20 10:57:08 +010077 }
78
79 strcpy(cpuClock, console_buffer);
80
81 } while (nbytes == 0);
82
83 if (strcmp(cpuClock, "500") == 0)
84 strcpy(plbClock, "166");
85 else if (strcmp(cpuClock, "533") == 0)
86 strcpy(plbClock, "133");
87 else {
88 do {
89 if (strcmp(cpuClock, "400") == 0)
90 printf("enter plb clock frequency 100, 133 Mhz or quit to abort\n");
91
92#ifdef CONFIG_STRESS
93 if (strcmp(cpuClock, "667") == 0)
94 printf("enter plb clock frequency 133, 166 Mhz or quit to abort\n");
95
96#endif
97 nbytes = readline (" ? ");
98
99 if (strcmp(console_buffer, "quit") == 0)
100 return 0;
101
102 if (strcmp(cpuClock, "400") == 0) {
Stefan Roese490e5732007-03-31 08:47:34 +0200103 if ((strcmp(console_buffer, "100") != 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100104 (strcmp(console_buffer, "133") != 0))
105 nbytes = 0;
106 }
107#ifdef CONFIG_STRESS
108 if (strcmp(cpuClock, "667") == 0) {
Stefan Roese490e5732007-03-31 08:47:34 +0200109 if ((strcmp(console_buffer, "133") != 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100110 (strcmp(console_buffer, "166") != 0))
111 nbytes = 0;
112 }
113#endif
114 strcpy(plbClock, console_buffer);
115
116 } while (nbytes == 0);
117 }
118
119 do {
120 printf("enter Pci-X clock frequency 33, 66, 100 or 133 Mhz or quit to abort\n");
121 nbytes = readline (" ? ");
122
123 if (strcmp(console_buffer, "quit") == 0)
124 return 0;
125
Stefan Roese490e5732007-03-31 08:47:34 +0200126 if ((strcmp(console_buffer, "33") != 0) &&
127 (strcmp(console_buffer, "66") != 0) &&
128 (strcmp(console_buffer, "100") != 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100129 (strcmp(console_buffer, "133") != 0)) {
130 nbytes = 0;
131 }
132 strcpy(pcixClock, console_buffer);
133
134 } while (nbytes == 0);
135
136 printf("\nsys clk = %sMhz\n", sysClock);
137 printf("cpu clk = %sMhz\n", cpuClock);
138 printf("plb clk = %sMhz\n", plbClock);
139 printf("Pci-X clk = %sMhz\n", pcixClock);
140
141 do {
142 printf("\npress [y] to write I2C bootstrap \n");
143 printf("or [n] to abort. \n");
144 printf("Don't forget to set board switches \n");
145 printf("according to your choice before re-starting \n");
146 printf("(refer to 440spe_uboot_kit_um_1_01.pdf) \n");
147
148 nbytes = readline (" ? ");
149 if (strcmp(console_buffer, "n") == 0)
150 return 0;
151
152 } while (nbytes == 0);
153
154 if (strcmp(sysClock, "33") == 0) {
Stefan Roese490e5732007-03-31 08:47:34 +0200155 if ((strcmp(cpuClock, "400") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100156 (strcmp(plbClock, "100") == 0))
157 data = 0x8678c206;
158
Stefan Roese490e5732007-03-31 08:47:34 +0200159 if ((strcmp(cpuClock, "400") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100160 (strcmp(plbClock, "133") == 0))
161 data = 0x8678c2c6;
162
163 if ((strcmp(cpuClock, "500") == 0))
164 data = 0x8778f2c6;
165
166 if ((strcmp(cpuClock, "533") == 0))
167 data = 0x87790252;
Stefan Roese4745aca2007-02-20 10:57:08 +0100168#ifdef CONFIG_STRESS
Stefan Roese490e5732007-03-31 08:47:34 +0200169 if ((strcmp(cpuClock, "667") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100170 (strcmp(plbClock, "133") == 0))
171 data = 0x87794256;
172
Stefan Roese490e5732007-03-31 08:47:34 +0200173 if ((strcmp(cpuClock, "667") == 0) &&
Stefan Roese4745aca2007-02-20 10:57:08 +0100174 (strcmp(plbClock, "166") == 0))
175 data = 0x87794206;
Stefan Roese4745aca2007-02-20 10:57:08 +0100176#endif
177 }
Stefan Roese4745aca2007-02-20 10:57:08 +0100178#ifdef DEBUG
Stefan Roeseb0021442008-07-10 09:58:06 +0200179 printf(" pin strap0 to write in i2c = %lx\n", data);
Stefan Roese4745aca2007-02-20 10:57:08 +0100180#endif /* DEBUG */
181
182 if (i2c_write(chip, 0, 1, (uchar *)&data, 4) != 0)
183 printf("Error writing strap0 in %s\n", argv[2]);
184
185 if (strcmp(pcixClock, "33") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200186 data = 0x000007E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100187
188 if (strcmp(pcixClock, "66") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200189 data = 0x000006E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100190
191 if (strcmp(pcixClock, "100") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200192 data = 0x000005E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100193
194 if (strcmp(pcixClock, "133") == 0)
Stefan Roese490e5732007-03-31 08:47:34 +0200195 data = 0x000004E1;
Stefan Roese4745aca2007-02-20 10:57:08 +0100196
197 if (strcmp(plbClock, "166") == 0)
Stefan Roeseda6ebc12007-03-31 13:16:23 +0200198/* data |= 0x05950000; */ /* this set's DDR2 clock == PLB clock */
199 data |= 0x05A50000; /* this set's DDR2 clock == 2 * PLB clock */
Stefan Roese4745aca2007-02-20 10:57:08 +0100200 else
201 data |= 0x05A50000;
202
203#ifdef DEBUG
Stefan Roeseb0021442008-07-10 09:58:06 +0200204 printf(" pin strap1 to write in i2c = %lx\n", data);
Stefan Roese4745aca2007-02-20 10:57:08 +0100205#endif /* DEBUG */
206
207 udelay(1000);
208 if (i2c_write(chip, 4, 1, (uchar *)&data, 4) != 0)
209 printf("Error writing strap1 in %s\n", argv[2]);
210
211 return 0;
212}
213
214U_BOOT_CMD(
215 bootstrap, 3, 1, do_bootstrap,
216 "bootstrap - program the serial device strap\n",
217 "wrclk [prom0|prom1] - program the serial device strap\n"
218 );