blob: 8b5b240edf0fa5b1db15b5d456ac4b290352aa75 [file] [log] [blame]
Peng Fanaeb9c062018-11-20 10:20:00 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Peng Fanaeb9c062018-11-20 10:20:00 +000011#include <asm/io.h>
12#include <errno.h>
13#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>
Yangbo Lu73340382019-06-21 11:42:28 +080021#include <fsl_esdhc_imx.h>
Peng Fanaeb9c062018-11-20 10:20:00 +000022#include <mmc.h>
23#include <power/pmic.h>
24#include <power/pfuze100_pmic.h>
25#include <spl.h>
26#include "../common/pfuze.h"
27
28DECLARE_GLOBAL_DATA_PTR;
29
30extern struct dram_timing_info dram_timing_b0;
31
Fabio Estevam639f1012019-05-18 13:18:45 -030032static void spl_dram_init(void)
Peng Fanaeb9c062018-11-20 10:20:00 +000033{
34 /* ddr init */
35 if ((get_cpu_rev() & 0xfff) == CHIP_REV_2_1)
36 ddr_init(&dram_timing);
37 else
38 ddr_init(&dram_timing_b0);
39}
40
41#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE)
42#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
Fabio Estevam639f1012019-05-18 13:18:45 -030043static struct i2c_pads_info i2c_pad_info1 = {
Peng Fanaeb9c062018-11-20 10:20:00 +000044 .scl = {
45 .i2c_mode = IMX8MQ_PAD_I2C1_SCL__I2C1_SCL | PC,
46 .gpio_mode = IMX8MQ_PAD_I2C1_SCL__GPIO5_IO14 | PC,
47 .gp = IMX_GPIO_NR(5, 14),
48 },
49 .sda = {
50 .i2c_mode = IMX8MQ_PAD_I2C1_SDA__I2C1_SDA | PC,
51 .gpio_mode = IMX8MQ_PAD_I2C1_SDA__GPIO5_IO15 | PC,
52 .gp = IMX_GPIO_NR(5, 15),
53 },
54};
55
56#define USDHC2_CD_GPIO IMX_GPIO_NR(2, 12)
57#define USDHC1_PWR_GPIO IMX_GPIO_NR(2, 10)
58#define USDHC2_PWR_GPIO IMX_GPIO_NR(2, 19)
59
60int board_mmc_getcd(struct mmc *mmc)
61{
62 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
63 int ret = 0;
64
65 switch (cfg->esdhc_base) {
66 case USDHC1_BASE_ADDR:
67 ret = 1;
68 break;
69 case USDHC2_BASE_ADDR:
70 ret = !gpio_get_value(USDHC2_CD_GPIO);
71 return ret;
72 }
73
74 return 1;
75}
76
77#define USDHC_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | \
78 PAD_CTL_FSEL2)
79#define USDHC_GPIO_PAD_CTRL (PAD_CTL_PUE | PAD_CTL_DSE1)
80
81static iomux_v3_cfg_t const usdhc1_pads[] = {
82 IMX8MQ_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
83 IMX8MQ_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
84 IMX8MQ_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
85 IMX8MQ_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
86 IMX8MQ_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
87 IMX8MQ_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
88 IMX8MQ_PAD_SD1_DATA4__USDHC1_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
89 IMX8MQ_PAD_SD1_DATA5__USDHC1_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
90 IMX8MQ_PAD_SD1_DATA6__USDHC1_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
91 IMX8MQ_PAD_SD1_DATA7__USDHC1_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
92 IMX8MQ_PAD_SD1_RESET_B__GPIO2_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
93};
94
95static iomux_v3_cfg_t const usdhc2_pads[] = {
96 IMX8MQ_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
97 IMX8MQ_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
98 IMX8MQ_PAD_SD2_DATA0__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
99 IMX8MQ_PAD_SD2_DATA1__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
100 IMX8MQ_PAD_SD2_DATA2__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0x16 */
101 IMX8MQ_PAD_SD2_DATA3__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), /* 0xd6 */
102 IMX8MQ_PAD_SD2_CD_B__GPIO2_IO12 | MUX_PAD_CTRL(USDHC_GPIO_PAD_CTRL),
103 IMX8MQ_PAD_SD2_RESET_B__GPIO2_IO19 | MUX_PAD_CTRL(USDHC_GPIO_PAD_CTRL),
104};
105
106static struct fsl_esdhc_cfg usdhc_cfg[2] = {
107 {USDHC1_BASE_ADDR, 0, 8},
108 {USDHC2_BASE_ADDR, 0, 4},
109};
110
111int board_mmc_init(bd_t *bis)
112{
113 int i, ret;
114 /*
115 * According to the board_mmc_init() the following map is done:
116 * (U-Boot device node) (Physical Port)
117 * mmc0 USDHC1
118 * mmc1 USDHC2
119 */
120 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
121 switch (i) {
122 case 0:
123 init_clk_usdhc(0);
124 usdhc_cfg[0].sdhc_clk = mxc_get_clock(USDHC1_CLK_ROOT);
125 imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
126 ARRAY_SIZE(usdhc1_pads));
127 gpio_request(USDHC1_PWR_GPIO, "usdhc1_reset");
128 gpio_direction_output(USDHC1_PWR_GPIO, 0);
129 udelay(500);
130 gpio_direction_output(USDHC1_PWR_GPIO, 1);
131 break;
132 case 1:
133 init_clk_usdhc(1);
134 usdhc_cfg[1].sdhc_clk = mxc_get_clock(USDHC2_CLK_ROOT);
135 imx_iomux_v3_setup_multiple_pads(usdhc2_pads,
136 ARRAY_SIZE(usdhc2_pads));
137 gpio_request(USDHC2_PWR_GPIO, "usdhc2_reset");
138 gpio_direction_output(USDHC2_PWR_GPIO, 0);
139 udelay(500);
140 gpio_direction_output(USDHC2_PWR_GPIO, 1);
141 break;
142 default:
143 printf("Warning: you configured more USDHC controllers(%d) than supported by the board\n", i + 1);
144 return -EINVAL;
145 }
146
147 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
148 if (ret)
149 return ret;
150 }
151
152 return 0;
153}
154
155#ifdef CONFIG_POWER
156#define I2C_PMIC 0
157int power_init_board(void)
158{
159 struct pmic *p;
160 int ret;
161 unsigned int reg;
162
163 ret = power_pfuze100_init(I2C_PMIC);
164 if (ret)
165 return -ENODEV;
166
167 p = pmic_get("PFUZE100");
168 ret = pmic_probe(p);
169 if (ret)
170 return -ENODEV;
171
172 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
173 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
174
175 pmic_reg_read(p, PFUZE100_SW3AVOL, &reg);
176 if ((reg & 0x3f) != 0x18) {
177 reg &= ~0x3f;
178 reg |= 0x18;
179 pmic_reg_write(p, PFUZE100_SW3AVOL, reg);
180 }
181
182 ret = pfuze_mode_init(p, APS_PFM);
183 if (ret < 0)
184 return ret;
185
186 /* set SW3A standby mode to off */
187 pmic_reg_read(p, PFUZE100_SW3AMODE, &reg);
188 reg &= ~0xf;
189 reg |= APS_OFF;
190 pmic_reg_write(p, PFUZE100_SW3AMODE, reg);
191
192 return 0;
193}
194#endif
195
196void spl_board_init(void)
197{
198 puts("Normal Boot\n");
199}
200
201#ifdef CONFIG_SPL_LOAD_FIT
202int board_fit_config_name_match(const char *name)
203{
204 /* Just empty function now - can't decide what to choose */
205 debug("%s: %s\n", __func__, name);
206
207 return 0;
208}
209#endif
210
211void board_init_f(ulong dummy)
212{
213 int ret;
214
215 /* Clear global data */
216 memset((void *)gd, 0, sizeof(gd_t));
217
218 arch_cpu_init();
219
220 init_uart_clk(0);
221
222 board_early_init_f();
223
224 timer_init();
225
226 preloader_console_init();
227
228 /* Clear the BSS. */
229 memset(__bss_start, 0, __bss_end - __bss_start);
230
231 ret = spl_init();
232 if (ret) {
233 debug("spl_init() failed: %d\n", ret);
234 hang();
235 }
236
237 enable_tzc380();
238
Peng Fanaeb9c062018-11-20 10:20:00 +0000239 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
240
241 power_init_board();
242
243 /* DDR initialization */
244 spl_dram_init();
245
246 board_init_r(NULL, 0);
247}