blob: b6afdfc9139384fd3c5a0d5426e7c61b6daf416b [file] [log] [blame]
Alifer Moraesa0a29482020-03-06 07:46:33 -03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2020 NXP
4 *
5 */
6
7#include <common.h>
8#include <hang.h>
9#include <asm/io.h>
10#include <errno.h>
11#include <asm/io.h>
12#include <asm/arch/ddr.h>
13#include <asm/arch/imx8mq_pins.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/arch/clock.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm/mach-imx/gpio.h>
18#include <asm/mach-imx/mxc_i2c.h>
19#include <asm/sections.h>
20#include <fsl_esdhc_imx.h>
21#include <mmc.h>
22#include <spl.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
26static void spl_dram_init(void)
27{
28 /* ddr init */
29 ddr_init(&dram_timing);
30}
31
32#define USDHC2_CD_GPIO IMX_GPIO_NR(2, 12)
33#define USDHC1_PWR_GPIO IMX_GPIO_NR(2, 10)
34#define USDHC2_PWR_GPIO IMX_GPIO_NR(2, 19)
35
36int board_mmc_getcd(struct mmc *mmc)
37{
38 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
39 int ret = 0;
40
41 switch (cfg->esdhc_base) {
42 case USDHC1_BASE_ADDR:
43 ret = 1;
44 break;
45 case USDHC2_BASE_ADDR:
46 ret = !gpio_get_value(USDHC2_CD_GPIO);
47 return ret;
48 }
49
50 return 1;
51}
52
53#define USDHC_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | \
54 PAD_CTL_FSEL2)
55#define USDHC_GPIO_PAD_CTRL (PAD_CTL_PUE | PAD_CTL_DSE1)
56
57static iomux_v3_cfg_t const usdhc1_pads[] = {
58 IMX8MQ_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
59 IMX8MQ_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
60 IMX8MQ_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
61 IMX8MQ_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
62 IMX8MQ_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
63 IMX8MQ_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
64 IMX8MQ_PAD_SD1_DATA4__USDHC1_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
65 IMX8MQ_PAD_SD1_DATA5__USDHC1_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
66 IMX8MQ_PAD_SD1_DATA6__USDHC1_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
67 IMX8MQ_PAD_SD1_DATA7__USDHC1_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
68 IMX8MQ_PAD_SD1_RESET_B__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
69};
70
71static iomux_v3_cfg_t const usdhc2_pads[] = {
72 IMX8MQ_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
73 IMX8MQ_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
74 IMX8MQ_PAD_SD2_DATA0__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
75 IMX8MQ_PAD_SD2_DATA1__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
76 IMX8MQ_PAD_SD2_DATA2__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0x16 */
77 IMX8MQ_PAD_SD2_DATA3__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
78 IMX8MQ_PAD_SD2_CD_B__GPIO2_IO12 | MUX_PAD_CTRL(USDHC_GPIO_PAD_CTRL),
79 IMX8MQ_PAD_SD2_RESET_B__GPIO2_IO19 | MUX_PAD_CTRL(USDHC_GPIO_PAD_CTRL),
80};
81
82static struct fsl_esdhc_cfg usdhc_cfg[2] = {
83 {USDHC1_BASE_ADDR},
84 {USDHC2_BASE_ADDR},
85};
86
87int board_mmc_init(bd_t *bis)
88{
89 int i, ret;
90 /*
91 * According to the board_mmc_init() the following map is done:
92 * (U-Boot device node) (Physical Port)
93 * mmc0 USDHC1
94 * mmc1 USDHC2
95 */
96 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
97 switch (i) {
98 case 0:
99 init_clk_usdhc(0);
100 usdhc_cfg[0].sdhc_clk = mxc_get_clock(USDHC1_CLK_ROOT);
101 usdhc_cfg[0].max_bus_width = 8;
102 imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
103 ARRAY_SIZE(usdhc1_pads));
104 gpio_request(USDHC1_PWR_GPIO, "usdhc1_reset");
105 gpio_direction_output(USDHC1_PWR_GPIO, 0);
106 udelay(500);
107 gpio_direction_output(USDHC1_PWR_GPIO, 1);
108 break;
109 case 1:
110 init_clk_usdhc(1);
111 usdhc_cfg[1].sdhc_clk = mxc_get_clock(USDHC2_CLK_ROOT);
112 usdhc_cfg[1].max_bus_width = 4;
113 imx_iomux_v3_setup_multiple_pads(usdhc2_pads,
114 ARRAY_SIZE(usdhc2_pads));
115 gpio_request(USDHC2_PWR_GPIO, "usdhc2_reset");
116 gpio_direction_output(USDHC2_PWR_GPIO, 0);
117 udelay(500);
118 gpio_direction_output(USDHC2_PWR_GPIO, 1);
119 break;
120 default:
121 printf("Warning: you configured more USDHC controllers(%d) than supported by the board\n", i + 1);
122 return -EINVAL;
123 }
124
125 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
126 if (ret)
127 return ret;
128 }
129
130 return 0;
131}
132
133void spl_board_init(void)
134{
135 puts("Normal Boot\n");
136}
137
138#ifdef CONFIG_SPL_LOAD_FIT
139int board_fit_config_name_match(const char *name)
140{
141 /* Just empty function now - can't decide what to choose */
142 debug("%s: %s\n", __func__, name);
143
144 return 0;
145}
146#endif
147
148void board_init_f(ulong dummy)
149{
150 int ret;
151
152 /* Clear global data */
153 memset((void *)gd, 0, sizeof(gd_t));
154
155 arch_cpu_init();
156
157 init_uart_clk(0);
158
159 board_early_init_f();
160
161 timer_init();
162
163 preloader_console_init();
164
165 /* Clear the BSS. */
166 memset(__bss_start, 0, __bss_end - __bss_start);
167
168 ret = spl_init();
169 if (ret) {
170 debug("spl_init() failed: %d\n", ret);
171 hang();
172 }
173
174 enable_tzc380();
175
176 /* DDR initialization */
177 spl_dram_init();
178
179 board_init_r(NULL, 0);
180}