blob: 843f2df649ec571faea9dc6f12ef788b3ad9c975 [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 Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Simon Glassa9dc0682019-12-28 10:44:59 -070016#include <time.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070017#include <vsprintf.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050018#include <watchdog.h>
19#include <command.h>
20#include <mpc83xx.h>
21#include <asm/processor.h>
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090023#include <linux/libfdt.h>
Andy Flemingfecff2b2008-08-31 16:33:26 -050024#include <tsec.h>
Ben Warren67731692008-10-22 23:32:48 -070025#include <netdev.h>
Andy Fleming1463b4b2008-10-30 16:50:14 -050026#include <fsl_esdhc.h>
Mario Six9164bdd2019-01-21 09:17:25 +010027#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang978679d2014-06-03 16:27:07 +080028#include <linux/immap_qe.h>
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +010029#include <asm/io.h>
30#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050031
Wolfgang Denk6405a152006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
Mario Six28fbefa2018-08-06 10:23:45 +020034#ifndef CONFIG_CPU_MPC83XX
Eran Liberty9095d4a2005-07-28 10:08:46 -050035int checkcpu(void)
36{
Dave Liua46daea2006-11-03 19:33:44 -060037 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050038 ulong clock = gd->cpu_clk;
39 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060040 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050041 char buf[32];
Simon Glass156283f2017-03-28 10:27:27 -060042 int ret;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050043 int i;
44
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050045 const struct cpu_type {
46 char name[15];
47 u32 partid;
48 } cpu_type_list [] = {
Ilya Yanoka3e5fd52010-06-28 16:44:33 +040049 CPU_TYPE_ENTRY(8308),
Gerlando Falautofe201cb2012-10-10 22:13:08 +000050 CPU_TYPE_ENTRY(8309),
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050051 CPU_TYPE_ENTRY(8311),
52 CPU_TYPE_ENTRY(8313),
53 CPU_TYPE_ENTRY(8314),
54 CPU_TYPE_ENTRY(8315),
55 CPU_TYPE_ENTRY(8321),
56 CPU_TYPE_ENTRY(8323),
57 CPU_TYPE_ENTRY(8343),
58 CPU_TYPE_ENTRY(8347_TBGA_),
59 CPU_TYPE_ENTRY(8347_PBGA_),
60 CPU_TYPE_ENTRY(8349),
61 CPU_TYPE_ENTRY(8358_TBGA_),
62 CPU_TYPE_ENTRY(8358_PBGA_),
63 CPU_TYPE_ENTRY(8360),
64 CPU_TYPE_ENTRY(8377),
65 CPU_TYPE_ENTRY(8378),
66 CPU_TYPE_ENTRY(8379),
67 };
Eran Liberty9095d4a2005-07-28 10:08:46 -050068
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060070
Simon Glass156283f2017-03-28 10:27:27 -060071 ret = prt_83xx_rsr();
72 if (ret)
73 return ret;
74
Kim Phillipsd82b0772007-04-30 15:26:21 -050075 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050076
77 switch (pvr & 0xffff0000) {
78 case PVR_E300C1:
79 printf("e300c1, ");
80 break;
81
82 case PVR_E300C2:
83 printf("e300c2, ");
84 break;
85
86 case PVR_E300C3:
87 printf("e300c3, ");
88 break;
89
Dave Liu5245ff52007-09-18 12:36:11 +080090 case PVR_E300C4:
91 printf("e300c4, ");
92 break;
93
Scott Wood7206a992007-04-16 14:34:16 -050094 default:
95 printf("Unknown core, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050096 }
97
Dave Liua46daea2006-11-03 19:33:44 -060098 spridr = immr->sysconf.spridr;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050099
100 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
101 if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) {
102 puts("MPC");
103 puts(cpu_type_list[i].name);
104 if (IS_E_PROCESSOR(spridr))
105 puts("E");
Kim Phillips39b48162010-04-15 17:36:02 -0500106 if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
107 SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
108 REVID_MAJOR(spridr) >= 2)
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500109 puts("A");
110 printf(", Rev: %d.%d", REVID_MAJOR(spridr),
111 REVID_MINOR(spridr));
112 break;
113 }
114
115 if (i == ARRAY_SIZE(cpu_type_list))
116 printf("(SPRIDR %08x unknown), ", spridr);
117
118 printf(" at %s MHz, ", strmhz(buf, clock));
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200119
Simon Glasscc76e9e2012-12-13 20:48:47 +0000120 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillipsd82b0772007-04-30 15:26:21 -0500121
Eran Liberty9095d4a2005-07-28 10:08:46 -0500122 return 0;
123}
Mario Six28fbefa2018-08-06 10:23:45 +0200124#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500125
Mario Six82ef4ba2018-08-06 10:23:35 +0200126#ifndef CONFIG_SYSRESET
Simon Glassed38aef2020-05-10 11:40:03 -0600127int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500128{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200129 ulong msr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500131
Michael Zaidman184154b2010-02-15 10:02:32 +0200132 puts("Resetting the board.\n");
133
Eran Liberty9095d4a2005-07-28 10:08:46 -0500134 /* Interrupts and MMU off */
Mario Sixc463b6d2019-01-21 09:18:21 +0100135 msr = mfmsr();
136 msr &= ~(MSR_EE | MSR_IR | MSR_DR);
137 mtmsr(msr);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500138
139 /* enable Reset Control Reg */
140 immap->reset.rpr = 0x52535445;
Mario Sixc463b6d2019-01-21 09:18:21 +0100141 sync();
142 isync();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500143
144 /* confirm Reset Control Reg is enabled */
Mario Sixc463b6d2019-01-21 09:18:21 +0100145 while(!((immap->reset.rcer) & RCER_CRE))
146 ;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500147
Eran Liberty9095d4a2005-07-28 10:08:46 -0500148 udelay(200);
149
150 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200151 immap->reset.rcr = RCR_SWHR;
152
Eran Liberty9095d4a2005-07-28 10:08:46 -0500153 return 1;
154}
Mario Six82ef4ba2018-08-06 10:23:35 +0200155#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500156
157/*
158 * Get timebase clock frequency (like cpu_clk in Hz)
159 */
Mario Six3c516552018-08-06 10:23:38 +0200160#ifndef CONFIG_TIMER
Eran Liberty9095d4a2005-07-28 10:08:46 -0500161unsigned long get_tbclk(void)
162{
Masahiro Yamada04cfea52016-09-06 22:17:38 +0900163 return (gd->bus_clk + 3L) / 4L;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500164}
Mario Six3c516552018-08-06 10:23:38 +0200165#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500166
167#if defined(CONFIG_WATCHDOG)
168void watchdog_reset (void)
169{
Timur Tabi054838e2006-10-31 18:44:42 -0600170 int re_enable = disable_interrupts();
171
172 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200173 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600174 immr->wdt.swsrr = 0x556c;
175 immr->wdt.swsrr = 0xaa39;
176
177 if (re_enable)
Simon Glassf87959b2019-11-14 12:57:40 -0700178 enable_interrupts();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500179}
Timur Tabi054838e2006-10-31 18:44:42 -0600180#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600181
Mario Six640b8c32019-01-21 09:18:19 +0100182#ifndef CONFIG_DM_ETH
Andy Flemingfecff2b2008-08-31 16:33:26 -0500183/*
184 * Initializes on-chip ethernet controllers.
185 * to override, implement board_eth_init()
Ben Warrend448a492008-06-23 22:57:27 -0700186 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900187int cpu_eth_init(struct bd_info *bis)
Ben Warrend448a492008-06-23 22:57:27 -0700188{
Haiying Wang511d8282009-06-04 16:12:41 -0400189#if defined(CONFIG_UEC_ETH)
190 uec_standard_init(bis);
Ben Warren67731692008-10-22 23:32:48 -0700191#endif
Haiying Wang511d8282009-06-04 16:12:41 -0400192
Andy Flemingfecff2b2008-08-31 16:33:26 -0500193#if defined(CONFIG_TSEC_ENET)
194 tsec_standard_init(bis);
Ben Warrend448a492008-06-23 22:57:27 -0700195#endif
Ben Warrend448a492008-06-23 22:57:27 -0700196 return 0;
197}
Mario Six640b8c32019-01-21 09:18:19 +0100198#endif /* !CONFIG_DM_ETH */
Andy Fleming1463b4b2008-10-30 16:50:14 -0500199
200/*
201 * Initializes on-chip MMC controllers.
202 * to override, implement board_mmc_init()
203 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900204int cpu_mmc_init(struct bd_info *bis)
Andy Fleming1463b4b2008-10-30 16:50:14 -0500205{
206#ifdef CONFIG_FSL_ESDHC
207 return fsl_esdhc_mmc_init(bis);
208#else
209 return 0;
210#endif
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +0100211}
Mario Six90b529f2019-01-21 09:18:20 +0100212
213void ppcDWstore(unsigned int *addr, unsigned int *value)
214{
215 asm("lfd 1, 0(%1)\n\t"
216 "stfd 1, 0(%0)"
217 :
218 : "r" (addr), "r" (value)
219 : "memory");
220}
221
222void ppcDWload(unsigned int *addr, unsigned int *ret)
223{
224 asm("lfd 1, 0(%0)\n\t"
225 "stfd 1, 0(%1)"
226 :
227 : "r" (addr), "r" (ret)
228 : "memory");
229}