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