blob: c8439a6347aef08fd09e5c548c1f32e3bfd4c313 [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 */
Albert ARIBAUDa9606732011-07-03 05:55:33 +000033 gd->ram_size = get_ram_size((void *)CONFIG_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
Benoît Thébaudeau7477d112012-09-18 04:48:42 +000038u32 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ébaudeau168dc712013-05-03 10:32:27 +000046#define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_DSE_HIGH)
47
Stefano Babic421834e2010-02-05 15:13:58 +010048static void setup_iomux_uart(void)
49{
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000050 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 Babic421834e2010-02-05 15:13:58 +010056
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000057 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
Stefano Babic421834e2010-02-05 15:13:58 +010058}
59
Stefano Babic96651272010-03-16 17:22:21 +010060#ifdef CONFIG_MXC_SPI
61static void setup_iomux_spi(void)
62{
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000063 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 Babic96651272010-03-16 17:22:21 +010075
Benoît Thébaudeau168dc712013-05-03 10:32:27 +000076 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babic96651272010-03-16 17:22:21 +010077}
78#endif
79
80static void power_init(void)
81{
82 unsigned int val;
Stefano Babic96651272010-03-16 17:22:21 +010083 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babicdba2efc2011-10-08 10:59:20 +020084 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000085 int ret;
86
Fabio Estevam21cb23f2013-11-20 20:26:03 -020087 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000088 if (ret)
89 return;
Stefano Babicdba2efc2011-10-08 10:59:20 +020090
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000091 p = pmic_get("FSL_PMIC");
92 if (!p)
93 return;
Stefano Babic96651272010-03-16 17:22:21 +010094
95 /* Write needed to Power Gate 2 register */
Stefano Babicdba2efc2011-10-08 10:59:20 +020096 pmic_reg_read(p, REG_POWER_MISC, &val);
Stefano Babic96651272010-03-16 17:22:21 +010097 val &= ~PWGT2SPIEN;
Stefano Babicdba2efc2011-10-08 10:59:20 +020098 pmic_reg_write(p, REG_POWER_MISC, val);
Stefano Babic96651272010-03-16 17:22:21 +010099
Shawn Guo4546eb72010-10-27 23:36:04 +0800100 /* Externally powered */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200101 pmic_reg_read(p, REG_CHARGE, &val);
Shawn Guo4546eb72010-10-27 23:36:04 +0800102 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200103 pmic_reg_write(p, REG_CHARGE, val);
Stefano Babic96651272010-03-16 17:22:21 +0100104
105 /* power up the system first */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200106 pmic_reg_write(p, REG_POWER_MISC, PWUP);
Stefano Babic96651272010-03-16 17:22:21 +0100107
108 /* Set core voltage to 1.1V */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200109 pmic_reg_read(p, REG_SW_0, &val);
Marek Vasutb043f702011-01-19 04:40:36 +0000110 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200111 pmic_reg_write(p, REG_SW_0, val);
Stefano Babic96651272010-03-16 17:22:21 +0100112
113 /* Setup VCC (SW2) to 1.25 */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200114 pmic_reg_read(p, REG_SW_1, &val);
Marek Vasutb043f702011-01-19 04:40:36 +0000115 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200116 pmic_reg_write(p, REG_SW_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100117
118 /* Setup 1V2_DIG1 (SW3) to 1.25 */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200119 pmic_reg_read(p, REG_SW_2, &val);
Marek Vasutb043f702011-01-19 04:40:36 +0000120 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200121 pmic_reg_write(p, REG_SW_2, val);
Stefano Babic96651272010-03-16 17:22:21 +0100122 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 Babicdba2efc2011-10-08 10:59:20 +0200129 pmic_reg_read(p, REG_SW_4, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100130 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 Babicdba2efc2011-10-08 10:59:20 +0200134 pmic_reg_write(p, REG_SW_4, val);
Stefano Babic96651272010-03-16 17:22:21 +0100135
136 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200137 pmic_reg_read(p, REG_SW_5, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100138 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 Babicdba2efc2011-10-08 10:59:20 +0200142 pmic_reg_write(p, REG_SW_5, val);
Stefano Babic96651272010-03-16 17:22:21 +0100143
144 /* Set VDIG to 1.65V, VGEN3 to 1.8V, VCAM to 2.6V */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200145 pmic_reg_read(p, REG_SETTING_0, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100146 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
147 val |= VDIG_1_65 | VGEN3_1_8 | VCAM_2_6;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200148 pmic_reg_write(p, REG_SETTING_0, val);
Stefano Babic96651272010-03-16 17:22:21 +0100149
150 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
Stefano Babicdba2efc2011-10-08 10:59:20 +0200151 pmic_reg_read(p, REG_SETTING_1, &val);
Stefano Babic96651272010-03-16 17:22:21 +0100152 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
153 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200154 pmic_reg_write(p, REG_SETTING_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100155
156 /* Configure VGEN3 and VCAM regulators to use external PNP */
157 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200158 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100159 udelay(200);
160
Stefano Babic96651272010-03-16 17:22:21 +0100161 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
162 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
163 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babicdba2efc2011-10-08 10:59:20 +0200164 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babic96651272010-03-16 17:22:21 +0100165
Benoît Thébaudeau168dc712013-05-03 10:32:27 +0000166 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_EIM_A20__GPIO2_14,
167 NO_PAD_CTRL));
Fabio Estevam6df20c92021-02-15 08:58:17 -0300168 gpio_request(IMX_GPIO_NR(2, 14), "gpio2_14");
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530169 gpio_direction_output(IMX_GPIO_NR(2, 14), 0);
Fabio Estevamc38e0d62011-10-25 03:14:00 +0000170
Stefano Babic96651272010-03-16 17:22:21 +0100171 udelay(500);
172
Ashok Kumar Reddy7d04bd72012-08-28 07:39:38 +0530173 gpio_set_value(IMX_GPIO_NR(2, 14), 1);
Stefano Babic96651272010-03-16 17:22:21 +0100174}
175
Liu Hui-R643431e929df2010-12-23 01:13:17 +0000176int board_early_init_f(void)
177{
178 setup_iomux_uart();
Vikram Narayanan9ddfa242012-11-10 02:28:52 +0000179 setup_iomux_lcd();
Liu Hui-R643431e929df2010-12-23 01:13:17 +0000180
181 return 0;
182}
183
Stefano Babic421834e2010-02-05 15:13:58 +0100184int board_init(void)
185{
Stefano Babic421834e2010-02-05 15:13:58 +0100186 /* address of boot parameters */
187 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
188
Stefano Babic421834e2010-02-05 15:13:58 +0100189 return 0;
190}
191
Helmut Raigerd5a184b2011-10-20 04:19:47 +0000192#ifdef CONFIG_BOARD_LATE_INIT
Stefano Babic96651272010-03-16 17:22:21 +0100193int board_late_init(void)
194{
195#ifdef CONFIG_MXC_SPI
196 setup_iomux_spi();
197 power_init();
198#endif
Fabio Estevam12ba8602012-05-09 06:39:41 +0000199
Stefano Babic96651272010-03-16 17:22:21 +0100200 return 0;
201}
202#endif
203
Fabio Estevam88920582012-08-05 07:31:33 +0000204/*
205 * Do not overwrite the console
206 * Use always serial for U-Boot console
207 */
208int overwrite_console(void)
209{
210 return 1;
211}
212
Stefano Babic421834e2010-02-05 15:13:58 +0100213int checkboard(void)
214{
Jason Liu8b7b69b2011-04-22 02:55:42 +0000215 puts("Board: MX51EVK\n");
Stefano Babic421834e2010-02-05 15:13:58 +0100216
Stefano Babic421834e2010-02-05 15:13:58 +0100217 return 0;
218}