Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 2 | /* |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 3 | * Copyright 2006,2010 Freescale Semiconductor |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 4 | * Jeff Brown |
| 5 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 9 | #include <command.h> |
Andy Fleming | db2b5bd | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 10 | #include <asm/io.h> |
Jon Loeliger | 4eab623 | 2008-01-15 13:42:41 -0600 | [diff] [blame] | 11 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 12 | #define pixis_base (u8 *)PIXIS_BASE |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * Simple board reset. |
| 16 | */ |
| 17 | void pixis_reset(void) |
| 18 | { |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 19 | out_8(pixis_base + PIXIS_RST, 0); |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 20 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 21 | while (1); |
| 22 | } |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 23 | |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 24 | /* |
| 25 | * Per table 27, page 58 of MPC8641HPCN spec. |
| 26 | */ |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 27 | static int set_px_sysclk(unsigned long sysclk) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 28 | { |
| 29 | u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux; |
| 30 | |
| 31 | switch (sysclk) { |
| 32 | case 33: |
| 33 | sysclk_s = 0x04; |
| 34 | sysclk_r = 0x04; |
| 35 | sysclk_v = 0x07; |
| 36 | sysclk_aux = 0x00; |
| 37 | break; |
| 38 | case 40: |
| 39 | sysclk_s = 0x01; |
| 40 | sysclk_r = 0x1F; |
| 41 | sysclk_v = 0x20; |
| 42 | sysclk_aux = 0x01; |
| 43 | break; |
| 44 | case 50: |
| 45 | sysclk_s = 0x01; |
| 46 | sysclk_r = 0x1F; |
| 47 | sysclk_v = 0x2A; |
| 48 | sysclk_aux = 0x02; |
| 49 | break; |
| 50 | case 66: |
| 51 | sysclk_s = 0x01; |
| 52 | sysclk_r = 0x04; |
| 53 | sysclk_v = 0x04; |
| 54 | sysclk_aux = 0x03; |
| 55 | break; |
| 56 | case 83: |
| 57 | sysclk_s = 0x01; |
| 58 | sysclk_r = 0x1F; |
| 59 | sysclk_v = 0x4B; |
| 60 | sysclk_aux = 0x04; |
| 61 | break; |
| 62 | case 100: |
| 63 | sysclk_s = 0x01; |
| 64 | sysclk_r = 0x1F; |
| 65 | sysclk_v = 0x5C; |
| 66 | sysclk_aux = 0x05; |
| 67 | break; |
| 68 | case 134: |
| 69 | sysclk_s = 0x06; |
| 70 | sysclk_r = 0x1F; |
| 71 | sysclk_v = 0x3B; |
| 72 | sysclk_aux = 0x06; |
| 73 | break; |
| 74 | case 166: |
| 75 | sysclk_s = 0x06; |
| 76 | sysclk_r = 0x1F; |
| 77 | sysclk_v = 0x4B; |
| 78 | sysclk_aux = 0x07; |
| 79 | break; |
| 80 | default: |
| 81 | printf("Unsupported SYSCLK frequency.\n"); |
| 82 | return 0; |
| 83 | } |
| 84 | |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 85 | vclkh = (sysclk_s << 5) | sysclk_r; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 86 | vclkl = sysclk_v; |
| 87 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 88 | out_8(pixis_base + PIXIS_VCLKH, vclkh); |
| 89 | out_8(pixis_base + PIXIS_VCLKL, vclkl); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 90 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 91 | out_8(pixis_base + PIXIS_AUX, sysclk_aux); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 92 | |
| 93 | return 1; |
| 94 | } |
| 95 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 96 | /* Set the CFG_SYSPLL bits |
| 97 | * |
| 98 | * This only has effect if PX_VCFGEN0[SYSPLL]=1, which is true if |
| 99 | * read_from_px_regs() is called. |
| 100 | */ |
| 101 | static int set_px_mpxpll(unsigned long mpxpll) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 102 | { |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 103 | switch (mpxpll) { |
| 104 | case 2: |
| 105 | case 4: |
| 106 | case 6: |
| 107 | case 8: |
| 108 | case 10: |
| 109 | case 12: |
| 110 | case 14: |
| 111 | case 16: |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 112 | clrsetbits_8(pixis_base + PIXIS_VSPEED1, 0x1F, mpxpll); |
| 113 | return 1; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 116 | printf("Unsupported MPXPLL ratio.\n"); |
| 117 | return 0; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 118 | } |
| 119 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 120 | static int set_px_corepll(unsigned long corepll) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 121 | { |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 122 | u8 val; |
| 123 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 124 | switch (corepll) { |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 125 | case 20: |
| 126 | val = 0x08; |
| 127 | break; |
| 128 | case 25: |
| 129 | val = 0x0C; |
| 130 | break; |
| 131 | case 30: |
| 132 | val = 0x10; |
| 133 | break; |
| 134 | case 35: |
| 135 | val = 0x1C; |
| 136 | break; |
| 137 | case 40: |
| 138 | val = 0x14; |
| 139 | break; |
| 140 | case 45: |
| 141 | val = 0x0E; |
| 142 | break; |
| 143 | default: |
| 144 | printf("Unsupported COREPLL ratio.\n"); |
| 145 | return 0; |
| 146 | } |
| 147 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 148 | clrsetbits_8(pixis_base + PIXIS_VSPEED0, 0x1F, val); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 149 | return 1; |
| 150 | } |
| 151 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 152 | #ifndef CFG_SYS_PIXIS_VCFGEN0_ENABLE |
| 153 | #define CFG_SYS_PIXIS_VCFGEN0_ENABLE 0x1C |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 154 | #endif |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 155 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 156 | /* Tell the PIXIS where to find the COREPLL, MPXPLL, SYSCLK values |
| 157 | * |
| 158 | * The PIXIS can be programmed to look at either the on-board dip switches |
| 159 | * or various other PIXIS registers to determine the values for COREPLL, |
| 160 | * MPXPLL, and SYSCLK. |
| 161 | * |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 162 | * CFG_SYS_PIXIS_VCFGEN0_ENABLE is the value to write to the PIXIS_VCFGEN0 |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 163 | * register that tells the pixis to use the various PIXIS register. |
| 164 | */ |
| 165 | static void read_from_px_regs(int set) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 166 | { |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 167 | u8 tmp = in_8(pixis_base + PIXIS_VCFGEN0); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 168 | |
| 169 | if (set) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 170 | tmp = tmp | CFG_SYS_PIXIS_VCFGEN0_ENABLE; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 171 | else |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 172 | tmp = tmp & ~CFG_SYS_PIXIS_VCFGEN0_ENABLE; |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 173 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 174 | out_8(pixis_base + PIXIS_VCFGEN0, tmp); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 175 | } |
| 176 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 177 | /* CFG_SYS_PIXIS_VBOOT_ENABLE is the value to write to the PX_VCFGEN1 |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 178 | * register that tells the pixis to use the PX_VBOOT[LBMAP] register. |
| 179 | */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 180 | #ifndef CFG_SYS_PIXIS_VBOOT_ENABLE |
| 181 | #define CFG_SYS_PIXIS_VBOOT_ENABLE 0x04 |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 182 | #endif |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 183 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 184 | /* Configure the source of the boot location |
| 185 | * |
| 186 | * The PIXIS can be programmed to look at either the on-board dip switches |
| 187 | * or the PX_VBOOT[LBMAP] register to determine where we should boot. |
| 188 | * |
| 189 | * If we want to boot from the alternate boot bank, we need to tell the PIXIS |
| 190 | * to ignore the on-board dip switches and use the PX_VBOOT[LBMAP] instead. |
| 191 | */ |
| 192 | static void read_from_px_regs_altbank(int set) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 193 | { |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 194 | u8 tmp = in_8(pixis_base + PIXIS_VCFGEN1); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 195 | |
| 196 | if (set) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 197 | tmp = tmp | CFG_SYS_PIXIS_VBOOT_ENABLE; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 198 | else |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 199 | tmp = tmp & ~CFG_SYS_PIXIS_VBOOT_ENABLE; |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 200 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 201 | out_8(pixis_base + PIXIS_VCFGEN1, tmp); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 202 | } |
| 203 | |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 204 | /* CFG_SYS_PIXIS_VBOOT_MASK contains the bits to set in VBOOT register that |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 205 | * tells the PIXIS what the alternate flash bank is. |
| 206 | * |
| 207 | * Note that it's not really a mask. It contains the actual LBMAP bits that |
| 208 | * must be set to select the alternate bank. This code assumes that the |
| 209 | * primary bank has these bits set to 0, and the alternate bank has these |
| 210 | * bits set to 1. |
| 211 | */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 212 | #ifndef CFG_SYS_PIXIS_VBOOT_MASK |
| 213 | #define CFG_SYS_PIXIS_VBOOT_MASK (0x40) |
Jason Jin | f08899a | 2007-10-29 19:26:21 +0800 | [diff] [blame] | 214 | #endif |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 215 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 216 | /* Tell the PIXIS to boot from the default flash bank |
| 217 | * |
| 218 | * Program the default flash bank into the VBOOT register. This register is |
| 219 | * used only if PX_VCFGEN1[FLASH]=1. |
| 220 | */ |
| 221 | static void clear_altbank(void) |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 222 | { |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 223 | clrbits_8(pixis_base + PIXIS_VBOOT, CFG_SYS_PIXIS_VBOOT_MASK); |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 224 | } |
| 225 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 226 | /* Tell the PIXIS to boot from the alternate flash bank |
| 227 | * |
| 228 | * Program the alternate flash bank into the VBOOT register. This register is |
| 229 | * used only if PX_VCFGEN1[FLASH]=1. |
| 230 | */ |
| 231 | static void set_altbank(void) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 232 | { |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 233 | setbits_8(pixis_base + PIXIS_VBOOT, CFG_SYS_PIXIS_VBOOT_MASK); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 236 | /* Reset the board with watchdog disabled. |
| 237 | * |
| 238 | * This respects the altbank setting. |
| 239 | */ |
| 240 | static void set_px_go(void) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 241 | { |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 242 | /* Disable the VELA sequencer and watchdog */ |
| 243 | clrbits_8(pixis_base + PIXIS_VCTL, 9); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 244 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 245 | /* Reboot by starting the VELA sequencer */ |
| 246 | setbits_8(pixis_base + PIXIS_VCTL, 0x1); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 247 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 248 | while (1); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 249 | } |
| 250 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 251 | /* Reset the board with watchdog enabled. |
| 252 | * |
| 253 | * This respects the altbank setting. |
| 254 | */ |
| 255 | static void set_px_go_with_watchdog(void) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 256 | { |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 257 | /* Disable the VELA sequencer */ |
| 258 | clrbits_8(pixis_base + PIXIS_VCTL, 1); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 259 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 260 | /* Enable the watchdog and reboot by starting the VELA sequencer */ |
| 261 | setbits_8(pixis_base + PIXIS_VCTL, 0x9); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 262 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 263 | while (1); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 264 | } |
| 265 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 266 | /* Disable the watchdog |
| 267 | * |
| 268 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 269 | static int pixis_disable_watchdog_cmd(struct cmd_tbl *cmdtp, int flag, int argc, |
| 270 | char *const argv[]) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 271 | { |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 272 | /* Disable the VELA sequencer and the watchdog */ |
| 273 | clrbits_8(pixis_base + PIXIS_VCTL, 9); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 278 | U_BOOT_CMD( |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 279 | diswd, 1, 0, pixis_disable_watchdog_cmd, |
| 280 | "Disable watchdog timer", |
| 281 | "" |
| 282 | ); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 283 | |
| 284 | /* |
| 285 | * This function takes the non-integral cpu:mpx pll ratio |
| 286 | * and converts it to an integer that can be used to assign |
| 287 | * FPGA register values. |
| 288 | * input: strptr i.e. argv[2] |
| 289 | */ |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 290 | static unsigned long strfractoint(char *strptr) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 291 | { |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 292 | int i, j; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 293 | int mulconst; |
Kumar Gala | 85e4412 | 2011-11-09 10:02:11 -0600 | [diff] [blame] | 294 | int no_dec = 0; |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 295 | unsigned long intval = 0, decval = 0; |
| 296 | char intarr[3], decarr[3]; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 297 | |
| 298 | /* Assign the integer part to intarr[] |
| 299 | * If there is no decimal point i.e. |
| 300 | * if the ratio is an integral value |
| 301 | * simply create the intarr. |
| 302 | */ |
| 303 | i = 0; |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 304 | while (strptr[i] != '.') { |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 305 | if (strptr[i] == 0) { |
| 306 | no_dec = 1; |
| 307 | break; |
| 308 | } |
| 309 | intarr[i] = strptr[i]; |
| 310 | i++; |
| 311 | } |
| 312 | |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 313 | intarr[i] = '\0'; |
| 314 | |
| 315 | if (no_dec) { |
| 316 | /* Currently needed only for single digit corepll ratios */ |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 317 | mulconst = 10; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 318 | decval = 0; |
| 319 | } else { |
| 320 | j = 0; |
Jon Loeliger | 4fbb09c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 321 | i++; /* Skipping the decimal point */ |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 322 | while ((strptr[i] >= '0') && (strptr[i] <= '9')) { |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 323 | decarr[j] = strptr[i]; |
| 324 | i++; |
| 325 | j++; |
| 326 | } |
| 327 | |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 328 | decarr[j] = '\0'; |
| 329 | |
| 330 | mulconst = 1; |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 331 | for (i = 0; i < j; i++) |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 332 | mulconst *= 10; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 333 | decval = dectoul(decarr, NULL); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 334 | } |
| 335 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 336 | intval = dectoul(intarr, NULL); |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 337 | intval = intval * mulconst; |
| 338 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 339 | return intval + decval; |
Jon Loeliger | d68e2ba | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 340 | } |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 341 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 342 | static int pixis_reset_cmd(struct cmd_tbl *cmdtp, int flag, int argc, |
| 343 | char *const argv[]) |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 344 | { |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 345 | unsigned int i; |
| 346 | char *p_cf = NULL; |
| 347 | char *p_cf_sysclk = NULL; |
| 348 | char *p_cf_corepll = NULL; |
| 349 | char *p_cf_mpxpll = NULL; |
| 350 | char *p_altbank = NULL; |
| 351 | char *p_wd = NULL; |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 352 | int unknown_param = 0; |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * No args is a simple reset request. |
| 356 | */ |
| 357 | if (argc <= 1) { |
| 358 | pixis_reset(); |
| 359 | /* not reached */ |
| 360 | } |
| 361 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 362 | for (i = 1; i < argc; i++) { |
| 363 | if (strcmp(argv[i], "cf") == 0) { |
| 364 | p_cf = argv[i]; |
| 365 | if (i + 3 >= argc) { |
| 366 | break; |
| 367 | } |
| 368 | p_cf_sysclk = argv[i+1]; |
| 369 | p_cf_corepll = argv[i+2]; |
| 370 | p_cf_mpxpll = argv[i+3]; |
| 371 | i += 3; |
| 372 | continue; |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 373 | } |
| 374 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 375 | if (strcmp(argv[i], "altbank") == 0) { |
| 376 | p_altbank = argv[i]; |
| 377 | continue; |
| 378 | } |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 379 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 380 | if (strcmp(argv[i], "wd") == 0) { |
| 381 | p_wd = argv[i]; |
| 382 | continue; |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 383 | } |
| 384 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 385 | unknown_param = 1; |
| 386 | } |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 387 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 388 | /* |
| 389 | * Check that cf has all required parms |
| 390 | */ |
| 391 | if ((p_cf && !(p_cf_sysclk && p_cf_corepll && p_cf_mpxpll)) |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 392 | || unknown_param) { |
Ed Swarthout | 06c70d6 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 393 | #ifdef CONFIG_SYS_LONGHELP |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 394 | puts(cmdtp->help); |
York Sun | 13444b2 | 2013-05-31 08:48:04 -0700 | [diff] [blame] | 395 | putc('\n'); |
Ed Swarthout | 06c70d6 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 396 | #endif |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 397 | return 1; |
| 398 | } |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 399 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 400 | /* |
| 401 | * PIXIS seems to be sensitive to the ordering of |
| 402 | * the registers that are touched. |
| 403 | */ |
| 404 | read_from_px_regs(0); |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 405 | |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 406 | if (p_altbank) |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 407 | read_from_px_regs_altbank(0); |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 408 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 409 | clear_altbank(); |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 410 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 411 | /* |
| 412 | * Clock configuration specified. |
| 413 | */ |
| 414 | if (p_cf) { |
| 415 | unsigned long sysclk; |
| 416 | unsigned long corepll; |
| 417 | unsigned long mpxpll; |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 418 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 419 | sysclk = dectoul(p_cf_sysclk, NULL); |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 420 | corepll = strfractoint(p_cf_corepll); |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 421 | mpxpll = dectoul(p_cf_mpxpll, NULL); |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 422 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 423 | if (!(set_px_sysclk(sysclk) |
| 424 | && set_px_corepll(corepll) |
| 425 | && set_px_mpxpll(mpxpll))) { |
Ed Swarthout | 06c70d6 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 426 | #ifdef CONFIG_SYS_LONGHELP |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 427 | puts(cmdtp->help); |
York Sun | 13444b2 | 2013-05-31 08:48:04 -0700 | [diff] [blame] | 428 | putc('\n'); |
Ed Swarthout | 06c70d6 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 429 | #endif |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 430 | return 1; |
| 431 | } |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 432 | read_from_px_regs(1); |
| 433 | } |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 434 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 435 | /* |
| 436 | * Altbank specified |
| 437 | * |
| 438 | * NOTE CHANGE IN BEHAVIOR: previous code would default |
| 439 | * to enabling watchdog if altbank is specified. |
| 440 | * Now the watchdog must be enabled explicitly using 'wd'. |
| 441 | */ |
| 442 | if (p_altbank) { |
| 443 | set_altbank(); |
| 444 | read_from_px_regs_altbank(1); |
| 445 | } |
| 446 | |
| 447 | /* |
| 448 | * Reset with watchdog specified. |
| 449 | */ |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 450 | if (p_wd) |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 451 | set_px_go_with_watchdog(); |
Timur Tabi | 7ba8b32 | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 452 | else |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 453 | set_px_go(); |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 454 | |
James Yang | 61f1781 | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 455 | /* |
| 456 | * Shouldn't be reached. |
| 457 | */ |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | |
| 462 | U_BOOT_CMD( |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 463 | pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 464 | "Reset the board using the FPGA sequencer", |
Haiying Wang | 57b6e9c | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 465 | " pixis_reset\n" |
| 466 | " pixis_reset [altbank]\n" |
| 467 | " pixis_reset altbank wd\n" |
| 468 | " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 469 | " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>" |
| 470 | ); |