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