Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2011 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame^] | 10 | #include <asm/global_data.h> |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 12 | #include <asm/gpio.h> |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 13 | #include <asm/arch/imx-regs.h> |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 14 | #include <asm/arch/iomux-mx25.h> |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 15 | #include <asm/arch/clock.h> |
| 16 | #include <mmc.h> |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 17 | #include <fsl_esdhc_imx.h> |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 18 | #include <i2c.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Fabio Estevam | cabe240 | 2012-12-11 04:58:02 +0000 | [diff] [blame] | 20 | #include <power/pmic.h> |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 21 | #include <fsl_pmic.h> |
| 22 | #include <mc34704.h> |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 23 | |
Benoît Thébaudeau | 1b1c526 | 2013-05-03 10:32:15 +0000 | [diff] [blame] | 24 | #define FEC_RESET_B IMX_GPIO_NR(4, 8) |
| 25 | #define FEC_ENABLE_B IMX_GPIO_NR(2, 3) |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 26 | #define CARD_DETECT IMX_GPIO_NR(2, 1) |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 30 | #ifdef CONFIG_FSL_ESDHC_IMX |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 31 | struct fsl_esdhc_cfg esdhc_cfg[1] = { |
| 32 | {IMX_MMC_SDHC1_BASE}, |
| 33 | }; |
| 34 | #endif |
| 35 | |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 36 | /* |
| 37 | * FIXME: need to revisit this |
| 38 | * The original code enabled PUE and 100-k pull-down without PKE, so the right |
| 39 | * value here is likely: |
| 40 | * 0 for no pull |
| 41 | * or: |
| 42 | * PAD_CTL_PUS_100K_DOWN for 100-k pull-down |
| 43 | */ |
| 44 | #define FEC_OUT_PAD_CTRL 0 |
| 45 | |
| 46 | #define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \ |
| 47 | PAD_CTL_ODE) |
| 48 | |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 49 | static void mx25pdk_fec_init(void) |
| 50 | { |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 51 | static const iomux_v3_cfg_t fec_pads[] = { |
| 52 | MX25_PAD_FEC_TX_CLK__FEC_TX_CLK, |
| 53 | MX25_PAD_FEC_RX_DV__FEC_RX_DV, |
| 54 | MX25_PAD_FEC_RDATA0__FEC_RDATA0, |
| 55 | NEW_PAD_CTRL(MX25_PAD_FEC_TDATA0__FEC_TDATA0, FEC_OUT_PAD_CTRL), |
| 56 | NEW_PAD_CTRL(MX25_PAD_FEC_TX_EN__FEC_TX_EN, FEC_OUT_PAD_CTRL), |
| 57 | NEW_PAD_CTRL(MX25_PAD_FEC_MDC__FEC_MDC, FEC_OUT_PAD_CTRL), |
| 58 | MX25_PAD_FEC_MDIO__FEC_MDIO, |
| 59 | MX25_PAD_FEC_RDATA1__FEC_RDATA1, |
| 60 | NEW_PAD_CTRL(MX25_PAD_FEC_TDATA1__FEC_TDATA1, FEC_OUT_PAD_CTRL), |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 61 | |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 62 | NEW_PAD_CTRL(MX25_PAD_D12__GPIO_4_8, 0), /* FEC_RESET_B */ |
| 63 | NEW_PAD_CTRL(MX25_PAD_A17__GPIO_2_3, 0), /* FEC_ENABLE_B */ |
| 64 | }; |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 65 | |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 66 | static const iomux_v3_cfg_t i2c_pads[] = { |
| 67 | NEW_PAD_CTRL(MX25_PAD_I2C1_CLK__I2C1_CLK, I2C_PAD_CTRL), |
| 68 | NEW_PAD_CTRL(MX25_PAD_I2C1_DAT__I2C1_DAT, I2C_PAD_CTRL), |
| 69 | }; |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 70 | |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 71 | imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads)); |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 72 | |
| 73 | /* Assert RESET and ENABLE low */ |
| 74 | gpio_direction_output(FEC_RESET_B, 0); |
| 75 | gpio_direction_output(FEC_ENABLE_B, 0); |
| 76 | |
| 77 | udelay(10); |
| 78 | |
| 79 | /* Deassert RESET and ENABLE */ |
| 80 | gpio_set_value(FEC_RESET_B, 1); |
| 81 | gpio_set_value(FEC_ENABLE_B, 1); |
| 82 | |
| 83 | /* Setup I2C pins so that PMIC can turn on PHY supply */ |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 84 | imx_iomux_v3_setup_multiple_pads(i2c_pads, ARRAY_SIZE(i2c_pads)); |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 87 | int dram_init(void) |
| 88 | { |
| 89 | /* dram_init must store complete ramsize in gd->ram_size */ |
| 90 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 91 | PHYS_SDRAM_1_SIZE); |
| 92 | return 0; |
| 93 | } |
| 94 | |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 95 | /* |
| 96 | * Set up input pins with hysteresis and 100-k pull-ups |
| 97 | */ |
| 98 | #define UART1_IN_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP) |
| 99 | /* |
| 100 | * FIXME: need to revisit this |
| 101 | * The original code enabled PUE and 100-k pull-down without PKE, so the right |
| 102 | * value here is likely: |
| 103 | * 0 for no pull |
| 104 | * or: |
| 105 | * PAD_CTL_PUS_100K_DOWN for 100-k pull-down |
| 106 | */ |
| 107 | #define UART1_OUT_PAD_CTRL 0 |
| 108 | |
| 109 | static void mx25pdk_uart1_init(void) |
| 110 | { |
| 111 | static const iomux_v3_cfg_t uart1_pads[] = { |
| 112 | NEW_PAD_CTRL(MX25_PAD_UART1_RXD__UART1_RXD, UART1_IN_PAD_CTRL), |
| 113 | NEW_PAD_CTRL(MX25_PAD_UART1_TXD__UART1_TXD, UART1_OUT_PAD_CTRL), |
| 114 | NEW_PAD_CTRL(MX25_PAD_UART1_RTS__UART1_RTS, UART1_OUT_PAD_CTRL), |
| 115 | NEW_PAD_CTRL(MX25_PAD_UART1_CTS__UART1_CTS, UART1_IN_PAD_CTRL), |
| 116 | }; |
| 117 | |
| 118 | imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); |
| 119 | } |
| 120 | |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 121 | int board_early_init_f(void) |
| 122 | { |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 123 | mx25pdk_uart1_init(); |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | int board_init(void) |
| 129 | { |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 130 | /* address of boot parameters */ |
| 131 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 136 | int board_late_init(void) |
| 137 | { |
| 138 | struct pmic *p; |
Fabio Estevam | cabe240 | 2012-12-11 04:58:02 +0000 | [diff] [blame] | 139 | int ret; |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 140 | |
| 141 | mx25pdk_fec_init(); |
| 142 | |
Fabio Estevam | 570aa2f | 2013-11-20 21:17:36 -0200 | [diff] [blame] | 143 | ret = pmic_init(I2C_0); |
Fabio Estevam | cabe240 | 2012-12-11 04:58:02 +0000 | [diff] [blame] | 144 | if (ret) |
| 145 | return ret; |
| 146 | |
| 147 | p = pmic_get("FSL_PMIC"); |
| 148 | if (!p) |
| 149 | return -ENODEV; |
| 150 | |
Fabio Estevam | 86a390d | 2015-02-21 17:22:50 -0200 | [diff] [blame] | 151 | /* Turn on Ethernet PHY and LCD supplies */ |
| 152 | pmic_reg_write(p, MC34704_GENERAL2_REG, ONOFFE | ONOFFA); |
Fabio Estevam | e00c89d | 2012-10-23 06:34:53 +0000 | [diff] [blame] | 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 157 | #ifdef CONFIG_FSL_ESDHC_IMX |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 158 | int board_mmc_getcd(struct mmc *mmc) |
| 159 | { |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 160 | /* Set up the Card Detect pin. */ |
| 161 | imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX25_PAD_A15__GPIO_2_1, 0)); |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 162 | |
| 163 | gpio_direction_input(CARD_DETECT); |
| 164 | return !gpio_get_value(CARD_DETECT); |
| 165 | } |
| 166 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 167 | int board_mmc_init(struct bd_info *bis) |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 168 | { |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 169 | static const iomux_v3_cfg_t sdhc1_pads[] = { |
| 170 | NEW_PAD_CTRL(MX25_PAD_SD1_CMD__SD1_CMD, NO_PAD_CTRL), |
| 171 | NEW_PAD_CTRL(MX25_PAD_SD1_CLK__SD1_CLK, NO_PAD_CTRL), |
| 172 | NEW_PAD_CTRL(MX25_PAD_SD1_DATA0__SD1_DATA0, NO_PAD_CTRL), |
| 173 | NEW_PAD_CTRL(MX25_PAD_SD1_DATA1__SD1_DATA1, NO_PAD_CTRL), |
| 174 | NEW_PAD_CTRL(MX25_PAD_SD1_DATA2__SD1_DATA2, NO_PAD_CTRL), |
| 175 | NEW_PAD_CTRL(MX25_PAD_SD1_DATA3__SD1_DATA3, NO_PAD_CTRL), |
| 176 | }; |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 177 | |
Benoît Thébaudeau | d6208a3 | 2013-05-03 10:32:14 +0000 | [diff] [blame] | 178 | imx_iomux_v3_setup_multiple_pads(sdhc1_pads, ARRAY_SIZE(sdhc1_pads)); |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 179 | |
Benoît Thébaudeau | 747778c | 2017-05-03 11:59:06 +0200 | [diff] [blame] | 180 | /* |
| 181 | * Set the eSDHC1 PER clock to the maximum frequency lower than or equal |
| 182 | * to 50 MHz that can be obtained, which requires to use UPLL as the |
| 183 | * clock source. This actually gives 48 MHz. |
| 184 | */ |
| 185 | imx_set_perclk(MXC_ESDHC1_CLK, true, 50000000); |
Fabio Estevam | af2a409 | 2012-10-23 06:34:49 +0000 | [diff] [blame] | 186 | esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK); |
| 187 | return fsl_esdhc_initialize(bis, &esdhc_cfg[0]); |
| 188 | } |
| 189 | #endif |
| 190 | |
Fabio Estevam | 419adbf | 2011-09-06 09:05:43 +0000 | [diff] [blame] | 191 | int checkboard(void) |
| 192 | { |
| 193 | puts("Board: MX25PDK\n"); |
| 194 | |
| 195 | return 0; |
| 196 | } |
Fabio Estevam | 4897d95 | 2016-01-11 18:09:15 -0200 | [diff] [blame] | 197 | |
| 198 | /* Lowlevel init isn't used on mx25pdk, so just provide a dummy one here */ |
| 199 | void lowlevel_init(void) {} |