blob: ca1e49ffa7b4ce9a73326c4a8036c73a0e979b91 [file] [log] [blame]
Shengzhou Liu49912402014-11-24 17:11:56 +08001/* Copyright 2014 Freescale Semiconductor, Inc.
2 *
3 * SPDX-License-Identifier: GPL-2.0+
4 */
5
6#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -07007#include <console.h>
Simon Glass4bc2ad22017-08-03 12:21:56 -06008#include <environment.h>
Shengzhou Liu49912402014-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 yuantian8dc02f32014-12-17 15:42:54 +080016#include "../common/sleep.h"
Simon Glassdd8e2242016-09-24 18:20:10 -060017#include "../common/spl.h"
Shengzhou Liu49912402014-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 Liu796b33a2015-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 Liu49912402014-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 yuantian8dc02f32014-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 Liu49912402014-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 Glass302445a2017-01-23 13:31:22 -0700108 arch_cpu_init();
Shengzhou Liu49912402014-11-24 17:11:56 +0800109 get_clocks();
110 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
111 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garg2ff056b2016-05-25 12:41:48 -0400112 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Shengzhou Liu49912402014-11-24 17:11:56 +0800113
114#ifdef CONFIG_SPL_NAND_BOOT
115 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
116 (uchar *)CONFIG_ENV_ADDR);
117#endif
118#ifdef CONFIG_SPL_MMC_BOOT
119 mmc_initialize(bd);
120 mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
121 (uchar *)CONFIG_ENV_ADDR);
122#endif
123#ifdef CONFIG_SPL_SPI_BOOT
Simon Glassdd8e2242016-09-24 18:20:10 -0600124 fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
125 (uchar *)CONFIG_ENV_ADDR);
Shengzhou Liu49912402014-11-24 17:11:56 +0800126#endif
127
128 gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
Simon Glass4bc2ad22017-08-03 12:21:56 -0600129 gd->env_valid = ENV_VALID;
Shengzhou Liu49912402014-11-24 17:11:56 +0800130
131 i2c_init_all();
132
Simon Glassd35f3382017-04-06 12:47:05 -0600133 dram_init();
Shengzhou Liu49912402014-11-24 17:11:56 +0800134
135#ifdef CONFIG_SPL_MMC_BOOT
136 mmc_boot();
137#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassdd8e2242016-09-24 18:20:10 -0600138 fsl_spi_boot();
Shengzhou Liu49912402014-11-24 17:11:56 +0800139#elif defined(CONFIG_SPL_NAND_BOOT)
140 nand_boot();
141#endif
142}