blob: 4d34622465b39f2ad37f502348e9577a7a920477 [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>
Simon Glassdb41d652019-12-28 10:45:07 -07008#include <hang.h>
Peng Fan9b15ce92019-08-27 06:26:08 +00009#include <spl.h>
10#include <asm/io.h>
11#include <asm/mach-imx/iomux-v3.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/imx8mm_pins.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/mach-imx/boot_mode.h>
16#include <asm/arch/ddr.h>
17
18#include <dm/uclass.h>
19#include <dm/device.h>
20#include <dm/uclass-internal.h>
21#include <dm/device-internal.h>
22
Peng Fan8c61eba2019-10-16 10:24:42 +000023#include <power/pmic.h>
24#include <power/bd71837.h>
25
Peng Fan9b15ce92019-08-27 06:26:08 +000026DECLARE_GLOBAL_DATA_PTR;
27
28int spl_board_boot_device(enum boot_device boot_dev_spl)
29{
30 switch (boot_dev_spl) {
31 case SD2_BOOT:
32 case MMC2_BOOT:
33 return BOOT_DEVICE_MMC1;
34 case SD3_BOOT:
35 case MMC3_BOOT:
36 return BOOT_DEVICE_MMC2;
37 default:
38 return BOOT_DEVICE_NONE;
39 }
40}
41
Alifer Moraes62cdfdc2020-01-14 15:55:00 -030042static void spl_dram_init(void)
Peng Fan9b15ce92019-08-27 06:26:08 +000043{
44 ddr_init(&dram_timing);
45}
46
47void spl_board_init(void)
48{
Peng Fan9b15ce92019-08-27 06:26:08 +000049 puts("Normal Boot\n");
Peng Fan9b15ce92019-08-27 06:26:08 +000050}
51
52#ifdef CONFIG_SPL_LOAD_FIT
53int board_fit_config_name_match(const char *name)
54{
55 /* Just empty function now - can't decide what to choose */
56 debug("%s: %s\n", __func__, name);
57
58 return 0;
59}
60#endif
61
62#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
63#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
64
65static iomux_v3_cfg_t const uart_pads[] = {
66 IMX8MM_PAD_UART2_RXD_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
67 IMX8MM_PAD_UART2_TXD_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
68};
69
70static iomux_v3_cfg_t const wdog_pads[] = {
71 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
72};
73
74int board_early_init_f(void)
75{
76 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
77
78 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
79
80 set_wdog_reset(wdog);
81
82 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
83
84 return 0;
85}
86
Alifer Moraes62cdfdc2020-01-14 15:55:00 -030087static int power_init_board(void)
Peng Fan8c61eba2019-10-16 10:24:42 +000088{
89 struct udevice *dev;
90 int ret;
91
92 ret = pmic_get("pmic@4b", &dev);
93 if (ret == -ENODEV) {
94 puts("No pmic\n");
95 return 0;
96 }
97 if (ret != 0)
98 return ret;
99
100 /* decrease RESET key long push time from the default 10s to 10ms */
101 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
102
103 /* unlock the PMIC regs */
104 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
105
106 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
107 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
108
109 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
110 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
111
112#ifndef CONFIG_IMX8M_LPDDR4
113 /* increase NVCC_DRAM_1V2 to 1.2v for DDR4 */
114 pmic_reg_write(dev, BD718XX_4TH_NODVS_BUCK_VOLT, 0x28);
115#endif
116
117 /* lock the PMIC regs */
118 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
119
120 return 0;
121}
122
Peng Fan9b15ce92019-08-27 06:26:08 +0000123void board_init_f(ulong dummy)
124{
Peng Fan1a997102019-10-16 10:24:39 +0000125 struct udevice *dev;
Peng Fan9b15ce92019-08-27 06:26:08 +0000126 int ret;
127
128 arch_cpu_init();
129
130 init_uart_clk(1);
131
132 board_early_init_f();
133
134 timer_init();
135
136 preloader_console_init();
137
138 /* Clear the BSS. */
139 memset(__bss_start, 0, __bss_end - __bss_start);
140
Peng Fan1a997102019-10-16 10:24:39 +0000141 ret = spl_early_init();
Peng Fan9b15ce92019-08-27 06:26:08 +0000142 if (ret) {
Peng Fan1a997102019-10-16 10:24:39 +0000143 debug("spl_early_init() failed: %d\n", ret);
144 hang();
145 }
146
147 ret = uclass_get_device_by_name(UCLASS_CLK,
148 "clock-controller@30380000",
149 &dev);
150 if (ret < 0) {
151 printf("Failed to find clock node. Check device tree\n");
Peng Fan9b15ce92019-08-27 06:26:08 +0000152 hang();
153 }
154
155 enable_tzc380();
156
Peng Fan8c61eba2019-10-16 10:24:42 +0000157 power_init_board();
158
Peng Fan9b15ce92019-08-27 06:26:08 +0000159 /* DDR initialization */
160 spl_dram_init();
161
162 board_init_r(NULL, 0);
163}