blob: 86364acf8ca018aaacb38bc357cffe37aaa52fe9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babic421834e2010-02-05 15:13:58 +01002/*
3 * (C) Copyright 2009 Freescale Semiconductor, Inc.
Stefano Babic421834e2010-02-05 15:13:58 +01004 */
5
6#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Stefano Babic421834e2010-02-05 15:13:58 +01009#include <asm/io.h>
Stefano Babic57008812011-08-21 23:29:52 +020010#include <asm/gpio.h>
Stefano Babic421834e2010-02-05 15:13:58 +010011#include <asm/arch/imx-regs.h>
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000012#include <asm/arch/iomux-mx51.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090014#include <linux/errno.h>
Stefano Babicac41d4d2010-03-05 17:54:37 +010015#include <asm/arch/sys_proto.h>
Stefano Babic96651272010-03-16 17:22:21 +010016#include <asm/arch/crm_regs.h>
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +000017#include <asm/arch/clock.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/mx5_video.h>
Stefano Babic421834e2010-02-05 15:13:58 +010019#include <i2c.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030020#include <input.h>
Stefano Babic421834e2010-02-05 15:13:58 +010021#include <mmc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080022#include <fsl_esdhc_imx.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000023#include <power/pmic.h>
Stefano Babic96651272010-03-16 17:22:21 +010024#include <fsl_pmic.h>
25#include <mc13892.h>
Mateusz Kulikowski3add69e2016-03-31 23:12:23 +020026#include <usb/ehci-ci.h>
Stefano Babic421834e2010-02-05 15:13:58 +010027
28DECLARE_GLOBAL_DATA_PTR;
29
Stefano Babic421834e2010-02-05 15:13:58 +010030int dram_init(void)
31{
Shawn Guobc08e7e2010-10-28 10:13:15 +080032 /* dram_init must store complete ramsize in gd->ram_size */
Tom Rinibb4dd962022-11-16 13:10:37 -050033 gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE,
Shawn Guobc08e7e2010-10-28 10:13:15 +080034 PHYS_SDRAM_1_SIZE);
Stefano Babic421834e2010-02-05 15:13:58 +010035 return 0;
36}
37
Tom Rini4cc38852021-08-30 09:16:30 -040038#ifdef CONFIG_REVISION_TAG
Benoît Thébaudeau7477d112012-09-18 04:48:42 +000039u32 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 Rini4cc38852021-08-30 09:16:30 -040046#endif
Benoît Thébaudeau7477d112012-09-18 04:48:42 +000047
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000048#define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_DSE_HIGH)
49
Stefano Babic421834e2010-02-05 15:13:58 +010050static void setup_iomux_uart(void)
51{
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000052 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 Babic421834e2010-02-05 15:13:58 +010058
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000059 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
Stefano Babic421834e2010-02-05 15:13:58 +010060}
61
Stefano Babic96651272010-03-16 17:22:21 +010062#ifdef CONFIG_MXC_SPI
63static void setup_iomux_spi(void)
64{
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000065 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 Babic96651272010-03-16 17:22:21 +010077
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000078 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babic96651272010-03-16 17:22:21 +010079}
80#endif
81
82static void power_init(void)
83{
84 unsigned int val;
Stefano Babic96651272010-03-16 17:22:21 +010085 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babicdba2efc2011-10-08 10:59:20 +020086 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000087 int ret;
88
Fabio Estevam21cb23f2013-11-20 20:26:03 -020089 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000090 if (ret)
91 return;
Stefano Babicdba2efc2011-10-08 10:59:20 +020092
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000093 p = pmic_get("FSL_PMIC");
94 if (!p)
95 return;
Stefano Babic96651272010-03-16 17:22:21 +010096
97 /* Write needed to Power Gate 2 register */
Stefano Babicdba2efc2011-10-08 10:59:20 +020098 pmic_reg_read(p, REG_POWER_MISC, &val);
Stefano Babic96651272010-03-16 17:22:21 +010099 val &= ~PWGT2SPIEN;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200100 pmic_reg_write(p, REG_POWER_MISC, val);
Stefano Babic96651272010-03-16 17:22:21 +0100101
Shawn Guo4546eb72010-10-27 23:36:04 +0800102 /* Externally powered */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200103 pmic_reg_read(p, REG_CHARGE, &val);
Shawn Guo4546eb72010-10-27 23:36:04 +0800104 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200105 pmic_reg_write(p, REG_CHARGE, val);
Stefano Babic96651272010-03-16 17:22:21 +0100106
107 /* power up the system first */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200108 pmic_reg_write(p, REG_POWER_MISC, PWUP);
Stefano Babic96651272010-03-16 17:22:21 +0100109
110 /* Set core voltage to 1.1V */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200111 pmic_reg_read(p, REG_SW_0, &val);
Marek Vasutb043f702011-01-19 04:40:36 +0000112 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200113 pmic_reg_write(p, REG_SW_0, val);
Stefano Babic96651272010-03-16 17:22:21 +0100114
115 /* Setup VCC (SW2) to 1.25 */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200116 pmic_reg_read(p, REG_SW_1, &val);
Marek Vasutb043f702011-01-19 04:40:36 +0000117 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200118 pmic_reg_write(p, REG_SW_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100119
120 /* Setup 1V2_DIG1 (SW3) to 1.25 */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200121 pmic_reg_read(p, REG_SW_2, &val);
Marek Vasutb043f702011-01-19 04:40:36 +0000122 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200123 pmic_reg_write(p, REG_SW_2, val);
Stefano Babic96651272010-03-16 17:22:21 +0100124 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 Babicdba2efc2011-10-08 10:59:20 +0200131 pmic_reg_read(p, REG_SW_4, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100132 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 Babicdba2efc2011-10-08 10:59:20 +0200136 pmic_reg_write(p, REG_SW_4, val);
Stefano Babic96651272010-03-16 17:22:21 +0100137
138 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200139 pmic_reg_read(p, REG_SW_5, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100140 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 Babicdba2efc2011-10-08 10:59:20 +0200144 pmic_reg_write(p, REG_SW_5, val);
Stefano Babic96651272010-03-16 17:22:21 +0100145
146 /* Set VDIG to 1.65V, VGEN3 to 1.8V, VCAM to 2.6V */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200147 pmic_reg_read(p, REG_SETTING_0, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100148 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
149 val |= VDIG_1_65 | VGEN3_1_8 | VCAM_2_6;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200150 pmic_reg_write(p, REG_SETTING_0, val);
Stefano Babic96651272010-03-16 17:22:21 +0100151
152 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200153 pmic_reg_read(p, REG_SETTING_1, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100154 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
155 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200156 pmic_reg_write(p, REG_SETTING_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100157
158 /* Configure VGEN3 and VCAM regulators to use external PNP */
159 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200160 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100161 udelay(200);
162
Stefano Babic96651272010-03-16 17:22:21 +0100163 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
164 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
165 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200166 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100167
Benoît Thébaudeau168dc712013-05-03 10:32:27 +0000168 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_EIM_A20__GPIO2_14,
169 NO_PAD_CTRL));
Fabio Estevam6df20c92021-02-15 08:58:17 -0300170 gpio_request(IMX_GPIO_NR(2, 14), "gpio2_14");
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530171 gpio_direction_output(IMX_GPIO_NR(2, 14), 0);
Fabio Estevamc38e0d62011-10-25 03:14:00 +0000172
Stefano Babic96651272010-03-16 17:22:21 +0100173 udelay(500);
174
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530175 gpio_set_value(IMX_GPIO_NR(2, 14), 1);
Stefano Babic96651272010-03-16 17:22:21 +0100176}
177
Liu Hui-R643431e929df2010-12-23 01:13:17 +0000178int board_early_init_f(void)
179{
180 setup_iomux_uart();
Vikram Narayanan9ddfa242012-11-10 02:28:52 +0000181 setup_iomux_lcd();
Liu Hui-R643431e929df2010-12-23 01:13:17 +0000182
183 return 0;
184}
185
Stefano Babic421834e2010-02-05 15:13:58 +0100186int board_init(void)
187{
Stefano Babic421834e2010-02-05 15:13:58 +0100188 /* address of boot parameters */
189 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
190
Stefano Babic421834e2010-02-05 15:13:58 +0100191 return 0;
192}
193
Helmut Raigerd5a184b2011-10-20 04:19:47 +0000194#ifdef CONFIG_BOARD_LATE_INIT
Stefano Babic96651272010-03-16 17:22:21 +0100195int board_late_init(void)
196{
197#ifdef CONFIG_MXC_SPI
198 setup_iomux_spi();
199 power_init();
200#endif
Fabio Estevam12ba8602012-05-09 06:39:41 +0000201
Stefano Babic96651272010-03-16 17:22:21 +0100202 return 0;
203}
204#endif
205
Fabio Estevam88920582012-08-05 07:31:33 +0000206/*
207 * Do not overwrite the console
208 * Use always serial for U-Boot console
209 */
210int overwrite_console(void)
211{
212 return 1;
213}
214
Stefano Babic421834e2010-02-05 15:13:58 +0100215int checkboard(void)
216{
Jason Liu8b7b69b2011-04-22 02:55:42 +0000217 puts("Board: MX51EVK\n");
Stefano Babic421834e2010-02-05 15:13:58 +0100218
Stefano Babic421834e2010-02-05 15:13:58 +0100219 return 0;
220}