blob: 9c67099a17ad92447600fbf362949df1634fb6af [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>
13#include <watchdog.h>
14#include <command.h>
15#include <mpc83xx.h>
16#include <asm/processor.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090017#include <linux/libfdt.h>
Andy Flemingfecff2b2008-08-31 16:33:26 -050018#include <tsec.h>
Ben Warren67731692008-10-22 23:32:48 -070019#include <netdev.h>
Andy Fleming1463b4b2008-10-30 16:50:14 -050020#include <fsl_esdhc.h>
Mario Six9164bdd2019-01-21 09:17:25 +010021#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang978679d2014-06-03 16:27:07 +080022#include <linux/immap_qe.h>
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +010023#include <asm/io.h>
24#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050025
Wolfgang Denk6405a152006-03-31 18:32:53 +020026DECLARE_GLOBAL_DATA_PTR;
27
Mario Six28fbefa2018-08-06 10:23:45 +020028#ifndef CONFIG_CPU_MPC83XX
Eran Liberty9095d4a2005-07-28 10:08:46 -050029int checkcpu(void)
30{
Dave Liua46daea2006-11-03 19:33:44 -060031 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050032 ulong clock = gd->cpu_clk;
33 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060034 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050035 char buf[32];
Simon Glass156283f2017-03-28 10:27:27 -060036 int ret;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050037 int i;
38
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050039 const struct cpu_type {
40 char name[15];
41 u32 partid;
42 } cpu_type_list [] = {
Ilya Yanoka3e5fd52010-06-28 16:44:33 +040043 CPU_TYPE_ENTRY(8308),
Gerlando Falautofe201cb2012-10-10 22:13:08 +000044 CPU_TYPE_ENTRY(8309),
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050045 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 Liberty9095d4a2005-07-28 10:08:46 -050062
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060064
Simon Glass156283f2017-03-28 10:27:27 -060065 ret = prt_83xx_rsr();
66 if (ret)
67 return ret;
68
Kim Phillipsd82b0772007-04-30 15:26:21 -050069 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050070
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 Liu5245ff52007-09-18 12:36:11 +080084 case PVR_E300C4:
85 printf("e300c4, ");
86 break;
87
Scott Wood7206a992007-04-16 14:34:16 -050088 default:
89 printf("Unknown core, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050090 }
91
Dave Liua46daea2006-11-03 19:33:44 -060092 spridr = immr->sysconf.spridr;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050093
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 Phillips39b48162010-04-15 17:36:02 -0500100 if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
101 SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
102 REVID_MAJOR(spridr) >= 2)
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500103 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));
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200113
Simon Glasscc76e9e2012-12-13 20:48:47 +0000114 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillipsd82b0772007-04-30 15:26:21 -0500115
Eran Liberty9095d4a2005-07-28 10:08:46 -0500116 return 0;
117}
Mario Six28fbefa2018-08-06 10:23:45 +0200118#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500119
Mario Six82ef4ba2018-08-06 10:23:35 +0200120#ifndef CONFIG_SYSRESET
Eran Liberty9095d4a2005-07-28 10:08:46 -0500121int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200122do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500123{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200124 ulong msr;
125#ifndef MPC83xx_RESET
126 ulong addr;
127#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500128
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200129 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500130
Michael Zaidman184154b2010-02-15 10:02:32 +0200131 puts("Resetting the board.\n");
132
Eran Liberty9095d4a2005-07-28 10:08:46 -0500133#ifdef MPC83xx_RESET
Michael Zaidman184154b2010-02-15 10:02:32 +0200134
Eran Liberty9095d4a2005-07-28 10:08:46 -0500135 /* Interrupts and MMU off */
136 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
137
138 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
139 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
140
141 /* enable Reset Control Reg */
142 immap->reset.rpr = 0x52535445;
Marian Balakowicz919b1872006-03-14 16:12:48 +0100143 __asm__ __volatile__ ("sync");
144 __asm__ __volatile__ ("isync");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500145
146 /* confirm Reset Control Reg is enabled */
147 while(!((immap->reset.rcer) & RCER_CRE));
148
Eran Liberty9095d4a2005-07-28 10:08:46 -0500149 udelay(200);
150
151 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200152 immap->reset.rcr = RCR_SWHR;
153
154#else /* ! MPC83xx_RESET */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500155
Wolfgang Denk301d0962005-08-05 19:49:35 +0200156 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
157
158 /* Interrupts and MMU off */
159 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500160
161 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
162 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
163
164 /*
165 * Trying to execute the next instruction at a non-existing address
166 * should cause a machine check, resulting in reset
167 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200168 addr = CONFIG_SYS_RESET_ADDRESS;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500169
Eran Liberty9095d4a2005-07-28 10:08:46 -0500170 ((void (*)(void)) addr) ();
Wolfgang Denk301d0962005-08-05 19:49:35 +0200171#endif /* MPC83xx_RESET */
172
Eran Liberty9095d4a2005-07-28 10:08:46 -0500173 return 1;
174}
Mario Six82ef4ba2018-08-06 10:23:35 +0200175#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500176
177/*
178 * Get timebase clock frequency (like cpu_clk in Hz)
179 */
Mario Six3c516552018-08-06 10:23:38 +0200180#ifndef CONFIG_TIMER
Eran Liberty9095d4a2005-07-28 10:08:46 -0500181unsigned long get_tbclk(void)
182{
Masahiro Yamada04cfea52016-09-06 22:17:38 +0900183 return (gd->bus_clk + 3L) / 4L;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500184}
Mario Six3c516552018-08-06 10:23:38 +0200185#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500186
187#if defined(CONFIG_WATCHDOG)
188void watchdog_reset (void)
189{
Timur Tabi054838e2006-10-31 18:44:42 -0600190 int re_enable = disable_interrupts();
191
192 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200193 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600194 immr->wdt.swsrr = 0x556c;
195 immr->wdt.swsrr = 0xaa39;
196
197 if (re_enable)
198 enable_interrupts ();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500199}
Timur Tabi054838e2006-10-31 18:44:42 -0600200#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600201
Mario Six640b8c32019-01-21 09:18:19 +0100202#ifndef CONFIG_DM_ETH
Andy Flemingfecff2b2008-08-31 16:33:26 -0500203/*
204 * Initializes on-chip ethernet controllers.
205 * to override, implement board_eth_init()
Ben Warrend448a492008-06-23 22:57:27 -0700206 */
Ben Warrend448a492008-06-23 22:57:27 -0700207int cpu_eth_init(bd_t *bis)
208{
Haiying Wang511d8282009-06-04 16:12:41 -0400209#if defined(CONFIG_UEC_ETH)
210 uec_standard_init(bis);
Ben Warren67731692008-10-22 23:32:48 -0700211#endif
Haiying Wang511d8282009-06-04 16:12:41 -0400212
Andy Flemingfecff2b2008-08-31 16:33:26 -0500213#if defined(CONFIG_TSEC_ENET)
214 tsec_standard_init(bis);
Ben Warrend448a492008-06-23 22:57:27 -0700215#endif
Ben Warrend448a492008-06-23 22:57:27 -0700216 return 0;
217}
Mario Six640b8c32019-01-21 09:18:19 +0100218#endif /* !CONFIG_DM_ETH */
Andy Fleming1463b4b2008-10-30 16:50:14 -0500219
220/*
221 * Initializes on-chip MMC controllers.
222 * to override, implement board_mmc_init()
223 */
224int cpu_mmc_init(bd_t *bis)
225{
226#ifdef CONFIG_FSL_ESDHC
227 return fsl_esdhc_mmc_init(bis);
228#else
229 return 0;
230#endif
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +0100231}
Mario Six90b529f2019-01-21 09:18:20 +0100232
233void ppcDWstore(unsigned int *addr, unsigned int *value)
234{
235 asm("lfd 1, 0(%1)\n\t"
236 "stfd 1, 0(%0)"
237 :
238 : "r" (addr), "r" (value)
239 : "memory");
240}
241
242void ppcDWload(unsigned int *addr, unsigned int *ret)
243{
244 asm("lfd 1, 0(%0)\n\t"
245 "stfd 1, 0(%1)"
246 :
247 : "r" (addr), "r" (ret)
248 : "memory");
249}