blob: 40cce1dbda694d93f4313a779b88d8fc3327b876 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Dipen Dudhat5d51bf92011-01-19 12:46:27 +05302 * Copyright 2004,2007-2011 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>
Becky Bruceee888da2010-06-17 11:37:25 -050035#include <asm/mmu.h>
Dipen Dudhat00c42942011-01-20 16:29:35 +053036#include <asm/fsl_ifc.h>
Becky Bruceee888da2010-06-17 11:37:25 -050037#include <asm/fsl_law.h>
Becky Bruce5e35d8a2010-12-17 17:17:56 -060038#include <asm/fsl_lbc.h>
York Sunc41b7442010-09-28 15:20:33 -070039#include <post.h>
40#include <asm/processor.h>
41#include <asm/fsl_ddr_sdram.h>
wdenk9c53f402003-10-15 23:53:47 +000042
James Yang957b1912008-02-08 16:44:53 -060043DECLARE_GLOBAL_DATA_PTR;
44
Ira W. Snydera85994c2011-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
wdenk9c53f402003-10-15 23:53:47 +000055int checkcpu (void)
56{
wdenka445ddf2004-06-09 00:34:46 +000057 sys_info_t sysinfo;
wdenka445ddf2004-06-09 00:34:46 +000058 uint pvr, svr;
59 uint ver;
60 uint major, minor;
Kumar Gala8ddf00c2008-06-10 16:53:46 -050061 struct cpu_type *cpu;
Wolfgang Denk20591042008-10-19 02:35:49 +020062 char buf1[32], buf2[32];
Kumar Gala1d39c9a2010-04-13 11:07:57 -050063#if defined(CONFIG_DDR_CLK_FREQ) || defined(CONFIG_FSL_CORENET)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala1d39c9a2010-04-13 11:07:57 -050065#endif /* CONFIG_FSL_CORENET */
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080066#ifdef CONFIG_DDR_CLK_FREQ
Jason Jinbfcd6c32008-09-27 14:40:57 +080067 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
68 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galadccd9e32009-03-19 02:46:19 -050069#else
70#ifdef CONFIG_FSL_CORENET
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080071 u32 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
72 >> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
Kumar Gala54b68102008-05-29 01:21:24 -050073#else
74 u32 ddr_ratio = 0;
Srikanth Srinivasanf58c2a42010-02-10 17:32:43 +080075#endif /* CONFIG_FSL_CORENET */
Kumar Galadccd9e32009-03-19 02:46:19 -050076#endif /* CONFIG_DDR_CLK_FREQ */
Timur Tabi47289422011-08-05 16:15:24 -050077 unsigned int i, core, nr_cores = cpu_numcores();
78 u32 mask = cpu_mask();
wdenk9c53f402003-10-15 23:53:47 +000079
wdenka445ddf2004-06-09 00:34:46 +000080 svr = get_svr();
wdenka445ddf2004-06-09 00:34:46 +000081 major = SVR_MAJ(svr);
82 minor = SVR_MIN(svr);
83
Poonam Aggrwal4baef822009-07-31 12:08:14 +053084 if (cpu_numcores() > 1) {
Poonam Aggrwal36a68432009-09-03 19:42:40 +053085#ifndef CONFIG_MP
86 puts("Unicore software on multiprocessor system!!\n"
87 "To enable mutlticore build define CONFIG_MP\n");
88#endif
Kim Phillips2ecbfeb2010-08-09 18:39:57 -050089 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Poonam Aggrwal4baef822009-07-31 12:08:14 +053090 printf("CPU%d: ", pic->whoami);
91 } else {
92 puts("CPU: ");
93 }
Andy Flemingf5740972008-02-06 01:19:40 -060094
Poonam Aggrwal4baef822009-07-31 12:08:14 +053095 cpu = gd->cpu;
Andy Flemingf5740972008-02-06 01:19:40 -060096
Poonam Aggrwalda6e1ca2009-09-02 13:35:21 +053097 puts(cpu->name);
98 if (IS_E_PROCESSOR(svr))
99 puts("E");
Andy Flemingf5740972008-02-06 01:19:40 -0600100
wdenka445ddf2004-06-09 00:34:46 +0000101 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk9c53f402003-10-15 23:53:47 +0000102
wdenk3f3262b2005-03-15 22:56:53 +0000103 pvr = get_pvr();
104 ver = PVR_VER(pvr);
105 major = PVR_MAJ(pvr);
106 minor = PVR_MIN(pvr);
107
108 printf("Core: ");
Kumar Galae222ed32011-07-25 09:28:39 -0500109 switch(ver) {
110 case PVR_VER_E500_V1:
111 case PVR_VER_E500_V2:
112 puts("E500");
113 break;
114 case PVR_VER_E500MC:
115 puts("E500MC");
116 break;
117 case PVR_VER_E5500:
118 puts("E5500");
119 break;
Kumar Galac1abf4a2012-08-17 08:20:23 +0000120 case PVR_VER_E6500:
121 puts("E6500");
122 break;
Kumar Galae222ed32011-07-25 09:28:39 -0500123 default:
Kumar Galabd2985c2009-10-21 13:23:54 -0500124 puts("Unknown");
Kumar Galae222ed32011-07-25 09:28:39 -0500125 break;
wdenk3f3262b2005-03-15 22:56:53 +0000126 }
Kumar Gala9f4a6892008-10-23 01:47:38 -0500127
wdenk3f3262b2005-03-15 22:56:53 +0000128 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
129
York Sun908412d2012-10-08 07:44:10 +0000130 if (nr_cores > CONFIG_MAX_CPUS) {
131 panic("\nUnexpected number of cores: %d, max is %d\n",
132 nr_cores, CONFIG_MAX_CPUS);
133 }
134
wdenka445ddf2004-06-09 00:34:46 +0000135 get_sys_info(&sysinfo);
136
Kumar Galaf92794c2009-02-04 09:35:57 -0600137 puts("Clock Configuration:");
Timur Tabi47289422011-08-05 16:15:24 -0500138 for_each_cpu(i, core, nr_cores, mask) {
Wolfgang Denk1f79d142009-02-19 00:41:08 +0100139 if (!(i & 3))
140 printf ("\n ");
Timur Tabi47289422011-08-05 16:15:24 -0500141 printf("CPU%d:%-4s MHz, ", core,
142 strmhz(buf1, sysinfo.freqProcessor[core]));
Kumar Galaf92794c2009-02-04 09:35:57 -0600143 }
144 printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
Kumar Gala54b68102008-05-29 01:21:24 -0500145
Kumar Galadccd9e32009-03-19 02:46:19 -0500146#ifdef CONFIG_FSL_CORENET
147 if (ddr_sync == 1) {
148 printf(" DDR:%-4s MHz (%s MT/s data rate) "
149 "(Synchronous), ",
150 strmhz(buf1, sysinfo.freqDDRBus/2),
151 strmhz(buf2, sysinfo.freqDDRBus));
152 } else {
153 printf(" DDR:%-4s MHz (%s MT/s data rate) "
154 "(Asynchronous), ",
155 strmhz(buf1, sysinfo.freqDDRBus/2),
156 strmhz(buf2, sysinfo.freqDDRBus));
157 }
158#else
Kumar Gala07db1702007-12-07 04:59:26 -0600159 switch (ddr_ratio) {
160 case 0x0:
Wolfgang Denk20591042008-10-19 02:35:49 +0200161 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
162 strmhz(buf1, sysinfo.freqDDRBus/2),
163 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Gala07db1702007-12-07 04:59:26 -0600164 break;
165 case 0x7:
Kumar Galadccd9e32009-03-19 02:46:19 -0500166 printf(" DDR:%-4s MHz (%s MT/s data rate) "
167 "(Synchronous), ",
Wolfgang Denk20591042008-10-19 02:35:49 +0200168 strmhz(buf1, sysinfo.freqDDRBus/2),
169 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Gala07db1702007-12-07 04:59:26 -0600170 break;
171 default:
Kumar Galadccd9e32009-03-19 02:46:19 -0500172 printf(" DDR:%-4s MHz (%s MT/s data rate) "
173 "(Asynchronous), ",
Wolfgang Denk20591042008-10-19 02:35:49 +0200174 strmhz(buf1, sysinfo.freqDDRBus/2),
175 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Gala07db1702007-12-07 04:59:26 -0600176 break;
177 }
Kumar Galadccd9e32009-03-19 02:46:19 -0500178#endif
wdenka445ddf2004-06-09 00:34:46 +0000179
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530180#if defined(CONFIG_FSL_LBC)
Kumar Galadccd9e32009-03-19 02:46:19 -0500181 if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
Trent Piepho0b691fc2008-12-03 15:16:37 -0800182 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
Kumar Galadccd9e32009-03-19 02:46:19 -0500183 } else {
Trent Piepho0b691fc2008-12-03 15:16:37 -0800184 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
185 sysinfo.freqLocalBus);
Kumar Galadccd9e32009-03-19 02:46:19 -0500186 }
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530187#endif
wdenka445ddf2004-06-09 00:34:46 +0000188
Kumar Gala17ec6fa2012-10-08 07:44:06 +0000189#if defined(CONFIG_FSL_IFC)
190 printf("IFC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
191#endif
192
Andy Flemingf5740972008-02-06 01:19:40 -0600193#ifdef CONFIG_CPM2
Wolfgang Denk20591042008-10-19 02:35:49 +0200194 printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
Andy Flemingf5740972008-02-06 01:19:40 -0600195#endif
wdenka445ddf2004-06-09 00:34:46 +0000196
Haiying Wang61414682009-05-20 12:30:29 -0400197#ifdef CONFIG_QE
198 printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
199#endif
200
Kumar Galadccd9e32009-03-19 02:46:19 -0500201#ifdef CONFIG_SYS_DPAA_FMAN
202 for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
Emil Medve3a9ed2f2010-06-17 00:08:29 -0500203 printf(" FMAN%d: %s MHz\n", i + 1,
Kumar Galadccd9e32009-03-19 02:46:19 -0500204 strmhz(buf1, sysinfo.freqFMan[i]));
205 }
206#endif
207
208#ifdef CONFIG_SYS_DPAA_PME
209 printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freqPME));
210#endif
211
wdenk3f3262b2005-03-15 22:56:53 +0000212 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk9c53f402003-10-15 23:53:47 +0000213
214 return 0;
215}
216
217
218/* ------------------------------------------------------------------------- */
219
Mike Frysinger6d1f6982010-10-20 03:41:17 -0400220int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk9c53f402003-10-15 23:53:47 +0000221{
Kumar Galaaff01532009-09-08 13:46:46 -0500222/* Everything after the first generation of PQ3 parts has RSTCR */
223#if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
224 defined(CONFIG_MPC8555) || defined(CONFIG_MPC8560)
Sergei Poselenov25147422008-05-08 14:17:08 +0200225 unsigned long val, msr;
226
wdenk9c53f402003-10-15 23:53:47 +0000227 /*
228 * Initiate hard reset in debug control register DBCR0
Kumar Galaaff01532009-09-08 13:46:46 -0500229 * Make sure MSR[DE] = 1. This only resets the core.
wdenk9c53f402003-10-15 23:53:47 +0000230 */
Sergei Poselenov25147422008-05-08 14:17:08 +0200231 msr = mfmsr ();
232 msr |= MSR_DE;
233 mtmsr (msr);
urwithsughosh@gmail.com06c2fb92007-09-24 13:32:13 -0400234
Sergei Poselenov25147422008-05-08 14:17:08 +0200235 val = mfspr(DBCR0);
236 val |= 0x70000000;
237 mtspr(DBCR0,val);
Kumar Galaaff01532009-09-08 13:46:46 -0500238#else
239 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Ira W. Snydera85994c2011-11-21 13:20:32 -0800240
241 /* Attempt board-specific reset */
242 board_reset();
243
244 /* Next try asserting HRESET_REQ */
245 out_be32(&gur->rstcr, 0x2);
Kumar Galaaff01532009-09-08 13:46:46 -0500246 udelay(100);
247#endif
Sergei Poselenov25147422008-05-08 14:17:08 +0200248
wdenk9c53f402003-10-15 23:53:47 +0000249 return 1;
250}
251
252
253/*
254 * Get timebase clock frequency
255 */
Kumar Galaf4fb90f2011-02-18 05:40:54 -0600256#ifndef CONFIG_SYS_FSL_TBCLK_DIV
257#define CONFIG_SYS_FSL_TBCLK_DIV 8
258#endif
wdenk9c53f402003-10-15 23:53:47 +0000259unsigned long get_tbclk (void)
260{
Kumar Galaf4fb90f2011-02-18 05:40:54 -0600261 unsigned long tbclk_div = CONFIG_SYS_FSL_TBCLK_DIV;
262
263 return (gd->bus_clk + (tbclk_div >> 1)) / tbclk_div;
wdenk9c53f402003-10-15 23:53:47 +0000264}
265
266
267#if defined(CONFIG_WATCHDOG)
268void
269watchdog_reset(void)
270{
271 int re_enable = disable_interrupts();
272 reset_85xx_watchdog();
273 if (re_enable) enable_interrupts();
274}
275
276void
277reset_85xx_watchdog(void)
278{
279 /*
280 * Clear TSR(WIS) bit by writing 1
281 */
Mark Marshall10b13c92012-09-09 23:06:03 +0000282 mtspr(SPRN_TSR, TSR_WIS);
wdenk9c53f402003-10-15 23:53:47 +0000283}
284#endif /* CONFIG_WATCHDOG */
285
Sergei Poselenovddc1a472008-06-06 15:42:40 +0200286/*
Andy Fleming6843a6e2008-10-30 16:51:33 -0500287 * Initializes on-chip MMC controllers.
288 * to override, implement board_mmc_init()
289 */
290int cpu_mmc_init(bd_t *bis)
291{
292#ifdef CONFIG_FSL_ESDHC
293 return fsl_esdhc_mmc_init(bis);
294#else
295 return 0;
296#endif
297}
Becky Bruceee888da2010-06-17 11:37:25 -0500298
299/*
300 * Print out the state of various machine registers.
Dipen Dudhat00c42942011-01-20 16:29:35 +0530301 * Currently prints out LAWs, BR0/OR0 for LBC, CSPR/CSOR/Timing
302 * parameters for IFC and TLBs
Becky Bruceee888da2010-06-17 11:37:25 -0500303 */
304void mpc85xx_reginfo(void)
305{
306 print_tlbcam();
307 print_laws();
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530308#if defined(CONFIG_FSL_LBC)
Becky Bruceee888da2010-06-17 11:37:25 -0500309 print_lbc_regs();
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530310#endif
Dipen Dudhat00c42942011-01-20 16:29:35 +0530311#ifdef CONFIG_FSL_IFC
312 print_ifc_regs();
313#endif
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530314
Becky Bruceee888da2010-06-17 11:37:25 -0500315}
York Sunc41b7442010-09-28 15:20:33 -0700316
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600317/* Common ddr init for non-corenet fsl 85xx platforms */
318#ifndef CONFIG_FSL_CORENET
Zhao Chenhui1a35f3d2011-01-28 17:58:37 +0800319#if defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SYS_INIT_L2_ADDR)
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600320phys_size_t initdram(int board_type)
321{
Zhao Chenhui1a35f3d2011-01-28 17:58:37 +0800322#if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
323 return fsl_ddr_sdram_size();
324#else
325 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
326#endif
327}
328#else /* CONFIG_SYS_RAMBOOT */
329phys_size_t initdram(int board_type)
330{
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600331 phys_size_t dram_size = 0;
332
Becky Bruce4212f232010-12-17 17:17:58 -0600333#if defined(CONFIG_SYS_FSL_ERRATUM_DDR_MSYNC_IN)
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600334 {
335 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
336 unsigned int x = 10;
337 unsigned int i;
338
339 /*
340 * Work around to stabilize DDR DLL
341 */
342 out_be32(&gur->ddrdllcr, 0x81000000);
343 asm("sync;isync;msync");
344 udelay(200);
345 while (in_be32(&gur->ddrdllcr) != 0x81000100) {
346 setbits_be32(&gur->devdisr, 0x00010000);
347 for (i = 0; i < x; i++)
348 ;
349 clrbits_be32(&gur->devdisr, 0x00010000);
350 x++;
351 }
352 }
353#endif
354
York Sune73cc042011-06-07 09:42:16 +0800355#if defined(CONFIG_SPD_EEPROM) || \
356 defined(CONFIG_DDR_SPD) || \
357 defined(CONFIG_SYS_DDR_RAW_TIMING)
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600358 dram_size = fsl_ddr_sdram();
359#else
360 dram_size = fixed_sdram();
361#endif
362 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
363 dram_size *= 0x100000;
364
365#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
366 /*
367 * Initialize and enable DDR ECC.
368 */
369 ddr_enable_ecc(dram_size);
370#endif
371
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530372#if defined(CONFIG_FSL_LBC)
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600373 /* Some boards also have sdram on the lbc */
Becky Bruceb88d3d02010-12-17 17:17:57 -0600374 lbc_sdram_init();
Dipen Dudhat5d51bf92011-01-19 12:46:27 +0530375#endif
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600376
Wolfgang Denkf2bbb532011-07-25 10:13:53 +0200377 debug("DDR: ");
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600378 return dram_size;
379}
Zhao Chenhui1a35f3d2011-01-28 17:58:37 +0800380#endif /* CONFIG_SYS_RAMBOOT */
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600381#endif
382
York Sunc41b7442010-09-28 15:20:33 -0700383#if CONFIG_POST & CONFIG_SYS_POST_MEMORY
384
385/* Board-specific functions defined in each board's ddr.c */
386void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
387 unsigned int ctrl_num);
388void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn,
389 phys_addr_t *rpn);
390unsigned int
391 setup_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
392
Becky Bruce69694472011-07-18 18:49:15 -0500393void clear_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
394
York Sunc41b7442010-09-28 15:20:33 -0700395static void dump_spd_ddr_reg(void)
396{
397 int i, j, k, m;
398 u8 *p_8;
399 u32 *p_32;
400 ccsr_ddr_t *ddr[CONFIG_NUM_DDR_CONTROLLERS];
401 generic_spd_eeprom_t
402 spd[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR];
403
404 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
405 fsl_ddr_get_spd(spd[i], i);
406
407 puts("SPD data of all dimms (zero vaule is omitted)...\n");
408 puts("Byte (hex) ");
409 k = 1;
410 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
411 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++)
412 printf("Dimm%d ", k++);
413 }
414 puts("\n");
415 for (k = 0; k < sizeof(generic_spd_eeprom_t); k++) {
416 m = 0;
417 printf("%3d (0x%02x) ", k, k);
418 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
419 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
420 p_8 = (u8 *) &spd[i][j];
421 if (p_8[k]) {
422 printf("0x%02x ", p_8[k]);
423 m++;
424 } else
425 puts(" ");
426 }
427 }
428 if (m)
429 puts("\n");
430 else
431 puts("\r");
432 }
433
434 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
435 switch (i) {
436 case 0:
437 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
438 break;
York Sune8dc17b2012-08-17 08:22:39 +0000439#if defined(CONFIG_SYS_MPC85xx_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1)
York Sunc41b7442010-09-28 15:20:33 -0700440 case 1:
441 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR2_ADDR;
442 break;
443#endif
York Sune8dc17b2012-08-17 08:22:39 +0000444#if defined(CONFIG_SYS_MPC85xx_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2)
445 case 2:
446 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR3_ADDR;
447 break;
448#endif
449#if defined(CONFIG_SYS_MPC85xx_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3)
450 case 3:
451 ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR4_ADDR;
452 break;
453#endif
York Sunc41b7442010-09-28 15:20:33 -0700454 default:
455 printf("%s unexpected controller number = %u\n",
456 __func__, i);
457 return;
458 }
459 }
460 printf("DDR registers dump for all controllers "
461 "(zero vaule is omitted)...\n");
462 puts("Offset (hex) ");
463 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
464 printf(" Base + 0x%04x", (u32)ddr[i] & 0xFFFF);
465 puts("\n");
466 for (k = 0; k < sizeof(ccsr_ddr_t)/4; k++) {
467 m = 0;
468 printf("%6d (0x%04x)", k * 4, k * 4);
469 for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
470 p_32 = (u32 *) ddr[i];
471 if (p_32[k]) {
472 printf(" 0x%08x", p_32[k]);
473 m++;
474 } else
475 puts(" ");
476 }
477 if (m)
478 puts("\n");
479 else
480 puts("\r");
481 }
482 puts("\n");
483}
484
485/* invalid the TLBs for DDR and setup new ones to cover p_addr */
486static int reset_tlb(phys_addr_t p_addr, u32 size, phys_addr_t *phys_offset)
487{
488 u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE;
489 unsigned long epn;
490 u32 tsize, valid, ptr;
York Sunc41b7442010-09-28 15:20:33 -0700491 int ddr_esel;
492
Becky Bruce69694472011-07-18 18:49:15 -0500493 clear_ddr_tlbs_phys(p_addr, size>>20);
York Sunc41b7442010-09-28 15:20:33 -0700494
495 /* Setup new tlb to cover the physical address */
496 setup_ddr_tlbs_phys(p_addr, size>>20);
497
498 ptr = vstart;
499 ddr_esel = find_tlb_idx((void *)ptr, 1);
500 if (ddr_esel != -1) {
501 read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, phys_offset);
502 } else {
503 printf("TLB error in function %s\n", __func__);
504 return -1;
505 }
506
507 return 0;
508}
509
510/*
511 * slide the testing window up to test another area
512 * for 32_bit system, the maximum testable memory is limited to
513 * CONFIG_MAX_MEM_MAPPED
514 */
515int arch_memory_test_advance(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
516{
517 phys_addr_t test_cap, p_addr;
518 phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
519
520#if !defined(CONFIG_PHYS_64BIT) || \
521 !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
522 (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
523 test_cap = p_size;
524#else
525 test_cap = gd->ram_size;
526#endif
527 p_addr = (*vstart) + (*size) + (*phys_offset);
528 if (p_addr < test_cap - 1) {
529 p_size = min(test_cap - p_addr, CONFIG_MAX_MEM_MAPPED);
530 if (reset_tlb(p_addr, p_size, phys_offset) == -1)
531 return -1;
532 *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
533 *size = (u32) p_size;
534 printf("Testing 0x%08llx - 0x%08llx\n",
535 (u64)(*vstart) + (*phys_offset),
536 (u64)(*vstart) + (*phys_offset) + (*size) - 1);
537 } else
538 return 1;
539
540 return 0;
541}
542
543/* initialization for testing area */
544int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
545{
546 phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
547
548 *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
549 *size = (u32) p_size; /* CONFIG_MAX_MEM_MAPPED < 4G */
550 *phys_offset = 0;
551
552#if !defined(CONFIG_PHYS_64BIT) || \
553 !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
554 (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
555 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
556 puts("Cannot test more than ");
557 print_size(CONFIG_MAX_MEM_MAPPED,
558 " without proper 36BIT support.\n");
559 }
560#endif
561 printf("Testing 0x%08llx - 0x%08llx\n",
562 (u64)(*vstart) + (*phys_offset),
563 (u64)(*vstart) + (*phys_offset) + (*size) - 1);
564
565 return 0;
566}
567
568/* invalid TLBs for DDR and remap as normal after testing */
569int arch_memory_test_cleanup(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
570{
571 unsigned long epn;
572 u32 tsize, valid, ptr;
573 phys_addr_t rpn = 0;
574 int ddr_esel;
575
576 /* disable the TLBs for this testing */
577 ptr = *vstart;
578
579 while (ptr < (*vstart) + (*size)) {
580 ddr_esel = find_tlb_idx((void *)ptr, 1);
581 if (ddr_esel != -1) {
582 read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
583 disable_tlb(ddr_esel);
584 }
585 ptr += TSIZE_TO_BYTES(tsize);
586 }
587
588 puts("Remap DDR ");
589 setup_ddr_tlbs(gd->ram_size>>20);
590 puts("\n");
591
592 return 0;
593}
594
595void arch_memory_failure_handle(void)
596{
597 dump_spd_ddr_reg();
598}
599#endif