1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2eb6b458cSPo Liu /* Copyright 2013 Freescale Semiconductor, Inc.
3eb6b458cSPo Liu */
4eb6b458cSPo Liu
5eb6b458cSPo Liu #include <common.h>
624b852a7SSimon Glass #include <console.h>
7203e94f6SSimon Glass #include <environment.h>
8eb6b458cSPo Liu #include <ns16550.h>
9eb6b458cSPo Liu #include <malloc.h>
10eb6b458cSPo Liu #include <mmc.h>
11eb6b458cSPo Liu #include <nand.h>
12eb6b458cSPo Liu #include <i2c.h>
13eb6b458cSPo Liu
14eb6b458cSPo Liu DECLARE_GLOBAL_DATA_PTR;
15eb6b458cSPo Liu
get_effective_memsize(void)16e3866163SYork Sun phys_size_t get_effective_memsize(void)
17eb6b458cSPo Liu {
18eb6b458cSPo Liu return CONFIG_SYS_L2_SIZE;
19eb6b458cSPo Liu }
20eb6b458cSPo Liu
board_init_f(ulong bootflag)21eb6b458cSPo Liu void board_init_f(ulong bootflag)
22eb6b458cSPo Liu {
23eb6b458cSPo Liu u32 plat_ratio;
24eb6b458cSPo Liu ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
25eb6b458cSPo Liu
26eb6b458cSPo Liu console_init_f();
27eb6b458cSPo Liu
28eb6b458cSPo Liu /* initialize selected port with appropriate baud rate */
29eb6b458cSPo Liu plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
30eb6b458cSPo Liu plat_ratio >>= 1;
31eb6b458cSPo Liu gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
32eb6b458cSPo Liu
33eb6b458cSPo Liu NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
34eb6b458cSPo Liu gd->bus_clk / 16 / CONFIG_BAUDRATE);
35eb6b458cSPo Liu
36eb6b458cSPo Liu /* copy code to RAM and jump to it - this should not return */
37eb6b458cSPo Liu /* NOTE - code has to be copied out of NAND buffer before
38eb6b458cSPo Liu * other blocks can be read.
39eb6b458cSPo Liu */
40eb6b458cSPo Liu relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
41eb6b458cSPo Liu }
42eb6b458cSPo Liu
board_init_r(gd_t * gd,ulong dest_addr)43eb6b458cSPo Liu void board_init_r(gd_t *gd, ulong dest_addr)
44eb6b458cSPo Liu {
45eb6b458cSPo Liu /* Pointer is writable since we allocated a register for it */
46eb6b458cSPo Liu gd = (gd_t *)CONFIG_SPL_GD_ADDR;
47eb6b458cSPo Liu bd_t *bd;
48eb6b458cSPo Liu
49eb6b458cSPo Liu memset(gd, 0, sizeof(gd_t));
50eb6b458cSPo Liu bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
51eb6b458cSPo Liu memset(bd, 0, sizeof(bd_t));
52eb6b458cSPo Liu gd->bd = bd;
53eb6b458cSPo Liu bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
54eb6b458cSPo Liu bd->bi_memsize = CONFIG_SYS_L2_SIZE;
55eb6b458cSPo Liu
56cbcbf71bSSimon Glass arch_cpu_init();
57eb6b458cSPo Liu get_clocks();
58eb6b458cSPo Liu mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
59eb6b458cSPo Liu CONFIG_SPL_RELOC_MALLOC_SIZE);
60ed4708aaSSumit Garg gd->flags |= GD_FLG_FULL_MALLOC_INIT;
61eb6b458cSPo Liu
62eb6b458cSPo Liu /* relocate environment function pointers etc. */
63eb6b458cSPo Liu nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
64eb6b458cSPo Liu (uchar *)CONFIG_ENV_ADDR);
65eb6b458cSPo Liu gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
66203e94f6SSimon Glass gd->env_valid = ENV_VALID;
67eb6b458cSPo Liu
68eb6b458cSPo Liu i2c_init_all();
69eb6b458cSPo Liu
70f1683aa7SSimon Glass dram_init();
71eb6b458cSPo Liu
72eb6b458cSPo Liu #ifdef CONFIG_SPL_NAND_BOOT
73eb6b458cSPo Liu puts("TPL\n");
74eb6b458cSPo Liu #else
75eb6b458cSPo Liu puts("SPL\n");
76eb6b458cSPo Liu #endif
77eb6b458cSPo Liu
78eb6b458cSPo Liu nand_boot();
79eb6b458cSPo Liu }
80