blob: e84e470ac2ad6092b8346a6e304ad4208c8c367a [file] [log] [blame]
Peng Fanc47e09d2019-12-30 17:46:21 +08001/*
2 * Copyright 2018-2019 NXP
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07008#include <cpu_func.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080012#include <spl.h>
13#include <asm/io.h>
14#include <errno.h>
15#include <asm/io.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm/arch/imx8mp_pins.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/mach-imx/boot_mode.h>
20#include <power/pmic.h>
21
22#include <power/pca9450.h>
23#include <asm/arch/clock.h>
24#include <asm/mach-imx/gpio.h>
25#include <asm/mach-imx/mxc_i2c.h>
26#include <fsl_esdhc.h>
27#include <mmc.h>
28#include <asm/arch/ddr.h>
29
30#include <dm/uclass.h>
31#include <dm/device.h>
32#include <dm/uclass-internal.h>
33#include <dm/device-internal.h>
34
35DECLARE_GLOBAL_DATA_PTR;
36
37int spl_board_boot_device(enum boot_device boot_dev_spl)
38{
39 return BOOT_DEVICE_BOOTROM;
40}
41
42void spl_dram_init(void)
43{
44 ddr_init(&dram_timing);
45}
46
47void spl_board_init(void)
48{
49 struct udevice *dev;
50 int ret;
51
52 puts("Normal Boot\n");
53
54 ret = uclass_get_device_by_name(UCLASS_CLK,
55 "clock-controller@30380000",
56 &dev);
57 if (ret < 0)
58 printf("Failed to find clock node. Check device tree\n");
59}
60
61#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE)
62#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
63struct i2c_pads_info i2c_pad_info1 = {
64 .scl = {
65 .i2c_mode = MX8MP_PAD_I2C1_SCL__I2C1_SCL | PC,
66 .gpio_mode = MX8MP_PAD_I2C1_SCL__GPIO5_IO14 | PC,
67 .gp = IMX_GPIO_NR(5, 14),
68 },
69 .sda = {
70 .i2c_mode = MX8MP_PAD_I2C1_SDA__I2C1_SDA | PC,
71 .gpio_mode = MX8MP_PAD_I2C1_SDA__GPIO5_IO15 | PC,
72 .gp = IMX_GPIO_NR(5, 15),
73 },
74};
75
76#ifdef CONFIG_POWER
77#define I2C_PMIC 0
78int power_init_board(void)
79{
80 struct pmic *p;
81 int ret;
82
83 ret = power_pca9450b_init(I2C_PMIC);
84 if (ret)
85 printf("power init failed");
86 p = pmic_get("PCA9450");
87 pmic_probe(p);
88
89 /* BUCKxOUT_DVS0/1 control BUCK123 output */
90 pmic_reg_write(p, PCA9450_BUCK123_DVS, 0x29);
91
92 /*
93 * increase VDD_SOC to typical value 0.95V before first
94 * DRAM access, set DVS1 to 0.85v for suspend.
95 * Enable DVS control through PMIC_STBY_REQ and
96 * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H)
97 */
98 pmic_reg_write(p, PCA9450_BUCK1OUT_DVS0, 0x1C);
99 pmic_reg_write(p, PCA9450_BUCK1OUT_DVS1, 0x14);
100 pmic_reg_write(p, PCA9450_BUCK1CTRL, 0x59);
101
102 /* set WDOG_B_CFG to cold reset */
103 pmic_reg_write(p, PCA9450_RESET_CTRL, 0xA1);
104
105 return 0;
106}
107#endif
108
109#ifdef CONFIG_SPL_LOAD_FIT
110int board_fit_config_name_match(const char *name)
111{
112 /* Just empty function now - can't decide what to choose */
113 debug("%s: %s\n", __func__, name);
114
115 return 0;
116}
117#endif
118
119void board_init_f(ulong dummy)
120{
121 int ret;
122
123 arch_cpu_init();
124
125 init_uart_clk(1);
126
127 board_early_init_f();
128
129 timer_init();
130
131 preloader_console_init();
132
133 /* Clear the BSS. */
134 memset(__bss_start, 0, __bss_end - __bss_start);
135
136 ret = spl_init();
137 if (ret) {
138 debug("spl_init() failed: %d\n", ret);
139 hang();
140 }
141
142 enable_tzc380();
143
Peng Fanc47e09d2019-12-30 17:46:21 +0800144 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
145
146 power_init_board();
147
148 /* DDR initialization */
149 spl_dram_init();
150
151 board_init_r(NULL, 0);
152}