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