1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2f45210d6SMatthew McClintock /*
3f45210d6SMatthew McClintock  * Copyright 2011 Freescale Semiconductor, Inc.
4f45210d6SMatthew McClintock  */
5f45210d6SMatthew McClintock 
6f45210d6SMatthew McClintock #include <common.h>
7f45210d6SMatthew McClintock #include <ns16550.h>
8f45210d6SMatthew McClintock #include <asm/io.h>
9f45210d6SMatthew McClintock #include <nand.h>
10f45210d6SMatthew McClintock #include <asm/fsl_law.h>
115614e71bSYork Sun #include <fsl_ddr_sdram.h>
12f45210d6SMatthew McClintock 
13f45210d6SMatthew McClintock 
14f45210d6SMatthew McClintock const static u32 sysclk_tbl[] = {
15f45210d6SMatthew McClintock 	66666000, 7499900, 83332500, 8999900,
16f45210d6SMatthew McClintock 	99999000, 11111000, 12499800, 13333200
17f45210d6SMatthew McClintock };
18f45210d6SMatthew McClintock 
board_init_f(ulong bootflag)19f45210d6SMatthew McClintock void board_init_f(ulong bootflag)
20f45210d6SMatthew McClintock {
21f45210d6SMatthew McClintock 	int px_spd;
22f45210d6SMatthew McClintock 	u32 plat_ratio, sys_clk, bus_clk;
23f45210d6SMatthew McClintock 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
24f45210d6SMatthew McClintock 
255d97fe2aSYing Zhang #if defined(CONFIG_SYS_NAND_BR_PRELIM) && defined(CONFIG_SYS_NAND_OR_PRELIM)
265d97fe2aSYing Zhang 	set_lbc_br(0, CONFIG_SYS_NAND_BR_PRELIM);
275d97fe2aSYing Zhang 	set_lbc_or(0, CONFIG_SYS_NAND_OR_PRELIM);
285d97fe2aSYing Zhang #endif
29f45210d6SMatthew McClintock 	/* for FPGA */
30f45210d6SMatthew McClintock 	set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
31f45210d6SMatthew McClintock 	set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
32f45210d6SMatthew McClintock 
33f45210d6SMatthew McClintock 	/* initialize selected port with appropriate baud rate */
34f45210d6SMatthew McClintock 	px_spd = in_8((unsigned char *)(PIXIS_BASE + PIXIS_SPD));
35f45210d6SMatthew McClintock 	sys_clk = sysclk_tbl[px_spd & PIXIS_SPD_SYSCLK_MASK];
36f45210d6SMatthew McClintock 	plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
37f45210d6SMatthew McClintock 	bus_clk = sys_clk * plat_ratio / 2;
38f45210d6SMatthew McClintock 
39f45210d6SMatthew McClintock 	NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
40f45210d6SMatthew McClintock 			bus_clk / 16 / CONFIG_BAUDRATE);
41f45210d6SMatthew McClintock 
42f45210d6SMatthew McClintock 	puts("\nNAND boot... ");
43f45210d6SMatthew McClintock 
44f45210d6SMatthew McClintock 	/* copy code to RAM and jump to it - this should not return */
45f45210d6SMatthew McClintock 	/* NOTE - code has to be copied out of NAND buffer before
46f45210d6SMatthew McClintock 	 * other blocks can be read.
47f45210d6SMatthew McClintock 	 */
48f45210d6SMatthew McClintock 	relocate_code(CONFIG_SPL_RELOC_STACK, 0,
49f45210d6SMatthew McClintock 			CONFIG_SPL_RELOC_TEXT_BASE);
50f45210d6SMatthew McClintock }
51f45210d6SMatthew McClintock 
board_init_r(gd_t * gd,ulong dest_addr)52f45210d6SMatthew McClintock void board_init_r(gd_t *gd, ulong dest_addr)
53f45210d6SMatthew McClintock {
545d97fe2aSYing Zhang 	puts("\nSecond program loader running in sram...");
55f45210d6SMatthew McClintock 	nand_boot();
56f45210d6SMatthew McClintock }
57f45210d6SMatthew McClintock 
putc(char c)58f45210d6SMatthew McClintock void putc(char c)
59f45210d6SMatthew McClintock {
60f45210d6SMatthew McClintock 	if (c == '\n')
61f45210d6SMatthew McClintock 		NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
62f45210d6SMatthew McClintock 
63f45210d6SMatthew McClintock 	NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
64f45210d6SMatthew McClintock }
65f45210d6SMatthew McClintock 
puts(const char * str)66f45210d6SMatthew McClintock void puts(const char *str)
67f45210d6SMatthew McClintock {
68f45210d6SMatthew McClintock 	while (*str)
69f45210d6SMatthew McClintock 		putc(*str++);
70f45210d6SMatthew McClintock }
71