blob: e8fccccafd299be51a78066d178727431ed057b7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam67d34d72011-06-07 07:02:53 +00002/*
3 * (C) Copyright 2011 Freescale Semiconductor, Inc.
Fabio Estevam67d34d72011-06-07 07:02:53 +00004 */
5
6#include <common.h>
7#include <asm/io.h>
8#include <asm/arch/imx-regs.h>
Fabio Estevam67d34d72011-06-07 07:02:53 +00009#include <asm/arch/sys_proto.h>
10#include <asm/arch/crm_regs.h>
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +000011#include <asm/arch/clock.h>
Benoît Thébaudeau76473952013-05-03 10:32:32 +000012#include <asm/arch/iomux-mx53.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090013#include <linux/errno.h>
Fabio Estevam67d34d72011-06-07 07:02:53 +000014#include <netdev.h>
15#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080016#include <fsl_esdhc_imx.h>
Stefano Babic025bba42011-08-21 10:56:06 +020017#include <asm/gpio.h>
Fabio Estevam67d34d72011-06-07 07:02:53 +000018
Fabio Estevam85818cf2012-08-21 10:01:58 +000019#define ETHERNET_INT IMX_GPIO_NR(2, 31)
Fabio Estevam67d34d72011-06-07 07:02:53 +000020
21DECLARE_GLOBAL_DATA_PTR;
22
Fabio Estevam67d34d72011-06-07 07:02:53 +000023int dram_init(void)
24{
25 u32 size1, size2;
26
Albert ARIBAUDa9606732011-07-03 05:55:33 +000027 size1 = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
28 size2 = get_ram_size((void *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
Fabio Estevam67d34d72011-06-07 07:02:53 +000029
30 gd->ram_size = size1 + size2;
31
32 return 0;
33}
Simon Glass2f949c32017-03-31 08:40:32 -060034int dram_init_banksize(void)
Fabio Estevam67d34d72011-06-07 07:02:53 +000035{
36 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
37 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
38
39 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
40 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060041
42 return 0;
Fabio Estevam67d34d72011-06-07 07:02:53 +000043}
44
Benoît Thébaudeau1f308f92013-04-11 09:35:39 +000045#ifdef CONFIG_NAND_MXC
46static void setup_iomux_nand(void)
47{
Benoît Thébaudeau76473952013-05-03 10:32:32 +000048 static const iomux_v3_cfg_t nand_pads[] = {
49 NEW_PAD_CTRL(MX53_PAD_NANDF_CS0__EMI_NANDF_CS_0,
50 PAD_CTL_DSE_HIGH),
51 NEW_PAD_CTRL(MX53_PAD_NANDF_CS1__EMI_NANDF_CS_1,
52 PAD_CTL_DSE_HIGH),
53 NEW_PAD_CTRL(MX53_PAD_NANDF_RB0__EMI_NANDF_RB_0,
54 PAD_CTL_PUS_100K_UP),
55 NEW_PAD_CTRL(MX53_PAD_NANDF_CLE__EMI_NANDF_CLE,
56 PAD_CTL_DSE_HIGH),
57 NEW_PAD_CTRL(MX53_PAD_NANDF_ALE__EMI_NANDF_ALE,
58 PAD_CTL_DSE_HIGH),
59 NEW_PAD_CTRL(MX53_PAD_NANDF_WP_B__EMI_NANDF_WP_B,
60 PAD_CTL_PUS_100K_UP),
61 NEW_PAD_CTRL(MX53_PAD_NANDF_RE_B__EMI_NANDF_RE_B,
62 PAD_CTL_DSE_HIGH),
63 NEW_PAD_CTRL(MX53_PAD_NANDF_WE_B__EMI_NANDF_WE_B,
64 PAD_CTL_DSE_HIGH),
65 NEW_PAD_CTRL(MX53_PAD_EIM_DA0__EMI_NAND_WEIM_DA_0,
66 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
67 NEW_PAD_CTRL(MX53_PAD_EIM_DA1__EMI_NAND_WEIM_DA_1,
68 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
69 NEW_PAD_CTRL(MX53_PAD_EIM_DA2__EMI_NAND_WEIM_DA_2,
70 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
71 NEW_PAD_CTRL(MX53_PAD_EIM_DA3__EMI_NAND_WEIM_DA_3,
72 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
73 NEW_PAD_CTRL(MX53_PAD_EIM_DA4__EMI_NAND_WEIM_DA_4,
74 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
75 NEW_PAD_CTRL(MX53_PAD_EIM_DA5__EMI_NAND_WEIM_DA_5,
76 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
77 NEW_PAD_CTRL(MX53_PAD_EIM_DA6__EMI_NAND_WEIM_DA_6,
78 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
79 NEW_PAD_CTRL(MX53_PAD_EIM_DA7__EMI_NAND_WEIM_DA_7,
80 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
81 };
82
Benoît Thébaudeau1f308f92013-04-11 09:35:39 +000083 u32 i, reg;
Benoît Thébaudeau1f308f92013-04-11 09:35:39 +000084
85 reg = __raw_readl(M4IF_BASE_ADDR + 0xc);
86 reg &= ~M4IF_GENP_WEIM_MM_MASK;
87 __raw_writel(reg, M4IF_BASE_ADDR + 0xc);
88 for (i = 0x4; i < 0x94; i += 0x18) {
89 reg = __raw_readl(WEIM_BASE_ADDR + i);
90 reg &= ~WEIM_GCR2_MUX16_BYP_GRANT_MASK;
91 __raw_writel(reg, WEIM_BASE_ADDR + i);
92 }
93
Benoît Thébaudeau76473952013-05-03 10:32:32 +000094 imx_iomux_v3_setup_multiple_pads(nand_pads, ARRAY_SIZE(nand_pads));
Benoît Thébaudeau1f308f92013-04-11 09:35:39 +000095}
96#else
97static void setup_iomux_nand(void)
98{
99}
100#endif
101
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000102#define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_DSE_HIGH | \
103 PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
104
Fabio Estevam67d34d72011-06-07 07:02:53 +0000105static void setup_iomux_uart(void)
106{
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000107 static const iomux_v3_cfg_t uart_pads[] = {
108 NEW_PAD_CTRL(MX53_PAD_PATA_DMACK__UART1_RXD_MUX, UART_PAD_CTRL),
109 NEW_PAD_CTRL(MX53_PAD_PATA_DIOW__UART1_TXD_MUX, UART_PAD_CTRL),
110 };
Fabio Estevam67d34d72011-06-07 07:02:53 +0000111
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000112 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
Fabio Estevam67d34d72011-06-07 07:02:53 +0000113}
114
Yangbo Lu73340382019-06-21 11:42:28 +0800115#ifdef CONFIG_FSL_ESDHC_IMX
Fabio Estevam67d34d72011-06-07 07:02:53 +0000116struct fsl_esdhc_cfg esdhc_cfg[2] = {
Benoît Thébaudeauc08d11c2012-08-13 07:28:16 +0000117 {MMC_SDHC1_BASE_ADDR},
118 {MMC_SDHC2_BASE_ADDR},
Fabio Estevam67d34d72011-06-07 07:02:53 +0000119};
120
Thierry Redingd7aebf42012-01-02 01:15:36 +0000121int board_mmc_getcd(struct mmc *mmc)
Fabio Estevam67d34d72011-06-07 07:02:53 +0000122{
123 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Thierry Redingd7aebf42012-01-02 01:15:36 +0000124 int ret;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000125
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000126 imx_iomux_v3_setup_pad(MX53_PAD_GPIO_1__GPIO1_1);
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530127 gpio_direction_input(IMX_GPIO_NR(1, 1));
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000128 imx_iomux_v3_setup_pad(MX53_PAD_GPIO_4__GPIO1_4);
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530129 gpio_direction_input(IMX_GPIO_NR(1, 4));
Fabio Estevamece39fa2011-11-15 05:51:30 +0000130
Fabio Estevam67d34d72011-06-07 07:02:53 +0000131 if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530132 ret = !gpio_get_value(IMX_GPIO_NR(1, 1));
Fabio Estevam67d34d72011-06-07 07:02:53 +0000133 else
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530134 ret = !gpio_get_value(IMX_GPIO_NR(1, 4));
Fabio Estevam67d34d72011-06-07 07:02:53 +0000135
Thierry Redingd7aebf42012-01-02 01:15:36 +0000136 return ret;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000137}
138
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000139#define SD_CMD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_DSE_HIGH | \
140 PAD_CTL_PUS_100K_UP)
141#define SD_CLK_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_DSE_HIGH)
142#define SD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | \
143 PAD_CTL_DSE_HIGH)
144
Fabio Estevam67d34d72011-06-07 07:02:53 +0000145int board_mmc_init(bd_t *bis)
146{
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000147 static const iomux_v3_cfg_t sd1_pads[] = {
148 NEW_PAD_CTRL(MX53_PAD_SD1_CMD__ESDHC1_CMD, SD_CMD_PAD_CTRL),
149 NEW_PAD_CTRL(MX53_PAD_SD1_CLK__ESDHC1_CLK, SD_CLK_PAD_CTRL),
150 NEW_PAD_CTRL(MX53_PAD_SD1_DATA0__ESDHC1_DAT0, SD_PAD_CTRL),
151 NEW_PAD_CTRL(MX53_PAD_SD1_DATA1__ESDHC1_DAT1, SD_PAD_CTRL),
152 NEW_PAD_CTRL(MX53_PAD_SD1_DATA2__ESDHC1_DAT2, SD_PAD_CTRL),
153 NEW_PAD_CTRL(MX53_PAD_SD1_DATA3__ESDHC1_DAT3, SD_PAD_CTRL),
154 };
155
156 static const iomux_v3_cfg_t sd2_pads[] = {
157 NEW_PAD_CTRL(MX53_PAD_SD2_CMD__ESDHC2_CMD, SD_CMD_PAD_CTRL),
158 NEW_PAD_CTRL(MX53_PAD_SD2_CLK__ESDHC2_CLK, SD_CLK_PAD_CTRL),
159 NEW_PAD_CTRL(MX53_PAD_SD2_DATA0__ESDHC2_DAT0, SD_PAD_CTRL),
160 NEW_PAD_CTRL(MX53_PAD_SD2_DATA1__ESDHC2_DAT1, SD_PAD_CTRL),
161 NEW_PAD_CTRL(MX53_PAD_SD2_DATA2__ESDHC2_DAT2, SD_PAD_CTRL),
162 NEW_PAD_CTRL(MX53_PAD_SD2_DATA3__ESDHC2_DAT3, SD_PAD_CTRL),
163 NEW_PAD_CTRL(MX53_PAD_PATA_DATA12__ESDHC2_DAT4, SD_PAD_CTRL),
164 NEW_PAD_CTRL(MX53_PAD_PATA_DATA13__ESDHC2_DAT5, SD_PAD_CTRL),
165 NEW_PAD_CTRL(MX53_PAD_PATA_DATA14__ESDHC2_DAT6, SD_PAD_CTRL),
166 NEW_PAD_CTRL(MX53_PAD_PATA_DATA15__ESDHC2_DAT7, SD_PAD_CTRL),
167 };
168
Fabio Estevam67d34d72011-06-07 07:02:53 +0000169 u32 index;
Fabio Estevamc3fb6822014-11-20 16:35:20 -0200170 int ret;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000171
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000172 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
173 esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
174
Fabio Estevam67d34d72011-06-07 07:02:53 +0000175 for (index = 0; index < CONFIG_SYS_FSL_ESDHC_NUM; index++) {
176 switch (index) {
177 case 0:
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000178 imx_iomux_v3_setup_multiple_pads(sd1_pads,
179 ARRAY_SIZE(sd1_pads));
Fabio Estevam67d34d72011-06-07 07:02:53 +0000180 break;
181 case 1:
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000182 imx_iomux_v3_setup_multiple_pads(sd2_pads,
183 ARRAY_SIZE(sd2_pads));
Fabio Estevam67d34d72011-06-07 07:02:53 +0000184 break;
185 default:
186 printf("Warning: you configured more ESDHC controller"
187 "(%d) as supported by the board(2)\n",
188 CONFIG_SYS_FSL_ESDHC_NUM);
Fabio Estevamc3fb6822014-11-20 16:35:20 -0200189 return -EINVAL;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000190 }
Fabio Estevamc3fb6822014-11-20 16:35:20 -0200191 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[index]);
192 if (ret)
193 return ret;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000194 }
195
Fabio Estevamc3fb6822014-11-20 16:35:20 -0200196 return 0;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000197}
198#endif
199
200static void weim_smc911x_iomux(void)
201{
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000202 static const iomux_v3_cfg_t weim_smc911x_pads[] = {
203 /* Data bus */
204 NEW_PAD_CTRL(MX53_PAD_EIM_D16__EMI_WEIM_D_16,
205 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
206 NEW_PAD_CTRL(MX53_PAD_EIM_D17__EMI_WEIM_D_17,
207 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
208 NEW_PAD_CTRL(MX53_PAD_EIM_D18__EMI_WEIM_D_18,
209 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
210 NEW_PAD_CTRL(MX53_PAD_EIM_D19__EMI_WEIM_D_19,
211 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
212 NEW_PAD_CTRL(MX53_PAD_EIM_D20__EMI_WEIM_D_20,
213 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
214 NEW_PAD_CTRL(MX53_PAD_EIM_D21__EMI_WEIM_D_21,
215 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
216 NEW_PAD_CTRL(MX53_PAD_EIM_D22__EMI_WEIM_D_22,
217 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
218 NEW_PAD_CTRL(MX53_PAD_EIM_D23__EMI_WEIM_D_23,
219 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
220 NEW_PAD_CTRL(MX53_PAD_EIM_D24__EMI_WEIM_D_24,
221 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
222 NEW_PAD_CTRL(MX53_PAD_EIM_D25__EMI_WEIM_D_25,
223 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
224 NEW_PAD_CTRL(MX53_PAD_EIM_D26__EMI_WEIM_D_26,
225 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
226 NEW_PAD_CTRL(MX53_PAD_EIM_D27__EMI_WEIM_D_27,
227 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
228 NEW_PAD_CTRL(MX53_PAD_EIM_D28__EMI_WEIM_D_28,
229 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
230 NEW_PAD_CTRL(MX53_PAD_EIM_D29__EMI_WEIM_D_29,
231 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
232 NEW_PAD_CTRL(MX53_PAD_EIM_D30__EMI_WEIM_D_30,
233 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
234 NEW_PAD_CTRL(MX53_PAD_EIM_D31__EMI_WEIM_D_31,
235 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
Fabio Estevam67d34d72011-06-07 07:02:53 +0000236
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000237 /* Address lines */
238 NEW_PAD_CTRL(MX53_PAD_EIM_DA0__EMI_NAND_WEIM_DA_0,
239 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
240 NEW_PAD_CTRL(MX53_PAD_EIM_DA1__EMI_NAND_WEIM_DA_1,
241 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
242 NEW_PAD_CTRL(MX53_PAD_EIM_DA2__EMI_NAND_WEIM_DA_2,
243 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
244 NEW_PAD_CTRL(MX53_PAD_EIM_DA3__EMI_NAND_WEIM_DA_3,
245 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
246 NEW_PAD_CTRL(MX53_PAD_EIM_DA4__EMI_NAND_WEIM_DA_4,
247 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
248 NEW_PAD_CTRL(MX53_PAD_EIM_DA5__EMI_NAND_WEIM_DA_5,
249 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
250 NEW_PAD_CTRL(MX53_PAD_EIM_DA6__EMI_NAND_WEIM_DA_6,
251 PAD_CTL_PKE | PAD_CTL_DSE_HIGH),
Fabio Estevam67d34d72011-06-07 07:02:53 +0000252
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000253 /* other EIM signals for ethernet */
254 MX53_PAD_EIM_OE__EMI_WEIM_OE,
255 MX53_PAD_EIM_RW__EMI_WEIM_RW,
256 MX53_PAD_EIM_CS1__EMI_WEIM_CS_1,
257 };
Fabio Estevam67d34d72011-06-07 07:02:53 +0000258
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000259 /* ETHERNET_INT as GPIO2_31 */
260 imx_iomux_v3_setup_pad(MX53_PAD_EIM_EB3__GPIO2_31);
261 gpio_direction_input(ETHERNET_INT);
Fabio Estevam67d34d72011-06-07 07:02:53 +0000262
Benoît Thébaudeau76473952013-05-03 10:32:32 +0000263 /* WEIM bus */
264 imx_iomux_v3_setup_multiple_pads(weim_smc911x_pads,
265 ARRAY_SIZE(weim_smc911x_pads));
Fabio Estevam67d34d72011-06-07 07:02:53 +0000266}
267
268static void weim_cs1_settings(void)
269{
270 struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
271
272 writel(MX53ARD_CS1GCR1, &weim_regs->cs1gcr1);
273 writel(0x0, &weim_regs->cs1gcr2);
274 writel(MX53ARD_CS1RCR1, &weim_regs->cs1rcr1);
275 writel(MX53ARD_CS1RCR2, &weim_regs->cs1rcr2);
276 writel(MX53ARD_CS1WCR1, &weim_regs->cs1wcr1);
277 writel(0x0, &weim_regs->cs1wcr2);
278 writel(0x0, &weim_regs->wcr);
279
280 set_chipselect_size(CS0_64M_CS1_64M);
281}
282
283int board_early_init_f(void)
284{
Benoît Thébaudeau1f308f92013-04-11 09:35:39 +0000285 setup_iomux_nand();
Fabio Estevam67d34d72011-06-07 07:02:53 +0000286 setup_iomux_uart();
287 return 0;
288}
289
290int board_init(void)
291{
Fabio Estevam67d34d72011-06-07 07:02:53 +0000292 /* address of boot parameters */
293 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
294
295 return 0;
296}
297
298int board_eth_init(bd_t *bis)
299{
Fabio Estevamc9088922012-03-19 13:41:25 +0000300 int rc = -ENODEV;
Fabio Estevam67d34d72011-06-07 07:02:53 +0000301
302 weim_smc911x_iomux();
303 weim_cs1_settings();
304
305#ifdef CONFIG_SMC911X
306 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
307#endif
308 return rc;
309}
310
311int checkboard(void)
312{
313 puts("Board: MX53ARD\n");
314
315 return 0;
316}