blob: f4e25f1f59c39472d0bd853776515617748f501f [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 Glass8f3f7612019-11-14 12:57:42 -070014#include <irq_func.h>
Simon Glassa9dc0682019-12-28 10:44:59 -070015#include <time.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070016#include <vsprintf.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050017#include <watchdog.h>
18#include <command.h>
19#include <mpc83xx.h>
20#include <asm/processor.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090021#include <linux/libfdt.h>
Andy Flemingfecff2b2008-08-31 16:33:26 -050022#include <tsec.h>
Ben Warren67731692008-10-22 23:32:48 -070023#include <netdev.h>
Andy Fleming1463b4b2008-10-30 16:50:14 -050024#include <fsl_esdhc.h>
Mario Six9164bdd2019-01-21 09:17:25 +010025#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang978679d2014-06-03 16:27:07 +080026#include <linux/immap_qe.h>
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +010027#include <asm/io.h>
28#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050029
Wolfgang Denk6405a152006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
Mario Six28fbefa2018-08-06 10:23:45 +020032#ifndef CONFIG_CPU_MPC83XX
Eran Liberty9095d4a2005-07-28 10:08:46 -050033int checkcpu(void)
34{
Dave Liua46daea2006-11-03 19:33:44 -060035 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050036 ulong clock = gd->cpu_clk;
37 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060038 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050039 char buf[32];
Simon Glass156283f2017-03-28 10:27:27 -060040 int ret;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050041 int i;
42
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050043 const struct cpu_type {
44 char name[15];
45 u32 partid;
46 } cpu_type_list [] = {
Ilya Yanoka3e5fd52010-06-28 16:44:33 +040047 CPU_TYPE_ENTRY(8308),
Gerlando Falautofe201cb2012-10-10 22:13:08 +000048 CPU_TYPE_ENTRY(8309),
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050049 CPU_TYPE_ENTRY(8311),
50 CPU_TYPE_ENTRY(8313),
51 CPU_TYPE_ENTRY(8314),
52 CPU_TYPE_ENTRY(8315),
53 CPU_TYPE_ENTRY(8321),
54 CPU_TYPE_ENTRY(8323),
55 CPU_TYPE_ENTRY(8343),
56 CPU_TYPE_ENTRY(8347_TBGA_),
57 CPU_TYPE_ENTRY(8347_PBGA_),
58 CPU_TYPE_ENTRY(8349),
59 CPU_TYPE_ENTRY(8358_TBGA_),
60 CPU_TYPE_ENTRY(8358_PBGA_),
61 CPU_TYPE_ENTRY(8360),
62 CPU_TYPE_ENTRY(8377),
63 CPU_TYPE_ENTRY(8378),
64 CPU_TYPE_ENTRY(8379),
65 };
Eran Liberty9095d4a2005-07-28 10:08:46 -050066
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020067 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060068
Simon Glass156283f2017-03-28 10:27:27 -060069 ret = prt_83xx_rsr();
70 if (ret)
71 return ret;
72
Kim Phillipsd82b0772007-04-30 15:26:21 -050073 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050074
75 switch (pvr & 0xffff0000) {
76 case PVR_E300C1:
77 printf("e300c1, ");
78 break;
79
80 case PVR_E300C2:
81 printf("e300c2, ");
82 break;
83
84 case PVR_E300C3:
85 printf("e300c3, ");
86 break;
87
Dave Liu5245ff52007-09-18 12:36:11 +080088 case PVR_E300C4:
89 printf("e300c4, ");
90 break;
91
Scott Wood7206a992007-04-16 14:34:16 -050092 default:
93 printf("Unknown core, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050094 }
95
Dave Liua46daea2006-11-03 19:33:44 -060096 spridr = immr->sysconf.spridr;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050097
98 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
99 if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) {
100 puts("MPC");
101 puts(cpu_type_list[i].name);
102 if (IS_E_PROCESSOR(spridr))
103 puts("E");
Kim Phillips39b48162010-04-15 17:36:02 -0500104 if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
105 SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
106 REVID_MAJOR(spridr) >= 2)
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500107 puts("A");
108 printf(", Rev: %d.%d", REVID_MAJOR(spridr),
109 REVID_MINOR(spridr));
110 break;
111 }
112
113 if (i == ARRAY_SIZE(cpu_type_list))
114 printf("(SPRIDR %08x unknown), ", spridr);
115
116 printf(" at %s MHz, ", strmhz(buf, clock));
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200117
Simon Glasscc76e9e2012-12-13 20:48:47 +0000118 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillipsd82b0772007-04-30 15:26:21 -0500119
Eran Liberty9095d4a2005-07-28 10:08:46 -0500120 return 0;
121}
Mario Six28fbefa2018-08-06 10:23:45 +0200122#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500123
Mario Six82ef4ba2018-08-06 10:23:35 +0200124#ifndef CONFIG_SYSRESET
Eran Liberty9095d4a2005-07-28 10:08:46 -0500125int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200126do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500127{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200128 ulong msr;
129#ifndef MPC83xx_RESET
130 ulong addr;
131#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500132
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500134
Michael Zaidman184154b2010-02-15 10:02:32 +0200135 puts("Resetting the board.\n");
136
Eran Liberty9095d4a2005-07-28 10:08:46 -0500137#ifdef MPC83xx_RESET
Michael Zaidman184154b2010-02-15 10:02:32 +0200138
Eran Liberty9095d4a2005-07-28 10:08:46 -0500139 /* Interrupts and MMU off */
Mario Sixc463b6d2019-01-21 09:18:21 +0100140 msr = mfmsr();
141 msr &= ~(MSR_EE | MSR_IR | MSR_DR);
142 mtmsr(msr);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500143
144 /* enable Reset Control Reg */
145 immap->reset.rpr = 0x52535445;
Mario Sixc463b6d2019-01-21 09:18:21 +0100146 sync();
147 isync();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500148
149 /* confirm Reset Control Reg is enabled */
Mario Sixc463b6d2019-01-21 09:18:21 +0100150 while(!((immap->reset.rcer) & RCER_CRE))
151 ;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500152
Eran Liberty9095d4a2005-07-28 10:08:46 -0500153 udelay(200);
154
155 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200156 immap->reset.rcr = RCR_SWHR;
157
158#else /* ! MPC83xx_RESET */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500159
Wolfgang Denk301d0962005-08-05 19:49:35 +0200160 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
161
162 /* Interrupts and MMU off */
Mario Sixc463b6d2019-01-21 09:18:21 +0100163 msr = mfmsr();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500164 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
Mario Sixc463b6d2019-01-21 09:18:21 +0100165 mtmsr(msr);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500166
167 /*
168 * Trying to execute the next instruction at a non-existing address
169 * should cause a machine check, resulting in reset
170 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200171 addr = CONFIG_SYS_RESET_ADDRESS;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500172
Eran Liberty9095d4a2005-07-28 10:08:46 -0500173 ((void (*)(void)) addr) ();
Wolfgang Denk301d0962005-08-05 19:49:35 +0200174#endif /* MPC83xx_RESET */
175
Eran Liberty9095d4a2005-07-28 10:08:46 -0500176 return 1;
177}
Mario Six82ef4ba2018-08-06 10:23:35 +0200178#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500179
180/*
181 * Get timebase clock frequency (like cpu_clk in Hz)
182 */
Mario Six3c516552018-08-06 10:23:38 +0200183#ifndef CONFIG_TIMER
Eran Liberty9095d4a2005-07-28 10:08:46 -0500184unsigned long get_tbclk(void)
185{
Masahiro Yamada04cfea52016-09-06 22:17:38 +0900186 return (gd->bus_clk + 3L) / 4L;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500187}
Mario Six3c516552018-08-06 10:23:38 +0200188#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500189
190#if defined(CONFIG_WATCHDOG)
191void watchdog_reset (void)
192{
Timur Tabi054838e2006-10-31 18:44:42 -0600193 int re_enable = disable_interrupts();
194
195 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200196 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600197 immr->wdt.swsrr = 0x556c;
198 immr->wdt.swsrr = 0xaa39;
199
200 if (re_enable)
Simon Glassf87959b2019-11-14 12:57:40 -0700201 enable_interrupts();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500202}
Timur Tabi054838e2006-10-31 18:44:42 -0600203#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600204
Mario Six640b8c32019-01-21 09:18:19 +0100205#ifndef CONFIG_DM_ETH
Andy Flemingfecff2b2008-08-31 16:33:26 -0500206/*
207 * Initializes on-chip ethernet controllers.
208 * to override, implement board_eth_init()
Ben Warrend448a492008-06-23 22:57:27 -0700209 */
Ben Warrend448a492008-06-23 22:57:27 -0700210int cpu_eth_init(bd_t *bis)
211{
Haiying Wang511d8282009-06-04 16:12:41 -0400212#if defined(CONFIG_UEC_ETH)
213 uec_standard_init(bis);
Ben Warren67731692008-10-22 23:32:48 -0700214#endif
Haiying Wang511d8282009-06-04 16:12:41 -0400215
Andy Flemingfecff2b2008-08-31 16:33:26 -0500216#if defined(CONFIG_TSEC_ENET)
217 tsec_standard_init(bis);
Ben Warrend448a492008-06-23 22:57:27 -0700218#endif
Ben Warrend448a492008-06-23 22:57:27 -0700219 return 0;
220}
Mario Six640b8c32019-01-21 09:18:19 +0100221#endif /* !CONFIG_DM_ETH */
Andy Fleming1463b4b2008-10-30 16:50:14 -0500222
223/*
224 * Initializes on-chip MMC controllers.
225 * to override, implement board_mmc_init()
226 */
227int cpu_mmc_init(bd_t *bis)
228{
229#ifdef CONFIG_FSL_ESDHC
230 return fsl_esdhc_mmc_init(bis);
231#else
232 return 0;
233#endif
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +0100234}
Mario Six90b529f2019-01-21 09:18:20 +0100235
236void ppcDWstore(unsigned int *addr, unsigned int *value)
237{
238 asm("lfd 1, 0(%1)\n\t"
239 "stfd 1, 0(%0)"
240 :
241 : "r" (addr), "r" (value)
242 : "memory");
243}
244
245void ppcDWload(unsigned int *addr, unsigned int *ret)
246{
247 asm("lfd 1, 0(%0)\n\t"
248 "stfd 1, 0(%1)"
249 :
250 : "r" (addr), "r" (ret)
251 : "memory");
252}