Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 9 | #include <asm/io.h> |
Stefano Babic | 5700881 | 2011-08-21 23:29:52 +0200 | [diff] [blame] | 10 | #include <asm/gpio.h> |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 11 | #include <asm/arch/imx-regs.h> |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 12 | #include <asm/arch/iomux-mx51.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 14 | #include <linux/errno.h> |
Stefano Babic | ac41d4d | 2010-03-05 17:54:37 +0100 | [diff] [blame] | 15 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 16 | #include <asm/arch/crm_regs.h> |
Benoît Thébaudeau | c58ff34 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 18 | #include <asm/mach-imx/mx5_video.h> |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 19 | #include <i2c.h> |
Diego Dorta | 2661c9c | 2017-09-22 12:12:18 -0300 | [diff] [blame] | 20 | #include <input.h> |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 21 | #include <mmc.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 22 | #include <fsl_esdhc_imx.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 23 | #include <power/pmic.h> |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 24 | #include <fsl_pmic.h> |
| 25 | #include <mc13892.h> |
Mateusz Kulikowski | 3add69e | 2016-03-31 23:12:23 +0200 | [diff] [blame] | 26 | #include <usb/ehci-ci.h> |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 30 | int dram_init(void) |
| 31 | { |
Shawn Guo | bc08e7e | 2010-10-28 10:13:15 +0800 | [diff] [blame] | 32 | /* dram_init must store complete ramsize in gd->ram_size */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 33 | gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, |
Shawn Guo | bc08e7e | 2010-10-28 10:13:15 +0800 | [diff] [blame] | 34 | PHYS_SDRAM_1_SIZE); |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 35 | return 0; |
| 36 | } |
| 37 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 38 | #ifdef CONFIG_REVISION_TAG |
Benoît Thébaudeau | 7477d11 | 2012-09-18 04:48:42 +0000 | [diff] [blame] | 39 | u32 get_board_rev(void) |
| 40 | { |
| 41 | u32 rev = get_cpu_rev(); |
| 42 | if (!gpio_get_value(IMX_GPIO_NR(1, 22))) |
| 43 | rev |= BOARD_REV_2_0 << BOARD_VER_OFFSET; |
| 44 | return rev; |
| 45 | } |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 46 | #endif |
Benoît Thébaudeau | 7477d11 | 2012-09-18 04:48:42 +0000 | [diff] [blame] | 47 | |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 48 | #define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_DSE_HIGH) |
| 49 | |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 50 | static void setup_iomux_uart(void) |
| 51 | { |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 52 | static const iomux_v3_cfg_t uart_pads[] = { |
| 53 | MX51_PAD_UART1_RXD__UART1_RXD, |
| 54 | MX51_PAD_UART1_TXD__UART1_TXD, |
| 55 | NEW_PAD_CTRL(MX51_PAD_UART1_RTS__UART1_RTS, UART_PAD_CTRL), |
| 56 | NEW_PAD_CTRL(MX51_PAD_UART1_CTS__UART1_CTS, UART_PAD_CTRL), |
| 57 | }; |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 58 | |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 59 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 62 | #ifdef CONFIG_MXC_SPI |
| 63 | static void setup_iomux_spi(void) |
| 64 | { |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 65 | static const iomux_v3_cfg_t spi_pads[] = { |
| 66 | NEW_PAD_CTRL(MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI, PAD_CTL_HYS | |
| 67 | PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST), |
| 68 | NEW_PAD_CTRL(MX51_PAD_CSPI1_MISO__ECSPI1_MISO, PAD_CTL_HYS | |
| 69 | PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST), |
| 70 | NEW_PAD_CTRL(MX51_PAD_CSPI1_SS1__ECSPI1_SS1, |
| 71 | MX51_GPIO_PAD_CTRL), |
| 72 | MX51_PAD_CSPI1_SS0__ECSPI1_SS0, |
| 73 | NEW_PAD_CTRL(MX51_PAD_CSPI1_RDY__ECSPI1_RDY, MX51_PAD_CTRL_2), |
| 74 | NEW_PAD_CTRL(MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK, PAD_CTL_HYS | |
| 75 | PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST), |
| 76 | }; |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 77 | |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 78 | imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads)); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 79 | } |
| 80 | #endif |
| 81 | |
| 82 | static void power_init(void) |
| 83 | { |
| 84 | unsigned int val; |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 85 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 86 | struct pmic *p; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 87 | int ret; |
| 88 | |
Tom Rini | 0b646eb | 2022-12-04 10:03:59 -0500 | [diff] [blame] | 89 | ret = pmic_init(CFG_FSL_PMIC_BUS); |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 90 | if (ret) |
| 91 | return; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 92 | |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 93 | p = pmic_get("FSL_PMIC"); |
| 94 | if (!p) |
| 95 | return; |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 96 | |
| 97 | /* Write needed to Power Gate 2 register */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 98 | pmic_reg_read(p, REG_POWER_MISC, &val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 99 | val &= ~PWGT2SPIEN; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 100 | pmic_reg_write(p, REG_POWER_MISC, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 101 | |
Shawn Guo | 4546eb7 | 2010-10-27 23:36:04 +0800 | [diff] [blame] | 102 | /* Externally powered */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 103 | pmic_reg_read(p, REG_CHARGE, &val); |
Shawn Guo | 4546eb7 | 2010-10-27 23:36:04 +0800 | [diff] [blame] | 104 | val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 105 | pmic_reg_write(p, REG_CHARGE, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 106 | |
| 107 | /* power up the system first */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 108 | pmic_reg_write(p, REG_POWER_MISC, PWUP); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 109 | |
| 110 | /* Set core voltage to 1.1V */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 111 | pmic_reg_read(p, REG_SW_0, &val); |
Marek Vasut | b043f70 | 2011-01-19 04:40:36 +0000 | [diff] [blame] | 112 | val = (val & ~SWx_VOLT_MASK) | SWx_1_100V; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 113 | pmic_reg_write(p, REG_SW_0, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 114 | |
| 115 | /* Setup VCC (SW2) to 1.25 */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 116 | pmic_reg_read(p, REG_SW_1, &val); |
Marek Vasut | b043f70 | 2011-01-19 04:40:36 +0000 | [diff] [blame] | 117 | val = (val & ~SWx_VOLT_MASK) | SWx_1_250V; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 118 | pmic_reg_write(p, REG_SW_1, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 119 | |
| 120 | /* Setup 1V2_DIG1 (SW3) to 1.25 */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 121 | pmic_reg_read(p, REG_SW_2, &val); |
Marek Vasut | b043f70 | 2011-01-19 04:40:36 +0000 | [diff] [blame] | 122 | val = (val & ~SWx_VOLT_MASK) | SWx_1_250V; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 123 | pmic_reg_write(p, REG_SW_2, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 124 | udelay(50); |
| 125 | |
| 126 | /* Raise the core frequency to 800MHz */ |
| 127 | writel(0x0, &mxc_ccm->cacrr); |
| 128 | |
| 129 | /* Set switchers in Auto in NORMAL mode & STANDBY mode */ |
| 130 | /* Setup the switcher mode for SW1 & SW2*/ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 131 | pmic_reg_read(p, REG_SW_4, &val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 132 | val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) | |
| 133 | (SWMODE_MASK << SWMODE2_SHIFT))); |
| 134 | val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) | |
| 135 | (SWMODE_AUTO_AUTO << SWMODE2_SHIFT); |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 136 | pmic_reg_write(p, REG_SW_4, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 137 | |
| 138 | /* Setup the switcher mode for SW3 & SW4 */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 139 | pmic_reg_read(p, REG_SW_5, &val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 140 | val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) | |
| 141 | (SWMODE_MASK << SWMODE4_SHIFT))); |
| 142 | val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) | |
| 143 | (SWMODE_AUTO_AUTO << SWMODE4_SHIFT); |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 144 | pmic_reg_write(p, REG_SW_5, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 145 | |
| 146 | /* Set VDIG to 1.65V, VGEN3 to 1.8V, VCAM to 2.6V */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 147 | pmic_reg_read(p, REG_SETTING_0, &val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 148 | val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK); |
| 149 | val |= VDIG_1_65 | VGEN3_1_8 | VCAM_2_6; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 150 | pmic_reg_write(p, REG_SETTING_0, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 151 | |
| 152 | /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */ |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 153 | pmic_reg_read(p, REG_SETTING_1, &val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 154 | val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK); |
| 155 | val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 156 | pmic_reg_write(p, REG_SETTING_1, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 157 | |
| 158 | /* Configure VGEN3 and VCAM regulators to use external PNP */ |
| 159 | val = VGEN3CONFIG | VCAMCONFIG; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 160 | pmic_reg_write(p, REG_MODE_1, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 161 | udelay(200); |
| 162 | |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 163 | /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */ |
| 164 | val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG | |
| 165 | VVIDEOEN | VAUDIOEN | VSDEN; |
Stefano Babic | dba2efc | 2011-10-08 10:59:20 +0200 | [diff] [blame] | 166 | pmic_reg_write(p, REG_MODE_1, val); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 167 | |
Benoît Thébaudeau | 168dc71 | 2013-05-03 10:32:27 +0000 | [diff] [blame] | 168 | imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_EIM_A20__GPIO2_14, |
| 169 | NO_PAD_CTRL)); |
Fabio Estevam | 6df20c9 | 2021-02-15 08:58:17 -0300 | [diff] [blame] | 170 | gpio_request(IMX_GPIO_NR(2, 14), "gpio2_14"); |
Ashok Kumar Reddy | 7d04bd7 | 2012-08-28 07:39:38 +0530 | [diff] [blame] | 171 | gpio_direction_output(IMX_GPIO_NR(2, 14), 0); |
Fabio Estevam | c38e0d6 | 2011-10-25 03:14:00 +0000 | [diff] [blame] | 172 | |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 173 | udelay(500); |
| 174 | |
Ashok Kumar Reddy | 7d04bd7 | 2012-08-28 07:39:38 +0530 | [diff] [blame] | 175 | gpio_set_value(IMX_GPIO_NR(2, 14), 1); |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Liu Hui-R64343 | 1e929df | 2010-12-23 01:13:17 +0000 | [diff] [blame] | 178 | int board_early_init_f(void) |
| 179 | { |
| 180 | setup_iomux_uart(); |
Vikram Narayanan | 9ddfa24 | 2012-11-10 02:28:52 +0000 | [diff] [blame] | 181 | setup_iomux_lcd(); |
Liu Hui-R64343 | 1e929df | 2010-12-23 01:13:17 +0000 | [diff] [blame] | 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 186 | int board_init(void) |
| 187 | { |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 188 | /* address of boot parameters */ |
| 189 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 190 | |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
Helmut Raiger | d5a184b | 2011-10-20 04:19:47 +0000 | [diff] [blame] | 194 | #ifdef CONFIG_BOARD_LATE_INIT |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 195 | int board_late_init(void) |
| 196 | { |
| 197 | #ifdef CONFIG_MXC_SPI |
| 198 | setup_iomux_spi(); |
| 199 | power_init(); |
| 200 | #endif |
Fabio Estevam | 12ba860 | 2012-05-09 06:39:41 +0000 | [diff] [blame] | 201 | |
Stefano Babic | 9665127 | 2010-03-16 17:22:21 +0100 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | #endif |
| 205 | |
Fabio Estevam | 8892058 | 2012-08-05 07:31:33 +0000 | [diff] [blame] | 206 | /* |
| 207 | * Do not overwrite the console |
| 208 | * Use always serial for U-Boot console |
| 209 | */ |
| 210 | int overwrite_console(void) |
| 211 | { |
| 212 | return 1; |
| 213 | } |
| 214 | |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 215 | int checkboard(void) |
| 216 | { |
Jason Liu | 8b7b69b | 2011-04-22 02:55:42 +0000 | [diff] [blame] | 217 | puts("Board: MX51EVK\n"); |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 218 | |
Stefano Babic | 421834e | 2010-02-05 15:13:58 +0100 | [diff] [blame] | 219 | return 0; |
| 220 | } |