xref: /rk3399_rockchip-uboot/board/freescale/p1_p2_rdb_pc/spl.c (revision 3e6e69834a31055054b7e5bf5b1ff91c619120e8)
1 /*
2  * Copyright 2013 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <ns16550.h>
9 #include <malloc.h>
10 #include <mmc.h>
11 #include <nand.h>
12 #include <i2c.h>
13 #include <fsl_esdhc.h>
14 
15 DECLARE_GLOBAL_DATA_PTR;
16 
17 static const u32 sysclk_tbl[] = {
18 	66666000, 7499900, 83332500, 8999900,
19 	99999000, 11111000, 12499800, 13333200
20 };
21 
22 ulong get_effective_memsize(void)
23 {
24 	return CONFIG_SYS_L2_SIZE;
25 }
26 
27 void board_init_f(ulong bootflag)
28 {
29 	u32 plat_ratio, bus_clk;
30 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
31 
32 	console_init_f();
33 
34 	/* Set pmuxcr to allow both i2c1 and i2c2 */
35 	setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000);
36 	setbits_be32(&gur->pmuxcr,
37 		     in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
38 
39 	/* Read back the register to synchronize the write. */
40 	in_be32(&gur->pmuxcr);
41 
42 	/* initialize selected port with appropriate baud rate */
43 	plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
44 	plat_ratio >>= 1;
45 	bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
46 	gd->bus_clk = bus_clk;
47 
48 	NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
49 		     bus_clk / 16 / CONFIG_BAUDRATE);
50 #ifdef CONFIG_SPL_MMC_BOOT
51 	puts("\nSD boot...\n");
52 #endif
53 
54 	/* copy code to RAM and jump to it - this should not return */
55 	/* NOTE - code has to be copied out of NAND buffer before
56 	 * other blocks can be read.
57 	 */
58 	relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
59 }
60 
61 void board_init_r(gd_t *gd, ulong dest_addr)
62 {
63 	/* Pointer is writable since we allocated a register for it */
64 	gd = (gd_t *)CONFIG_SPL_GD_ADDR;
65 	bd_t *bd;
66 
67 	memset(gd, 0, sizeof(gd_t));
68 	bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
69 	memset(bd, 0, sizeof(bd_t));
70 	gd->bd = bd;
71 	bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
72 	bd->bi_memsize = CONFIG_SYS_L2_SIZE;
73 
74 	probecpu();
75 	get_clocks();
76 	mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
77 			CONFIG_SPL_RELOC_MALLOC_SIZE);
78 
79 	env_init();
80 #ifdef CONFIG_SPL_MMC_BOOT
81 	mmc_initialize(bd);
82 #endif
83 	/* relocate environment function pointers etc. */
84 	env_relocate();
85 
86 #ifdef CONFIG_SYS_I2C
87 	i2c_init_all();
88 #else
89 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
90 #endif
91 
92 	gd->ram_size = initdram(0);
93 	puts("Second program loader running in sram...\n");
94 
95 #ifdef CONFIG_SPL_MMC_BOOT
96 	mmc_boot();
97 #endif
98 }
99