1d5b7177fSFabio Estevam // SPDX-License-Identifier: GPL-2.0+
2d5b7177fSFabio Estevam /*
3d5b7177fSFabio Estevam * Copyright (C) 2018 Technexion Ltd.
4d5b7177fSFabio Estevam *
5d5b7177fSFabio Estevam * Author: Richard Hu <richard.hu@technexion.com>
6d5b7177fSFabio Estevam */
7d5b7177fSFabio Estevam
8d5b7177fSFabio Estevam #include <asm/arch/imx-regs.h>
9d5b7177fSFabio Estevam #include <asm/arch/crm_regs.h>
10d5b7177fSFabio Estevam #include <asm/arch/sys_proto.h>
11d5b7177fSFabio Estevam #include <asm/arch-mx7/mx7-ddr.h>
12d5b7177fSFabio Estevam #include <asm/gpio.h>
13d5b7177fSFabio Estevam #include <spl.h>
14d5b7177fSFabio Estevam
15d5b7177fSFabio Estevam #if defined(CONFIG_SPL_BUILD)
1678d30a1bSFabio Estevam
1778d30a1bSFabio Estevam #ifdef CONFIG_SPL_OS_BOOT
spl_start_uboot(void)1878d30a1bSFabio Estevam int spl_start_uboot(void)
1978d30a1bSFabio Estevam {
2078d30a1bSFabio Estevam return 0;
2178d30a1bSFabio Estevam }
2278d30a1bSFabio Estevam #endif
2378d30a1bSFabio Estevam
24d5b7177fSFabio Estevam static struct ddrc ddrc_regs_val = {
25d5b7177fSFabio Estevam .mstr = 0x01040001,
26d5b7177fSFabio Estevam .rfshtmg = 0x00400046,
27d5b7177fSFabio Estevam .init1 = 0x00690000,
28d5b7177fSFabio Estevam .init0 = 0x00020083,
29d5b7177fSFabio Estevam .init3 = 0x09300004,
30d5b7177fSFabio Estevam .init4 = 0x04080000,
31d5b7177fSFabio Estevam .init5 = 0x00100004,
32d5b7177fSFabio Estevam .rankctl = 0x0000033F,
33d5b7177fSFabio Estevam .dramtmg0 = 0x09081109,
34d5b7177fSFabio Estevam .dramtmg1 = 0x0007020d,
35d5b7177fSFabio Estevam .dramtmg2 = 0x03040407,
36d5b7177fSFabio Estevam .dramtmg3 = 0x00002006,
37d5b7177fSFabio Estevam .dramtmg4 = 0x04020205,
38d5b7177fSFabio Estevam .dramtmg5 = 0x03030202,
39d5b7177fSFabio Estevam .dramtmg8 = 0x00000803,
40d5b7177fSFabio Estevam .zqctl0 = 0x00800020,
41d5b7177fSFabio Estevam .dfitmg0 = 0x02098204,
42d5b7177fSFabio Estevam .dfitmg1 = 0x00030303,
43d5b7177fSFabio Estevam .dfiupd0 = 0x80400003,
44d5b7177fSFabio Estevam .dfiupd1 = 0x00100020,
45d5b7177fSFabio Estevam .dfiupd2 = 0x80100004,
46d5b7177fSFabio Estevam .addrmap4 = 0x00000F0F,
47d5b7177fSFabio Estevam .odtcfg = 0x06000604,
48d5b7177fSFabio Estevam .odtmap = 0x00000001,
49d5b7177fSFabio Estevam .rfshtmg = 0x00400046,
50d5b7177fSFabio Estevam .dramtmg0 = 0x09081109,
51d5b7177fSFabio Estevam .addrmap0 = 0x0000001f,
52d5b7177fSFabio Estevam .addrmap1 = 0x00080808,
53d5b7177fSFabio Estevam .addrmap4 = 0x00000f0f,
54d5b7177fSFabio Estevam .addrmap5 = 0x07070707,
55d5b7177fSFabio Estevam .addrmap6 = 0x0f0f0707,
56d5b7177fSFabio Estevam };
57d5b7177fSFabio Estevam
58d5b7177fSFabio Estevam static struct ddrc_mp ddrc_mp_val = {
59d5b7177fSFabio Estevam .pctrl_0 = 0x00000001,
60d5b7177fSFabio Estevam };
61d5b7177fSFabio Estevam
62d5b7177fSFabio Estevam static struct ddr_phy ddr_phy_regs_val = {
63d5b7177fSFabio Estevam .phy_con0 = 0x17420f40,
64d5b7177fSFabio Estevam .phy_con1 = 0x10210100,
65d5b7177fSFabio Estevam .phy_con4 = 0x00060807,
66d5b7177fSFabio Estevam .mdll_con0 = 0x1010007e,
67d5b7177fSFabio Estevam .drvds_con0 = 0x00000d6e,
68d5b7177fSFabio Estevam .cmd_sdll_con0 = 0x00000010,
69d5b7177fSFabio Estevam .offset_lp_con0 = 0x0000000f,
70d5b7177fSFabio Estevam .offset_rd_con0 = 0x08080808,
71d5b7177fSFabio Estevam .offset_wr_con0 = 0x08080808,
72d5b7177fSFabio Estevam };
73d5b7177fSFabio Estevam
74d5b7177fSFabio Estevam static struct mx7_calibration calib_param = {
75d5b7177fSFabio Estevam .num_val = 5,
76d5b7177fSFabio Estevam .values = {
77d5b7177fSFabio Estevam 0x0E407304,
78d5b7177fSFabio Estevam 0x0E447304,
79d5b7177fSFabio Estevam 0x0E447306,
80d5b7177fSFabio Estevam 0x0E447304,
81d5b7177fSFabio Estevam 0x0E447304,
82d5b7177fSFabio Estevam },
83d5b7177fSFabio Estevam };
84d5b7177fSFabio Estevam
gpr_init(void)85d5b7177fSFabio Estevam static void gpr_init(void)
86d5b7177fSFabio Estevam {
87d5b7177fSFabio Estevam struct iomuxc_gpr_base_regs *gpr_regs =
88d5b7177fSFabio Estevam (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
89d5b7177fSFabio Estevam writel(0x4F400005, &gpr_regs->gpr[1]);
90d5b7177fSFabio Estevam }
91d5b7177fSFabio Estevam
is_1g(void)92d5b7177fSFabio Estevam static bool is_1g(void)
93d5b7177fSFabio Estevam {
94d5b7177fSFabio Estevam gpio_direction_input(IMX_GPIO_NR(1, 12));
95d5b7177fSFabio Estevam return !gpio_get_value(IMX_GPIO_NR(1, 12));
96d5b7177fSFabio Estevam }
97d5b7177fSFabio Estevam
ddr_init(void)98d5b7177fSFabio Estevam static void ddr_init(void)
99d5b7177fSFabio Estevam {
100*e5ccad5dSFabio Estevam if (is_1g())
101d5b7177fSFabio Estevam ddrc_regs_val.addrmap6 = 0x0f070707;
102d5b7177fSFabio Estevam
103d5b7177fSFabio Estevam mx7_dram_cfg(&ddrc_regs_val, &ddrc_mp_val, &ddr_phy_regs_val,
104d5b7177fSFabio Estevam &calib_param);
105d5b7177fSFabio Estevam }
106d5b7177fSFabio Estevam
board_init_f(ulong dummy)107d5b7177fSFabio Estevam void board_init_f(ulong dummy)
108d5b7177fSFabio Estevam {
109d5b7177fSFabio Estevam arch_cpu_init();
110d5b7177fSFabio Estevam gpr_init();
111d5b7177fSFabio Estevam board_early_init_f();
112d5b7177fSFabio Estevam timer_init();
113d5b7177fSFabio Estevam preloader_console_init();
114d5b7177fSFabio Estevam ddr_init();
115d5b7177fSFabio Estevam memset(__bss_start, 0, __bss_end - __bss_start);
116d5b7177fSFabio Estevam board_init_r(NULL, 0);
117d5b7177fSFabio Estevam }
118d5b7177fSFabio Estevam
reset_cpu(ulong addr)119d5b7177fSFabio Estevam void reset_cpu(ulong addr)
120d5b7177fSFabio Estevam {
121d5b7177fSFabio Estevam }
122d5b7177fSFabio Estevam #endif
123