blob: 48392c48e5cc6e832137a523df5557f0d0266c48 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marcin Niestroj55676522016-12-07 16:46:33 +01002/*
3 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
4 * Copyright (C) 2016 Grinn
Marcin Niestroj55676522016-12-07 16:46:33 +01005 */
6
Simon Glass1e268642020-05-10 11:39:55 -06007#include <common.h>
Simon Glassadaaa482019-11-14 12:57:43 -07008#include <command.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010010#include <asm/arch/clock.h>
11#include <asm/arch/iomux.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/crm_regs.h>
Marcin Niestrojeb000ee2017-01-25 10:31:48 +010014#include <asm/arch/litesom.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010015#include <asm/arch/mx6ul_pins.h>
16#include <asm/arch/mx6-pins.h>
17#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010019#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020020#include <asm/mach-imx/iomux-v3.h>
21#include <asm/mach-imx/boot_mode.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010022#include <asm/io.h>
23#include <common.h>
Simon Glass07dc93c2019-08-01 09:46:47 -060024#include <env.h>
Yangbo Lu73340382019-06-21 11:42:28 +080025#include <fsl_esdhc_imx.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010026#include <linux/sizes.h>
27#include <linux/fb.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010028#include <miiphy.h>
29#include <mmc.h>
30#include <netdev.h>
31#include <spl.h>
Marcin Niestroj55676522016-12-07 16:46:33 +010032
33DECLARE_GLOBAL_DATA_PTR;
34
35#define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
36 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
37 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
38
39#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
40 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
41 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
42
43#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \
44 PAD_CTL_SPEED_HIGH | \
45 PAD_CTL_DSE_48ohm | PAD_CTL_SRE_FAST)
46
47#define MDIO_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \
48 PAD_CTL_DSE_48ohm | PAD_CTL_SRE_FAST | PAD_CTL_ODE)
49
50#define ENET_CLK_PAD_CTRL (PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
51
52static iomux_v3_cfg_t const uart1_pads[] = {
53 MX6_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
54 MX6_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
55};
56
57static iomux_v3_cfg_t const sd_pads[] = {
58 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
59 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
60 MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
61 MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
62 MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
63 MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
64
65 /* CD */
66 MX6_PAD_UART1_RTS_B__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL),
67};
68
Marcin Niestroj55676522016-12-07 16:46:33 +010069static void setup_iomux_uart(void)
70{
71 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
72}
73
Yangbo Lu73340382019-06-21 11:42:28 +080074#ifdef CONFIG_FSL_ESDHC_IMX
Marcin Niestroj55676522016-12-07 16:46:33 +010075static struct fsl_esdhc_cfg sd_cfg = {USDHC1_BASE_ADDR, 0, 4};
76
77#define SD_CD_GPIO IMX_GPIO_NR(1, 19)
78
79static int mmc_get_env_devno(void)
80{
81 u32 soc_sbmr = readl(SRC_BASE_ADDR + 0x4);
82 int dev_no;
83 u32 bootsel;
84
85 bootsel = (soc_sbmr & 0x000000FF) >> 6;
86
87 /* If not boot from sd/mmc, use default value */
88 if (bootsel != 1)
89 return CONFIG_SYS_MMC_ENV_DEV;
90
91 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
92 dev_no = (soc_sbmr & 0x00001800) >> 11;
93
94 return dev_no;
95}
96
97int board_mmc_getcd(struct mmc *mmc)
98{
99 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
100 int ret = 0;
101
102 switch (cfg->esdhc_base) {
103 case USDHC1_BASE_ADDR:
104 ret = !gpio_get_value(SD_CD_GPIO);
105 break;
106 case USDHC2_BASE_ADDR:
107 ret = 1;
108 break;
109 }
110
111 return ret;
112}
113
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900114int board_mmc_init(struct bd_info *bis)
Marcin Niestroj55676522016-12-07 16:46:33 +0100115{
116 int ret;
117
118 /* SD */
119 imx_iomux_v3_setup_multiple_pads(sd_pads, ARRAY_SIZE(sd_pads));
120 gpio_direction_input(SD_CD_GPIO);
121 sd_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
122
123 ret = fsl_esdhc_initialize(bis, &sd_cfg);
124 if (ret) {
125 printf("Warning: failed to initialize mmc dev 0 (SD)\n");
126 return ret;
127 }
128
129 return litesom_mmc_init(bis);
130}
131
132static int check_mmc_autodetect(void)
133{
Simon Glass64b723f2017-08-03 12:22:12 -0600134 char *autodetect_str = env_get("mmcautodetect");
Marcin Niestroj55676522016-12-07 16:46:33 +0100135
136 if ((autodetect_str != NULL) &&
137 (strcmp(autodetect_str, "yes") == 0)) {
138 return 1;
139 }
140
141 return 0;
142}
143
144void board_late_mmc_init(void)
145{
146 char cmd[32];
147 char mmcblk[32];
148 u32 dev_no = mmc_get_env_devno();
149
150 if (!check_mmc_autodetect())
151 return;
152
Simon Glass4d949a22017-08-03 12:22:10 -0600153 env_set_ulong("mmcdev", dev_no);
Marcin Niestroj55676522016-12-07 16:46:33 +0100154
155 /* Set mmcblk env */
156 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
157 dev_no);
Simon Glass6a38e412017-08-03 12:22:09 -0600158 env_set("mmcroot", mmcblk);
Marcin Niestroj55676522016-12-07 16:46:33 +0100159
160 sprintf(cmd, "mmc dev %d", dev_no);
161 run_command(cmd, 0);
162}
163#endif
164
165#ifdef CONFIG_FEC_MXC
Marcin Niestroj55676522016-12-07 16:46:33 +0100166static int setup_fec(void)
167{
168 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
169 int ret;
170
171 /* Use 50M anatop loopback REF_CLK1 for ENET1, clear gpr1[13],
172 set gpr1[17]*/
173 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC1_MASK,
174 IOMUX_GPR1_FEC1_CLOCK_MUX1_SEL_MASK);
175
176 ret = enable_fec_anatop_clock(0, ENET_50MHZ);
177 if (ret)
178 return ret;
179
180 enable_enet_clk(1);
181
182 return 0;
183}
184#endif
185
Marcin Niestroj55676522016-12-07 16:46:33 +0100186int board_early_init_f(void)
187{
188 setup_iomux_uart();
189
190 return 0;
191}
192
193int board_init(void)
194{
195 /* Address of boot parameters */
196 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
197
198#ifdef CONFIG_FEC_MXC
199 setup_fec();
200#endif
201
202 return 0;
203}
204
205#ifdef CONFIG_CMD_BMODE
206static const struct boot_mode board_boot_modes[] = {
207 /* 4 bit bus width */
208 {"sd", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
209 {"emmc", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00)},
210 {NULL, 0},
211};
212#endif
213
214int board_late_init(void)
215{
216#ifdef CONFIG_CMD_BMODE
217 add_board_boot_modes(board_boot_modes);
218#endif
219
220#ifdef CONFIG_ENV_IS_IN_MMC
221 board_late_mmc_init();
222#endif
223
224 return 0;
225}
226
227int checkboard(void)
228{
229 puts("Board: Grinn liteBoard\n");
230
231 return 0;
232}
233
234#ifdef CONFIG_SPL_BUILD
235void board_boot_order(u32 *spl_boot_list)
236{
237 struct src *psrc = (struct src *)SRC_BASE_ADDR;
238 unsigned gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
239 unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
240 unsigned port = (reg >> 11) & 0x1;
241
242 if (port == 0) {
243 spl_boot_list[0] = BOOT_DEVICE_MMC1;
244 spl_boot_list[1] = BOOT_DEVICE_MMC2;
245 } else {
246 spl_boot_list[0] = BOOT_DEVICE_MMC2;
247 spl_boot_list[1] = BOOT_DEVICE_MMC1;
248 }
249}
250
251void board_init_f(ulong dummy)
252{
253 litesom_init_f();
254}
255#endif