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