Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1 | /* |
Dave Liu | 03051c3 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 2 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * CPU specific code for the MPC83xx family. |
| 9 | * |
| 10 | * Derived from the MPC8260 and MPC85xx. |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <watchdog.h> |
| 15 | #include <command.h> |
| 16 | #include <mpc83xx.h> |
| 17 | #include <asm/processor.h> |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 18 | #include <libfdt.h> |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 19 | #include <tsec.h> |
Ben Warren | 0e8454e | 2008-10-22 23:32:48 -0700 | [diff] [blame] | 20 | #include <netdev.h> |
Andy Fleming | e1ac387 | 2008-10-30 16:50:14 -0500 | [diff] [blame] | 21 | #include <fsl_esdhc.h> |
Heiko Schocher | 9950969 | 2014-01-25 07:53:47 +0100 | [diff] [blame] | 22 | #if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_MPC831x) |
Zhao Qiang | 38d67a4e | 2014-06-03 16:27:07 +0800 | [diff] [blame] | 23 | #include <linux/immap_qe.h> |
Heiko Schocher | f70fd13 | 2009-02-24 11:30:51 +0100 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #endif |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 26 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 29 | int checkcpu(void) |
| 30 | { |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 31 | volatile immap_t *immr; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 32 | ulong clock = gd->cpu_clk; |
| 33 | u32 pvr = get_pvr(); |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 34 | u32 spridr; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 35 | char buf[32]; |
Simon Glass | d891ab9 | 2017-03-28 10:27:27 -0600 | [diff] [blame] | 36 | int ret; |
Kim Phillips | e5c4ade | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 37 | int i; |
| 38 | |
Kim Phillips | e5c4ade | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 39 | const struct cpu_type { |
| 40 | char name[15]; |
| 41 | u32 partid; |
| 42 | } cpu_type_list [] = { |
Ilya Yanok | 7c619dd | 2010-06-28 16:44:33 +0400 | [diff] [blame] | 43 | CPU_TYPE_ENTRY(8308), |
Gerlando Falauto | a88731a | 2012-10-10 22:13:08 +0000 | [diff] [blame] | 44 | CPU_TYPE_ENTRY(8309), |
Kim Phillips | e5c4ade | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 45 | CPU_TYPE_ENTRY(8311), |
| 46 | CPU_TYPE_ENTRY(8313), |
| 47 | CPU_TYPE_ENTRY(8314), |
| 48 | CPU_TYPE_ENTRY(8315), |
| 49 | CPU_TYPE_ENTRY(8321), |
| 50 | CPU_TYPE_ENTRY(8323), |
| 51 | CPU_TYPE_ENTRY(8343), |
| 52 | CPU_TYPE_ENTRY(8347_TBGA_), |
| 53 | CPU_TYPE_ENTRY(8347_PBGA_), |
| 54 | CPU_TYPE_ENTRY(8349), |
| 55 | CPU_TYPE_ENTRY(8358_TBGA_), |
| 56 | CPU_TYPE_ENTRY(8358_PBGA_), |
| 57 | CPU_TYPE_ENTRY(8360), |
| 58 | CPU_TYPE_ENTRY(8377), |
| 59 | CPU_TYPE_ENTRY(8378), |
| 60 | CPU_TYPE_ENTRY(8379), |
| 61 | }; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 62 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 63 | immr = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 64 | |
Simon Glass | d891ab9 | 2017-03-28 10:27:27 -0600 | [diff] [blame] | 65 | ret = prt_83xx_rsr(); |
| 66 | if (ret) |
| 67 | return ret; |
| 68 | |
Kim Phillips | 54b2d43 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 69 | puts("CPU: "); |
Scott Wood | 95e7ef8 | 2007-04-16 14:34:16 -0500 | [diff] [blame] | 70 | |
| 71 | switch (pvr & 0xffff0000) { |
| 72 | case PVR_E300C1: |
| 73 | printf("e300c1, "); |
| 74 | break; |
| 75 | |
| 76 | case PVR_E300C2: |
| 77 | printf("e300c2, "); |
| 78 | break; |
| 79 | |
| 80 | case PVR_E300C3: |
| 81 | printf("e300c3, "); |
| 82 | break; |
| 83 | |
Dave Liu | 03051c3 | 2007-09-18 12:36:11 +0800 | [diff] [blame] | 84 | case PVR_E300C4: |
| 85 | printf("e300c4, "); |
| 86 | break; |
| 87 | |
Scott Wood | 95e7ef8 | 2007-04-16 14:34:16 -0500 | [diff] [blame] | 88 | default: |
| 89 | printf("Unknown core, "); |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 92 | spridr = immr->sysconf.spridr; |
Rafal Jaworowski | 6902df5 | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 93 | |
Kim Phillips | e5c4ade | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 94 | for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++) |
| 95 | if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) { |
| 96 | puts("MPC"); |
| 97 | puts(cpu_type_list[i].name); |
| 98 | if (IS_E_PROCESSOR(spridr)) |
| 99 | puts("E"); |
Kim Phillips | dfe812c | 2010-04-15 17:36:02 -0500 | [diff] [blame] | 100 | if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY || |
| 101 | SPR_FAMILY(spridr) == SPR_836X_FAMILY) && |
| 102 | REVID_MAJOR(spridr) >= 2) |
Kim Phillips | e5c4ade | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 103 | puts("A"); |
| 104 | printf(", Rev: %d.%d", REVID_MAJOR(spridr), |
| 105 | REVID_MINOR(spridr)); |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | if (i == ARRAY_SIZE(cpu_type_list)) |
| 110 | printf("(SPRIDR %08x unknown), ", spridr); |
| 111 | |
| 112 | printf(" at %s MHz, ", strmhz(buf, clock)); |
| 113 | |
Simon Glass | c6731fe | 2012-12-13 20:48:47 +0000 | [diff] [blame] | 114 | printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk)); |
Kim Phillips | 54b2d43 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 115 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 119 | int |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 120 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 121 | { |
Wolfgang Denk | 07a2505 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 122 | ulong msr; |
| 123 | #ifndef MPC83xx_RESET |
| 124 | ulong addr; |
| 125 | #endif |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 126 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 127 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 128 | |
Michael Zaidman | 4c006dd | 2010-02-15 10:02:32 +0200 | [diff] [blame] | 129 | puts("Resetting the board.\n"); |
| 130 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 131 | #ifdef MPC83xx_RESET |
Michael Zaidman | 4c006dd | 2010-02-15 10:02:32 +0200 | [diff] [blame] | 132 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 133 | /* Interrupts and MMU off */ |
| 134 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
| 135 | |
| 136 | msr &= ~( MSR_EE | MSR_IR | MSR_DR); |
| 137 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 138 | |
| 139 | /* enable Reset Control Reg */ |
| 140 | immap->reset.rpr = 0x52535445; |
Marian Balakowicz | 6d8ae5a | 2006-03-14 16:12:48 +0100 | [diff] [blame] | 141 | __asm__ __volatile__ ("sync"); |
| 142 | __asm__ __volatile__ ("isync"); |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 143 | |
| 144 | /* confirm Reset Control Reg is enabled */ |
| 145 | while(!((immap->reset.rcer) & RCER_CRE)); |
| 146 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 147 | udelay(200); |
| 148 | |
| 149 | /* perform reset, only one bit */ |
Wolfgang Denk | 07a2505 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 150 | immap->reset.rcr = RCR_SWHR; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 151 | |
Wolfgang Denk | 07a2505 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 152 | #else /* ! MPC83xx_RESET */ |
| 153 | |
| 154 | immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */ |
| 155 | |
| 156 | /* Interrupts and MMU off */ |
| 157 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 158 | |
| 159 | msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); |
| 160 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 161 | |
| 162 | /* |
| 163 | * Trying to execute the next instruction at a non-existing address |
| 164 | * should cause a machine check, resulting in reset |
| 165 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 166 | addr = CONFIG_SYS_RESET_ADDRESS; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 167 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 168 | ((void (*)(void)) addr) (); |
Wolfgang Denk | 07a2505 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 169 | #endif /* MPC83xx_RESET */ |
| 170 | |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 171 | return 1; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* |
| 176 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 177 | */ |
| 178 | |
| 179 | unsigned long get_tbclk(void) |
| 180 | { |
Masahiro Yamada | 63a7578 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 181 | return (gd->bus_clk + 3L) / 4L; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
| 185 | #if defined(CONFIG_WATCHDOG) |
| 186 | void watchdog_reset (void) |
| 187 | { |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 188 | int re_enable = disable_interrupts(); |
| 189 | |
| 190 | /* Reset the 83xx watchdog */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 191 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 192 | immr->wdt.swsrr = 0x556c; |
| 193 | immr->wdt.swsrr = 0xaa39; |
| 194 | |
| 195 | if (re_enable) |
| 196 | enable_interrupts (); |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 197 | } |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 198 | #endif |
Kumar Gala | 62ec641 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 199 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 200 | /* |
| 201 | * Initializes on-chip ethernet controllers. |
| 202 | * to override, implement board_eth_init() |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 203 | */ |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 204 | int cpu_eth_init(bd_t *bis) |
| 205 | { |
Haiying Wang | 8e55258 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 206 | #if defined(CONFIG_UEC_ETH) |
| 207 | uec_standard_init(bis); |
Ben Warren | 0e8454e | 2008-10-22 23:32:48 -0700 | [diff] [blame] | 208 | #endif |
Haiying Wang | 8e55258 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 209 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 210 | #if defined(CONFIG_TSEC_ENET) |
| 211 | tsec_standard_init(bis); |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 212 | #endif |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 213 | return 0; |
| 214 | } |
Andy Fleming | e1ac387 | 2008-10-30 16:50:14 -0500 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | * Initializes on-chip MMC controllers. |
| 218 | * to override, implement board_mmc_init() |
| 219 | */ |
| 220 | int cpu_mmc_init(bd_t *bis) |
| 221 | { |
| 222 | #ifdef CONFIG_FSL_ESDHC |
| 223 | return fsl_esdhc_mmc_init(bis); |
| 224 | #else |
| 225 | return 0; |
| 226 | #endif |
| 227 | } |