blob: 5863e335a8bcd0dbd353a6d02dc837406233e07e [file] [log] [blame]
Oliver Grautedafcd992019-09-20 07:08:41 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2017-2018 NXP
4 */
Tom Rinidec7ea02024-05-20 13:35:03 -06005#include <config.h>
Oliver Grautedafcd992019-09-20 07:08:41 +00006#include <dm.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06007#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Oliver Grautedafcd992019-09-20 07:08:41 +000010#include <spl.h>
11#include <fsl_esdhc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Oliver Grautedafcd992019-09-20 07:08:41 +000013
14#include <asm/io.h>
15#include <asm/gpio.h>
16#include <asm/arch/clock.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080017#include <firmware/imx/sci/sci.h>
Oliver Grautedafcd992019-09-20 07:08:41 +000018#include <asm/arch/imx8-pins.h>
19#include <asm/arch/iomux.h>
Shiji Yangbb112342023-08-03 09:47:16 +080020#include <asm/sections.h>
Oliver Grautedafcd992019-09-20 07:08:41 +000021
22DECLARE_GLOBAL_DATA_PTR;
23
24#define ESDHC_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
25 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
26 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
27 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
28
29#define ESDHC_CLK_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
30 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
31 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
32 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
33
34#define ENET_INPUT_PAD_CTRL ((SC_PAD_CONFIG_OD_IN << PADRING_CONFIG_SHIFT) | \
35 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
36 (SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
37 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
38
39#define ENET_NORMAL_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
40 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
41 (SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
42 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
43
44#define FSPI_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
45 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
46 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
47 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
48
49#define GPIO_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
50 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
51 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
52 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
53
54#define I2C_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
55 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
56 (SC_PAD_28FDSOI_DSE_DV_LOW << PADRING_DSE_SHIFT) | \
57 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
58
59#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
60 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
61 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
62 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
63#ifdef CONFIG_FSL_ESDHC
64
65#define USDHC1_CD_GPIO IMX_GPIO_NR(5, 22)
66#define USDHC2_CD_GPIO IMX_GPIO_NR(4, 12)
67
Tom Rini376b88a2022-10-28 20:27:13 -040068static struct fsl_esdhc_cfg usdhc_cfg[CFG_SYS_FSL_USDHC_NUM] = {
Oliver Grautedafcd992019-09-20 07:08:41 +000069 {USDHC1_BASE_ADDR, 0, 8},
70 {USDHC2_BASE_ADDR, 0, 4},
71 {USDHC3_BASE_ADDR, 0, 4},
72};
73
74static iomux_cfg_t emmc0[] = {
75 SC_P_EMMC0_CLK | MUX_PAD_CTRL(ESDHC_CLK_PAD_CTRL),
76 SC_P_EMMC0_CMD | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
77 SC_P_EMMC0_DATA0 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
78 SC_P_EMMC0_DATA1 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
79 SC_P_EMMC0_DATA2 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
80 SC_P_EMMC0_DATA3 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
81 SC_P_EMMC0_DATA4 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
82 SC_P_EMMC0_DATA5 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
83 SC_P_EMMC0_DATA6 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
84 SC_P_EMMC0_DATA7 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
85 SC_P_EMMC0_RESET_B | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
86 SC_P_EMMC0_STROBE | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
87};
88
89static iomux_cfg_t usdhc2_sd[] = {
90 SC_P_USDHC2_CLK | MUX_PAD_CTRL(ESDHC_CLK_PAD_CTRL),
91 SC_P_USDHC2_CMD | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
92 SC_P_USDHC2_DATA0 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
93 SC_P_USDHC2_DATA1 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
94 SC_P_USDHC2_DATA2 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
95 SC_P_USDHC2_DATA3 | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
96 SC_P_USDHC2_RESET_B | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
97 SC_P_USDHC2_WP | MUX_MODE_ALT(3) | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
98 SC_P_USDHC2_CD_B | MUX_MODE_ALT(3) | MUX_PAD_CTRL(ESDHC_PAD_CTRL),
99};
100
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900101int board_mmc_init(struct bd_info *bis)
Oliver Grautedafcd992019-09-20 07:08:41 +0000102{
103 int i, ret;
104
105 /*
106 * According to the board_mmc_init() the following map is done:
107 * (U-Boot device node) (Physical Port)
108 * mmc0 USDHC1
109 * mmc1 USDHC2
110 * mmc2 USDHC3
111 */
Tom Rini376b88a2022-10-28 20:27:13 -0400112 for (i = 0; i < CFG_SYS_FSL_USDHC_NUM; i++) {
Oliver Grautedafcd992019-09-20 07:08:41 +0000113 switch (i) {
114 case 0:
115 ret = sc_pm_set_resource_power_mode(-1, SC_R_SDHC_0, SC_PM_PW_MODE_ON);
Peng Fanc5657872023-06-15 18:09:02 +0800116 if (ret)
Oliver Grautedafcd992019-09-20 07:08:41 +0000117 return ret;
118
119 imx8_iomux_setup_multiple_pads(emmc0, ARRAY_SIZE(emmc0));
120 init_clk_usdhc(0);
121 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
122 break;
123 case 1:
124 ret = sc_pm_set_resource_power_mode(-1, SC_R_SDHC_2, SC_PM_PW_MODE_ON);
Peng Fanc5657872023-06-15 18:09:02 +0800125 if (ret)
Oliver Grautedafcd992019-09-20 07:08:41 +0000126 return ret;
127 ret = sc_pm_set_resource_power_mode(-1, SC_R_GPIO_4, SC_PM_PW_MODE_ON);
Peng Fanc5657872023-06-15 18:09:02 +0800128 if (ret)
Oliver Grautedafcd992019-09-20 07:08:41 +0000129 return ret;
130
131 imx8_iomux_setup_multiple_pads(usdhc2_sd, ARRAY_SIZE(usdhc2_sd));
132 init_clk_usdhc(2);
133 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
134 gpio_request(USDHC2_CD_GPIO, "sd2_cd");
135 gpio_direction_input(USDHC2_CD_GPIO);
136 break;
137 default:
138 printf("Warning: you configured more USDHC controllers"
139 "(%d) than supported by the board\n", i + 1);
140 return 0;
141 }
142 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
143 if (ret) {
144 printf("Warning: failed to initialize mmc dev %d\n", i);
145 return ret;
146 }
147 }
148
149 return 0;
150}
151
152int board_mmc_getcd(struct mmc *mmc)
153{
154 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
155 int ret = 0;
156
157 switch (cfg->esdhc_base) {
158 case USDHC1_BASE_ADDR:
159 ret = 1;
160 break;
161 case USDHC2_BASE_ADDR:
162 ret = !gpio_get_value(USDHC1_CD_GPIO);
163 break;
164 case USDHC3_BASE_ADDR:
165 ret = !gpio_get_value(USDHC2_CD_GPIO);
166 break;
167 }
168
169 return ret;
170}
171
172#endif /* CONFIG_FSL_ESDHC */
173
174void spl_board_init(void)
175{
Simon Glassa5820472021-08-08 12:20:14 -0600176#if defined(CONFIG_SPL_SPI)
Oliver Grautedafcd992019-09-20 07:08:41 +0000177 if (sc_rm_is_resource_owned(-1, SC_R_FSPI_0)) {
178 if (sc_pm_set_resource_power_mode(-1, SC_R_FSPI_0, SC_PM_PW_MODE_ON)) {
179 puts("Warning: failed to initialize FSPI0\n");
180 }
181 }
182#endif
183
184 puts("Normal Boot\n");
185}
186
187void spl_board_prepare_for_boot(void)
188{
Simon Glassa5820472021-08-08 12:20:14 -0600189#if defined(CONFIG_SPL_SPI)
Oliver Grautedafcd992019-09-20 07:08:41 +0000190 if (sc_rm_is_resource_owned(-1, SC_R_FSPI_0)) {
191 if (sc_pm_set_resource_power_mode(-1, SC_R_FSPI_0, SC_PM_PW_MODE_OFF)) {
192 puts("Warning: failed to turn off FSPI0\n");
193 }
194 }
195#endif
196}
197
198#ifdef CONFIG_SPL_LOAD_FIT
199int board_fit_config_name_match(const char *name)
200{
201 /* Just empty function now - can't decide what to choose */
202 debug("%s: %s\n", __func__, name);
203
204 return 0;
205}
206#endif
207
208void board_init_f(ulong dummy)
209{
210 /* Clear global data */
211 memset((void *)gd, 0, sizeof(gd_t));
212
213 arch_cpu_init();
214
215 board_early_init_f();
216
217 timer_init();
218
219 preloader_console_init();
220
221 /* Clear the BSS. */
222 memset(__bss_start, 0, __bss_end - __bss_start);
223
224 board_init_r(NULL, 0);
225}