blob: d125dc9317ef08dfb92d84e47e5305921dbab4d7 [file] [log] [blame]
Peng Fan9b15ce92019-08-27 06:26:08 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 */
5
6#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -07007#include <cpu_func.h>
Peng Fan9b15ce92019-08-27 06:26:08 +00008#include <spl.h>
9#include <asm/io.h>
10#include <asm/mach-imx/iomux-v3.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/imx8mm_pins.h>
13#include <asm/arch/sys_proto.h>
14#include <asm/mach-imx/boot_mode.h>
15#include <asm/arch/ddr.h>
16
17#include <dm/uclass.h>
18#include <dm/device.h>
19#include <dm/uclass-internal.h>
20#include <dm/device-internal.h>
21
Peng Fan8c61eba2019-10-16 10:24:42 +000022#include <power/pmic.h>
23#include <power/bd71837.h>
24
Peng Fan9b15ce92019-08-27 06:26:08 +000025DECLARE_GLOBAL_DATA_PTR;
26
27int spl_board_boot_device(enum boot_device boot_dev_spl)
28{
29 switch (boot_dev_spl) {
30 case SD2_BOOT:
31 case MMC2_BOOT:
32 return BOOT_DEVICE_MMC1;
33 case SD3_BOOT:
34 case MMC3_BOOT:
35 return BOOT_DEVICE_MMC2;
36 default:
37 return BOOT_DEVICE_NONE;
38 }
39}
40
41void spl_dram_init(void)
42{
43 ddr_init(&dram_timing);
44}
45
46void spl_board_init(void)
47{
Peng Fan9b15ce92019-08-27 06:26:08 +000048 puts("Normal Boot\n");
Peng Fan9b15ce92019-08-27 06:26:08 +000049}
50
51#ifdef CONFIG_SPL_LOAD_FIT
52int board_fit_config_name_match(const char *name)
53{
54 /* Just empty function now - can't decide what to choose */
55 debug("%s: %s\n", __func__, name);
56
57 return 0;
58}
59#endif
60
61#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
62#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
63
64static iomux_v3_cfg_t const uart_pads[] = {
65 IMX8MM_PAD_UART2_RXD_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
66 IMX8MM_PAD_UART2_TXD_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
67};
68
69static iomux_v3_cfg_t const wdog_pads[] = {
70 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
71};
72
73int board_early_init_f(void)
74{
75 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
76
77 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
78
79 set_wdog_reset(wdog);
80
81 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
82
83 return 0;
84}
85
Peng Fan8c61eba2019-10-16 10:24:42 +000086int power_init_board(void)
87{
88 struct udevice *dev;
89 int ret;
90
91 ret = pmic_get("pmic@4b", &dev);
92 if (ret == -ENODEV) {
93 puts("No pmic\n");
94 return 0;
95 }
96 if (ret != 0)
97 return ret;
98
99 /* decrease RESET key long push time from the default 10s to 10ms */
100 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
101
102 /* unlock the PMIC regs */
103 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
104
105 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
106 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
107
108 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
109 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
110
111#ifndef CONFIG_IMX8M_LPDDR4
112 /* increase NVCC_DRAM_1V2 to 1.2v for DDR4 */
113 pmic_reg_write(dev, BD718XX_4TH_NODVS_BUCK_VOLT, 0x28);
114#endif
115
116 /* lock the PMIC regs */
117 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
118
119 return 0;
120}
121
Peng Fan9b15ce92019-08-27 06:26:08 +0000122void board_init_f(ulong dummy)
123{
Peng Fan1a997102019-10-16 10:24:39 +0000124 struct udevice *dev;
Peng Fan9b15ce92019-08-27 06:26:08 +0000125 int ret;
126
127 arch_cpu_init();
128
129 init_uart_clk(1);
130
131 board_early_init_f();
132
133 timer_init();
134
135 preloader_console_init();
136
137 /* Clear the BSS. */
138 memset(__bss_start, 0, __bss_end - __bss_start);
139
Peng Fan1a997102019-10-16 10:24:39 +0000140 ret = spl_early_init();
Peng Fan9b15ce92019-08-27 06:26:08 +0000141 if (ret) {
Peng Fan1a997102019-10-16 10:24:39 +0000142 debug("spl_early_init() failed: %d\n", ret);
143 hang();
144 }
145
146 ret = uclass_get_device_by_name(UCLASS_CLK,
147 "clock-controller@30380000",
148 &dev);
149 if (ret < 0) {
150 printf("Failed to find clock node. Check device tree\n");
Peng Fan9b15ce92019-08-27 06:26:08 +0000151 hang();
152 }
153
154 enable_tzc380();
155
Peng Fan8c61eba2019-10-16 10:24:42 +0000156 power_init_board();
157
Peng Fan9b15ce92019-08-27 06:26:08 +0000158 /* DDR initialization */
159 spl_dram_init();
160
161 board_init_r(NULL, 0);
162}
163
164int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
165{
166 puts ("resetting ...\n");
167
168 reset_cpu(WDOG1_BASE_ADDR);
169
170 return 0;
171}