Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 2 | /* |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 3 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * CPU specific code for the MPC83xx family. |
| 8 | * |
| 9 | * Derived from the MPC8260 and MPC85xx. |
| 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 1fa70f8 | 2019-11-14 12:57:34 -0700 | [diff] [blame] | 13 | #include <cpu_func.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 14 | #include <irq_func.h> |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 15 | #include <vsprintf.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 16 | #include <watchdog.h> |
| 17 | #include <command.h> |
| 18 | #include <mpc83xx.h> |
| 19 | #include <asm/processor.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 20 | #include <linux/libfdt.h> |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 21 | #include <tsec.h> |
Ben Warren | 6773169 | 2008-10-22 23:32:48 -0700 | [diff] [blame] | 22 | #include <netdev.h> |
Andy Fleming | 1463b4b | 2008-10-30 16:50:14 -0500 | [diff] [blame] | 23 | #include <fsl_esdhc.h> |
Mario Six | 9164bdd | 2019-01-21 09:17:25 +0100 | [diff] [blame] | 24 | #if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X) |
Zhao Qiang | 978679d | 2014-06-03 16:27:07 +0800 | [diff] [blame] | 25 | #include <linux/immap_qe.h> |
Heiko Schocher | d2c4f3a | 2009-02-24 11:30:51 +0100 | [diff] [blame] | 26 | #include <asm/io.h> |
| 27 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 28 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Mario Six | 28fbefa | 2018-08-06 10:23:45 +0200 | [diff] [blame] | 31 | #ifndef CONFIG_CPU_MPC83XX |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 32 | int checkcpu(void) |
| 33 | { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 34 | volatile immap_t *immr; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 35 | ulong clock = gd->cpu_clk; |
| 36 | u32 pvr = get_pvr(); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 37 | u32 spridr; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 38 | char buf[32]; |
Simon Glass | 156283f | 2017-03-28 10:27:27 -0600 | [diff] [blame] | 39 | int ret; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 40 | int i; |
| 41 | |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 42 | const struct cpu_type { |
| 43 | char name[15]; |
| 44 | u32 partid; |
| 45 | } cpu_type_list [] = { |
Ilya Yanok | a3e5fd5 | 2010-06-28 16:44:33 +0400 | [diff] [blame] | 46 | CPU_TYPE_ENTRY(8308), |
Gerlando Falauto | fe201cb | 2012-10-10 22:13:08 +0000 | [diff] [blame] | 47 | CPU_TYPE_ENTRY(8309), |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 48 | CPU_TYPE_ENTRY(8311), |
| 49 | CPU_TYPE_ENTRY(8313), |
| 50 | CPU_TYPE_ENTRY(8314), |
| 51 | CPU_TYPE_ENTRY(8315), |
| 52 | CPU_TYPE_ENTRY(8321), |
| 53 | CPU_TYPE_ENTRY(8323), |
| 54 | CPU_TYPE_ENTRY(8343), |
| 55 | CPU_TYPE_ENTRY(8347_TBGA_), |
| 56 | CPU_TYPE_ENTRY(8347_PBGA_), |
| 57 | CPU_TYPE_ENTRY(8349), |
| 58 | CPU_TYPE_ENTRY(8358_TBGA_), |
| 59 | CPU_TYPE_ENTRY(8358_PBGA_), |
| 60 | CPU_TYPE_ENTRY(8360), |
| 61 | CPU_TYPE_ENTRY(8377), |
| 62 | CPU_TYPE_ENTRY(8378), |
| 63 | CPU_TYPE_ENTRY(8379), |
| 64 | }; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 65 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 66 | immr = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 67 | |
Simon Glass | 156283f | 2017-03-28 10:27:27 -0600 | [diff] [blame] | 68 | ret = prt_83xx_rsr(); |
| 69 | if (ret) |
| 70 | return ret; |
| 71 | |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 72 | puts("CPU: "); |
Scott Wood | 7206a99 | 2007-04-16 14:34:16 -0500 | [diff] [blame] | 73 | |
| 74 | switch (pvr & 0xffff0000) { |
| 75 | case PVR_E300C1: |
| 76 | printf("e300c1, "); |
| 77 | break; |
| 78 | |
| 79 | case PVR_E300C2: |
| 80 | printf("e300c2, "); |
| 81 | break; |
| 82 | |
| 83 | case PVR_E300C3: |
| 84 | printf("e300c3, "); |
| 85 | break; |
| 86 | |
Dave Liu | 5245ff5 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 87 | case PVR_E300C4: |
| 88 | printf("e300c4, "); |
| 89 | break; |
| 90 | |
Scott Wood | 7206a99 | 2007-04-16 14:34:16 -0500 | [diff] [blame] | 91 | default: |
| 92 | printf("Unknown core, "); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 95 | spridr = immr->sysconf.spridr; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 96 | |
| 97 | for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) |
| 98 | if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) { |
| 99 | puts("MPC"); |
| 100 | puts(cpu_type_list[i].name); |
| 101 | if (IS_E_PROCESSOR(spridr)) |
| 102 | puts("E"); |
Kim Phillips | 39b4816 | 2010-04-15 17:36:02 -0500 | [diff] [blame] | 103 | if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY || |
| 104 | SPR_FAMILY(spridr) == SPR_836X_FAMILY) && |
| 105 | REVID_MAJOR(spridr) >= 2) |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 106 | puts("A"); |
| 107 | printf(", Rev: %d.%d", REVID_MAJOR(spridr), |
| 108 | REVID_MINOR(spridr)); |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | if (i == ARRAY_SIZE(cpu_type_list)) |
| 113 | printf("(SPRIDR %08x unknown), ", spridr); |
| 114 | |
| 115 | printf(" at %s MHz, ", strmhz(buf, clock)); |
Rafal Jaworowski | 384da5e | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 116 | |
Simon Glass | cc76e9e | 2012-12-13 20:48:47 +0000 | [diff] [blame] | 117 | printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk)); |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 118 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 119 | return 0; |
| 120 | } |
Mario Six | 28fbefa | 2018-08-06 10:23:45 +0200 | [diff] [blame] | 121 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 122 | |
Mario Six | 82ef4ba | 2018-08-06 10:23:35 +0200 | [diff] [blame] | 123 | #ifndef CONFIG_SYSRESET |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 124 | int |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 125 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 126 | { |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 127 | ulong msr; |
| 128 | #ifndef MPC83xx_RESET |
| 129 | ulong addr; |
| 130 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 131 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 133 | |
Michael Zaidman | 184154b | 2010-02-15 10:02:32 +0200 | [diff] [blame] | 134 | puts("Resetting the board.\n"); |
| 135 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 136 | #ifdef MPC83xx_RESET |
Michael Zaidman | 184154b | 2010-02-15 10:02:32 +0200 | [diff] [blame] | 137 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 138 | /* Interrupts and MMU off */ |
Mario Six | c463b6d | 2019-01-21 09:18:21 +0100 | [diff] [blame] | 139 | msr = mfmsr(); |
| 140 | msr &= ~(MSR_EE | MSR_IR | MSR_DR); |
| 141 | mtmsr(msr); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 142 | |
| 143 | /* enable Reset Control Reg */ |
| 144 | immap->reset.rpr = 0x52535445; |
Mario Six | c463b6d | 2019-01-21 09:18:21 +0100 | [diff] [blame] | 145 | sync(); |
| 146 | isync(); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 147 | |
| 148 | /* confirm Reset Control Reg is enabled */ |
Mario Six | c463b6d | 2019-01-21 09:18:21 +0100 | [diff] [blame] | 149 | while(!((immap->reset.rcer) & RCER_CRE)) |
| 150 | ; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 151 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 152 | udelay(200); |
| 153 | |
| 154 | /* perform reset, only one bit */ |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 155 | immap->reset.rcr = RCR_SWHR; |
| 156 | |
| 157 | #else /* ! MPC83xx_RESET */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 158 | |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 159 | immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */ |
| 160 | |
| 161 | /* Interrupts and MMU off */ |
Mario Six | c463b6d | 2019-01-21 09:18:21 +0100 | [diff] [blame] | 162 | msr = mfmsr(); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 163 | msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); |
Mario Six | c463b6d | 2019-01-21 09:18:21 +0100 | [diff] [blame] | 164 | mtmsr(msr); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * Trying to execute the next instruction at a non-existing address |
| 168 | * should cause a machine check, resulting in reset |
| 169 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 170 | addr = CONFIG_SYS_RESET_ADDRESS; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 171 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 172 | ((void (*)(void)) addr) (); |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 173 | #endif /* MPC83xx_RESET */ |
| 174 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 175 | return 1; |
| 176 | } |
Mario Six | 82ef4ba | 2018-08-06 10:23:35 +0200 | [diff] [blame] | 177 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 181 | */ |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 182 | #ifndef CONFIG_TIMER |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 183 | unsigned long get_tbclk(void) |
| 184 | { |
Masahiro Yamada | 04cfea5 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 185 | return (gd->bus_clk + 3L) / 4L; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 186 | } |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 187 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 188 | |
| 189 | #if defined(CONFIG_WATCHDOG) |
| 190 | void watchdog_reset (void) |
| 191 | { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 192 | int re_enable = disable_interrupts(); |
| 193 | |
| 194 | /* Reset the 83xx watchdog */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 195 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 196 | immr->wdt.swsrr = 0x556c; |
| 197 | immr->wdt.swsrr = 0xaa39; |
| 198 | |
| 199 | if (re_enable) |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 200 | enable_interrupts(); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 201 | } |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 202 | #endif |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 203 | |
Mario Six | 640b8c3 | 2019-01-21 09:18:19 +0100 | [diff] [blame] | 204 | #ifndef CONFIG_DM_ETH |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 205 | /* |
| 206 | * Initializes on-chip ethernet controllers. |
| 207 | * to override, implement board_eth_init() |
Ben Warren | d448a49 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 208 | */ |
Ben Warren | d448a49 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 209 | int cpu_eth_init(bd_t *bis) |
| 210 | { |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 211 | #if defined(CONFIG_UEC_ETH) |
| 212 | uec_standard_init(bis); |
Ben Warren | 6773169 | 2008-10-22 23:32:48 -0700 | [diff] [blame] | 213 | #endif |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 214 | |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 215 | #if defined(CONFIG_TSEC_ENET) |
| 216 | tsec_standard_init(bis); |
Ben Warren | d448a49 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 217 | #endif |
Ben Warren | d448a49 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 218 | return 0; |
| 219 | } |
Mario Six | 640b8c3 | 2019-01-21 09:18:19 +0100 | [diff] [blame] | 220 | #endif /* !CONFIG_DM_ETH */ |
Andy Fleming | 1463b4b | 2008-10-30 16:50:14 -0500 | [diff] [blame] | 221 | |
| 222 | /* |
| 223 | * Initializes on-chip MMC controllers. |
| 224 | * to override, implement board_mmc_init() |
| 225 | */ |
| 226 | int cpu_mmc_init(bd_t *bis) |
| 227 | { |
| 228 | #ifdef CONFIG_FSL_ESDHC |
| 229 | return fsl_esdhc_mmc_init(bis); |
| 230 | #else |
| 231 | return 0; |
| 232 | #endif |
Heiko Schocher | d2c4f3a | 2009-02-24 11:30:51 +0100 | [diff] [blame] | 233 | } |
Mario Six | 90b529f | 2019-01-21 09:18:20 +0100 | [diff] [blame] | 234 | |
| 235 | void ppcDWstore(unsigned int *addr, unsigned int *value) |
| 236 | { |
| 237 | asm("lfd 1, 0(%1)\n\t" |
| 238 | "stfd 1, 0(%0)" |
| 239 | : |
| 240 | : "r" (addr), "r" (value) |
| 241 | : "memory"); |
| 242 | } |
| 243 | |
| 244 | void ppcDWload(unsigned int *addr, unsigned int *ret) |
| 245 | { |
| 246 | asm("lfd 1, 0(%0)\n\t" |
| 247 | "stfd 1, 0(%1)" |
| 248 | : |
| 249 | : "r" (addr), "r" (ret) |
| 250 | : "memory"); |
| 251 | } |