blob: 15b7b231eea524dcce53f0788efcdf91e3aee6ac [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +08002 * Copyright 2004,2007-2010 Freescale Semiconductor, Inc.
wdenk9c53f402003-10-15 23:53:47 +00003 * (C) Copyright 2002, 2003 Motorola Inc.
4 * Xianghua Xiao (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
Andy Flemingfecff2b2008-08-31 16:33:26 -050028#include <config.h>
wdenk9c53f402003-10-15 23:53:47 +000029#include <common.h>
30#include <watchdog.h>
31#include <command.h>
Andy Fleming6843a6e2008-10-30 16:51:33 -050032#include <fsl_esdhc.h>
wdenk9c53f402003-10-15 23:53:47 +000033#include <asm/cache.h>
Sergei Poselenovddc1a472008-06-06 15:42:40 +020034#include <asm/io.h>
wdenk9c53f402003-10-15 23:53:47 +000035
James Yang957b1912008-02-08 16:44:53 -060036DECLARE_GLOBAL_DATA_PTR;
37
wdenk9c53f402003-10-15 23:53:47 +000038int checkcpu (void)
39{
wdenka445ddf2004-06-09 00:34:46 +000040 sys_info_t sysinfo;
wdenka445ddf2004-06-09 00:34:46 +000041 uint pvr, svr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050042 uint fam;
wdenka445ddf2004-06-09 00:34:46 +000043 uint ver;
44 uint major, minor;
Kumar Gala8ddf00c2008-06-10 16:53:46 -050045 struct cpu_type *cpu;
Wolfgang Denk20591042008-10-19 02:35:49 +020046 char buf1[32], buf2[32];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080048#ifdef CONFIG_DDR_CLK_FREQ
Jason Jinbfcd6c32008-09-27 14:40:57 +080049 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
50 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galadccd9e32009-03-19 02:46:19 -050051#else
52#ifdef CONFIG_FSL_CORENET
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080053 u32 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
54 >> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
Kumar Gala54b68102008-05-29 01:21:24 -050055#else
56 u32 ddr_ratio = 0;
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080057#endif /* CONFIG_FSL_CORENET */
Kumar Galadccd9e32009-03-19 02:46:19 -050058#endif /* CONFIG_DDR_CLK_FREQ */
Haiying Wangbb8aea72009-01-15 11:58:35 -050059 int i;
wdenk9c53f402003-10-15 23:53:47 +000060
wdenka445ddf2004-06-09 00:34:46 +000061 svr = get_svr();
wdenka445ddf2004-06-09 00:34:46 +000062 major = SVR_MAJ(svr);
Kumar Galacd777282008-08-12 11:14:19 -050063#ifdef CONFIG_MPC8536
64 major &= 0x7; /* the msb of this nibble is a mfg code */
65#endif
wdenka445ddf2004-06-09 00:34:46 +000066 minor = SVR_MIN(svr);
67
Poonam Aggrwal4baef822009-07-31 12:08:14 +053068 if (cpu_numcores() > 1) {
Poonam Aggrwal36a68432009-09-03 19:42:40 +053069#ifndef CONFIG_MP
70 puts("Unicore software on multiprocessor system!!\n"
71 "To enable mutlticore build define CONFIG_MP\n");
72#endif
Poonam Aggrwal4baef822009-07-31 12:08:14 +053073 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
74 printf("CPU%d: ", pic->whoami);
75 } else {
76 puts("CPU: ");
77 }
Andy Flemingf5740972008-02-06 01:19:40 -060078
Poonam Aggrwal4baef822009-07-31 12:08:14 +053079 cpu = gd->cpu;
Andy Flemingf5740972008-02-06 01:19:40 -060080
Poonam Aggrwalda6e1ca2009-09-02 13:35:21 +053081 puts(cpu->name);
82 if (IS_E_PROCESSOR(svr))
83 puts("E");
Andy Flemingf5740972008-02-06 01:19:40 -060084
wdenka445ddf2004-06-09 00:34:46 +000085 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk9c53f402003-10-15 23:53:47 +000086
wdenk3f3262b2005-03-15 22:56:53 +000087 pvr = get_pvr();
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050088 fam = PVR_FAM(pvr);
wdenk3f3262b2005-03-15 22:56:53 +000089 ver = PVR_VER(pvr);
90 major = PVR_MAJ(pvr);
91 minor = PVR_MIN(pvr);
92
93 printf("Core: ");
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050094 switch (fam) {
95 case PVR_FAM(PVR_85xx):
wdenk3f3262b2005-03-15 22:56:53 +000096 puts("E500");
97 break;
98 default:
99 puts("Unknown");
100 break;
101 }
Kumar Gala9f4a6892008-10-23 01:47:38 -0500102
103 if (PVR_MEM(pvr) == 0x03)
104 puts("MC");
105
wdenk3f3262b2005-03-15 22:56:53 +0000106 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
107
wdenka445ddf2004-06-09 00:34:46 +0000108 get_sys_info(&sysinfo);
109
Kumar Galaf92794c2009-02-04 09:35:57 -0600110 puts("Clock Configuration:");
Poonam Aggrwal4baef822009-07-31 12:08:14 +0530111 for (i = 0; i < cpu_numcores(); i++) {
Wolfgang Denk1f79d142009-02-19 00:41:08 +0100112 if (!(i & 3))
113 printf ("\n ");
Haiying Wangbb8aea72009-01-15 11:58:35 -0500114 printf("CPU%d:%-4s MHz, ",
115 i,strmhz(buf1, sysinfo.freqProcessor[i]));
Kumar Galaf92794c2009-02-04 09:35:57 -0600116 }
117 printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
Kumar Gala54b68102008-05-29 01:21:24 -0500118
Kumar Galadccd9e32009-03-19 02:46:19 -0500119#ifdef CONFIG_FSL_CORENET
120 if (ddr_sync == 1) {
121 printf(" DDR:%-4s MHz (%s MT/s data rate) "
122 "(Synchronous), ",
123 strmhz(buf1, sysinfo.freqDDRBus/2),
124 strmhz(buf2, sysinfo.freqDDRBus));
125 } else {
126 printf(" DDR:%-4s MHz (%s MT/s data rate) "
127 "(Asynchronous), ",
128 strmhz(buf1, sysinfo.freqDDRBus/2),
129 strmhz(buf2, sysinfo.freqDDRBus));
130 }
131#else
Kumar Gala07db1702007-12-07 04:59:26 -0600132 switch (ddr_ratio) {
133 case 0x0:
Wolfgang Denk20591042008-10-19 02:35:49 +0200134 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
135 strmhz(buf1, sysinfo.freqDDRBus/2),
136 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Gala07db1702007-12-07 04:59:26 -0600137 break;
138 case 0x7:
Kumar Galadccd9e32009-03-19 02:46:19 -0500139 printf(" DDR:%-4s MHz (%s MT/s data rate) "
140 "(Synchronous), ",
Wolfgang Denk20591042008-10-19 02:35:49 +0200141 strmhz(buf1, sysinfo.freqDDRBus/2),
142 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Gala07db1702007-12-07 04:59:26 -0600143 break;
144 default:
Kumar Galadccd9e32009-03-19 02:46:19 -0500145 printf(" DDR:%-4s MHz (%s MT/s data rate) "
146 "(Asynchronous), ",
Wolfgang Denk20591042008-10-19 02:35:49 +0200147 strmhz(buf1, sysinfo.freqDDRBus/2),
148 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Gala07db1702007-12-07 04:59:26 -0600149 break;
150 }
Kumar Galadccd9e32009-03-19 02:46:19 -0500151#endif
wdenka445ddf2004-06-09 00:34:46 +0000152
Kumar Galadccd9e32009-03-19 02:46:19 -0500153 if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
Trent Piepho0b691fc2008-12-03 15:16:37 -0800154 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
Kumar Galadccd9e32009-03-19 02:46:19 -0500155 } else {
Trent Piepho0b691fc2008-12-03 15:16:37 -0800156 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
157 sysinfo.freqLocalBus);
Kumar Galadccd9e32009-03-19 02:46:19 -0500158 }
wdenka445ddf2004-06-09 00:34:46 +0000159
Andy Flemingf5740972008-02-06 01:19:40 -0600160#ifdef CONFIG_CPM2
Wolfgang Denk20591042008-10-19 02:35:49 +0200161 printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
Andy Flemingf5740972008-02-06 01:19:40 -0600162#endif
wdenka445ddf2004-06-09 00:34:46 +0000163
Haiying Wang61414682009-05-20 12:30:29 -0400164#ifdef CONFIG_QE
165 printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
166#endif
167
Kumar Galadccd9e32009-03-19 02:46:19 -0500168#ifdef CONFIG_SYS_DPAA_FMAN
169 for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
170 printf(" FMAN%d: %s MHz\n", i,
171 strmhz(buf1, sysinfo.freqFMan[i]));
172 }
173#endif
174
175#ifdef CONFIG_SYS_DPAA_PME
176 printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freqPME));
177#endif
178
wdenk3f3262b2005-03-15 22:56:53 +0000179 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk9c53f402003-10-15 23:53:47 +0000180
181 return 0;
182}
183
184
185/* ------------------------------------------------------------------------- */
186
187int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
188{
Kumar Galaaff01532009-09-08 13:46:46 -0500189/* Everything after the first generation of PQ3 parts has RSTCR */
190#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
191 defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
Sergei Poselenov25147422008-05-08 14:17:08 +0200192 unsigned long val, msr;
193
wdenk9c53f402003-10-15 23:53:47 +0000194 /*
195 * Initiate hard reset in debug control register DBCR0
Kumar Galaaff01532009-09-08 13:46:46 -0500196 * Make sure MSR[DE] = 1. This only resets the core.
wdenk9c53f402003-10-15 23:53:47 +0000197 */
Sergei Poselenov25147422008-05-08 14:17:08 +0200198 msr = mfmsr ();
199 msr |= MSR_DE;
200 mtmsr (msr);
urwithsughosh@gmail.com06c2fb92007-09-24 13:32:13 -0400201
Sergei Poselenov25147422008-05-08 14:17:08 +0200202 val = mfspr(DBCR0);
203 val |= 0x70000000;
204 mtspr(DBCR0,val);
Kumar Galaaff01532009-09-08 13:46:46 -0500205#else
206 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
207 out_be32(&gur->rstcr, 0x2); /* HRESET_REQ */
208 udelay(100);
209#endif
Sergei Poselenov25147422008-05-08 14:17:08 +0200210
wdenk9c53f402003-10-15 23:53:47 +0000211 return 1;
212}
213
214
215/*
216 * Get timebase clock frequency
217 */
218unsigned long get_tbclk (void)
219{
Kumar Gala24f86a82009-09-17 01:52:37 -0500220#ifdef CONFIG_FSL_CORENET
221 return (gd->bus_clk + 8) / 16;
222#else
James Yang957b1912008-02-08 16:44:53 -0600223 return (gd->bus_clk + 4UL)/8UL;
Kumar Gala24f86a82009-09-17 01:52:37 -0500224#endif
wdenk9c53f402003-10-15 23:53:47 +0000225}
226
227
228#if defined(CONFIG_WATCHDOG)
229void
230watchdog_reset(void)
231{
232 int re_enable = disable_interrupts();
233 reset_85xx_watchdog();
234 if (re_enable) enable_interrupts();
235}
236
237void
238reset_85xx_watchdog(void)
239{
240 /*
241 * Clear TSR(WIS) bit by writing 1
242 */
243 unsigned long val;
Andy Flemingeac342d2007-04-23 01:44:44 -0500244 val = mfspr(SPRN_TSR);
245 val |= TSR_WIS;
246 mtspr(SPRN_TSR, val);
wdenk9c53f402003-10-15 23:53:47 +0000247}
248#endif /* CONFIG_WATCHDOG */
249
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200250/*
Sergei Poselenov9030a692008-08-15 15:42:11 +0200251 * Configures a UPM. The function requires the respective MxMR to be set
252 * before calling this function. "size" is the number or entries, not a sizeof.
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200253 */
254void upmconfig (uint upm, uint * table, uint size)
255{
256 int i, mdr, mad, old_mad = 0;
257 volatile u32 *mxmr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200258 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200259 volatile u32 *brp,*orp;
260 volatile u8* dummy = NULL;
261 int upmmask;
262
263 switch (upm) {
264 case UPMA:
265 mxmr = &lbc->mamr;
266 upmmask = BR_MS_UPMA;
267 break;
268 case UPMB:
269 mxmr = &lbc->mbmr;
270 upmmask = BR_MS_UPMB;
271 break;
272 case UPMC:
273 mxmr = &lbc->mcmr;
274 upmmask = BR_MS_UPMC;
275 break;
276 default:
277 printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
278 hang();
279 }
280
281 /* Find the address for the dummy write transaction */
282 for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
283 i++, brp += 2, orp += 2) {
Wolfgang Denk41df50a2008-06-28 23:34:37 +0200284
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200285 /* Look for a valid BR with selected UPM */
Sergei Poselenov9030a692008-08-15 15:42:11 +0200286 if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
287 dummy = (volatile u8*)(in_be32(brp) & BR_BA);
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200288 break;
289 }
290 }
291
292 if (i == 8) {
293 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
294 hang();
295 }
296
297 for (i = 0; i < size; i++) {
298 /* 1 */
Sergei Poselenov9030a692008-08-15 15:42:11 +0200299 out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200300 /* 2 */
301 out_be32(&lbc->mdr, table[i]);
302 /* 3 */
303 mdr = in_be32(&lbc->mdr);
304 /* 4 */
305 *(volatile u8 *)dummy = 0;
306 /* 5 */
307 do {
Sergei Poselenov9030a692008-08-15 15:42:11 +0200308 mad = in_be32(mxmr) & MxMR_MAD_MSK;
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200309 } while (mad <= old_mad && !(!mad && i == (size-1)));
310 old_mad = mad;
311 }
Sergei Poselenov9030a692008-08-15 15:42:11 +0200312 out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200313}
Ben Warrend448a492008-06-23 22:57:27 -0700314
Andy Fleming6843a6e2008-10-30 16:51:33 -0500315/*
316 * Initializes on-chip MMC controllers.
317 * to override, implement board_mmc_init()
318 */
319int cpu_mmc_init(bd_t *bis)
320{
321#ifdef CONFIG_FSL_ESDHC
322 return fsl_esdhc_mmc_init(bis);
323#else
324 return 0;
325#endif
326}