blob: 240194ad804081874507fbc73175b11a16d2f7ba [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ying Zhang1233cbc2014-01-24 15:50:09 +08002/* Copyright 2013 Freescale Semiconductor, Inc.
Ying Zhang1233cbc2014-01-24 15:50:09 +08003 */
4
5#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -07006#include <console.h>
Simon Glass79fd2142019-08-01 09:46:43 -06007#include <env.h>
Simon Glass9d1f6192019-08-02 09:44:25 -06008#include <env_internal.h>
Simon Glass284f71b2019-12-28 10:44:45 -07009#include <init.h>
Ying Zhang1233cbc2014-01-24 15:50:09 +080010#include <ns16550.h>
11#include <malloc.h>
12#include <mmc.h>
13#include <nand.h>
14#include <i2c.h>
15#include <fsl_esdhc.h>
16#include <spi_flash.h>
Simon Glassdd8e2242016-09-24 18:20:10 -060017#include "../common/spl.h"
Ying Zhang1233cbc2014-01-24 15:50:09 +080018
19DECLARE_GLOBAL_DATA_PTR;
20
Tom Rini21818062014-02-25 12:44:13 -050021phys_size_t get_effective_memsize(void)
Ying Zhang1233cbc2014-01-24 15:50:09 +080022{
23 return CONFIG_SYS_L2_SIZE;
24}
25
26void board_init_f(ulong bootflag)
27{
28 u32 plat_ratio;
29 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
Jaiprakash Singhdd888062015-03-20 19:28:27 -070030 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
Ying Zhang1233cbc2014-01-24 15:50:09 +080031
32 console_init_f();
33
34 /* Clock configuration to access CPLD using IFC(GPCM) */
Jaiprakash Singhdd888062015-03-20 19:28:27 -070035 setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
Ying Zhang1233cbc2014-01-24 15:50:09 +080036
York Sun7f945ca2016-11-16 13:30:06 -080037#ifdef CONFIG_TARGET_P1010RDB_PB
Ying Zhang1233cbc2014-01-24 15:50:09 +080038 setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS);
39#endif
40
41 /* initialize selected port with appropriate baud rate */
42 plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
43 plat_ratio >>= 1;
44 gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
45
46 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
47 gd->bus_clk / 16 / CONFIG_BAUDRATE);
48
49#ifdef CONFIG_SPL_MMC_BOOT
50 puts("\nSD boot...\n");
51#elif defined(CONFIG_SPL_SPI_BOOT)
52 puts("\nSPI Flash boot...\n");
53#endif
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
61void 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
Simon Glass302445a2017-01-23 13:31:22 -070074 arch_cpu_init();
Ying Zhang1233cbc2014-01-24 15:50:09 +080075 get_clocks();
76 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
77 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garg2ff056b2016-05-25 12:41:48 -040078 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Ying Zhang1233cbc2014-01-24 15:50:09 +080079
80#ifndef CONFIG_SPL_NAND_BOOT
81 env_init();
82#endif
83#ifdef CONFIG_SPL_MMC_BOOT
84 mmc_initialize(bd);
85#endif
86
87 /* relocate environment function pointers etc. */
88#ifdef CONFIG_SPL_NAND_BOOT
89 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rini5cd7ece2019-11-18 20:02:10 -050090 (uchar *)SPL_ENV_ADDR);
91 gd->env_addr = (ulong)(SPL_ENV_ADDR);
Simon Glass4bc2ad22017-08-03 12:21:56 -060092 gd->env_valid = ENV_VALID;
Ying Zhang1233cbc2014-01-24 15:50:09 +080093#else
94 env_relocate();
95#endif
96
97 i2c_init_all();
98
Simon Glassd35f3382017-04-06 12:47:05 -060099 dram_init();
Ying Zhang1233cbc2014-01-24 15:50:09 +0800100#ifdef CONFIG_SPL_NAND_BOOT
101 puts("\nTertiary program loader running in sram...");
102#else
103 puts("\nSecond program loader running in sram...");
104#endif
105
106#ifdef CONFIG_SPL_MMC_BOOT
107 mmc_boot();
108#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassdd8e2242016-09-24 18:20:10 -0600109 fsl_spi_boot();
Ying Zhang1233cbc2014-01-24 15:50:09 +0800110#elif defined(CONFIG_SPL_NAND_BOOT)
111 nand_boot();
112#endif
113}