1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
294a45bb1SScott Wood /*
394a45bb1SScott Wood  * Copyright 2011 Freescale Semiconductor, Inc.
494a45bb1SScott Wood  */
594a45bb1SScott Wood 
694a45bb1SScott Wood #include <common.h>
794a45bb1SScott Wood #include <ns16550.h>
894a45bb1SScott Wood #include <asm/io.h>
994a45bb1SScott Wood #include <nand.h>
1013d1143fSScott Wood #include <linux/compiler.h>
1194a45bb1SScott Wood #include <asm/fsl_law.h>
125614e71bSYork Sun #include <fsl_ddr_sdram.h>
1394a45bb1SScott Wood #include <asm/global_data.h>
1494a45bb1SScott Wood 
1594a45bb1SScott Wood DECLARE_GLOBAL_DATA_PTR;
1694a45bb1SScott Wood 
board_init_f(ulong bootflag)1794a45bb1SScott Wood void board_init_f(ulong bootflag)
1894a45bb1SScott Wood {
1994a45bb1SScott Wood 	u32 plat_ratio;
2094a45bb1SScott Wood 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
2162c6ef33SYing Zhang 
2262c6ef33SYing Zhang #if defined(CONFIG_SYS_NAND_BR_PRELIM) && defined(CONFIG_SYS_NAND_OR_PRELIM)
2362c6ef33SYing Zhang 	set_lbc_br(0, CONFIG_SYS_NAND_BR_PRELIM);
2462c6ef33SYing Zhang 	set_lbc_or(0, CONFIG_SYS_NAND_OR_PRELIM);
2594a45bb1SScott Wood #endif
2694a45bb1SScott Wood 
2794a45bb1SScott Wood 	/* initialize selected port with appropriate baud rate */
2894a45bb1SScott Wood 	plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
2994a45bb1SScott Wood 	plat_ratio >>= 1;
3094a45bb1SScott Wood 	gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
3194a45bb1SScott Wood 
3294a45bb1SScott Wood 	NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
3394a45bb1SScott Wood 			gd->bus_clk / 16 / CONFIG_BAUDRATE);
3494a45bb1SScott Wood 
3594a45bb1SScott Wood 	puts("\nNAND boot... ");
3694a45bb1SScott Wood 
3794a45bb1SScott Wood 	/* copy code to RAM and jump to it - this should not return */
3894a45bb1SScott Wood 	/* NOTE - code has to be copied out of NAND buffer before
3994a45bb1SScott Wood 	 * other blocks can be read.
4094a45bb1SScott Wood 	 */
4194a45bb1SScott Wood 	relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
4294a45bb1SScott Wood }
4394a45bb1SScott Wood 
board_init_r(gd_t * gd,ulong dest_addr)4494a45bb1SScott Wood void board_init_r(gd_t *gd, ulong dest_addr)
4594a45bb1SScott Wood {
4662c6ef33SYing Zhang 	puts("\nSecond program loader running in sram...");
4794a45bb1SScott Wood 	nand_boot();
4894a45bb1SScott Wood }
4994a45bb1SScott Wood 
putc(char c)5094a45bb1SScott Wood void putc(char c)
5194a45bb1SScott Wood {
5294a45bb1SScott Wood 	if (c == '\n')
5394a45bb1SScott Wood 		NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
5494a45bb1SScott Wood 
5594a45bb1SScott Wood 	NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
5694a45bb1SScott Wood }
5794a45bb1SScott Wood 
puts(const char * str)5894a45bb1SScott Wood void puts(const char *str)
5994a45bb1SScott Wood {
6094a45bb1SScott Wood 	while (*str)
6194a45bb1SScott Wood 		putc(*str++);
6294a45bb1SScott Wood }
63