Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 1 | /* |
| 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 Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 30 | #define CONFIG_STRESS /* enable 667 MHz CPU freq selection */ |
Stefan Roese | da6ebc1 | 2007-03-31 13:16:23 +0200 | [diff] [blame] | 31 | #define DEBUG |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 32 | |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 33 | static 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) { |
Peter Tyser | 62c3ae7 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 46 | cmd_usage(cmdtp); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 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 Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 55 | /* on Katmai SysClk is always 33MHz */ |
| 56 | strcpy(sysClock, "33"); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 57 | |
| 58 | do { |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 59 | #ifdef CONFIG_STRESS |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 60 | printf("enter cpu clock frequency 400, 500, 533, 667 MHz or quit to abort\n"); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 61 | #else |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 62 | printf("enter cpu clock frequency 400, 500, 533 MHz or quit to abort\n"); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 63 | #endif |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 64 | nbytes = readline (" ? "); |
| 65 | |
| 66 | if (strcmp(console_buffer, "quit") == 0) |
| 67 | return 0; |
| 68 | |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 69 | if ((strcmp(console_buffer, "400") != 0) && |
| 70 | (strcmp(console_buffer, "500") != 0) && |
| 71 | (strcmp(console_buffer, "533") != 0) |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 72 | #ifdef CONFIG_STRESS |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 73 | && (strcmp(console_buffer, "667") != 0) |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 74 | #endif |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 75 | ) { |
| 76 | nbytes = 0; |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 77 | } |
| 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) |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 90 | printf("enter plb clock frequency 100, 133 MHz or quit to abort\n"); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 91 | |
| 92 | #ifdef CONFIG_STRESS |
| 93 | if (strcmp(cpuClock, "667") == 0) |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 94 | printf("enter plb clock frequency 133, 166 MHz or quit to abort\n"); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 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 Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 103 | if ((strcmp(console_buffer, "100") != 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 104 | (strcmp(console_buffer, "133") != 0)) |
| 105 | nbytes = 0; |
| 106 | } |
| 107 | #ifdef CONFIG_STRESS |
| 108 | if (strcmp(cpuClock, "667") == 0) { |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 109 | if ((strcmp(console_buffer, "133") != 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 110 | (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 { |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 120 | printf("enter Pci-X clock frequency 33, 66, 100 or 133 MHz or quit to abort\n"); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 121 | nbytes = readline (" ? "); |
| 122 | |
| 123 | if (strcmp(console_buffer, "quit") == 0) |
| 124 | return 0; |
| 125 | |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 126 | if ((strcmp(console_buffer, "33") != 0) && |
| 127 | (strcmp(console_buffer, "66") != 0) && |
| 128 | (strcmp(console_buffer, "100") != 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 129 | (strcmp(console_buffer, "133") != 0)) { |
| 130 | nbytes = 0; |
| 131 | } |
| 132 | strcpy(pcixClock, console_buffer); |
| 133 | |
| 134 | } while (nbytes == 0); |
| 135 | |
Wolfgang Denk | 8ed44d9 | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 136 | printf("\nsys clk = %s MHz\n", sysClock); |
| 137 | printf("cpu clk = %s MHz\n", cpuClock); |
| 138 | printf("plb clk = %s MHz\n", plbClock); |
| 139 | printf("Pci-X clk = %s MHz\n", pcixClock); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 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 Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 155 | if ((strcmp(cpuClock, "400") == 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 156 | (strcmp(plbClock, "100") == 0)) |
| 157 | data = 0x8678c206; |
| 158 | |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 159 | if ((strcmp(cpuClock, "400") == 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 160 | (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 Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 168 | #ifdef CONFIG_STRESS |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 169 | if ((strcmp(cpuClock, "667") == 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 170 | (strcmp(plbClock, "133") == 0)) |
| 171 | data = 0x87794256; |
| 172 | |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 173 | if ((strcmp(cpuClock, "667") == 0) && |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 174 | (strcmp(plbClock, "166") == 0)) |
| 175 | data = 0x87794206; |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 176 | #endif |
| 177 | } |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 178 | #ifdef DEBUG |
Stefan Roese | b002144 | 2008-07-10 09:58:06 +0200 | [diff] [blame] | 179 | printf(" pin strap0 to write in i2c = %lx\n", data); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 180 | #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 Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 186 | data = 0x000007E1; |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 187 | |
| 188 | if (strcmp(pcixClock, "66") == 0) |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 189 | data = 0x000006E1; |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 190 | |
| 191 | if (strcmp(pcixClock, "100") == 0) |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 192 | data = 0x000005E1; |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 193 | |
| 194 | if (strcmp(pcixClock, "133") == 0) |
Stefan Roese | 490e573 | 2007-03-31 08:47:34 +0200 | [diff] [blame] | 195 | data = 0x000004E1; |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 196 | |
| 197 | if (strcmp(plbClock, "166") == 0) |
Stefan Roese | da6ebc1 | 2007-03-31 13:16:23 +0200 | [diff] [blame] | 198 | /* data |= 0x05950000; */ /* this set's DDR2 clock == PLB clock */ |
| 199 | data |= 0x05A50000; /* this set's DDR2 clock == 2 * PLB clock */ |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 200 | else |
| 201 | data |= 0x05A50000; |
| 202 | |
| 203 | #ifdef DEBUG |
Stefan Roese | b002144 | 2008-07-10 09:58:06 +0200 | [diff] [blame] | 204 | printf(" pin strap1 to write in i2c = %lx\n", data); |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 205 | #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 | |
| 214 | U_BOOT_CMD( |
| 215 | bootstrap, 3, 1, do_bootstrap, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 216 | "program the serial device strap", |
Stefan Roese | 4745aca | 2007-02-20 10:57:08 +0100 | [diff] [blame] | 217 | "wrclk [prom0|prom1] - program the serial device strap\n" |
| 218 | ); |