blob: 68ecde7909729e9abfc46fd890d0efc8a3bf11c0 [file] [log] [blame]
Chunhe Lan373762c2015-03-20 17:08:54 +08001/*
2 * Copyright 2015 Freescale Semiconductor, Inc.
3 *
4 * Author: Chunhe Lan <Chunhe.Lan@freescale.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <asm/spl.h>
11#include <malloc.h>
12#include <ns16550.h>
13#include <nand.h>
14#include <mmc.h>
15#include <fsl_esdhc.h>
16#include <i2c.h>
17
18#include "t4rdb.h"
19
20#define FSL_CORENET_CCSR_PORSR1_RCW_MASK 0xFF800000
21
22DECLARE_GLOBAL_DATA_PTR;
23
24phys_size_t get_effective_memsize(void)
25{
26 return CONFIG_SYS_L3_SIZE;
27}
28
29unsigned long get_board_sys_clk(void)
30{
31 return CONFIG_SYS_CLK_FREQ;
32}
33
34unsigned long get_board_ddr_clk(void)
35{
36 return CONFIG_DDR_CLK_FREQ;
37}
38
39void board_init_f(ulong bootflag)
40{
41 u32 plat_ratio, sys_clk, ccb_clk;
42 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
43
44 /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
45 memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
46
47 /* Update GD pointer */
48 gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
49
50 /* compiler optimization barrier needed for GCC >= 3.4 */
51 __asm__ __volatile__("" : : : "memory");
52
53 console_init_f();
54
55 /* initialize selected port with appropriate baud rate */
56 sys_clk = get_board_sys_clk();
57 plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
58 ccb_clk = sys_clk * plat_ratio / 2;
59
60 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
61 ccb_clk / 16 / CONFIG_BAUDRATE);
62
63 puts("\nSD boot...\n");
64
65 relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
66}
67
68void board_init_r(gd_t *gd, ulong dest_addr)
69{
70 bd_t *bd;
71
72 bd = (bd_t *)(gd + sizeof(gd_t));
73 memset(bd, 0, sizeof(bd_t));
74 gd->bd = bd;
75 bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR;
76 bd->bi_memsize = CONFIG_SYS_L3_SIZE;
77
78 probecpu();
79 get_clocks();
80 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
81 CONFIG_SPL_RELOC_MALLOC_SIZE);
82
83 mmc_initialize(bd);
84 mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
85 (uchar *)CONFIG_ENV_ADDR);
86
87 gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
88 gd->env_valid = 1;
89
90 i2c_init_all();
91
92 gd->ram_size = initdram(0);
93
94 mmc_boot();
95}