blob: f86fee9c88ebfb645f54b83ade782eadd1683e1d [file] [log] [blame]
Fabio Estevam6ed39812018-06-29 15:19:11 -03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Technexion Ltd.
4 *
5 * Author: Richard Hu <richard.hu@technexion.com>
6 */
7
Simon Glass1e268642020-05-10 11:39:55 -06008#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Joris Offouga525447f2019-04-04 14:00:55 +020011#include <asm/arch/clock.h>
Fabio Estevam6ed39812018-06-29 15:19:11 -030012#include <asm/arch/imx-regs.h>
13#include <asm/arch/crm_regs.h>
Joris Offouga525447f2019-04-04 14:00:55 +020014#include <asm/arch/mx7-pins.h>
Fabio Estevam6ed39812018-06-29 15:19:11 -030015#include <asm/arch/sys_proto.h>
16#include <asm/arch-mx7/mx7-ddr.h>
Joris Offouga525447f2019-04-04 14:00:55 +020017#include <asm/mach-imx/iomux-v3.h>
Fabio Estevam6ed39812018-06-29 15:19:11 -030018#include <asm/gpio.h>
Yangbo Lu73340382019-06-21 11:42:28 +080019#include <fsl_esdhc_imx.h>
Fabio Estevam6ed39812018-06-29 15:19:11 -030020#include <spl.h>
21
22#if defined(CONFIG_SPL_BUILD)
Fabio Estevamdbc3ba02018-06-29 15:19:14 -030023
24#ifdef CONFIG_SPL_OS_BOOT
25int spl_start_uboot(void)
26{
Fabio Estevamc11d44a2019-09-11 14:30:28 -030027 /* Break into full U-Boot on 'c' */
28 if (serial_tstc() && serial_getc() == 'c')
29 return 1;
30
Fabio Estevamdbc3ba02018-06-29 15:19:14 -030031 return 0;
32}
33#endif
34
Fabio Estevam6ed39812018-06-29 15:19:11 -030035static struct ddrc ddrc_regs_val = {
36 .mstr = 0x01040001,
37 .rfshtmg = 0x00400046,
38 .init1 = 0x00690000,
39 .init0 = 0x00020083,
40 .init3 = 0x09300004,
41 .init4 = 0x04080000,
42 .init5 = 0x00100004,
43 .rankctl = 0x0000033F,
44 .dramtmg0 = 0x09081109,
45 .dramtmg1 = 0x0007020d,
46 .dramtmg2 = 0x03040407,
47 .dramtmg3 = 0x00002006,
48 .dramtmg4 = 0x04020205,
49 .dramtmg5 = 0x03030202,
50 .dramtmg8 = 0x00000803,
51 .zqctl0 = 0x00800020,
52 .dfitmg0 = 0x02098204,
53 .dfitmg1 = 0x00030303,
54 .dfiupd0 = 0x80400003,
55 .dfiupd1 = 0x00100020,
56 .dfiupd2 = 0x80100004,
57 .addrmap4 = 0x00000F0F,
58 .odtcfg = 0x06000604,
59 .odtmap = 0x00000001,
60 .rfshtmg = 0x00400046,
61 .dramtmg0 = 0x09081109,
62 .addrmap0 = 0x0000001f,
63 .addrmap1 = 0x00080808,
Fabio Estevam63f23e52023-01-11 09:22:58 -030064 .addrmap2 = 0x00000000,
65 .addrmap3 = 0x00000000,
Fabio Estevam6ed39812018-06-29 15:19:11 -030066 .addrmap4 = 0x00000f0f,
67 .addrmap5 = 0x07070707,
68 .addrmap6 = 0x0f0f0707,
69};
70
71static struct ddrc_mp ddrc_mp_val = {
72 .pctrl_0 = 0x00000001,
73};
74
75static struct ddr_phy ddr_phy_regs_val = {
76 .phy_con0 = 0x17420f40,
77 .phy_con1 = 0x10210100,
78 .phy_con4 = 0x00060807,
79 .mdll_con0 = 0x1010007e,
80 .drvds_con0 = 0x00000d6e,
81 .cmd_sdll_con0 = 0x00000010,
82 .offset_lp_con0 = 0x0000000f,
83 .offset_rd_con0 = 0x08080808,
84 .offset_wr_con0 = 0x08080808,
85};
86
87static struct mx7_calibration calib_param = {
88 .num_val = 5,
89 .values = {
90 0x0E407304,
91 0x0E447304,
92 0x0E447306,
93 0x0E447304,
94 0x0E447304,
95 },
96};
97
98static void gpr_init(void)
99{
100 struct iomuxc_gpr_base_regs *gpr_regs =
101 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
102 writel(0x4F400005, &gpr_regs->gpr[1]);
103}
104
Fabio Estevam63f23e52023-01-11 09:22:58 -0300105/*
106 * Revision Detection
107 *
108 * GPIO1_12 GPIO1_13
109 * 0 0 1GB DDR3
110 * 0 1 2GB DDR3
111 * 1 0 512MB DDR3
112 */
113
114static int imx7d_pico_detect_board(void)
Fabio Estevam6ed39812018-06-29 15:19:11 -0300115{
116 gpio_direction_input(IMX_GPIO_NR(1, 12));
Fabio Estevam63f23e52023-01-11 09:22:58 -0300117 gpio_direction_input(IMX_GPIO_NR(1, 13));
118
119 return gpio_get_value(IMX_GPIO_NR(1, 12)) << 1 |
120 gpio_get_value(IMX_GPIO_NR(1, 13));
Fabio Estevam6ed39812018-06-29 15:19:11 -0300121}
122
123static void ddr_init(void)
124{
Fabio Estevam63f23e52023-01-11 09:22:58 -0300125 switch (imx7d_pico_detect_board()) {
126 case 0:
Fabio Estevam6ed39812018-06-29 15:19:11 -0300127 ddrc_regs_val.addrmap6 = 0x0f070707;
Fabio Estevam63f23e52023-01-11 09:22:58 -0300128 break;
129 case 1:
130 ddrc_regs_val.addrmap0 = 0x0000001f;
131 ddrc_regs_val.addrmap1 = 0x00181818;
132 ddrc_regs_val.addrmap4 = 0x00000f0f;
133 ddrc_regs_val.addrmap5 = 0x04040404;
134 ddrc_regs_val.addrmap6 = 0x04040404;
135 break;
136 }
Fabio Estevam6ed39812018-06-29 15:19:11 -0300137
138 mx7_dram_cfg(&ddrc_regs_val, &ddrc_mp_val, &ddr_phy_regs_val,
139 &calib_param);
140}
141
142void board_init_f(ulong dummy)
143{
144 arch_cpu_init();
145 gpr_init();
146 board_early_init_f();
147 timer_init();
148 preloader_console_init();
149 ddr_init();
150 memset(__bss_start, 0, __bss_end - __bss_start);
151 board_init_r(NULL, 0);
152}
153
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100154void reset_cpu(void)
Fabio Estevam6ed39812018-06-29 15:19:11 -0300155{
156}
Joris Offouga525447f2019-04-04 14:00:55 +0200157
158#define USDHC_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
159 PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU47KOHM)
160
161static iomux_v3_cfg_t const usdhc3_pads[] = {
162 MX7D_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
163 MX7D_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
164 MX7D_PAD_SD3_DATA0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
165 MX7D_PAD_SD3_DATA1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
166 MX7D_PAD_SD3_DATA2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
167 MX7D_PAD_SD3_DATA3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
168 MX7D_PAD_SD3_DATA4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
169 MX7D_PAD_SD3_DATA5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
170 MX7D_PAD_SD3_DATA6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
171 MX7D_PAD_SD3_DATA7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
172 MX7D_PAD_GPIO1_IO14__GPIO1_IO14 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
173};
174
175static struct fsl_esdhc_cfg usdhc_cfg[1] = {
176 {USDHC3_BASE_ADDR},
177};
178
179int board_mmc_getcd(struct mmc *mmc)
180{
181 /* Assume uSDHC3 emmc is always present */
182 return 1;
183}
184
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900185int board_mmc_init(struct bd_info *bis)
Joris Offouga525447f2019-04-04 14:00:55 +0200186{
187 imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
188 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
189 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
190}
Fabio Estevam6ed39812018-06-29 15:19:11 -0300191#endif