blob: 20ed82fbcdfb77abef93fb4db8b780df9aaa9dd6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eran Liberty9095d4a2005-07-28 10:08:46 -05002/*
Dave Liu5245ff52007-09-18 12:36:11 +08003 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
Eran Liberty9095d4a2005-07-28 10:08:46 -05004 */
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 Glass1fa70f82019-11-14 12:57:34 -070013#include <cpu_func.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070014#include <vsprintf.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050015#include <watchdog.h>
16#include <command.h>
17#include <mpc83xx.h>
18#include <asm/processor.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090019#include <linux/libfdt.h>
Andy Flemingfecff2b2008-08-31 16:33:26 -050020#include <tsec.h>
Ben Warren67731692008-10-22 23:32:48 -070021#include <netdev.h>
Andy Fleming1463b4b2008-10-30 16:50:14 -050022#include <fsl_esdhc.h>
Mario Six9164bdd2019-01-21 09:17:25 +010023#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang978679d2014-06-03 16:27:07 +080024#include <linux/immap_qe.h>
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +010025#include <asm/io.h>
26#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050027
Wolfgang Denk6405a152006-03-31 18:32:53 +020028DECLARE_GLOBAL_DATA_PTR;
29
Mario Six28fbefa2018-08-06 10:23:45 +020030#ifndef CONFIG_CPU_MPC83XX
Eran Liberty9095d4a2005-07-28 10:08:46 -050031int checkcpu(void)
32{
Dave Liua46daea2006-11-03 19:33:44 -060033 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050034 ulong clock = gd->cpu_clk;
35 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060036 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050037 char buf[32];
Simon Glass156283f2017-03-28 10:27:27 -060038 int ret;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050039 int i;
40
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050041 const struct cpu_type {
42 char name[15];
43 u32 partid;
44 } cpu_type_list [] = {
Ilya Yanoka3e5fd52010-06-28 16:44:33 +040045 CPU_TYPE_ENTRY(8308),
Gerlando Falautofe201cb2012-10-10 22:13:08 +000046 CPU_TYPE_ENTRY(8309),
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050047 CPU_TYPE_ENTRY(8311),
48 CPU_TYPE_ENTRY(8313),
49 CPU_TYPE_ENTRY(8314),
50 CPU_TYPE_ENTRY(8315),
51 CPU_TYPE_ENTRY(8321),
52 CPU_TYPE_ENTRY(8323),
53 CPU_TYPE_ENTRY(8343),
54 CPU_TYPE_ENTRY(8347_TBGA_),
55 CPU_TYPE_ENTRY(8347_PBGA_),
56 CPU_TYPE_ENTRY(8349),
57 CPU_TYPE_ENTRY(8358_TBGA_),
58 CPU_TYPE_ENTRY(8358_PBGA_),
59 CPU_TYPE_ENTRY(8360),
60 CPU_TYPE_ENTRY(8377),
61 CPU_TYPE_ENTRY(8378),
62 CPU_TYPE_ENTRY(8379),
63 };
Eran Liberty9095d4a2005-07-28 10:08:46 -050064
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060066
Simon Glass156283f2017-03-28 10:27:27 -060067 ret = prt_83xx_rsr();
68 if (ret)
69 return ret;
70
Kim Phillipsd82b0772007-04-30 15:26:21 -050071 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050072
73 switch (pvr & 0xffff0000) {
74 case PVR_E300C1:
75 printf("e300c1, ");
76 break;
77
78 case PVR_E300C2:
79 printf("e300c2, ");
80 break;
81
82 case PVR_E300C3:
83 printf("e300c3, ");
84 break;
85
Dave Liu5245ff52007-09-18 12:36:11 +080086 case PVR_E300C4:
87 printf("e300c4, ");
88 break;
89
Scott Wood7206a992007-04-16 14:34:16 -050090 default:
91 printf("Unknown core, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050092 }
93
Dave Liua46daea2006-11-03 19:33:44 -060094 spridr = immr->sysconf.spridr;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050095
96 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
97 if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) {
98 puts("MPC");
99 puts(cpu_type_list[i].name);
100 if (IS_E_PROCESSOR(spridr))
101 puts("E");
Kim Phillips39b48162010-04-15 17:36:02 -0500102 if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
103 SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
104 REVID_MAJOR(spridr) >= 2)
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500105 puts("A");
106 printf(", Rev: %d.%d", REVID_MAJOR(spridr),
107 REVID_MINOR(spridr));
108 break;
109 }
110
111 if (i == ARRAY_SIZE(cpu_type_list))
112 printf("(SPRIDR %08x unknown), ", spridr);
113
114 printf(" at %s MHz, ", strmhz(buf, clock));
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200115
Simon Glasscc76e9e2012-12-13 20:48:47 +0000116 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillipsd82b0772007-04-30 15:26:21 -0500117
Eran Liberty9095d4a2005-07-28 10:08:46 -0500118 return 0;
119}
Mario Six28fbefa2018-08-06 10:23:45 +0200120#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500121
Mario Six82ef4ba2018-08-06 10:23:35 +0200122#ifndef CONFIG_SYSRESET
Eran Liberty9095d4a2005-07-28 10:08:46 -0500123int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200124do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500125{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200126 ulong msr;
127#ifndef MPC83xx_RESET
128 ulong addr;
129#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500130
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500132
Michael Zaidman184154b2010-02-15 10:02:32 +0200133 puts("Resetting the board.\n");
134
Eran Liberty9095d4a2005-07-28 10:08:46 -0500135#ifdef MPC83xx_RESET
Michael Zaidman184154b2010-02-15 10:02:32 +0200136
Eran Liberty9095d4a2005-07-28 10:08:46 -0500137 /* Interrupts and MMU off */
Mario Sixc463b6d2019-01-21 09:18:21 +0100138 msr = mfmsr();
139 msr &= ~(MSR_EE | MSR_IR | MSR_DR);
140 mtmsr(msr);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500141
142 /* enable Reset Control Reg */
143 immap->reset.rpr = 0x52535445;
Mario Sixc463b6d2019-01-21 09:18:21 +0100144 sync();
145 isync();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500146
147 /* confirm Reset Control Reg is enabled */
Mario Sixc463b6d2019-01-21 09:18:21 +0100148 while(!((immap->reset.rcer) & RCER_CRE))
149 ;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500150
Eran Liberty9095d4a2005-07-28 10:08:46 -0500151 udelay(200);
152
153 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200154 immap->reset.rcr = RCR_SWHR;
155
156#else /* ! MPC83xx_RESET */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500157
Wolfgang Denk301d0962005-08-05 19:49:35 +0200158 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
159
160 /* Interrupts and MMU off */
Mario Sixc463b6d2019-01-21 09:18:21 +0100161 msr = mfmsr();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500162 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
Mario Sixc463b6d2019-01-21 09:18:21 +0100163 mtmsr(msr);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500164
165 /*
166 * Trying to execute the next instruction at a non-existing address
167 * should cause a machine check, resulting in reset
168 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200169 addr = CONFIG_SYS_RESET_ADDRESS;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500170
Eran Liberty9095d4a2005-07-28 10:08:46 -0500171 ((void (*)(void)) addr) ();
Wolfgang Denk301d0962005-08-05 19:49:35 +0200172#endif /* MPC83xx_RESET */
173
Eran Liberty9095d4a2005-07-28 10:08:46 -0500174 return 1;
175}
Mario Six82ef4ba2018-08-06 10:23:35 +0200176#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500177
178/*
179 * Get timebase clock frequency (like cpu_clk in Hz)
180 */
Mario Six3c516552018-08-06 10:23:38 +0200181#ifndef CONFIG_TIMER
Eran Liberty9095d4a2005-07-28 10:08:46 -0500182unsigned long get_tbclk(void)
183{
Masahiro Yamada04cfea52016-09-06 22:17:38 +0900184 return (gd->bus_clk + 3L) / 4L;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500185}
Mario Six3c516552018-08-06 10:23:38 +0200186#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500187
188#if defined(CONFIG_WATCHDOG)
189void watchdog_reset (void)
190{
Timur Tabi054838e2006-10-31 18:44:42 -0600191 int re_enable = disable_interrupts();
192
193 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600195 immr->wdt.swsrr = 0x556c;
196 immr->wdt.swsrr = 0xaa39;
197
198 if (re_enable)
Simon Glassf87959b2019-11-14 12:57:40 -0700199 enable_interrupts();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500200}
Timur Tabi054838e2006-10-31 18:44:42 -0600201#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600202
Mario Six640b8c32019-01-21 09:18:19 +0100203#ifndef CONFIG_DM_ETH
Andy Flemingfecff2b2008-08-31 16:33:26 -0500204/*
205 * Initializes on-chip ethernet controllers.
206 * to override, implement board_eth_init()
Ben Warrend448a492008-06-23 22:57:27 -0700207 */
Ben Warrend448a492008-06-23 22:57:27 -0700208int cpu_eth_init(bd_t *bis)
209{
Haiying Wang511d8282009-06-04 16:12:41 -0400210#if defined(CONFIG_UEC_ETH)
211 uec_standard_init(bis);
Ben Warren67731692008-10-22 23:32:48 -0700212#endif
Haiying Wang511d8282009-06-04 16:12:41 -0400213
Andy Flemingfecff2b2008-08-31 16:33:26 -0500214#if defined(CONFIG_TSEC_ENET)
215 tsec_standard_init(bis);
Ben Warrend448a492008-06-23 22:57:27 -0700216#endif
Ben Warrend448a492008-06-23 22:57:27 -0700217 return 0;
218}
Mario Six640b8c32019-01-21 09:18:19 +0100219#endif /* !CONFIG_DM_ETH */
Andy Fleming1463b4b2008-10-30 16:50:14 -0500220
221/*
222 * Initializes on-chip MMC controllers.
223 * to override, implement board_mmc_init()
224 */
225int cpu_mmc_init(bd_t *bis)
226{
227#ifdef CONFIG_FSL_ESDHC
228 return fsl_esdhc_mmc_init(bis);
229#else
230 return 0;
231#endif
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +0100232}
Mario Six90b529f2019-01-21 09:18:20 +0100233
234void ppcDWstore(unsigned int *addr, unsigned int *value)
235{
236 asm("lfd 1, 0(%1)\n\t"
237 "stfd 1, 0(%0)"
238 :
239 : "r" (addr), "r" (value)
240 : "memory");
241}
242
243void ppcDWload(unsigned int *addr, unsigned int *ret)
244{
245 asm("lfd 1, 0(%0)\n\t"
246 "stfd 1, 0(%1)"
247 :
248 : "r" (addr), "r" (ret)
249 : "memory");
250}