blob: a6c063556e8360ba85bd1fe604c15d9316e3f49d [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Eran Liberty9095d4a2005-07-28 10:08:46 -050022#include <asm/processor.h>
Simon Glassdbd79542020-05-10 11:40:11 -060023#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090024#include <linux/libfdt.h>
Andy Flemingfecff2b2008-08-31 16:33:26 -050025#include <tsec.h>
Ben Warren67731692008-10-22 23:32:48 -070026#include <netdev.h>
Andy Fleming1463b4b2008-10-30 16:50:14 -050027#include <fsl_esdhc.h>
Mario Six9164bdd2019-01-21 09:17:25 +010028#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang978679d2014-06-03 16:27:07 +080029#include <linux/immap_qe.h>
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +010030#include <asm/io.h>
31#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050032
Wolfgang Denk6405a152006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
34
Mario Six28fbefa2018-08-06 10:23:45 +020035#ifndef CONFIG_CPU_MPC83XX
Eran Liberty9095d4a2005-07-28 10:08:46 -050036int checkcpu(void)
37{
Dave Liua46daea2006-11-03 19:33:44 -060038 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050039 ulong clock = gd->cpu_clk;
40 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060041 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050042 char buf[32];
Simon Glass156283f2017-03-28 10:27:27 -060043 int ret;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050044 int i;
45
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050046 const struct cpu_type {
47 char name[15];
48 u32 partid;
49 } cpu_type_list [] = {
Ilya Yanoka3e5fd52010-06-28 16:44:33 +040050 CPU_TYPE_ENTRY(8308),
Gerlando Falautofe201cb2012-10-10 22:13:08 +000051 CPU_TYPE_ENTRY(8309),
Kim Phillipsecb2d6f2008-03-28 10:19:07 -050052 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 Liberty9095d4a2005-07-28 10:08:46 -050069
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060071
Simon Glass156283f2017-03-28 10:27:27 -060072 ret = prt_83xx_rsr();
73 if (ret)
74 return ret;
75
Kim Phillipsd82b0772007-04-30 15:26:21 -050076 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050077
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 Liu5245ff52007-09-18 12:36:11 +080091 case PVR_E300C4:
92 printf("e300c4, ");
93 break;
94
Scott Wood7206a992007-04-16 14:34:16 -050095 default:
96 printf("Unknown core, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050097 }
98
Dave Liua46daea2006-11-03 19:33:44 -060099 spridr = immr->sysconf.spridr;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500100
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 Phillips39b48162010-04-15 17:36:02 -0500107 if ((SPR_FAMILY(spridr) == SPR_834X_FAMILY ||
108 SPR_FAMILY(spridr) == SPR_836X_FAMILY) &&
109 REVID_MAJOR(spridr) >= 2)
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500110 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));
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200120
Simon Glasscc76e9e2012-12-13 20:48:47 +0000121 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillipsd82b0772007-04-30 15:26:21 -0500122
Eran Liberty9095d4a2005-07-28 10:08:46 -0500123 return 0;
124}
Mario Six28fbefa2018-08-06 10:23:45 +0200125#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500126
Mario Six82ef4ba2018-08-06 10:23:35 +0200127#ifndef CONFIG_SYSRESET
Simon Glassed38aef2020-05-10 11:40:03 -0600128int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Eran Liberty9095d4a2005-07-28 10:08:46 -0500129{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200130 ulong msr;
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 /* Interrupts and MMU off */
Mario Sixc463b6d2019-01-21 09:18:21 +0100136 msr = mfmsr();
137 msr &= ~(MSR_EE | MSR_IR | MSR_DR);
138 mtmsr(msr);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500139
140 /* enable Reset Control Reg */
141 immap->reset.rpr = 0x52535445;
Mario Sixc463b6d2019-01-21 09:18:21 +0100142 sync();
143 isync();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500144
145 /* confirm Reset Control Reg is enabled */
Mario Sixc463b6d2019-01-21 09:18:21 +0100146 while(!((immap->reset.rcer) & RCER_CRE))
147 ;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500148
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
Eran Liberty9095d4a2005-07-28 10:08:46 -0500154 return 1;
155}
Mario Six82ef4ba2018-08-06 10:23:35 +0200156#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500157
158/*
159 * Get timebase clock frequency (like cpu_clk in Hz)
160 */
Mario Six3c516552018-08-06 10:23:38 +0200161#ifndef CONFIG_TIMER
Eran Liberty9095d4a2005-07-28 10:08:46 -0500162unsigned long get_tbclk(void)
163{
Masahiro Yamada04cfea52016-09-06 22:17:38 +0900164 return (gd->bus_clk + 3L) / 4L;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500165}
Mario Six3c516552018-08-06 10:23:38 +0200166#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500167
168#if defined(CONFIG_WATCHDOG)
169void watchdog_reset (void)
170{
Timur Tabi054838e2006-10-31 18:44:42 -0600171 int re_enable = disable_interrupts();
172
173 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200174 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600175 immr->wdt.swsrr = 0x556c;
176 immr->wdt.swsrr = 0xaa39;
177
178 if (re_enable)
Simon Glassf87959b2019-11-14 12:57:40 -0700179 enable_interrupts();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500180}
Timur Tabi054838e2006-10-31 18:44:42 -0600181#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600182
Andy Fleming1463b4b2008-10-30 16:50:14 -0500183/*
184 * Initializes on-chip MMC controllers.
185 * to override, implement board_mmc_init()
186 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900187int cpu_mmc_init(struct bd_info *bis)
Andy Fleming1463b4b2008-10-30 16:50:14 -0500188{
189#ifdef CONFIG_FSL_ESDHC
190 return fsl_esdhc_mmc_init(bis);
191#else
192 return 0;
193#endif
Heiko Schocherd2c4f3a2009-02-24 11:30:51 +0100194}
Mario Six90b529f2019-01-21 09:18:20 +0100195
196void ppcDWstore(unsigned int *addr, unsigned int *value)
197{
198 asm("lfd 1, 0(%1)\n\t"
199 "stfd 1, 0(%0)"
200 :
201 : "r" (addr), "r" (value)
202 : "memory");
203}
204
205void ppcDWload(unsigned int *addr, unsigned int *ret)
206{
207 asm("lfd 1, 0(%0)\n\t"
208 "stfd 1, 0(%1)"
209 :
210 : "r" (addr), "r" (ret)
211 : "memory");
212}