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