blob: 4fb9323873982979a713bd5a1d2293a50aa23874 [file] [log] [blame]
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +05301/* Copyright 2013 Freescale Semiconductor, Inc.
2 *
3 * SPDX-License-Identifier: GPL-2.0+
4 */
5
6#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -07007#include <console.h>
Simon Glass203e94f2017-08-03 12:21:56 -06008#include <environment.h>
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +05309#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 Yuantian00233522014-11-21 11:17:16 +080016#include "../common/sleep.h"
Simon Glassea022a32016-09-24 18:20:10 -060017#include "../common/spl.h"
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +053018
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
36#define FSL_CORENET_CCSR_PORSR1_RCW_MASK 0xFF800000
37void board_init_f(ulong bootflag)
38{
39 u32 plat_ratio, sys_clk, uart_clk;
Prabhakar Kushwaha9f074e62014-10-29 22:33:09 +053040#if defined(CONFIG_SPL_NAND_BOOT) && defined(CONFIG_A008044_WORKAROUND)
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +053041 u32 porsr1, pinctl;
Prabhakar Kushwaha31530e02014-10-29 22:33:55 +053042 u32 svr = get_svr();
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +053043#endif
44 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
45
Prabhakar Kushwaha9f074e62014-10-29 22:33:09 +053046#if defined(CONFIG_SPL_NAND_BOOT) && defined(CONFIG_A008044_WORKAROUND)
Prabhakar Kushwaha31530e02014-10-29 22:33:55 +053047 if (IS_SVR_REV(svr, 1, 0)) {
48 /*
49 * There is T1040 SoC issue where NOR, FPGA are inaccessible
50 * during NAND boot because IFC signals > IFC_AD7 are not
51 * enabled. This workaround changes RCW source to make all
52 * signals enabled.
53 */
54 porsr1 = in_be32(&gur->porsr1);
55 pinctl = ((porsr1 & ~(FSL_CORENET_CCSR_PORSR1_RCW_MASK))
56 | 0x24800000);
57 out_be32((unsigned int *)(CONFIG_SYS_DCSRBAR + 0x20000),
58 pinctl);
59 }
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +053060#endif
61
62 /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
63 memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
64
65 /* Update GD pointer */
66 gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
67
Tang Yuantiance249d92014-07-23 17:27:53 +080068#ifdef CONFIG_DEEP_SLEEP
69 /* disable the console if boot from deep sleep */
Tang Yuantian00233522014-11-21 11:17:16 +080070 if (is_warm_boot())
71 fsl_dp_disable_console();
Tang Yuantiance249d92014-07-23 17:27:53 +080072#endif
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +053073 /* compiler optimization barrier needed for GCC >= 3.4 */
74 __asm__ __volatile__("" : : : "memory");
75
76 console_init_f();
77
78 /* initialize selected port with appropriate baud rate */
79 sys_clk = get_board_sys_clk();
80 plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
81 uart_clk = sys_clk * plat_ratio / 2;
82
83 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
84 uart_clk / 16 / CONFIG_BAUDRATE);
85
86 relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
87}
88
89void board_init_r(gd_t *gd, ulong dest_addr)
90{
91 bd_t *bd;
92
93 bd = (bd_t *)(gd + sizeof(gd_t));
94 memset(bd, 0, sizeof(bd_t));
95 gd->bd = bd;
96 bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR;
97 bd->bi_memsize = CONFIG_SYS_L3_SIZE;
98
Simon Glasscbcbf712017-01-23 13:31:22 -070099 arch_cpu_init();
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530100 get_clocks();
101 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
102 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garged4708a2016-05-25 12:41:48 -0400103 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530104
105#ifdef CONFIG_SPL_MMC_BOOT
106 mmc_initialize(bd);
107#endif
108
109 /* relocate environment function pointers etc. */
110#ifdef CONFIG_SPL_NAND_BOOT
111 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
112 (uchar *)CONFIG_ENV_ADDR);
113#endif
114#ifdef CONFIG_SPL_MMC_BOOT
115 mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
116 (uchar *)CONFIG_ENV_ADDR);
117#endif
118#ifdef CONFIG_SPL_SPI_BOOT
Simon Glassea022a32016-09-24 18:20:10 -0600119 fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
120 (uchar *)CONFIG_ENV_ADDR);
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530121#endif
122 gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
Simon Glass203e94f2017-08-03 12:21:56 -0600123 gd->env_valid = ENV_VALID;
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530124
125 i2c_init_all();
126
127 puts("\n\n");
128
Simon Glassf1683aa2017-04-06 12:47:05 -0600129 dram_init();
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530130
131#ifdef CONFIG_SPL_MMC_BOOT
132 mmc_boot();
133#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassea022a32016-09-24 18:20:10 -0600134 fsl_spi_boot();
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530135#elif defined(CONFIG_SPL_NAND_BOOT)
136 nand_boot();
137#endif
138}