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