1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2004,2007-2011 Freescale Semiconductor, Inc.
4 * (C) Copyright 2002, 2003 Motorola Inc.
20 #include <fsl_esdhc.h>
21 #include <asm/cache.h>
25 #include <asm/fsl_law.h>
26 #include <asm/fsl_lbc.h>
28 #include <asm/processor.h>
29 #include <fsl_ddr_sdram.h>
32 DECLARE_GLOBAL_DATA_PTR;
35 * Default board reset function
42 void board_reset(void) __attribute__((weak, alias("__board_reset")));
51 char buf1[32], buf2[32];
52 #if defined(CONFIG_DDR_CLK_FREQ) || defined(CONFIG_FSL_CORENET)
53 ccsr_gur_t __iomem *gur =
54 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
58 * Cornet platforms use ddr sync bit in RCW to indicate sync vs async
59 * mode. Previous platform use ddr ratio to do the same. This
60 * information is only for display here.
62 #ifdef CONFIG_FSL_CORENET
63 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
64 u32 ddr_sync = 0; /* only async mode is supported */
66 u32 ddr_sync = ((gur->rcwsr[5]) & FSL_CORENET_RCWSR5_DDR_SYNC)
67 >> FSL_CORENET_RCWSR5_DDR_SYNC_SHIFT;
68 #endif /* CONFIG_SYS_FSL_QORIQ_CHASSIS2 */
69 #else /* CONFIG_FSL_CORENET */
70 #ifdef CONFIG_DDR_CLK_FREQ
71 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
72 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
75 #endif /* CONFIG_DDR_CLK_FREQ */
76 #endif /* CONFIG_FSL_CORENET */
78 unsigned int i, core, nr_cores = cpu_numcores();
79 u32 mask = cpu_mask();
81 #ifdef CONFIG_HETROGENOUS_CLUSTERS
82 unsigned int j, dsp_core, dsp_numcores = cpu_num_dspcores();
83 u32 dsp_mask = cpu_dsp_mask();
90 #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
91 if (SVR_SOC_VER(svr) == SVR_T4080) {
93 (void __iomem *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
95 setbits_be32(&gur->devdisr2, FSL_CORENET_DEVDISR2_DTSEC1_6 ||
96 FSL_CORENET_DEVDISR2_DTSEC1_9);
97 setbits_be32(&gur->devdisr3, FSL_CORENET_DEVDISR3_PCIE3);
98 setbits_be32(&gur->devdisr5, FSL_CORENET_DEVDISR5_DDR3);
100 /* It needs SW to disable core4~7 as HW design sake on T4080 */
101 for (i = 4; i < 8; i++)
104 /* request core4~7 into PH20 state, prior to entering PCL10
105 * state, all cores in cluster should be placed in PH20 state.
107 setbits_be32(&rcpm->pcph20setr, 0xf0);
109 /* put the 2nd cluster into PCL10 state */
110 setbits_be32(&rcpm->clpcl10setr, 1 << 1);
114 if (cpu_numcores() > 1) {
116 puts("Unicore software on multiprocessor system!!\n"
117 "To enable mutlticore build define CONFIG_MP\n");
119 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
120 printf("CPU%d: ", pic->whoami);
128 if (IS_E_PROCESSOR(svr))
131 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
135 major = PVR_MAJ(pvr);
136 minor = PVR_MIN(pvr);
140 case PVR_VER_E500_V1:
141 case PVR_VER_E500_V2:
158 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
160 if (nr_cores > CONFIG_MAX_CPUS) {
161 panic("\nUnexpected number of cores: %d, max is %d\n",
162 nr_cores, CONFIG_MAX_CPUS);
165 get_sys_info(&sysinfo);
167 #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
168 if (sysinfo.diff_sysclk == 1)
169 puts("Single Source Clock Configuration\n");
172 puts("Clock Configuration:");
173 for_each_cpu(i, core, nr_cores, mask) {
176 printf("CPU%d:%-4s MHz, ", core,
177 strmhz(buf1, sysinfo.freq_processor[core]));
180 #ifdef CONFIG_HETROGENOUS_CLUSTERS
181 for_each_cpu(j, dsp_core, dsp_numcores, dsp_mask) {
184 printf("DSP CPU%d:%-4s MHz, ", j,
185 strmhz(buf1, sysinfo.freq_processor_dsp[dsp_core]));
189 printf("\n CCB:%-4s MHz,", strmhz(buf1, sysinfo.freq_systembus));
192 #ifdef CONFIG_FSL_CORENET
194 printf(" DDR:%-4s MHz (%s MT/s data rate) "
196 strmhz(buf1, sysinfo.freq_ddrbus/2),
197 strmhz(buf2, sysinfo.freq_ddrbus));
199 printf(" DDR:%-4s MHz (%s MT/s data rate) "
201 strmhz(buf1, sysinfo.freq_ddrbus/2),
202 strmhz(buf2, sysinfo.freq_ddrbus));
207 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
208 strmhz(buf1, sysinfo.freq_ddrbus/2),
209 strmhz(buf2, sysinfo.freq_ddrbus));
212 printf(" DDR:%-4s MHz (%s MT/s data rate) "
214 strmhz(buf1, sysinfo.freq_ddrbus/2),
215 strmhz(buf2, sysinfo.freq_ddrbus));
218 printf(" DDR:%-4s MHz (%s MT/s data rate) "
220 strmhz(buf1, sysinfo.freq_ddrbus/2),
221 strmhz(buf2, sysinfo.freq_ddrbus));
226 #if defined(CONFIG_FSL_LBC)
227 if (sysinfo.freq_localbus > LCRR_CLKDIV) {
228 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus));
230 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
231 sysinfo.freq_localbus);
235 #if defined(CONFIG_FSL_IFC)
236 printf("IFC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus));
240 printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freq_systembus));
244 printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freq_qe));
247 #if defined(CONFIG_SYS_CPRI)
249 printf("CPRI:%-4s MHz", strmhz(buf1, sysinfo.freq_cpri));
252 #if defined(CONFIG_SYS_MAPLE)
254 printf("MAPLE:%-4s MHz, ", strmhz(buf1, sysinfo.freq_maple));
255 printf("MAPLE-ULB:%-4s MHz, ", strmhz(buf1, sysinfo.freq_maple_ulb));
256 printf("MAPLE-eTVPE:%-4s MHz\n",
257 strmhz(buf1, sysinfo.freq_maple_etvpe));
260 #ifdef CONFIG_SYS_DPAA_FMAN
261 for (i = 0; i < CONFIG_SYS_NUM_FMAN; i++) {
262 printf(" FMAN%d: %s MHz\n", i + 1,
263 strmhz(buf1, sysinfo.freq_fman[i]));
267 #ifdef CONFIG_SYS_DPAA_QBMAN
268 printf(" QMAN: %s MHz\n", strmhz(buf1, sysinfo.freq_qman));
271 #ifdef CONFIG_SYS_DPAA_PME
272 printf(" PME: %s MHz\n", strmhz(buf1, sysinfo.freq_pme));
275 puts("L1: D-cache 32 KiB enabled\n I-cache 32 KiB enabled\n");
277 #ifdef CONFIG_FSL_CORENET
278 /* Display the RCW, so that no one gets confused as to what RCW
279 * we're actually using for this boot.
281 puts("Reset Configuration Word (RCW):");
282 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
283 u32 rcw = in_be32(&gur->rcwsr[i]);
286 printf("\n %08x:", i * 4);
287 printf(" %08x", rcw);
296 /* ------------------------------------------------------------------------- */
298 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
300 /* Everything after the first generation of PQ3 parts has RSTCR */
301 #if defined(CONFIG_ARCH_MPC8540) || defined(CONFIG_ARCH_MPC8541) || \
302 defined(CONFIG_ARCH_MPC8555) || defined(CONFIG_ARCH_MPC8560)
303 unsigned long val, msr;
306 * Initiate hard reset in debug control register DBCR0
307 * Make sure MSR[DE] = 1. This only resets the core.
317 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
319 /* Attempt board-specific reset */
322 /* Next try asserting HRESET_REQ */
323 out_be32(&gur->rstcr, 0x2);
332 * Get timebase clock frequency
334 #ifndef CONFIG_SYS_FSL_TBCLK_DIV
335 #define CONFIG_SYS_FSL_TBCLK_DIV 8
337 __weak unsigned long get_tbclk(void)
339 unsigned long tbclk_div = CONFIG_SYS_FSL_TBCLK_DIV;
341 return (gd->bus_clk + (tbclk_div >> 1)) / tbclk_div;
345 #if defined(CONFIG_WATCHDOG)
346 #define WATCHDOG_MASK (TCR_WP(63) | TCR_WRC(3) | TCR_WIE)
348 init_85xx_watchdog(void)
350 mtspr(SPRN_TCR, (mfspr(SPRN_TCR) & ~WATCHDOG_MASK) |
351 TCR_WP(CONFIG_WATCHDOG_PRESC) | TCR_WRC(CONFIG_WATCHDOG_RC));
355 reset_85xx_watchdog(void)
358 * Clear TSR(WIS) bit by writing 1
360 mtspr(SPRN_TSR, TSR_WIS);
366 int re_enable = disable_interrupts();
368 reset_85xx_watchdog();
372 #endif /* CONFIG_WATCHDOG */
375 * Initializes on-chip MMC controllers.
376 * to override, implement board_mmc_init()
378 int cpu_mmc_init(bd_t *bis)
380 #ifdef CONFIG_FSL_ESDHC
381 return fsl_esdhc_mmc_init(bis);
388 * Print out the state of various machine registers.
389 * Currently prints out LAWs, BR0/OR0 for LBC, CSPR/CSOR/Timing
390 * parameters for IFC and TLBs
392 void print_reginfo(void)
396 #if defined(CONFIG_FSL_LBC)
399 #ifdef CONFIG_FSL_IFC
405 /* Common ddr init for non-corenet fsl 85xx platforms */
406 #ifndef CONFIG_FSL_CORENET
407 #if (defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)) && \
408 !defined(CONFIG_SYS_INIT_L2_ADDR)
411 #if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD) || \
412 defined(CONFIG_ARCH_QEMU_E500)
413 gd->ram_size = fsl_ddr_sdram_size();
415 gd->ram_size = (phys_size_t)CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
420 #else /* CONFIG_SYS_RAMBOOT */
423 phys_size_t dram_size = 0;
425 #if defined(CONFIG_SYS_FSL_ERRATUM_DDR_MSYNC_IN)
427 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
432 * Work around to stabilize DDR DLL
434 out_be32(&gur->ddrdllcr, 0x81000000);
435 asm("sync;isync;msync");
437 while (in_be32(&gur->ddrdllcr) != 0x81000100) {
438 setbits_be32(&gur->devdisr, 0x00010000);
439 for (i = 0; i < x; i++)
441 clrbits_be32(&gur->devdisr, 0x00010000);
447 #if defined(CONFIG_SPD_EEPROM) || \
448 defined(CONFIG_DDR_SPD) || \
449 defined(CONFIG_SYS_DDR_RAW_TIMING)
450 dram_size = fsl_ddr_sdram();
452 dram_size = fixed_sdram();
454 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
455 dram_size *= 0x100000;
457 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
459 * Initialize and enable DDR ECC.
461 ddr_enable_ecc(dram_size);
464 #if defined(CONFIG_FSL_LBC)
465 /* Some boards also have sdram on the lbc */
470 gd->ram_size = dram_size;
474 #endif /* CONFIG_SYS_RAMBOOT */
477 #if CONFIG_POST & CONFIG_SYS_POST_MEMORY
479 /* Board-specific functions defined in each board's ddr.c */
480 void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
481 unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl);
482 void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn,
485 setup_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
487 void clear_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg);
489 static void dump_spd_ddr_reg(void)
494 struct ccsr_ddr __iomem *ddr[CONFIG_SYS_NUM_DDR_CTLRS];
496 spd[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR];
498 for (i = 0; i < CONFIG_SYS_NUM_DDR_CTLRS; i++)
499 fsl_ddr_get_spd(spd[i], i, CONFIG_DIMM_SLOTS_PER_CTLR);
501 puts("SPD data of all dimms (zero value is omitted)...\n");
504 for (i = 0; i < CONFIG_SYS_NUM_DDR_CTLRS; i++) {
505 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++)
506 printf("Dimm%d ", k++);
509 for (k = 0; k < sizeof(generic_spd_eeprom_t); k++) {
511 printf("%3d (0x%02x) ", k, k);
512 for (i = 0; i < CONFIG_SYS_NUM_DDR_CTLRS; i++) {
513 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
514 p_8 = (u8 *) &spd[i][j];
516 printf("0x%02x ", p_8[k]);
528 for (i = 0; i < CONFIG_SYS_NUM_DDR_CTLRS; i++) {
531 ddr[i] = (void *)CONFIG_SYS_FSL_DDR_ADDR;
533 #if defined(CONFIG_SYS_FSL_DDR2_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 1)
535 ddr[i] = (void *)CONFIG_SYS_FSL_DDR2_ADDR;
538 #if defined(CONFIG_SYS_FSL_DDR3_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 2)
540 ddr[i] = (void *)CONFIG_SYS_FSL_DDR3_ADDR;
543 #if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 3)
545 ddr[i] = (void *)CONFIG_SYS_FSL_DDR4_ADDR;
549 printf("%s unexpected controller number = %u\n",
554 printf("DDR registers dump for all controllers "
555 "(zero value is omitted)...\n");
556 puts("Offset (hex) ");
557 for (i = 0; i < CONFIG_SYS_NUM_DDR_CTLRS; i++)
558 printf(" Base + 0x%04x", (u32)ddr[i] & 0xFFFF);
560 for (k = 0; k < sizeof(struct ccsr_ddr)/4; k++) {
562 printf("%6d (0x%04x)", k * 4, k * 4);
563 for (i = 0; i < CONFIG_SYS_NUM_DDR_CTLRS; i++) {
564 p_32 = (u32 *) ddr[i];
566 printf(" 0x%08x", p_32[k]);
579 /* invalid the TLBs for DDR and setup new ones to cover p_addr */
580 static int reset_tlb(phys_addr_t p_addr, u32 size, phys_addr_t *phys_offset)
582 u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE;
584 u32 tsize, valid, ptr;
587 clear_ddr_tlbs_phys(p_addr, size>>20);
589 /* Setup new tlb to cover the physical address */
590 setup_ddr_tlbs_phys(p_addr, size>>20);
593 ddr_esel = find_tlb_idx((void *)ptr, 1);
594 if (ddr_esel != -1) {
595 read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, phys_offset);
597 printf("TLB error in function %s\n", __func__);
605 * slide the testing window up to test another area
606 * for 32_bit system, the maximum testable memory is limited to
607 * CONFIG_MAX_MEM_MAPPED
609 int arch_memory_test_advance(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
611 phys_addr_t test_cap, p_addr;
612 phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
614 #if !defined(CONFIG_PHYS_64BIT) || \
615 !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
616 (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
619 test_cap = gd->ram_size;
621 p_addr = (*vstart) + (*size) + (*phys_offset);
622 if (p_addr < test_cap - 1) {
623 p_size = min(test_cap - p_addr, CONFIG_MAX_MEM_MAPPED);
624 if (reset_tlb(p_addr, p_size, phys_offset) == -1)
626 *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
627 *size = (u32) p_size;
628 printf("Testing 0x%08llx - 0x%08llx\n",
629 (u64)(*vstart) + (*phys_offset),
630 (u64)(*vstart) + (*phys_offset) + (*size) - 1);
637 /* initialization for testing area */
638 int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
640 phys_size_t p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
642 *vstart = CONFIG_SYS_DDR_SDRAM_BASE;
643 *size = (u32) p_size; /* CONFIG_MAX_MEM_MAPPED < 4G */
646 #if !defined(CONFIG_PHYS_64BIT) || \
647 !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
648 (CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
649 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
650 puts("Cannot test more than ");
651 print_size(CONFIG_MAX_MEM_MAPPED,
652 " without proper 36BIT support.\n");
655 printf("Testing 0x%08llx - 0x%08llx\n",
656 (u64)(*vstart) + (*phys_offset),
657 (u64)(*vstart) + (*phys_offset) + (*size) - 1);
662 /* invalid TLBs for DDR and remap as normal after testing */
663 int arch_memory_test_cleanup(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
666 u32 tsize, valid, ptr;
670 /* disable the TLBs for this testing */
673 while (ptr < (*vstart) + (*size)) {
674 ddr_esel = find_tlb_idx((void *)ptr, 1);
675 if (ddr_esel != -1) {
676 read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
677 disable_tlb(ddr_esel);
679 ptr += TSIZE_TO_BYTES(tsize);
683 setup_ddr_tlbs(gd->ram_size>>20);
689 void arch_memory_failure_handle(void)