blob: 4ef7f6f180600c6ff02b69f555b72289121f6b3c [file] [log] [blame]
Peng Fanf9220172019-08-27 06:26:08 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 */
5
6#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.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>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Peng Fanf9220172019-08-27 06:26:08 +000013#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Peng Fanf9220172019-08-27 06:26:08 +000015#include <asm/io.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/imx8mm_pins.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/mach-imx/boot_mode.h>
21#include <asm/arch/ddr.h>
22
23#include <dm/uclass.h>
24#include <dm/device.h>
25#include <dm/uclass-internal.h>
26#include <dm/device-internal.h>
27
Peng Fana9e04332019-10-16 10:24:42 +000028#include <power/pmic.h>
Ye Li79e69702021-03-19 15:56:55 +080029#include <power/pca9450.h>
Peng Fana9e04332019-10-16 10:24:42 +000030
Peng Fanf9220172019-08-27 06:26:08 +000031DECLARE_GLOBAL_DATA_PTR;
32
33int spl_board_boot_device(enum boot_device boot_dev_spl)
34{
35 switch (boot_dev_spl) {
36 case SD2_BOOT:
37 case MMC2_BOOT:
38 return BOOT_DEVICE_MMC1;
39 case SD3_BOOT:
40 case MMC3_BOOT:
41 return BOOT_DEVICE_MMC2;
42 default:
43 return BOOT_DEVICE_NONE;
44 }
45}
46
Alifer Moraesf0119b62020-01-14 15:55:00 -030047static void spl_dram_init(void)
Peng Fanf9220172019-08-27 06:26:08 +000048{
49 ddr_init(&dram_timing);
50}
51
52void spl_board_init(void)
53{
Peng Fanf9220172019-08-27 06:26:08 +000054 puts("Normal Boot\n");
Peng Fanf9220172019-08-27 06:26:08 +000055}
56
57#ifdef CONFIG_SPL_LOAD_FIT
58int board_fit_config_name_match(const char *name)
59{
60 /* Just empty function now - can't decide what to choose */
61 debug("%s: %s\n", __func__, name);
62
63 return 0;
64}
65#endif
66
67#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
68#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
69
70static iomux_v3_cfg_t const uart_pads[] = {
71 IMX8MM_PAD_UART2_RXD_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
72 IMX8MM_PAD_UART2_TXD_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
73};
74
75static iomux_v3_cfg_t const wdog_pads[] = {
76 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
77};
78
79int board_early_init_f(void)
80{
81 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
82
83 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
84
85 set_wdog_reset(wdog);
86
87 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
88
89 return 0;
90}
91
Alifer Moraesf0119b62020-01-14 15:55:00 -030092static int power_init_board(void)
Peng Fana9e04332019-10-16 10:24:42 +000093{
94 struct udevice *dev;
95 int ret;
96
Ye Li79e69702021-03-19 15:56:55 +080097 ret = pmic_get("pca9450@25", &dev);
Peng Fana9e04332019-10-16 10:24:42 +000098 if (ret == -ENODEV) {
99 puts("No pmic\n");
100 return 0;
101 }
102 if (ret != 0)
103 return ret;
104
Ye Li79e69702021-03-19 15:56:55 +0800105 /* BUCKxOUT_DVS0/1 control BUCK123 output */
106 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Peng Fana9e04332019-10-16 10:24:42 +0000107
Ye Li79e69702021-03-19 15:56:55 +0800108 /* Buck 1 DVS control through PMIC_STBY_REQ */
109 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
Peng Fana9e04332019-10-16 10:24:42 +0000110
Ye Li79e69702021-03-19 15:56:55 +0800111 /* Set DVS1 to 0.8v for suspend */
112 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10);
Peng Fana9e04332019-10-16 10:24:42 +0000113
Ye Li79e69702021-03-19 15:56:55 +0800114 /* increase VDD_DRAM to 0.95v for 3Ghz DDR */
115 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C);
Peng Fana9e04332019-10-16 10:24:42 +0000116
Ye Li79e69702021-03-19 15:56:55 +0800117 /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */
118 pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a);
119
120 /* set VDD_SNVS_0V8 from default 0.85V */
121 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
Peng Fana9e04332019-10-16 10:24:42 +0000122
Ye Li79e69702021-03-19 15:56:55 +0800123 /* set WDOG_B_CFG to cold reset */
124 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
Peng Fana9e04332019-10-16 10:24:42 +0000125
126 return 0;
127}
128
Peng Fanf9220172019-08-27 06:26:08 +0000129void board_init_f(ulong dummy)
130{
Peng Fanb9b76882019-10-16 10:24:39 +0000131 struct udevice *dev;
Peng Fanf9220172019-08-27 06:26:08 +0000132 int ret;
133
134 arch_cpu_init();
135
136 init_uart_clk(1);
137
138 board_early_init_f();
139
140 timer_init();
141
142 preloader_console_init();
143
144 /* Clear the BSS. */
145 memset(__bss_start, 0, __bss_end - __bss_start);
146
Peng Fanb9b76882019-10-16 10:24:39 +0000147 ret = spl_early_init();
Peng Fanf9220172019-08-27 06:26:08 +0000148 if (ret) {
Peng Fanb9b76882019-10-16 10:24:39 +0000149 debug("spl_early_init() failed: %d\n", ret);
150 hang();
151 }
152
153 ret = uclass_get_device_by_name(UCLASS_CLK,
154 "clock-controller@30380000",
155 &dev);
156 if (ret < 0) {
157 printf("Failed to find clock node. Check device tree\n");
Peng Fanf9220172019-08-27 06:26:08 +0000158 hang();
159 }
160
161 enable_tzc380();
162
Peng Fana9e04332019-10-16 10:24:42 +0000163 power_init_board();
164
Peng Fanf9220172019-08-27 06:26:08 +0000165 /* DDR initialization */
166 spl_dram_init();
167
168 board_init_r(NULL, 0);
169}