blob: 3c8cbd4252d0861fce3fc94acffc5dcb6d5b152e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eran Libertyf046ccd2005-07-28 10:08:46 -05002/*
Dave Liu03051c32007-09-18 12:36:11 +08003 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
Eran Libertyf046ccd2005-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
Simon Glass30c7c432019-11-14 12:57:34 -070012#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070013#include <irq_func.h>
Simon Glass90526e92020-05-10 11:39:56 -060014#include <net.h>
Simon Glass049f8d62019-12-28 10:44:59 -070015#include <time.h>
Simon Glass2189d5f2019-11-14 12:57:20 -070016#include <vsprintf.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050017#include <watchdog.h>
18#include <command.h>
19#include <mpc83xx.h>
Simon Glass401d1c42020-10-30 21:38:53 -060020#include <asm/global_data.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050021#include <asm/processor.h>
Simon Glassc05ed002020-05-10 11:40:11 -060022#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090023#include <linux/libfdt.h>
Andy Fleming75b9d4a2008-08-31 16:33:26 -050024#include <tsec.h>
Ben Warren0e8454e2008-10-22 23:32:48 -070025#include <netdev.h>
Andy Fleminge1ac3872008-10-30 16:50:14 -050026#include <fsl_esdhc.h>
Mario Six9403fc42019-01-21 09:17:25 +010027#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang38d67a4e2014-06-03 16:27:07 +080028#include <linux/immap_qe.h>
Heiko Schocherf70fd132009-02-24 11:30:51 +010029#include <asm/io.h>
30#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -050031
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
Mario Six19fbdca2018-08-06 10:23:45 +020034#ifndef CONFIG_CPU_MPC83XX
Eran Libertyf046ccd2005-07-28 10:08:46 -050035int checkcpu(void)
36{
Dave Liu5f820432006-11-03 19:33:44 -060037 volatile immap_t *immr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050038 ulong clock = gd->cpu_clk;
39 u32 pvr = get_pvr();
Dave Liu5f820432006-11-03 19:33:44 -060040 u32 spridr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050041 char buf[32];
Simon Glassd891ab92017-03-28 10:27:27 -060042 int ret;
Kim Phillipse5c4ade2008-03-28 10:19:07 -050043 int i;
44
Kim Phillipse5c4ade2008-03-28 10:19:07 -050045 const struct cpu_type {
46 char name[15];
47 u32 partid;
48 } cpu_type_list [] = {
Ilya Yanok7c619dd2010-06-28 16:44:33 +040049 CPU_TYPE_ENTRY(8308),
Gerlando Falautoa88731a2012-10-10 22:13:08 +000050 CPU_TYPE_ENTRY(8309),
Kim Phillipse5c4ade2008-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 Libertyf046ccd2005-07-28 10:08:46 -050068
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu5f820432006-11-03 19:33:44 -060070
Simon Glassd891ab92017-03-28 10:27:27 -060071 ret = prt_83xx_rsr();
72 if (ret)
73 return ret;
74
Kim Phillips54b2d432007-04-30 15:26:21 -050075 puts("CPU: ");
Scott Wood95e7ef82007-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 Liu03051c32007-09-18 12:36:11 +080090 case PVR_E300C4:
91 printf("e300c4, ");
92 break;
93
Scott Wood95e7ef82007-04-16 14:34:16 -050094 default:
95 printf("Unknown core, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050096 }
97
Dave Liu5f820432006-11-03 19:33:44 -060098 spridr = immr->sysconf.spridr;
Rafal Jaworowski6902df52005-10-17 02:39:53 +020099
Kim Phillipse5c4ade2008-03-28 10:19:07 -0500100 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 Phillipsdfe812c2010-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 Phillipse5c4ade2008-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));
119
Simon Glassc6731fe2012-12-13 20:48:47 +0000120 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillips54b2d432007-04-30 15:26:21 -0500121
Eran Libertyf046ccd2005-07-28 10:08:46 -0500122 return 0;
123}
Mario Six19fbdca2018-08-06 10:23:45 +0200124#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500125
Mario Six76fdad12018-08-06 10:23:35 +0200126#ifndef CONFIG_SYSRESET
Simon Glass09140112020-05-10 11:40:03 -0600127int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Eran Libertyf046ccd2005-07-28 10:08:46 -0500128{
Wolfgang Denk07a25052005-08-05 19:49:35 +0200129 ulong msr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200130 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500131
Michael Zaidman4c006dd2010-02-15 10:02:32 +0200132 puts("Resetting the board.\n");
133
Eran Libertyf046ccd2005-07-28 10:08:46 -0500134 /* Interrupts and MMU off */
Mario Six5c229982019-01-21 09:18:21 +0100135 msr = mfmsr();
136 msr &= ~(MSR_EE | MSR_IR | MSR_DR);
137 mtmsr(msr);
Eran Libertyf046ccd2005-07-28 10:08:46 -0500138
139 /* enable Reset Control Reg */
140 immap->reset.rpr = 0x52535445;
Mario Six5c229982019-01-21 09:18:21 +0100141 sync();
142 isync();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500143
144 /* confirm Reset Control Reg is enabled */
Mario Six5c229982019-01-21 09:18:21 +0100145 while(!((immap->reset.rcer) & RCER_CRE))
146 ;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500147
Eran Libertyf046ccd2005-07-28 10:08:46 -0500148 udelay(200);
149
150 /* perform reset, only one bit */
Wolfgang Denk07a25052005-08-05 19:49:35 +0200151 immap->reset.rcr = RCR_SWHR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500152
Eran Libertyf046ccd2005-07-28 10:08:46 -0500153 return 1;
154}
Mario Six76fdad12018-08-06 10:23:35 +0200155#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500156
157/*
158 * Get timebase clock frequency (like cpu_clk in Hz)
159 */
Mario Six2c217492018-08-06 10:23:38 +0200160#ifndef CONFIG_TIMER
Eran Libertyf046ccd2005-07-28 10:08:46 -0500161unsigned long get_tbclk(void)
162{
Masahiro Yamada63a75782016-09-06 22:17:38 +0900163 return (gd->bus_clk + 3L) / 4L;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500164}
Mario Six2c217492018-08-06 10:23:38 +0200165#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500166
Andy Fleminge1ac3872008-10-30 16:50:14 -0500167/*
168 * Initializes on-chip MMC controllers.
169 * to override, implement board_mmc_init()
170 */
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900171int cpu_mmc_init(struct bd_info *bis)
Andy Fleminge1ac3872008-10-30 16:50:14 -0500172{
173#ifdef CONFIG_FSL_ESDHC
174 return fsl_esdhc_mmc_init(bis);
175#else
176 return 0;
177#endif
178}
Mario Six1e718f42019-01-21 09:18:20 +0100179
180void ppcDWstore(unsigned int *addr, unsigned int *value)
181{
182 asm("lfd 1, 0(%1)\n\t"
183 "stfd 1, 0(%0)"
184 :
185 : "r" (addr), "r" (value)
186 : "memory");
187}
188
189void ppcDWload(unsigned int *addr, unsigned int *ret)
190{
191 asm("lfd 1, 0(%0)\n\t"
192 "stfd 1, 0(%1)"
193 :
194 : "r" (addr), "r" (ret)
195 : "memory");
196}