blob: 8d531898bd891e6868f1d2a70812b5b616beeab6 [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
12#include <common.h>
Simon Glass30c7c432019-11-14 12:57:34 -070013#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070014#include <irq_func.h>
Simon Glass90526e92020-05-10 11:39:56 -060015#include <net.h>
Simon Glass049f8d62019-12-28 10:44:59 -070016#include <time.h>
Simon Glass2189d5f2019-11-14 12:57:20 -070017#include <vsprintf.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050018#include <watchdog.h>
19#include <command.h>
20#include <mpc83xx.h>
Simon Glass401d1c42020-10-30 21:38:53 -060021#include <asm/global_data.h>
Eran Libertyf046ccd2005-07-28 10:08:46 -050022#include <asm/processor.h>
Simon Glassc05ed002020-05-10 11:40:11 -060023#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090024#include <linux/libfdt.h>
Andy Fleming75b9d4a2008-08-31 16:33:26 -050025#include <tsec.h>
Ben Warren0e8454e2008-10-22 23:32:48 -070026#include <netdev.h>
Andy Fleminge1ac3872008-10-30 16:50:14 -050027#include <fsl_esdhc.h>
Mario Six9403fc42019-01-21 09:17:25 +010028#if defined(CONFIG_BOOTCOUNT_LIMIT) && !defined(CONFIG_ARCH_MPC831X)
Zhao Qiang38d67a4e2014-06-03 16:27:07 +080029#include <linux/immap_qe.h>
Heiko Schocherf70fd132009-02-24 11:30:51 +010030#include <asm/io.h>
31#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -050032
Wolfgang Denkd87080b2006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
34
Mario Six19fbdca2018-08-06 10:23:45 +020035#ifndef CONFIG_CPU_MPC83XX
Eran Libertyf046ccd2005-07-28 10:08:46 -050036int checkcpu(void)
37{
Dave Liu5f820432006-11-03 19:33:44 -060038 volatile immap_t *immr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050039 ulong clock = gd->cpu_clk;
40 u32 pvr = get_pvr();
Dave Liu5f820432006-11-03 19:33:44 -060041 u32 spridr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050042 char buf[32];
Simon Glassd891ab92017-03-28 10:27:27 -060043 int ret;
Kim Phillipse5c4ade2008-03-28 10:19:07 -050044 int i;
45
Kim Phillipse5c4ade2008-03-28 10:19:07 -050046 const struct cpu_type {
47 char name[15];
48 u32 partid;
49 } cpu_type_list [] = {
Ilya Yanok7c619dd2010-06-28 16:44:33 +040050 CPU_TYPE_ENTRY(8308),
Gerlando Falautoa88731a2012-10-10 22:13:08 +000051 CPU_TYPE_ENTRY(8309),
Kim Phillipse5c4ade2008-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 Libertyf046ccd2005-07-28 10:08:46 -050069
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020070 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu5f820432006-11-03 19:33:44 -060071
Simon Glassd891ab92017-03-28 10:27:27 -060072 ret = prt_83xx_rsr();
73 if (ret)
74 return ret;
75
Kim Phillips54b2d432007-04-30 15:26:21 -050076 puts("CPU: ");
Scott Wood95e7ef82007-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 Liu03051c32007-09-18 12:36:11 +080091 case PVR_E300C4:
92 printf("e300c4, ");
93 break;
94
Scott Wood95e7ef82007-04-16 14:34:16 -050095 default:
96 printf("Unknown core, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050097 }
98
Dave Liu5f820432006-11-03 19:33:44 -060099 spridr = immr->sysconf.spridr;
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200100
Kim Phillipse5c4ade2008-03-28 10:19:07 -0500101 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 Phillipsdfe812c2010-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 Phillipse5c4ade2008-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));
120
Simon Glassc6731fe2012-12-13 20:48:47 +0000121 printf("CSB: %s MHz\n", strmhz(buf, gd->arch.csb_clk));
Kim Phillips54b2d432007-04-30 15:26:21 -0500122
Eran Libertyf046ccd2005-07-28 10:08:46 -0500123 return 0;
124}
Mario Six19fbdca2018-08-06 10:23:45 +0200125#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500126
Mario Six76fdad12018-08-06 10:23:35 +0200127#ifndef CONFIG_SYSRESET
Simon Glass09140112020-05-10 11:40:03 -0600128int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Eran Libertyf046ccd2005-07-28 10:08:46 -0500129{
Wolfgang Denk07a25052005-08-05 19:49:35 +0200130 ulong msr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200131 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500132
Michael Zaidman4c006dd2010-02-15 10:02:32 +0200133 puts("Resetting the board.\n");
134
Eran Libertyf046ccd2005-07-28 10:08:46 -0500135 /* Interrupts and MMU off */
Mario Six5c229982019-01-21 09:18:21 +0100136 msr = mfmsr();
137 msr &= ~(MSR_EE | MSR_IR | MSR_DR);
138 mtmsr(msr);
Eran Libertyf046ccd2005-07-28 10:08:46 -0500139
140 /* enable Reset Control Reg */
141 immap->reset.rpr = 0x52535445;
Mario Six5c229982019-01-21 09:18:21 +0100142 sync();
143 isync();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500144
145 /* confirm Reset Control Reg is enabled */
Mario Six5c229982019-01-21 09:18:21 +0100146 while(!((immap->reset.rcer) & RCER_CRE))
147 ;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500148
Eran Libertyf046ccd2005-07-28 10:08:46 -0500149 udelay(200);
150
151 /* perform reset, only one bit */
Wolfgang Denk07a25052005-08-05 19:49:35 +0200152 immap->reset.rcr = RCR_SWHR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500153
Eran Libertyf046ccd2005-07-28 10:08:46 -0500154 return 1;
155}
Mario Six76fdad12018-08-06 10:23:35 +0200156#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500157
158/*
159 * Get timebase clock frequency (like cpu_clk in Hz)
160 */
Mario Six2c217492018-08-06 10:23:38 +0200161#ifndef CONFIG_TIMER
Eran Libertyf046ccd2005-07-28 10:08:46 -0500162unsigned long get_tbclk(void)
163{
Masahiro Yamada63a75782016-09-06 22:17:38 +0900164 return (gd->bus_clk + 3L) / 4L;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500165}
Mario Six2c217492018-08-06 10:23:38 +0200166#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500167
168#if defined(CONFIG_WATCHDOG)
169void watchdog_reset (void)
170{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600171 int re_enable = disable_interrupts();
172
173 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200174 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600175 immr->wdt.swsrr = 0x556c;
176 immr->wdt.swsrr = 0xaa39;
177
178 if (re_enable)
Simon Glass9d3915b2019-11-14 12:57:40 -0700179 enable_interrupts();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500180}
Timur Tabi2ad6b512006-10-31 18:44:42 -0600181#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600182
Mario Six88358362019-01-21 09:18:19 +0100183#ifndef CONFIG_DM_ETH
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500184/*
185 * Initializes on-chip ethernet controllers.
186 * to override, implement board_eth_init()
Ben Warrendd354792008-06-23 22:57:27 -0700187 */
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900188int cpu_eth_init(struct bd_info *bis)
Ben Warrendd354792008-06-23 22:57:27 -0700189{
Haiying Wang8e552582009-06-04 16:12:41 -0400190#if defined(CONFIG_UEC_ETH)
191 uec_standard_init(bis);
Ben Warren0e8454e2008-10-22 23:32:48 -0700192#endif
Haiying Wang8e552582009-06-04 16:12:41 -0400193
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500194#if defined(CONFIG_TSEC_ENET)
195 tsec_standard_init(bis);
Ben Warrendd354792008-06-23 22:57:27 -0700196#endif
Ben Warrendd354792008-06-23 22:57:27 -0700197 return 0;
198}
Mario Six88358362019-01-21 09:18:19 +0100199#endif /* !CONFIG_DM_ETH */
Andy Fleminge1ac3872008-10-30 16:50:14 -0500200
201/*
202 * Initializes on-chip MMC controllers.
203 * to override, implement board_mmc_init()
204 */
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900205int cpu_mmc_init(struct bd_info *bis)
Andy Fleminge1ac3872008-10-30 16:50:14 -0500206{
207#ifdef CONFIG_FSL_ESDHC
208 return fsl_esdhc_mmc_init(bis);
209#else
210 return 0;
211#endif
212}
Mario Six1e718f42019-01-21 09:18:20 +0100213
214void ppcDWstore(unsigned int *addr, unsigned int *value)
215{
216 asm("lfd 1, 0(%1)\n\t"
217 "stfd 1, 0(%0)"
218 :
219 : "r" (addr), "r" (value)
220 : "memory");
221}
222
223void ppcDWload(unsigned int *addr, unsigned int *ret)
224{
225 asm("lfd 1, 0(%0)\n\t"
226 "stfd 1, 0(%1)"
227 :
228 : "r" (addr), "r" (ret)
229 : "memory");
230}