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