blob: 0936f282204962289dc8401237fc27fa745c5a0e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liu48c6f322014-11-24 17:11:56 +08002/* Copyright 2014 Freescale Semiconductor, Inc.
Shengzhou Liu48c6f322014-11-24 17:11:56 +08003 */
4
5#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -07006#include <console.h>
Simon Glassf3998fd2019-08-02 09:44:25 -06007#include <env_internal.h>
Simon Glass94133872019-12-28 10:44:45 -07008#include <init.h>
Shengzhou Liu48c6f322014-11-24 17:11:56 +08009#include <malloc.h>
10#include <ns16550.h>
11#include <nand.h>
12#include <i2c.h>
13#include <mmc.h>
14#include <fsl_esdhc.h>
15#include <spi_flash.h>
tang yuantianf49b8c12014-12-17 15:42:54 +080016#include "../common/sleep.h"
Simon Glassea022a32016-09-24 18:20:10 -060017#include "../common/spl.h"
Shengzhou Liu48c6f322014-11-24 17:11:56 +080018
19DECLARE_GLOBAL_DATA_PTR;
20
21phys_size_t get_effective_memsize(void)
22{
23 return CONFIG_SYS_L3_SIZE;
24}
25
26unsigned long get_board_sys_clk(void)
27{
28 return CONFIG_SYS_CLK_FREQ;
29}
30
31unsigned long get_board_ddr_clk(void)
32{
33 return CONFIG_DDR_CLK_FREQ;
34}
35
Shengzhou Liue04dd122015-07-28 10:46:47 +080036#if defined(CONFIG_SPL_MMC_BOOT)
37#define GPIO1_SD_SEL 0x00020000
38int board_mmc_getcd(struct mmc *mmc)
39{
40 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
41 u32 val = in_be32(&pgpio->gpdat);
42
43 /* GPIO1_14, 0: eMMC, 1: SD */
44 val &= GPIO1_SD_SEL;
45
46 return val ? -1 : 1;
47}
48
49int board_mmc_getwp(struct mmc *mmc)
50{
51 ccsr_gpio_t __iomem *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
52 u32 val = in_be32(&pgpio->gpdat);
53
54 val &= GPIO1_SD_SEL;
55
56 return val ? -1 : 0;
57}
58#endif
59
Shengzhou Liu48c6f322014-11-24 17:11:56 +080060void board_init_f(ulong bootflag)
61{
62 u32 plat_ratio, sys_clk, ccb_clk;
63 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
64
65 /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
66 memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
67
68 /* Update GD pointer */
69 gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
70
71 console_init_f();
72
tang yuantianf49b8c12014-12-17 15:42:54 +080073#ifdef CONFIG_DEEP_SLEEP
74 /* disable the console if boot from deep sleep */
75 if (is_warm_boot())
76 fsl_dp_disable_console();
77#endif
78
Shengzhou Liu48c6f322014-11-24 17:11:56 +080079 /* initialize selected port with appropriate baud rate */
80 sys_clk = get_board_sys_clk();
81 plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
82 ccb_clk = sys_clk * plat_ratio / 2;
83
84 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
85 ccb_clk / 16 / CONFIG_BAUDRATE);
86
87#if defined(CONFIG_SPL_MMC_BOOT)
88 puts("\nSD boot...\n");
89#elif defined(CONFIG_SPL_SPI_BOOT)
90 puts("\nSPI boot...\n");
91#elif defined(CONFIG_SPL_NAND_BOOT)
92 puts("\nNAND boot...\n");
93#endif
94
95 relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
96}
97
98void board_init_r(gd_t *gd, ulong dest_addr)
99{
100 bd_t *bd;
101
102 bd = (bd_t *)(gd + sizeof(gd_t));
103 memset(bd, 0, sizeof(bd_t));
104 gd->bd = bd;
105 bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR;
106 bd->bi_memsize = CONFIG_SYS_L3_SIZE;
107
Simon Glasscbcbf712017-01-23 13:31:22 -0700108 arch_cpu_init();
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800109 get_clocks();
110 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
111 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garged4708a2016-05-25 12:41:48 -0400112 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800113
114#ifdef CONFIG_SPL_NAND_BOOT
115 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rinia09fea12019-11-18 20:02:10 -0500116 (uchar *)SPL_ENV_ADDR);
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800117#endif
118#ifdef CONFIG_SPL_MMC_BOOT
119 mmc_initialize(bd);
120 mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rinia09fea12019-11-18 20:02:10 -0500121 (uchar *)SPL_ENV_ADDR);
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800122#endif
123#ifdef CONFIG_SPL_SPI_BOOT
Simon Glassea022a32016-09-24 18:20:10 -0600124 fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rinia09fea12019-11-18 20:02:10 -0500125 (uchar *)SPL_ENV_ADDR);
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800126#endif
127
Tom Rinia09fea12019-11-18 20:02:10 -0500128 gd->env_addr = (ulong)(SPL_ENV_ADDR);
Simon Glass203e94f2017-08-03 12:21:56 -0600129 gd->env_valid = ENV_VALID;
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800130
131 i2c_init_all();
132
Simon Glassf1683aa2017-04-06 12:47:05 -0600133 dram_init();
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800134
135#ifdef CONFIG_SPL_MMC_BOOT
136 mmc_boot();
137#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassea022a32016-09-24 18:20:10 -0600138 fsl_spi_boot();
Shengzhou Liu48c6f322014-11-24 17:11:56 +0800139#elif defined(CONFIG_SPL_NAND_BOOT)
140 nand_boot();
141#endif
142}