blob: d418cd8f4c0dbb19a4d4130adc37baad7f66ce49 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jason Liuf5b81c82011-05-13 01:58:55 +00002/*
3 * Copyright (C) 2011 Freescale Semiconductor, Inc.
4 * Jason Liu <r64343@freescale.com>
Jason Liuf5b81c82011-05-13 01:58:55 +00005 */
6
7#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Jason Liuf5b81c82011-05-13 01:58:55 +000011#include <asm/io.h>
12#include <asm/arch/imx-regs.h>
Jason Liuf5b81c82011-05-13 01:58:55 +000013#include <asm/arch/sys_proto.h>
14#include <asm/arch/crm_regs.h>
Stefano Babic59dffd62012-02-22 00:24:41 +000015#include <asm/arch/clock.h>
Benoît Thébaudeaub66011e2013-05-03 10:32:34 +000016#include <asm/arch/iomux-mx53.h>
Jason Liuf5b81c82011-05-13 01:58:55 +000017#include <asm/arch/clock.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060018#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090019#include <linux/errno.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020020#include <asm/mach-imx/mx5_video.h>
Jason Liuf5b81c82011-05-13 01:58:55 +000021#include <i2c.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030022#include <input.h>
Yangbo Lu73340382019-06-21 11:42:28 +080023#include <fsl_esdhc_imx.h>
Stefano Babic831096b2011-08-21 10:59:33 +020024#include <asm/gpio.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000025#include <power/pmic.h>
Fabio Estevam2fc58322012-04-30 08:12:04 +000026#include <dialog_pmic.h>
Fabio Estevam082a1122012-05-07 10:25:59 +000027#include <fsl_pmic.h>
Fabio Estevam20c49da2012-05-10 15:07:35 +000028#include <linux/fb.h>
29#include <ipu_pixfmt.h>
Fabio Estevam219ae642023-02-15 11:41:51 -030030#include <dm/uclass.h>
31#include <dm/device.h>
Fabio Estevam20c49da2012-05-10 15:07:35 +000032
Fabio Estevam642af862012-08-21 10:01:56 +000033#define MX53LOCO_LCD_POWER IMX_GPIO_NR(3, 24)
Jason Liuf5b81c82011-05-13 01:58:55 +000034
35DECLARE_GLOBAL_DATA_PTR;
36
Tom Rini4cc38852021-08-30 09:16:30 -040037#ifdef CONFIG_REVISION_TAG
Fabio Estevam8b3533c2012-05-08 03:40:49 +000038u32 get_board_rev(void)
39{
40 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
41 struct fuse_bank *bank = &iim->bank[0];
42 struct fuse_bank0_regs *fuse =
43 (struct fuse_bank0_regs *)bank->fuse_regs;
Fabio Estevam219ae642023-02-15 11:41:51 -030044 struct udevice *bus;
45 struct udevice *dev;
Fabio Estevam8b3533c2012-05-08 03:40:49 +000046
47 int rev = readl(&fuse->gp[6]);
48
Fabio Estevam219ae642023-02-15 11:41:51 -030049 ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
50 if (ret)
51 return ret;
52
53 if (!dm_i2c_probe(bus, CFG_SYS_DIALOG_PMIC_I2C_ADDR, 0, &dev))
Fabio Estevam99f896e2012-05-29 05:54:39 +000054 rev = 0;
55
Fabio Estevam8b3533c2012-05-08 03:40:49 +000056 return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
57}
Tom Rini4cc38852021-08-30 09:16:30 -040058#endif
Fabio Estevam8b3533c2012-05-08 03:40:49 +000059
Benoît Thébaudeaub66011e2013-05-03 10:32:34 +000060#define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_DSE_HIGH | \
61 PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
62
Jason Liuf5b81c82011-05-13 01:58:55 +000063static void setup_iomux_uart(void)
64{
Benoît Thébaudeaub66011e2013-05-03 10:32:34 +000065 static const iomux_v3_cfg_t uart_pads[] = {
66 NEW_PAD_CTRL(MX53_PAD_CSI0_DAT11__UART1_RXD_MUX, UART_PAD_CTRL),
67 NEW_PAD_CTRL(MX53_PAD_CSI0_DAT10__UART1_TXD_MUX, UART_PAD_CTRL),
68 };
Jason Liuf5b81c82011-05-13 01:58:55 +000069
Benoît Thébaudeaub66011e2013-05-03 10:32:34 +000070 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
Jason Liuf5b81c82011-05-13 01:58:55 +000071}
72
Fabio Estevam2fc58322012-04-30 08:12:04 +000073static int power_init(void)
74{
Fabio Estevam082a1122012-05-07 10:25:59 +000075 unsigned int val;
Fabio Estevamfbbdadf2012-12-28 04:05:29 +000076 int ret;
Fabio Estevam2fc58322012-04-30 08:12:04 +000077 struct pmic *p;
Fabio Estevam219ae642023-02-15 11:41:51 -030078 struct udevice *bus;
79 struct udevice *dev;
Fabio Estevam2fc58322012-04-30 08:12:04 +000080
Fabio Estevam219ae642023-02-15 11:41:51 -030081 ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
82 if (ret)
83 return ret;
84
85 if (!dm_i2c_probe(bus, CFG_SYS_DIALOG_PMIC_I2C_ADDR, 0, &dev)) {
Fabio Estevamdf5b4c32012-12-28 04:05:28 +000086 ret = pmic_dialog_init(I2C_PMIC);
87 if (ret)
88 return ret;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000089
90 p = pmic_get("DIALOG_PMIC");
91 if (!p)
92 return -ENODEV;
Fabio Estevam2fc58322012-04-30 08:12:04 +000093
Simon Glass6a38e412017-08-03 12:22:09 -060094 env_set("fdt_file", "imx53-qsb.dtb");
Fabio Estevama68b1512014-11-10 17:38:19 -020095
Fabio Estevam082a1122012-05-07 10:25:59 +000096 /* Set VDDA to 1.25V */
97 val = DA9052_BUCKCORE_BCOREEN | DA_BUCKCORE_VBCORE_1_250V;
98 ret = pmic_reg_write(p, DA9053_BUCKCORE_REG, val);
Fabio Estevamfbbdadf2012-12-28 04:05:29 +000099 if (ret) {
100 printf("Writing to BUCKCORE_REG failed: %d\n", ret);
101 return ret;
102 }
Fabio Estevam2fc58322012-04-30 08:12:04 +0000103
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000104 pmic_reg_read(p, DA9053_SUPPLY_REG, &val);
Fabio Estevam082a1122012-05-07 10:25:59 +0000105 val |= DA9052_SUPPLY_VBCOREGO;
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000106 ret = pmic_reg_write(p, DA9053_SUPPLY_REG, val);
107 if (ret) {
108 printf("Writing to SUPPLY_REG failed: %d\n", ret);
109 return ret;
110 }
Fabio Estevam2fc58322012-04-30 08:12:04 +0000111
Fabio Estevam082a1122012-05-07 10:25:59 +0000112 /* Set Vcc peripheral to 1.30V */
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000113 ret = pmic_reg_write(p, DA9053_BUCKPRO_REG, 0x62);
114 if (ret) {
115 printf("Writing to BUCKPRO_REG failed: %d\n", ret);
116 return ret;
117 }
118
119 ret = pmic_reg_write(p, DA9053_SUPPLY_REG, 0x62);
120 if (ret) {
121 printf("Writing to SUPPLY_REG failed: %d\n", ret);
122 return ret;
123 }
124
125 return ret;
Fabio Estevam082a1122012-05-07 10:25:59 +0000126 }
127
Fabio Estevam219ae642023-02-15 11:41:51 -0300128 if (!dm_i2c_probe(bus, CFG_SYS_FSL_PMIC_I2C_ADDR, 0, &dev)) {
129 ret = pmic_init(0);
Fabio Estevamdf5b4c32012-12-28 04:05:28 +0000130 if (ret)
131 return ret;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000132
Fabio Estevam39ffa1f2012-12-11 06:36:58 +0000133 p = pmic_get("FSL_PMIC");
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000134 if (!p)
135 return -ENODEV;
Fabio Estevam082a1122012-05-07 10:25:59 +0000136
Simon Glass6a38e412017-08-03 12:22:09 -0600137 env_set("fdt_file", "imx53-qsrb.dtb");
Fabio Estevama68b1512014-11-10 17:38:19 -0200138
Fabio Estevam082a1122012-05-07 10:25:59 +0000139 /* Set VDDGP to 1.25V for 1GHz on SW1 */
140 pmic_reg_read(p, REG_SW_0, &val);
141 val = (val & ~SWx_VOLT_MASK_MC34708) | SWx_1_250V_MC34708;
142 ret = pmic_reg_write(p, REG_SW_0, val);
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000143 if (ret) {
144 printf("Writing to REG_SW_0 failed: %d\n", ret);
145 return ret;
146 }
Fabio Estevam082a1122012-05-07 10:25:59 +0000147
148 /* Set VCC as 1.30V on SW2 */
149 pmic_reg_read(p, REG_SW_1, &val);
150 val = (val & ~SWx_VOLT_MASK_MC34708) | SWx_1_300V_MC34708;
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000151 ret = pmic_reg_write(p, REG_SW_1, val);
152 if (ret) {
153 printf("Writing to REG_SW_1 failed: %d\n", ret);
154 return ret;
155 }
Fabio Estevam082a1122012-05-07 10:25:59 +0000156
157 /* Set global reset timer to 4s */
158 pmic_reg_read(p, REG_POWER_CTL2, &val);
159 val = (val & ~TIMER_MASK_MC34708) | TIMER_4S_MC34708;
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000160 ret = pmic_reg_write(p, REG_POWER_CTL2, val);
161 if (ret) {
162 printf("Writing to REG_POWER_CTL2 failed: %d\n", ret);
163 return ret;
164 }
Fabio Estevam0436b7a2012-05-07 10:26:00 +0000165
166 /* Set VUSBSEL and VUSBEN for USB PHY supply*/
167 pmic_reg_read(p, REG_MODE_0, &val);
168 val |= (VUSBSEL_MC34708 | VUSBEN_MC34708);
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000169 ret = pmic_reg_write(p, REG_MODE_0, val);
170 if (ret) {
171 printf("Writing to REG_MODE_0 failed: %d\n", ret);
172 return ret;
173 }
Fabio Estevam0436b7a2012-05-07 10:26:00 +0000174
175 /* Set SWBST to 5V in auto mode */
176 val = SWBST_AUTO;
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000177 ret = pmic_reg_write(p, SWBST_CTRL, val);
178 if (ret) {
179 printf("Writing to SWBST_CTRL failed: %d\n", ret);
180 return ret;
181 }
182
183 return ret;
Fabio Estevam082a1122012-05-07 10:25:59 +0000184 }
Fabio Estevam2fc58322012-04-30 08:12:04 +0000185
Fabio Estevamfbbdadf2012-12-28 04:05:29 +0000186 return -1;
Fabio Estevam2fc58322012-04-30 08:12:04 +0000187}
188
189static void clock_1GHz(void)
190{
191 int ret;
Benoît Thébaudeauafac1652012-09-27 10:19:58 +0000192 u32 ref_clk = MXC_HCLK;
Fabio Estevam2fc58322012-04-30 08:12:04 +0000193 /*
194 * After increasing voltage to 1.25V, we can switch
195 * CPU clock to 1GHz and DDR to 400MHz safely
196 */
197 ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
198 if (ret)
199 printf("CPU: Switch CPU clock to 1GHZ failed\n");
200
201 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
202 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
203 if (ret)
204 printf("CPU: Switch DDR clock to 400MHz failed\n");
205}
206
Jason Liuf5b81c82011-05-13 01:58:55 +0000207int board_early_init_f(void)
208{
209 setup_iomux_uart();
Vikram Narayanan8bb48d62012-11-10 02:32:46 +0000210 setup_iomux_lcd();
Jason Liuf5b81c82011-05-13 01:58:55 +0000211
212 return 0;
213}
214
Stefano Babiccbf6c9c2012-08-05 00:18:53 +0000215/*
216 * Do not overwrite the console
217 * Use always serial for U-Boot console
218 */
219int overwrite_console(void)
Fabio Estevam026c9862012-04-30 08:12:03 +0000220{
Stefano Babiccbf6c9c2012-08-05 00:18:53 +0000221 return 1;
Fabio Estevam026c9862012-04-30 08:12:03 +0000222}
Fabio Estevam026c9862012-04-30 08:12:03 +0000223
Jason Liuf5b81c82011-05-13 01:58:55 +0000224int board_init(void)
225{
Jason Liuf5b81c82011-05-13 01:58:55 +0000226 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
227
Stefano Babic59dffd62012-02-22 00:24:41 +0000228 mxc_set_sata_internal_clock();
Fabio Estevamb665c832012-12-26 05:50:20 +0000229
Fabio Estevamb665c832012-12-26 05:50:20 +0000230 return 0;
231}
232
233int board_late_init(void)
234{
Fabio Estevam99f896e2012-05-29 05:54:39 +0000235 if (!power_init())
236 clock_1GHz();
Stefano Babic59dffd62012-02-22 00:24:41 +0000237
Jason Liuf5b81c82011-05-13 01:58:55 +0000238 return 0;
239}
240
241int checkboard(void)
242{
243 puts("Board: MX53 LOCO\n");
244
245 return 0;
246}