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