blob: c59f0fb922af35be6c5e9db0d84f18d5add56e74 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevamadac83a2011-09-06 09:05:43 +00002/*
3 * (C) Copyright 2011 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevamadac83a2011-09-06 09:05:43 +00006 */
7
8#include <common.h>
9#include <asm/io.h>
Fabio Estevam1de48fa2012-10-23 06:34:49 +000010#include <asm/gpio.h>
Fabio Estevamadac83a2011-09-06 09:05:43 +000011#include <asm/arch/imx-regs.h>
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000012#include <asm/arch/iomux-mx25.h>
Fabio Estevam1de48fa2012-10-23 06:34:49 +000013#include <asm/arch/clock.h>
14#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080015#include <fsl_esdhc_imx.h>
Fabio Estevam90c3aae2012-10-23 06:34:53 +000016#include <i2c.h>
Fabio Estevam592fd4e2012-12-11 04:58:02 +000017#include <power/pmic.h>
Fabio Estevam90c3aae2012-10-23 06:34:53 +000018#include <fsl_pmic.h>
19#include <mc34704.h>
Fabio Estevam1de48fa2012-10-23 06:34:49 +000020
Benoît Thébaudeau518e7a92013-05-03 10:32:15 +000021#define FEC_RESET_B IMX_GPIO_NR(4, 8)
22#define FEC_ENABLE_B IMX_GPIO_NR(2, 3)
Fabio Estevam1de48fa2012-10-23 06:34:49 +000023#define CARD_DETECT IMX_GPIO_NR(2, 1)
Fabio Estevamadac83a2011-09-06 09:05:43 +000024
25DECLARE_GLOBAL_DATA_PTR;
26
Yangbo Lu73340382019-06-21 11:42:28 +080027#ifdef CONFIG_FSL_ESDHC_IMX
Fabio Estevam1de48fa2012-10-23 06:34:49 +000028struct fsl_esdhc_cfg esdhc_cfg[1] = {
29 {IMX_MMC_SDHC1_BASE},
30};
31#endif
32
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000033/*
34 * FIXME: need to revisit this
35 * The original code enabled PUE and 100-k pull-down without PKE, so the right
36 * value here is likely:
37 * 0 for no pull
38 * or:
39 * PAD_CTL_PUS_100K_DOWN for 100-k pull-down
40 */
41#define FEC_OUT_PAD_CTRL 0
42
43#define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \
44 PAD_CTL_ODE)
45
Fabio Estevam90c3aae2012-10-23 06:34:53 +000046static void mx25pdk_fec_init(void)
47{
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000048 static const iomux_v3_cfg_t fec_pads[] = {
49 MX25_PAD_FEC_TX_CLK__FEC_TX_CLK,
50 MX25_PAD_FEC_RX_DV__FEC_RX_DV,
51 MX25_PAD_FEC_RDATA0__FEC_RDATA0,
52 NEW_PAD_CTRL(MX25_PAD_FEC_TDATA0__FEC_TDATA0, FEC_OUT_PAD_CTRL),
53 NEW_PAD_CTRL(MX25_PAD_FEC_TX_EN__FEC_TX_EN, FEC_OUT_PAD_CTRL),
54 NEW_PAD_CTRL(MX25_PAD_FEC_MDC__FEC_MDC, FEC_OUT_PAD_CTRL),
55 MX25_PAD_FEC_MDIO__FEC_MDIO,
56 MX25_PAD_FEC_RDATA1__FEC_RDATA1,
57 NEW_PAD_CTRL(MX25_PAD_FEC_TDATA1__FEC_TDATA1, FEC_OUT_PAD_CTRL),
Fabio Estevam90c3aae2012-10-23 06:34:53 +000058
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000059 NEW_PAD_CTRL(MX25_PAD_D12__GPIO_4_8, 0), /* FEC_RESET_B */
60 NEW_PAD_CTRL(MX25_PAD_A17__GPIO_2_3, 0), /* FEC_ENABLE_B */
61 };
Fabio Estevam90c3aae2012-10-23 06:34:53 +000062
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000063 static const iomux_v3_cfg_t i2c_pads[] = {
64 NEW_PAD_CTRL(MX25_PAD_I2C1_CLK__I2C1_CLK, I2C_PAD_CTRL),
65 NEW_PAD_CTRL(MX25_PAD_I2C1_DAT__I2C1_DAT, I2C_PAD_CTRL),
66 };
Fabio Estevam90c3aae2012-10-23 06:34:53 +000067
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000068 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
Fabio Estevam90c3aae2012-10-23 06:34:53 +000069
70 /* Assert RESET and ENABLE low */
71 gpio_direction_output(FEC_RESET_B, 0);
72 gpio_direction_output(FEC_ENABLE_B, 0);
73
74 udelay(10);
75
76 /* Deassert RESET and ENABLE */
77 gpio_set_value(FEC_RESET_B, 1);
78 gpio_set_value(FEC_ENABLE_B, 1);
79
80 /* Setup I2C pins so that PMIC can turn on PHY supply */
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000081 imx_iomux_v3_setup_multiple_pads(i2c_pads, ARRAY_SIZE(i2c_pads));
Fabio Estevam90c3aae2012-10-23 06:34:53 +000082}
83
Fabio Estevamadac83a2011-09-06 09:05:43 +000084int dram_init(void)
85{
86 /* dram_init must store complete ramsize in gd->ram_size */
87 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
88 PHYS_SDRAM_1_SIZE);
89 return 0;
90}
91
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +000092/*
93 * Set up input pins with hysteresis and 100-k pull-ups
94 */
95#define UART1_IN_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP)
96/*
97 * FIXME: need to revisit this
98 * The original code enabled PUE and 100-k pull-down without PKE, so the right
99 * value here is likely:
100 * 0 for no pull
101 * or:
102 * PAD_CTL_PUS_100K_DOWN for 100-k pull-down
103 */
104#define UART1_OUT_PAD_CTRL 0
105
106static void mx25pdk_uart1_init(void)
107{
108 static const iomux_v3_cfg_t uart1_pads[] = {
109 NEW_PAD_CTRL(MX25_PAD_UART1_RXD__UART1_RXD, UART1_IN_PAD_CTRL),
110 NEW_PAD_CTRL(MX25_PAD_UART1_TXD__UART1_TXD, UART1_OUT_PAD_CTRL),
111 NEW_PAD_CTRL(MX25_PAD_UART1_RTS__UART1_RTS, UART1_OUT_PAD_CTRL),
112 NEW_PAD_CTRL(MX25_PAD_UART1_CTS__UART1_CTS, UART1_IN_PAD_CTRL),
113 };
114
115 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
116}
117
Fabio Estevamadac83a2011-09-06 09:05:43 +0000118int board_early_init_f(void)
119{
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +0000120 mx25pdk_uart1_init();
Fabio Estevamadac83a2011-09-06 09:05:43 +0000121
122 return 0;
123}
124
125int board_init(void)
126{
Fabio Estevamadac83a2011-09-06 09:05:43 +0000127 /* address of boot parameters */
128 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
129
130 return 0;
131}
Fabio Estevam1de48fa2012-10-23 06:34:49 +0000132
Fabio Estevam90c3aae2012-10-23 06:34:53 +0000133int board_late_init(void)
134{
135 struct pmic *p;
Fabio Estevam592fd4e2012-12-11 04:58:02 +0000136 int ret;
Fabio Estevam90c3aae2012-10-23 06:34:53 +0000137
138 mx25pdk_fec_init();
139
Fabio Estevamf330cec2013-11-20 21:17:36 -0200140 ret = pmic_init(I2C_0);
Fabio Estevam592fd4e2012-12-11 04:58:02 +0000141 if (ret)
142 return ret;
143
144 p = pmic_get("FSL_PMIC");
145 if (!p)
146 return -ENODEV;
147
Fabio Estevam4eb32c22015-02-21 17:22:50 -0200148 /* Turn on Ethernet PHY and LCD supplies */
149 pmic_reg_write(p, MC34704_GENERAL2_REG, ONOFFE | ONOFFA);
Fabio Estevam90c3aae2012-10-23 06:34:53 +0000150
151 return 0;
152}
153
Yangbo Lu73340382019-06-21 11:42:28 +0800154#ifdef CONFIG_FSL_ESDHC_IMX
Fabio Estevam1de48fa2012-10-23 06:34:49 +0000155int board_mmc_getcd(struct mmc *mmc)
156{
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +0000157 /* Set up the Card Detect pin. */
158 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX25_PAD_A15__GPIO_2_1, 0));
Fabio Estevam1de48fa2012-10-23 06:34:49 +0000159
160 gpio_direction_input(CARD_DETECT);
161 return !gpio_get_value(CARD_DETECT);
162}
163
164int board_mmc_init(bd_t *bis)
165{
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +0000166 static const iomux_v3_cfg_t sdhc1_pads[] = {
167 NEW_PAD_CTRL(MX25_PAD_SD1_CMD__SD1_CMD, NO_PAD_CTRL),
168 NEW_PAD_CTRL(MX25_PAD_SD1_CLK__SD1_CLK, NO_PAD_CTRL),
169 NEW_PAD_CTRL(MX25_PAD_SD1_DATA0__SD1_DATA0, NO_PAD_CTRL),
170 NEW_PAD_CTRL(MX25_PAD_SD1_DATA1__SD1_DATA1, NO_PAD_CTRL),
171 NEW_PAD_CTRL(MX25_PAD_SD1_DATA2__SD1_DATA2, NO_PAD_CTRL),
172 NEW_PAD_CTRL(MX25_PAD_SD1_DATA3__SD1_DATA3, NO_PAD_CTRL),
173 };
Fabio Estevam1de48fa2012-10-23 06:34:49 +0000174
Benoît Thébaudeaua12f2222013-05-03 10:32:14 +0000175 imx_iomux_v3_setup_multiple_pads(sdhc1_pads, ARRAY_SIZE(sdhc1_pads));
Fabio Estevam1de48fa2012-10-23 06:34:49 +0000176
Benoît Thébaudeau2e0071b2017-05-03 11:59:06 +0200177 /*
178 * Set the eSDHC1 PER clock to the maximum frequency lower than or equal
179 * to 50 MHz that can be obtained, which requires to use UPLL as the
180 * clock source. This actually gives 48 MHz.
181 */
182 imx_set_perclk(MXC_ESDHC1_CLK, true, 50000000);
Fabio Estevam1de48fa2012-10-23 06:34:49 +0000183 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
184 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
185}
186#endif
Fabio Estevamadac83a2011-09-06 09:05:43 +0000187
188int checkboard(void)
189{
190 puts("Board: MX25PDK\n");
191
192 return 0;
193}
Fabio Estevam1385f462016-01-11 18:09:15 -0200194
195/* Lowlevel init isn't used on mx25pdk, so just provide a dummy one here */
196void lowlevel_init(void) {}