blob: f493483c1ede543e015eb9d0575a8c1315b87328 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
Dipen Dudhatbeba93e2011-01-19 12:46:27 +05302 * Copyright 2004,2007-2011 Freescale Semiconductor, Inc.
wdenk42d1f032003-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 Fleming75b9d4a2008-08-31 16:33:26 -050028#include <config.h>
wdenk42d1f032003-10-15 23:53:47 +000029#include <common.h>
30#include <watchdog.h>
31#include <command.h>
Andy Fleming80522dc2008-10-30 16:51:33 -050032#include <fsl_esdhc.h>
wdenk42d1f032003-10-15 23:53:47 +000033#include <asm/cache.h>
Sergei Poselenov740280e2008-06-06 15:42:40 +020034#include <asm/io.h>
Becky Bruce199e2622010-06-17 11:37:25 -050035#include <asm/mmu.h>
Dipen Dudhatd789b5f2011-01-20 16:29:35 +053036#include <asm/fsl_ifc.h>
Becky Bruce199e2622010-06-17 11:37:25 -050037#include <asm/fsl_law.h>
Becky Bruce38dba0c2010-12-17 17:17:56 -060038#include <asm/fsl_lbc.h>
York Sunebbe11d2010-09-28 15:20:33 -070039#include <post.h>
40#include <asm/processor.h>
41#include <asm/fsl_ddr_sdram.h>
wdenk42d1f032003-10-15 23:53:47 +000042
James Yang591933c2008-02-08 16:44:53 -060043DECLARE_GLOBAL_DATA_PTR;
44
Ira W. Snyderc18de0d2011-11-21 13:20:32 -080045/*
46 * Default board reset function
47 */
48static void
49__board_reset(void)
50{
51 /* Do nothing */
52}
53void board_reset(void) __attribute__((weak, alias("__board_reset")));
54
wdenk42d1f032003-10-15 23:53:47 +000055int checkcpu (void)
56{
wdenk97d80fc2004-06-09 00:34:46 +000057 sys_info_t sysinfo;
wdenk97d80fc2004-06-09 00:34:46 +000058 uint pvr, svr;
59 uint ver;
60 uint major, minor;
Kumar Gala4dbdb762008-06-10 16:53:46 -050061 struct cpu_type *cpu;
Wolfgang Denk08ef89e2008-10-19 02:35:49 +020062 char buf1[32], buf2[32];
York Sun379c5142012-10-08 07:44:16 +000063#if defined(CONFIG_DDR_CLK_FREQ) || \
64 (defined(CONFIG_FSL_CORENET) && !defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2))
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala9ce3c222010-04-13 11:07:57 -050066#endif /* CONFIG_FSL_CORENET */
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080067#ifdef CONFIG_DDR_CLK_FREQ
68 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
69 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
70#else
Kumar Gala39aaca12009-03-19 02:46:19 -050071#ifdef CONFIG_FSL_CORENET
York Sun379c5142012-10-08 07:44:16 +000072 u32 ddr_sync ;
73#ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
74 ddr_sync = 0; /* only async mode is supported */
75#else
76 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
Kumar Gala39aaca12009-03-19 02:46:19 -050077 >> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
York Sun379c5142012-10-08 07:44:16 +000078#endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
Kumar Gala39aaca12009-03-19 02:46:19 -050079#else
Kumar Galaee1e35b2008-05-29 01:21:24 -050080 u32 ddr_ratio = 0;
Srikanth Srinivasanab48ca12010-02-10 17:32:43 +080081#endif /* CONFIG_FSL_CORENET */
Kumar Gala39aaca12009-03-19 02:46:19 -050082#endif /* CONFIG_DDR_CLK_FREQ */
Timur Tabifbb9ecf2011-08-05 16:15:24 -050083 unsigned int i, core, nr_cores = cpu_numcores();
84 u32 mask = cpu_mask();
wdenk42d1f032003-10-15 23:53:47 +000085
wdenk97d80fc2004-06-09 00:34:46 +000086 svr = get_svr();
wdenk97d80fc2004-06-09 00:34:46 +000087 major = SVR_MAJ(svr);
88 minor = SVR_MIN(svr);
89
Poonam Aggrwal0e870982009-07-31 12:08:14 +053090 if (cpu_numcores() > 1) {
Poonam Aggrwal21170c82009-09-03 19:42:40 +053091#ifndef CONFIG_MP
92 puts("Unicore software on multiprocessor system!!\n"
93 "To enable mutlticore build define CONFIG_MP\n");
94#endif
Kim Phillips680c6132010-08-09 18:39:57 -050095 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Poonam Aggrwal0e870982009-07-31 12:08:14 +053096 printf("CPU%d: ", pic->whoami);
97 } else {
98 puts("CPU: ");
99 }
Andy Fleming1ced1212008-02-06 01:19:40 -0600100
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530101 cpu = gd->cpu;
102
Poonam Aggrwal58442dc2009-09-02 13:35:21 +0530103 puts(cpu->name);
104 if (IS_E_PROCESSOR(svr))
105 puts("E");
Andy Fleming1ced1212008-02-06 01:19:40 -0600106
wdenk97d80fc2004-06-09 00:34:46 +0000107 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk42d1f032003-10-15 23:53:47 +0000108
wdenk6c9e7892005-03-15 22:56:53 +0000109 pvr = get_pvr();
110 ver = PVR_VER(pvr);
111 major = PVR_MAJ(pvr);
112 minor = PVR_MIN(pvr);
113
114 printf("Core: ");
Kumar Gala89927382011-07-25 09:28:39 -0500115 switch(ver) {
116 case PVR_VER_E500_V1:
117 case PVR_VER_E500_V2:
118 puts("E500");
119 break;
120 case PVR_VER_E500MC:
121 puts("E500MC");
122 break;
123 case PVR_VER_E5500:
124 puts("E5500");
125 break;
Kumar Gala5b6b85a2012-08-17 08:20:23 +0000126 case PVR_VER_E6500:
127 puts("E6500");
128 break;
Kumar Gala89927382011-07-25 09:28:39 -0500129 default:
Kumar Gala2a3a96c2009-10-21 13:23:54 -0500130 puts("Unknown");
Kumar Gala89927382011-07-25 09:28:39 -0500131 break;
wdenk6c9e7892005-03-15 22:56:53 +0000132 }
Kumar Gala0f060c32008-10-23 01:47:38 -0500133
wdenk6c9e7892005-03-15 22:56:53 +0000134 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
135
York Sun2f1712b2012-10-08 07:44:10 +0000136 if (nr_cores > CONFIG_MAX_CPUS) {
137 panic("\nUnexpected number of cores: %d, max is %d\n",
138 nr_cores, CONFIG_MAX_CPUS);
139 }
140
wdenk97d80fc2004-06-09 00:34:46 +0000141 get_sys_info(&sysinfo);
142
Kumar Galab29dee32009-02-04 09:35:57 -0600143 puts("Clock Configuration:");
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500144 for_each_cpu(i, core, nr_cores, mask) {
Wolfgang Denk1bba30e2009-02-19 00:41:08 +0100145 if (!(i & 3))
146 printf ("\n ");
Timur Tabifbb9ecf2011-08-05 16:15:24 -0500147 printf("CPU%d:%-4s MHz, ", core,
148 strmhz(buf1, sysinfo.freqProcessor[core]));
Kumar Galab29dee32009-02-04 09:35:57 -0600149 }
150 printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
Kumar Galaee1e35b2008-05-29 01:21:24 -0500151
Kumar Gala39aaca12009-03-19 02:46:19 -0500152#ifdef CONFIG_FSL_CORENET
153 if (ddr_sync == 1) {
154 printf(" DDR:%-4s MHz (%s MT/s data rate) "
155 "(Synchronous), ",
156 strmhz(buf1, sysinfo.freqDDRBus/2),
157 strmhz(buf2, sysinfo.freqDDRBus));
158 } else {
159 printf(" DDR:%-4s MHz (%s MT/s data rate) "
160 "(Asynchronous), ",
161 strmhz(buf1, sysinfo.freqDDRBus/2),
162 strmhz(buf2, sysinfo.freqDDRBus));
163 }
164#else
Kumar Galad4357932007-12-07 04:59:26 -0600165 switch (ddr_ratio) {
166 case 0x0:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200167 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
168 strmhz(buf1, sysinfo.freqDDRBus/2),
169 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600170 break;
171 case 0x7:
Kumar Gala39aaca12009-03-19 02:46:19 -0500172 printf(" DDR:%-4s MHz (%s MT/s data rate) "
173 "(Synchronous), ",
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200174 strmhz(buf1, sysinfo.freqDDRBus/2),
175 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600176 break;
177 default:
Kumar Gala39aaca12009-03-19 02:46:19 -0500178 printf(" DDR:%-4s MHz (%s MT/s data rate) "
179 "(Asynchronous), ",
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200180 strmhz(buf1, sysinfo.freqDDRBus/2),
181 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600182 break;
183 }
Kumar Gala39aaca12009-03-19 02:46:19 -0500184#endif
wdenk97d80fc2004-06-09 00:34:46 +0000185
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530186#if defined(CONFIG_FSL_LBC)
Kumar Gala39aaca12009-03-19 02:46:19 -0500187 if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
Trent Piephoada591d2008-12-03 15:16:37 -0800188 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
Kumar Gala39aaca12009-03-19 02:46:19 -0500189 } else {
Trent Piephoada591d2008-12-03 15:16:37 -0800190 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
191 sysinfo.freqLocalBus);
Kumar Gala39aaca12009-03-19 02:46:19 -0500192 }
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530193#endif
wdenk97d80fc2004-06-09 00:34:46 +0000194
Kumar Gala800c73c2012-10-08 07:44:06 +0000195#if defined(CONFIG_FSL_IFC)
196 printf("IFC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
197#endif
198
Andy Fleming1ced1212008-02-06 01:19:40 -0600199#ifdef CONFIG_CPM2
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200200 printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
Andy Fleming1ced1212008-02-06 01:19:40 -0600201#endif
wdenk97d80fc2004-06-09 00:34:46 +0000202
Haiying Wangb3d7f202009-05-20 12:30:29 -0400203#ifdef CONFIG_QE
204 printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
205#endif
206
Kumar Gala39aaca12009-03-19 02:46:19 -0500207#ifdef CONFIG_SYS_DPAA_FMAN
208 for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
Emil Medve7eda1f82010-06-17 00:08:29 -0500209 printf(" FMAN%d: %s MHz\n", i + 1,
Kumar Gala39aaca12009-03-19 02:46:19 -0500210 strmhz(buf1, sysinfo.freqFMan[i]));
211 }
212#endif
213
214#ifdef CONFIG_SYS_DPAA_PME
215 printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freqPME));
216#endif
217
wdenk6c9e7892005-03-15 22:56:53 +0000218 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk42d1f032003-10-15 23:53:47 +0000219
220 return 0;
221}
222
223
224/* ------------------------------------------------------------------------- */
225
Mike Frysinger882b7d72010-10-20 03:41:17 -0400226int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk42d1f032003-10-15 23:53:47 +0000227{
Kumar Galac3483222009-09-08 13:46:46 -0500228/* Everything after the first generation of PQ3 parts has RSTCR */
229#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
230 defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
Sergei Poselenov793670c2008-05-08 14:17:08 +0200231 unsigned long val, msr;
232
wdenk42d1f032003-10-15 23:53:47 +0000233 /*
234 * Initiate hard reset in debug control register DBCR0
Kumar Galac3483222009-09-08 13:46:46 -0500235 * Make sure MSR[DE] = 1. This only resets the core.
wdenk42d1f032003-10-15 23:53:47 +0000236 */
Sergei Poselenov793670c2008-05-08 14:17:08 +0200237 msr = mfmsr ();
238 msr |= MSR_DE;
239 mtmsr (msr);
urwithsughosh@gmail.comdf909682007-09-24 13:32:13 -0400240
Sergei Poselenov793670c2008-05-08 14:17:08 +0200241 val = mfspr(DBCR0);
242 val |= 0x70000000;
243 mtspr(DBCR0,val);
Kumar Galac3483222009-09-08 13:46:46 -0500244#else
245 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Ira W. Snyderc18de0d2011-11-21 13:20:32 -0800246
247 /* Attempt board-specific reset */
248 board_reset();
249
250 /* Next try asserting HRESET_REQ */
251 out_be32(&gur->rstcr, 0x2);
Kumar Galac3483222009-09-08 13:46:46 -0500252 udelay(100);
253#endif
Sergei Poselenov793670c2008-05-08 14:17:08 +0200254
wdenk42d1f032003-10-15 23:53:47 +0000255 return 1;
256}
257
258
259/*
260 * Get timebase clock frequency
261 */
Kumar Gala66412c62011-02-18 05:40:54 -0600262#ifndef CONFIG_SYS_FSL_TBCLK_DIV
263#define CONFIG_SYS_FSL_TBCLK_DIV 8
264#endif
wdenk42d1f032003-10-15 23:53:47 +0000265unsigned long get_tbclk (void)
266{
Kumar Gala66412c62011-02-18 05:40:54 -0600267 unsigned long tbclk_div = CONFIG_SYS_FSL_TBCLK_DIV;
268
269 return (gd->bus_clk + (tbclk_div >> 1)) / tbclk_div;
wdenk42d1f032003-10-15 23:53:47 +0000270}
271
272
273#if defined(CONFIG_WATCHDOG)
274void
275watchdog_reset(void)
276{
277 int re_enable = disable_interrupts();
278 reset_85xx_watchdog();
279 if (re_enable) enable_interrupts();
280}
281
282void
283reset_85xx_watchdog(void)
284{
285 /*
286 * Clear TSR(WIS) bit by writing 1
287 */
Mark Marshall320d53d2012-09-09 23:06:03 +0000288 mtspr(SPRN_TSR, TSR_WIS);
wdenk42d1f032003-10-15 23:53:47 +0000289}
290#endif /* CONFIG_WATCHDOG */
291
Sergei Poselenov740280e2008-06-06 15:42:40 +0200292/*
Andy Fleming80522dc2008-10-30 16:51:33 -0500293 * Initializes on-chip MMC controllers.
294 * to override, implement board_mmc_init()
295 */
296int cpu_mmc_init(bd_t *bis)
297{
298#ifdef CONFIG_FSL_ESDHC
299 return fsl_esdhc_mmc_init(bis);
300#else
301 return 0;
302#endif
303}
Becky Bruce199e2622010-06-17 11:37:25 -0500304
305/*
306 * Print out the state of various machine registers.
Dipen Dudhatd789b5f2011-01-20 16:29:35 +0530307 * Currently prints out LAWs, BR0/OR0 for LBC, CSPR/CSOR/Timing
308 * parameters for IFC and TLBs
Becky Bruce199e2622010-06-17 11:37:25 -0500309 */
310void mpc85xx_reginfo(void)
311{
312 print_tlbcam();
313 print_laws();
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530314#if defined(CONFIG_FSL_LBC)
Becky Bruce199e2622010-06-17 11:37:25 -0500315 print_lbc_regs();
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530316#endif
Dipen Dudhatd789b5f2011-01-20 16:29:35 +0530317#ifdef CONFIG_FSL_IFC
318 print_ifc_regs();
319#endif
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530320
Becky Bruce199e2622010-06-17 11:37:25 -0500321}
York Sunebbe11d2010-09-28 15:20:33 -0700322
Becky Bruce38dba0c2010-12-17 17:17:56 -0600323/* Common ddr init for non-corenet fsl 85xx platforms */
324#ifndef CONFIG_FSL_CORENET
Zhao Chenhuic1fc2d42011-01-28 17:58:37 +0800325#if defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SYS_INIT_L2_ADDR)
326phys_size_t initdram(int board_type)
327{
328#if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
329 return fsl_ddr_sdram_size();
330#else
331 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
332#endif
333}
334#else /* CONFIG_SYS_RAMBOOT */
Becky Bruce38dba0c2010-12-17 17:17:56 -0600335phys_size_t initdram(int board_type)
336{
337 phys_size_t dram_size = 0;
338
Becky Bruce810c4422010-12-17 17:17:58 -0600339#if defined(CONFIG_SYS_FSL_ERRATUM_DDR_MSYNC_IN)
Becky Bruce38dba0c2010-12-17 17:17:56 -0600340 {
341 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
342 unsigned int x = 10;
343 unsigned int i;
344
345 /*
346 * Work around to stabilize DDR DLL
347 */
348 out_be32(&gur->ddrdllcr, 0x81000000);
349 asm("sync;isync;msync");
350 udelay(200);
351 while (in_be32(&gur->ddrdllcr) != 0x81000100) {
352 setbits_be32(&gur->devdisr, 0x00010000);
353 for (i = 0; i < x; i++)
354 ;
355 clrbits_be32(&gur->devdisr, 0x00010000);
356 x++;
357 }
358 }
359#endif
360
York Sun1b3e3c42011-06-07 09:42:16 +0800361#if defined(CONFIG_SPD_EEPROM) || \
362 defined(CONFIG_DDR_SPD) || \
363 defined(CONFIG_SYS_DDR_RAW_TIMING)
Becky Bruce38dba0c2010-12-17 17:17:56 -0600364 dram_size = fsl_ddr_sdram();
365#else
366 dram_size = fixed_sdram();
367#endif
368 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
369 dram_size *= 0x100000;
370
371#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
372 /*
373 * Initialize and enable DDR ECC.
374 */
375 ddr_enable_ecc(dram_size);
376#endif
377
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530378#if defined(CONFIG_FSL_LBC)
Becky Bruce38dba0c2010-12-17 17:17:56 -0600379 /* Some boards also have sdram on the lbc */
Becky Bruce70961ba2010-12-17 17:17:57 -0600380 lbc_sdram_init();
Dipen Dudhatbeba93e2011-01-19 12:46:27 +0530381#endif
Becky Bruce38dba0c2010-12-17 17:17:56 -0600382
Wolfgang Denk21cd5812011-07-25 10:13:53 +0200383 debug("DDR: ");
Becky Bruce38dba0c2010-12-17 17:17:56 -0600384 return dram_size;
385}
Zhao Chenhuic1fc2d42011-01-28 17:58:37 +0800386#endif /* CONFIG_SYS_RAMBOOT */
Becky Bruce38dba0c2010-12-17 17:17:56 -0600387#endif
388
York Sunebbe11d2010-09-28 15:20:33 -0700389#if CONFIG_POST & CONFIG_SYS_POST_MEMORY
390
391/* Board-specific functions defined in each board's ddr.c */
392void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
393 unsigned int ctrl_num);
394void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn,
395 phys_addr_t *rpn);
396unsigned int
397 setup_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
398
Becky Bruce9cdfe282011-07-18 18:49:15 -0500399void clear_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
400
York Sunebbe11d2010-09-28 15:20:33 -0700401static void dump_spd_ddr_reg(void)
402{
403 int i, j, k, m;
404 u8 *p_8;
405 u32 *p_32;
406 ccsr_ddr_t *ddr[CONFIG_NUM_DDR_CONTROLLERS];
407 generic_spd_eeprom_t
408 spd[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR];
409
410 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
411 fsl_ddr_get_spd(spd[i], i);
412
413 puts("SPD data of all dimms (zero vaule is omitted)...\n");
414 puts("Byte (hex) ");
415 k = 1;
416 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
417 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++)
418 printf("Dimm%d ", k++);
419 }
420 puts("\n");
421 for (k = 0; k < sizeof(generic_spd_eeprom_t); k++) {
422 m = 0;
423 printf("%3d (0x%02x) ", k, k);
424 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
425 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
426 p_8 = (u8 *) &spd[i][j];
427 if (p_8[k]) {
428 printf("0x%02x ", p_8[k]);
429 m++;
430 } else
431 puts(" ");
432 }
433 }
434 if (m)
435 puts("\n");
436 else
437 puts("\r");
438 }
439
440 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
441 switch (i) {
442 case 0:
443 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
444 break;
York Suna4c66502012-08-17 08:22:39 +0000445#if defined(CONFIG_SYS_MPC85xx_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1)
York Sunebbe11d2010-09-28 15:20:33 -0700446 case 1:
447 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR2_ADDR;
448 break;
449#endif
York Suna4c66502012-08-17 08:22:39 +0000450#if defined(CONFIG_SYS_MPC85xx_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2)
451 case 2:
452 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR3_ADDR;
453 break;
454#endif
455#if defined(CONFIG_SYS_MPC85xx_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3)
456 case 3:
457 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR4_ADDR;
458 break;
459#endif
York Sunebbe11d2010-09-28 15:20:33 -0700460 default:
461 printf("%s unexpected controller number = %u\n",
462 __func__, i);
463 return;
464 }
465 }
466 printf("DDR registers dump for all controllers "
467 "(zero vaule is omitted)...\n");
468 puts("Offset (hex) ");
469 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
470 printf(" Base + 0x%04x", (u32)ddr[i] & 0xFFFF);
471 puts("\n");
472 for (k = 0; k < sizeof(ccsr_ddr_t)/4; k++) {
473 m = 0;
474 printf("%6d (0x%04x)", k * 4, k * 4);
475 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
476 p_32 = (u32 *) ddr[i];
477 if (p_32[k]) {
478 printf(" 0x%08x", p_32[k]);
479 m++;
480 } else
481 puts(" ");
482 }
483 if (m)
484 puts("\n");
485 else
486 puts("\r");
487 }
488 puts("\n");
489}
490
491/* invalid the TLBs for DDR and setup new ones to cover p_addr */
492static int reset_tlb(phys_addr_t p_addr, u32 size, phys_addr_t *phys_offset)
493{
494 u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE;
495 unsigned long epn;
496 u32 tsize, valid, ptr;
York Sunebbe11d2010-09-28 15:20:33 -0700497 int ddr_esel;
498
Becky Bruce9cdfe282011-07-18 18:49:15 -0500499 clear_ddr_tlbs_phys(p_addr, size>>20);
York Sunebbe11d2010-09-28 15:20:33 -0700500
501 /* Setup new tlb to cover the physical address */
502 setup_ddr_tlbs_phys(p_addr, size>>20);
503
504 ptr = vstart;
505 ddr_esel = find_tlb_idx((void *)ptr, 1);
506 if (ddr_esel != -1) {
507 read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, phys_offset);
508 } else {
509 printf("TLB error in function %s\n", __func__);
510 return -1;
511 }
512
513 return 0;
514}
515
516/*
517 * slide the testing window up to test another area
518 * for 32_bit system, the maximum testable memory is limited to
519 * CONFIG_MAX_MEM_MAPPED
520 */
521int arch_memory_test_advance(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
522{
523 phys_addr_t test_cap, p_addr;
524 phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
525
526#if !defined(CONFIG_PHYS_64BIT) || \
527 !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
528 (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
529 test_cap = p_size;
530#else
531 test_cap = gd->ram_size;
532#endif
533 p_addr = (*vstart) + (*size) + (*phys_offset);
534 if (p_addr < test_cap - 1) {
535 p_size = min(test_cap - p_addr, CONFIG_MAX_MEM_MAPPED);
536 if (reset_tlb(p_addr, p_size, phys_offset) == -1)
537 return -1;
538 *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
539 *size = (u32) p_size;
540 printf("Testing 0x%08llx - 0x%08llx\n",
541 (u64)(*vstart) + (*phys_offset),
542 (u64)(*vstart) + (*phys_offset) + (*size) - 1);
543 } else
544 return 1;
545
546 return 0;
547}
548
549/* initialization for testing area */
550int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
551{
552 phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
553
554 *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
555 *size = (u32) p_size; /* CONFIG_MAX_MEM_MAPPED < 4G */
556 *phys_offset = 0;
557
558#if !defined(CONFIG_PHYS_64BIT) || \
559 !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
560 (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
561 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
562 puts("Cannot test more than ");
563 print_size(CONFIG_MAX_MEM_MAPPED,
564 " without proper 36BIT support.\n");
565 }
566#endif
567 printf("Testing 0x%08llx - 0x%08llx\n",
568 (u64)(*vstart) + (*phys_offset),
569 (u64)(*vstart) + (*phys_offset) + (*size) - 1);
570
571 return 0;
572}
573
574/* invalid TLBs for DDR and remap as normal after testing */
575int arch_memory_test_cleanup(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
576{
577 unsigned long epn;
578 u32 tsize, valid, ptr;
579 phys_addr_t rpn = 0;
580 int ddr_esel;
581
582 /* disable the TLBs for this testing */
583 ptr = *vstart;
584
585 while (ptr < (*vstart) + (*size)) {
586 ddr_esel = find_tlb_idx((void *)ptr, 1);
587 if (ddr_esel != -1) {
588 read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
589 disable_tlb(ddr_esel);
590 }
591 ptr += TSIZE_TO_BYTES(tsize);
592 }
593
594 puts("Remap DDR ");
595 setup_ddr_tlbs(gd->ram_size>>20);
596 puts("\n");
597
598 return 0;
599}
600
601void arch_memory_failure_handle(void)
602{
603 dump_spd_ddr_reg();
604}
605#endif