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