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