clk: fixed-rate: Enable DM_FLAG_PRE_RELOC flag
[platform/kernel/u-boot.git] / board / freescale / p1010rdb / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright 2013 Freescale Semiconductor, Inc.
3  */
4
5 #include <common.h>
6 #include <clock_legacy.h>
7 #include <console.h>
8 #include <env.h>
9 #include <env_internal.h>
10 #include <init.h>
11 #include <ns16550.h>
12 #include <malloc.h>
13 #include <mmc.h>
14 #include <nand.h>
15 #include <i2c.h>
16 #include <fsl_esdhc.h>
17 #include <spi_flash.h>
18 #include "../common/spl.h"
19
20 DECLARE_GLOBAL_DATA_PTR;
21
22 phys_size_t 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;
30         ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
31         struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
32
33         console_init_f();
34
35         /* Clock configuration to access CPLD using IFC(GPCM) */
36         setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
37
38 #ifdef CONFIG_TARGET_P1010RDB_PB
39         setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
40 #endif
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         gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
46
47         NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
48                      gd->bus_clk / 16 / CONFIG_BAUDRATE);
49
50 #ifdef CONFIG_SPL_MMC_BOOT
51         puts("\nSD boot...\n");
52 #elif defined(CONFIG_SPL_SPI_BOOT)
53         puts("\nSPI Flash boot...\n");
54 #endif
55         /* copy code to RAM and jump to it - this should not return */
56         /* NOTE - code has to be copied out of NAND buffer before
57          * other blocks can be read.
58         */
59         relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
60 }
61
62 void board_init_r(gd_t *gd, ulong dest_addr)
63 {
64         /* Pointer is writable since we allocated a register for it */
65         gd = (gd_t *)CONFIG_SPL_GD_ADDR;
66         struct bd_info *bd;
67
68         memset(gd, 0, sizeof(gd_t));
69         bd = (struct bd_info *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
70         memset(bd, 0, sizeof(struct bd_info));
71         gd->bd = bd;
72         bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
73         bd->bi_memsize = CONFIG_SYS_L2_SIZE;
74
75         arch_cpu_init();
76         get_clocks();
77         mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
78                         CONFIG_SPL_RELOC_MALLOC_SIZE);
79         gd->flags |= GD_FLG_FULL_MALLOC_INIT;
80
81 #ifndef CONFIG_SPL_NAND_BOOT
82         env_init();
83 #endif
84 #ifdef CONFIG_SPL_MMC_BOOT
85         mmc_initialize(bd);
86 #endif
87
88         /* relocate environment function pointers etc. */
89 #ifdef CONFIG_SPL_NAND_BOOT
90         nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
91                             (uchar *)SPL_ENV_ADDR);
92                             gd->env_addr  = (ulong)(SPL_ENV_ADDR);
93         gd->env_valid = ENV_VALID;
94 #else
95         env_relocate();
96 #endif
97
98         i2c_init_all();
99
100         dram_init();
101 #ifdef CONFIG_SPL_NAND_BOOT
102         puts("\nTertiary program loader running in sram...");
103 #else
104         puts("\nSecond program loader running in sram...");
105 #endif
106
107 #ifdef CONFIG_SPL_MMC_BOOT
108         mmc_boot();
109 #elif defined(CONFIG_SPL_SPI_BOOT)
110         fsl_spi_boot();
111 #elif defined(CONFIG_SPL_NAND_BOOT)
112         nand_boot();
113 #endif
114 }