Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 1 | /* |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 2 | * Copyright 2006,2010 Freescale Semiconductor |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 3 | * Jeff Brown |
| 4 | * Srikanth Srinivasan (srikanth.srinivasan@freescale.com) |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 26 | #include <command.h> |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 27 | #include <asm/io.h> |
Jon Loeliger | ad8f868 | 2008-01-15 13:42:41 -0600 | [diff] [blame] | 28 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 29 | #define pixis_base (u8 *)PIXIS_BASE |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Simple board reset. |
| 33 | */ |
| 34 | void pixis_reset(void) |
| 35 | { |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 36 | out_8(pixis_base + PIXIS_RST, 0); |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 37 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 38 | while (1); |
| 39 | } |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 40 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 41 | /* |
| 42 | * Per table 27, page 58 of MPC8641HPCN spec. |
| 43 | */ |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 44 | static int set_px_sysclk(unsigned long sysclk) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 45 | { |
| 46 | u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux; |
| 47 | |
| 48 | switch (sysclk) { |
| 49 | case 33: |
| 50 | sysclk_s = 0x04; |
| 51 | sysclk_r = 0x04; |
| 52 | sysclk_v = 0x07; |
| 53 | sysclk_aux = 0x00; |
| 54 | break; |
| 55 | case 40: |
| 56 | sysclk_s = 0x01; |
| 57 | sysclk_r = 0x1F; |
| 58 | sysclk_v = 0x20; |
| 59 | sysclk_aux = 0x01; |
| 60 | break; |
| 61 | case 50: |
| 62 | sysclk_s = 0x01; |
| 63 | sysclk_r = 0x1F; |
| 64 | sysclk_v = 0x2A; |
| 65 | sysclk_aux = 0x02; |
| 66 | break; |
| 67 | case 66: |
| 68 | sysclk_s = 0x01; |
| 69 | sysclk_r = 0x04; |
| 70 | sysclk_v = 0x04; |
| 71 | sysclk_aux = 0x03; |
| 72 | break; |
| 73 | case 83: |
| 74 | sysclk_s = 0x01; |
| 75 | sysclk_r = 0x1F; |
| 76 | sysclk_v = 0x4B; |
| 77 | sysclk_aux = 0x04; |
| 78 | break; |
| 79 | case 100: |
| 80 | sysclk_s = 0x01; |
| 81 | sysclk_r = 0x1F; |
| 82 | sysclk_v = 0x5C; |
| 83 | sysclk_aux = 0x05; |
| 84 | break; |
| 85 | case 134: |
| 86 | sysclk_s = 0x06; |
| 87 | sysclk_r = 0x1F; |
| 88 | sysclk_v = 0x3B; |
| 89 | sysclk_aux = 0x06; |
| 90 | break; |
| 91 | case 166: |
| 92 | sysclk_s = 0x06; |
| 93 | sysclk_r = 0x1F; |
| 94 | sysclk_v = 0x4B; |
| 95 | sysclk_aux = 0x07; |
| 96 | break; |
| 97 | default: |
| 98 | printf("Unsupported SYSCLK frequency.\n"); |
| 99 | return 0; |
| 100 | } |
| 101 | |
Jon Loeliger | 80e955c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 102 | vclkh = (sysclk_s << 5) | sysclk_r; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 103 | vclkl = sysclk_v; |
| 104 | |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 105 | out_8(pixis_base + PIXIS_VCLKH, vclkh); |
| 106 | out_8(pixis_base + PIXIS_VCLKL, vclkl); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 107 | |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 108 | out_8(pixis_base + PIXIS_AUX, sysclk_aux); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 109 | |
| 110 | return 1; |
| 111 | } |
| 112 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 113 | /* Set the CFG_SYSPLL bits |
| 114 | * |
| 115 | * This only has effect if PX_VCFGEN0[SYSPLL]=1, which is true if |
| 116 | * read_from_px_regs() is called. |
| 117 | */ |
| 118 | static int set_px_mpxpll(unsigned long mpxpll) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 119 | { |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 120 | switch (mpxpll) { |
| 121 | case 2: |
| 122 | case 4: |
| 123 | case 6: |
| 124 | case 8: |
| 125 | case 10: |
| 126 | case 12: |
| 127 | case 14: |
| 128 | case 16: |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 129 | clrsetbits_8(pixis_base + PIXIS_VSPEED1, 0x1F, mpxpll); |
| 130 | return 1; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 133 | printf("Unsupported MPXPLL ratio.\n"); |
| 134 | return 0; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 137 | static int set_px_corepll(unsigned long corepll) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 138 | { |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 139 | u8 val; |
| 140 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 141 | switch (corepll) { |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 142 | case 20: |
| 143 | val = 0x08; |
| 144 | break; |
| 145 | case 25: |
| 146 | val = 0x0C; |
| 147 | break; |
| 148 | case 30: |
| 149 | val = 0x10; |
| 150 | break; |
| 151 | case 35: |
| 152 | val = 0x1C; |
| 153 | break; |
| 154 | case 40: |
| 155 | val = 0x14; |
| 156 | break; |
| 157 | case 45: |
| 158 | val = 0x0E; |
| 159 | break; |
| 160 | default: |
| 161 | printf("Unsupported COREPLL ratio.\n"); |
| 162 | return 0; |
| 163 | } |
| 164 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 165 | clrsetbits_8(pixis_base + PIXIS_VSPEED0, 0x1F, val); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 166 | return 1; |
| 167 | } |
| 168 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 169 | #ifndef CONFIG_SYS_PIXIS_VCFGEN0_ENABLE |
| 170 | #define CONFIG_SYS_PIXIS_VCFGEN0_ENABLE 0x1C |
| 171 | #endif |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 172 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 173 | /* Tell the PIXIS where to find the COREPLL, MPXPLL, SYSCLK values |
| 174 | * |
| 175 | * The PIXIS can be programmed to look at either the on-board dip switches |
| 176 | * or various other PIXIS registers to determine the values for COREPLL, |
| 177 | * MPXPLL, and SYSCLK. |
| 178 | * |
| 179 | * CONFIG_SYS_PIXIS_VCFGEN0_ENABLE is the value to write to the PIXIS_VCFGEN0 |
| 180 | * register that tells the pixis to use the various PIXIS register. |
| 181 | */ |
| 182 | static void read_from_px_regs(int set) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 183 | { |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 184 | u8 tmp = in_8(pixis_base + PIXIS_VCFGEN0); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 185 | |
| 186 | if (set) |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 187 | tmp = tmp | CONFIG_SYS_PIXIS_VCFGEN0_ENABLE; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 188 | else |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 189 | tmp = tmp & ~CONFIG_SYS_PIXIS_VCFGEN0_ENABLE; |
| 190 | |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 191 | out_8(pixis_base + PIXIS_VCFGEN0, tmp); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 192 | } |
| 193 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 194 | /* CONFIG_SYS_PIXIS_VBOOT_ENABLE is the value to write to the PX_VCFGEN1 |
| 195 | * register that tells the pixis to use the PX_VBOOT[LBMAP] register. |
| 196 | */ |
| 197 | #ifndef CONFIG_SYS_PIXIS_VBOOT_ENABLE |
| 198 | #define CONFIG_SYS_PIXIS_VBOOT_ENABLE 0x04 |
| 199 | #endif |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 200 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 201 | /* Configure the source of the boot location |
| 202 | * |
| 203 | * The PIXIS can be programmed to look at either the on-board dip switches |
| 204 | * or the PX_VBOOT[LBMAP] register to determine where we should boot. |
| 205 | * |
| 206 | * If we want to boot from the alternate boot bank, we need to tell the PIXIS |
| 207 | * to ignore the on-board dip switches and use the PX_VBOOT[LBMAP] instead. |
| 208 | */ |
| 209 | static void read_from_px_regs_altbank(int set) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 210 | { |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 211 | u8 tmp = in_8(pixis_base + PIXIS_VCFGEN1); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 212 | |
| 213 | if (set) |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 214 | tmp = tmp | CONFIG_SYS_PIXIS_VBOOT_ENABLE; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 215 | else |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 216 | tmp = tmp & ~CONFIG_SYS_PIXIS_VBOOT_ENABLE; |
| 217 | |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 218 | out_8(pixis_base + PIXIS_VCFGEN1, tmp); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 221 | /* CONFIG_SYS_PIXIS_VBOOT_MASK contains the bits to set in VBOOT register that |
| 222 | * tells the PIXIS what the alternate flash bank is. |
| 223 | * |
| 224 | * Note that it's not really a mask. It contains the actual LBMAP bits that |
| 225 | * must be set to select the alternate bank. This code assumes that the |
| 226 | * primary bank has these bits set to 0, and the alternate bank has these |
| 227 | * bits set to 1. |
| 228 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 229 | #ifndef CONFIG_SYS_PIXIS_VBOOT_MASK |
| 230 | #define CONFIG_SYS_PIXIS_VBOOT_MASK (0x40) |
Jason Jin | db74b3c | 2007-10-29 19:26:21 +0800 | [diff] [blame] | 231 | #endif |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 232 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 233 | /* Tell the PIXIS to boot from the default flash bank |
| 234 | * |
| 235 | * Program the default flash bank into the VBOOT register. This register is |
| 236 | * used only if PX_VCFGEN1[FLASH]=1. |
| 237 | */ |
| 238 | static void clear_altbank(void) |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 239 | { |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 240 | clrbits_8(pixis_base + PIXIS_VBOOT, CONFIG_SYS_PIXIS_VBOOT_MASK); |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 243 | /* Tell the PIXIS to boot from the alternate flash bank |
| 244 | * |
| 245 | * Program the alternate flash bank into the VBOOT register. This register is |
| 246 | * used only if PX_VCFGEN1[FLASH]=1. |
| 247 | */ |
| 248 | static void set_altbank(void) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 249 | { |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 250 | setbits_8(pixis_base + PIXIS_VBOOT, CONFIG_SYS_PIXIS_VBOOT_MASK); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 253 | /* Reset the board with watchdog disabled. |
| 254 | * |
| 255 | * This respects the altbank setting. |
| 256 | */ |
| 257 | static void set_px_go(void) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 258 | { |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 259 | /* Disable the VELA sequencer and watchdog */ |
| 260 | clrbits_8(pixis_base + PIXIS_VCTL, 9); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 261 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 262 | /* Reboot by starting the VELA sequencer */ |
| 263 | setbits_8(pixis_base + PIXIS_VCTL, 0x1); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 264 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 265 | while (1); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 268 | /* Reset the board with watchdog enabled. |
| 269 | * |
| 270 | * This respects the altbank setting. |
| 271 | */ |
| 272 | static void set_px_go_with_watchdog(void) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 273 | { |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 274 | /* Disable the VELA sequencer */ |
| 275 | clrbits_8(pixis_base + PIXIS_VCTL, 1); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 276 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 277 | /* Enable the watchdog and reboot by starting the VELA sequencer */ |
| 278 | setbits_8(pixis_base + PIXIS_VCTL, 0x9); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 279 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 280 | while (1); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 281 | } |
| 282 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 283 | /* Disable the watchdog |
| 284 | * |
| 285 | */ |
| 286 | static int pixis_disable_watchdog_cmd(cmd_tbl_t *cmdtp, int flag, int argc, |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 287 | char * const argv[]) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 288 | { |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 289 | /* Disable the VELA sequencer and the watchdog */ |
| 290 | clrbits_8(pixis_base + PIXIS_VCTL, 9); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 295 | U_BOOT_CMD( |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 296 | diswd, 1, 0, pixis_disable_watchdog_cmd, |
| 297 | "Disable watchdog timer", |
| 298 | "" |
| 299 | ); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 300 | |
Liu Yu | bff188b | 2008-10-10 11:40:58 +0800 | [diff] [blame] | 301 | #ifdef CONFIG_PIXIS_SGMII_CMD |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 302 | |
| 303 | /* Enable or disable SGMII mode for a TSEC |
| 304 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 305 | static int pixis_set_sgmii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 306 | { |
| 307 | int which_tsec = -1; |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 308 | unsigned char mask; |
| 309 | unsigned char switch_mask; |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 310 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 311 | if ((argc > 2) && (strcmp(argv[1], "all") != 0)) |
| 312 | which_tsec = simple_strtoul(argv[1], NULL, 0); |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 313 | |
| 314 | switch (which_tsec) { |
Liu Yu | bff188b | 2008-10-10 11:40:58 +0800 | [diff] [blame] | 315 | #ifdef CONFIG_TSEC1 |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 316 | case 1: |
| 317 | mask = PIXIS_VSPEED2_TSEC1SER; |
| 318 | switch_mask = PIXIS_VCFGEN1_TSEC1SER; |
| 319 | break; |
Liu Yu | bff188b | 2008-10-10 11:40:58 +0800 | [diff] [blame] | 320 | #endif |
| 321 | #ifdef CONFIG_TSEC2 |
| 322 | case 2: |
| 323 | mask = PIXIS_VSPEED2_TSEC2SER; |
| 324 | switch_mask = PIXIS_VCFGEN1_TSEC2SER; |
| 325 | break; |
| 326 | #endif |
| 327 | #ifdef CONFIG_TSEC3 |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 328 | case 3: |
| 329 | mask = PIXIS_VSPEED2_TSEC3SER; |
| 330 | switch_mask = PIXIS_VCFGEN1_TSEC3SER; |
| 331 | break; |
Liu Yu | bff188b | 2008-10-10 11:40:58 +0800 | [diff] [blame] | 332 | #endif |
| 333 | #ifdef CONFIG_TSEC4 |
| 334 | case 4: |
| 335 | mask = PIXIS_VSPEED2_TSEC4SER; |
| 336 | switch_mask = PIXIS_VCFGEN1_TSEC4SER; |
| 337 | break; |
| 338 | #endif |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 339 | default: |
Liu Yu | bff188b | 2008-10-10 11:40:58 +0800 | [diff] [blame] | 340 | mask = PIXIS_VSPEED2_MASK; |
| 341 | switch_mask = PIXIS_VCFGEN1_MASK; |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 342 | break; |
| 343 | } |
| 344 | |
| 345 | /* Toggle whether the switches or FPGA control the settings */ |
| 346 | if (!strcmp(argv[argc - 1], "switch")) |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 347 | clrbits_8(pixis_base + PIXIS_VCFGEN1, switch_mask); |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 348 | else |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 349 | setbits_8(pixis_base + PIXIS_VCFGEN1, switch_mask); |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 350 | |
| 351 | /* If it's not the switches, enable or disable SGMII, as specified */ |
| 352 | if (!strcmp(argv[argc - 1], "on")) |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 353 | clrbits_8(pixis_base + PIXIS_VSPEED2, mask); |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 354 | else if (!strcmp(argv[argc - 1], "off")) |
Kumar Gala | 048e7ef | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 355 | setbits_8(pixis_base + PIXIS_VSPEED2, mask); |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | U_BOOT_CMD( |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 361 | pixis_set_sgmii, CONFIG_SYS_MAXARGS, 1, pixis_set_sgmii, |
| 362 | "pixis_set_sgmii" |
| 363 | " - Enable or disable SGMII mode for a given TSEC \n", |
| 364 | "\npixis_set_sgmii [TSEC num] <on|off|switch>\n" |
| 365 | " TSEC num: 1,2,3,4 or 'all'. 'all' is default.\n" |
| 366 | " on - enables SGMII\n" |
| 367 | " off - disables SGMII\n" |
| 368 | " switch - use switch settings" |
| 369 | ); |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 370 | |
Andy Fleming | 5a8a163 | 2008-08-31 16:33:30 -0500 | [diff] [blame] | 371 | #endif |
| 372 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 373 | /* |
| 374 | * This function takes the non-integral cpu:mpx pll ratio |
| 375 | * and converts it to an integer that can be used to assign |
| 376 | * FPGA register values. |
| 377 | * input: strptr i.e. argv[2] |
| 378 | */ |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 379 | static unsigned long strfractoint(char *strptr) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 380 | { |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 381 | int i, j; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 382 | int mulconst; |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 383 | int intarr_len, no_dec = 0; |
| 384 | unsigned long intval = 0, decval = 0; |
| 385 | char intarr[3], decarr[3]; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 386 | |
| 387 | /* Assign the integer part to intarr[] |
| 388 | * If there is no decimal point i.e. |
| 389 | * if the ratio is an integral value |
| 390 | * simply create the intarr. |
| 391 | */ |
| 392 | i = 0; |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 393 | while (strptr[i] != '.') { |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 394 | if (strptr[i] == 0) { |
| 395 | no_dec = 1; |
| 396 | break; |
| 397 | } |
| 398 | intarr[i] = strptr[i]; |
| 399 | i++; |
| 400 | } |
| 401 | |
| 402 | /* Assign length of integer part to intarr_len. */ |
| 403 | intarr_len = i; |
| 404 | intarr[i] = '\0'; |
| 405 | |
| 406 | if (no_dec) { |
| 407 | /* Currently needed only for single digit corepll ratios */ |
Jon Loeliger | 80e955c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 408 | mulconst = 10; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 409 | decval = 0; |
| 410 | } else { |
| 411 | j = 0; |
Jon Loeliger | 80e955c | 2006-08-22 12:25:27 -0500 | [diff] [blame] | 412 | i++; /* Skipping the decimal point */ |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 413 | while ((strptr[i] >= '0') && (strptr[i] <= '9')) { |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 414 | decarr[j] = strptr[i]; |
| 415 | i++; |
| 416 | j++; |
| 417 | } |
| 418 | |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 419 | decarr[j] = '\0'; |
| 420 | |
| 421 | mulconst = 1; |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 422 | for (i = 0; i < j; i++) |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 423 | mulconst *= 10; |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 424 | decval = simple_strtoul(decarr, NULL, 10); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 425 | } |
| 426 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 427 | intval = simple_strtoul(intarr, NULL, 10); |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 428 | intval = intval * mulconst; |
| 429 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 430 | return intval + decval; |
Jon Loeliger | 126aa70 | 2006-05-30 17:47:00 -0500 | [diff] [blame] | 431 | } |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 432 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 433 | static int pixis_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 434 | { |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 435 | unsigned int i; |
| 436 | char *p_cf = NULL; |
| 437 | char *p_cf_sysclk = NULL; |
| 438 | char *p_cf_corepll = NULL; |
| 439 | char *p_cf_mpxpll = NULL; |
| 440 | char *p_altbank = NULL; |
| 441 | char *p_wd = NULL; |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 442 | int unknown_param = 0; |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 443 | |
| 444 | /* |
| 445 | * No args is a simple reset request. |
| 446 | */ |
| 447 | if (argc <= 1) { |
| 448 | pixis_reset(); |
| 449 | /* not reached */ |
| 450 | } |
| 451 | |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 452 | for (i = 1; i < argc; i++) { |
| 453 | if (strcmp(argv[i], "cf") == 0) { |
| 454 | p_cf = argv[i]; |
| 455 | if (i + 3 >= argc) { |
| 456 | break; |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 457 | } |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 458 | p_cf_sysclk = argv[i+1]; |
| 459 | p_cf_corepll = argv[i+2]; |
| 460 | p_cf_mpxpll = argv[i+3]; |
| 461 | i += 3; |
| 462 | continue; |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 463 | } |
| 464 | |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 465 | if (strcmp(argv[i], "altbank") == 0) { |
| 466 | p_altbank = argv[i]; |
| 467 | continue; |
| 468 | } |
| 469 | |
| 470 | if (strcmp(argv[i], "wd") == 0) { |
| 471 | p_wd = argv[i]; |
| 472 | continue; |
| 473 | } |
| 474 | |
| 475 | unknown_param = 1; |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * Check that cf has all required parms |
| 480 | */ |
| 481 | if ((p_cf && !(p_cf_sysclk && p_cf_corepll && p_cf_mpxpll)) |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 482 | || unknown_param) { |
Ed Swarthout | f7fecc3 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 483 | #ifdef CONFIG_SYS_LONGHELP |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 484 | puts(cmdtp->help); |
Ed Swarthout | f7fecc3 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 485 | #endif |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 486 | return 1; |
| 487 | } |
| 488 | |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 489 | /* |
| 490 | * PIXIS seems to be sensitive to the ordering of |
| 491 | * the registers that are touched. |
| 492 | */ |
| 493 | read_from_px_regs(0); |
| 494 | |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 495 | if (p_altbank) |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 496 | read_from_px_regs_altbank(0); |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 497 | |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 498 | clear_altbank(); |
| 499 | |
| 500 | /* |
| 501 | * Clock configuration specified. |
| 502 | */ |
| 503 | if (p_cf) { |
| 504 | unsigned long sysclk; |
| 505 | unsigned long corepll; |
| 506 | unsigned long mpxpll; |
| 507 | |
| 508 | sysclk = simple_strtoul(p_cf_sysclk, NULL, 10); |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 509 | corepll = strfractoint(p_cf_corepll); |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 510 | mpxpll = simple_strtoul(p_cf_mpxpll, NULL, 10); |
| 511 | |
| 512 | if (!(set_px_sysclk(sysclk) |
| 513 | && set_px_corepll(corepll) |
| 514 | && set_px_mpxpll(mpxpll))) { |
Ed Swarthout | f7fecc3 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 515 | #ifdef CONFIG_SYS_LONGHELP |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 516 | puts(cmdtp->help); |
Ed Swarthout | f7fecc3 | 2008-10-08 23:38:01 -0500 | [diff] [blame] | 517 | #endif |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 518 | return 1; |
| 519 | } |
| 520 | read_from_px_regs(1); |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Altbank specified |
| 525 | * |
| 526 | * NOTE CHANGE IN BEHAVIOR: previous code would default |
| 527 | * to enabling watchdog if altbank is specified. |
| 528 | * Now the watchdog must be enabled explicitly using 'wd'. |
| 529 | */ |
| 530 | if (p_altbank) { |
| 531 | set_altbank(); |
| 532 | read_from_px_regs_altbank(1); |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Reset with watchdog specified. |
| 537 | */ |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 538 | if (p_wd) |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 539 | set_px_go_with_watchdog(); |
Timur Tabi | 2feb4af | 2010-03-31 17:44:13 -0500 | [diff] [blame] | 540 | else |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 541 | set_px_go(); |
James Yang | 16c3cde | 2008-01-16 11:58:08 -0600 | [diff] [blame] | 542 | |
| 543 | /* |
| 544 | * Shouldn't be reached. |
| 545 | */ |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | U_BOOT_CMD( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 551 | pixis_reset, CONFIG_SYS_MAXARGS, 1, pixis_reset_cmd, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 552 | "Reset the board using the FPGA sequencer", |
Haiying Wang | 3d98b85 | 2007-01-22 12:37:30 -0600 | [diff] [blame] | 553 | " pixis_reset\n" |
| 554 | " pixis_reset [altbank]\n" |
| 555 | " pixis_reset altbank wd\n" |
| 556 | " pixis_reset altbank cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 557 | " pixis_reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>" |
| 558 | ); |