blob: b4d46f11f98d251665c69f77027aa8b57cf4528d [file] [log] [blame]
Adam Fordd42247d2020-12-11 06:01:46 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2020 Compass Electronics Group, LLC
4 */
5
6#include <common.h>
7#include <hang.h>
8#include <image.h>
9#include <init.h>
10#include <log.h>
11#include <asm/io.h>
12#include <errno.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Adam Fordd42247d2020-12-11 06:01:46 -060014#include <asm/io.h>
15#include <asm/arch/ddr.h>
16#include <asm/arch/imx8mn_pins.h>
17#include <asm/mach-imx/boot_mode.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/arch/clock.h>
20#include <asm/mach-imx/iomux-v3.h>
21#include <asm/mach-imx/gpio.h>
22#include <asm/mach-imx/mxc_i2c.h>
Shiji Yangbb112342023-08-03 09:47:16 +080023#include <asm/sections.h>
Adam Fordd42247d2020-12-11 06:01:46 -060024#include <fsl_esdhc_imx.h>
25#include <mmc.h>
26#include <linux/delay.h>
27#include <power/pmic.h>
28#include <power/bd71837.h>
29#include <spl.h>
30
31#include <dm/uclass.h>
32#include <dm/device.h>
33#include <dm/uclass-internal.h>
34#include <dm/device-internal.h>
35
36DECLARE_GLOBAL_DATA_PTR;
37
38int spl_board_boot_device(enum boot_device boot_dev_spl)
39{
40 return BOOT_DEVICE_BOOTROM;
41}
42
43void spl_dram_init(void)
44{
45 ddr_init(&dram_timing);
46}
47
48void spl_board_init(void)
49{
50 struct udevice *dev;
51 int ret;
52
53 debug("Normal Boot\n");
54
55 ret = uclass_get_device_by_name(UCLASS_CLK,
56 "clock-controller@30380000",
57 &dev);
58 if (ret < 0)
59 puts("Failed to find clock node. Check device tree\n");
60}
61
62#ifdef CONFIG_SPL_LOAD_FIT
63int board_fit_config_name_match(const char *name)
64{
65 /* Just empty function now - can't decide what to choose */
66 debug("%s: %s\n", __func__, name);
67
68 return 0;
69}
70#endif
71
Adam Fordd42247d2020-12-11 06:01:46 -060072#define PWM1_PAD_CTRL (PAD_CTL_FSEL2 | PAD_CTL_DSE6)
73
74static iomux_v3_cfg_t const pwm_pads[] = {
75 IMX8MN_PAD_GPIO1_IO01__PWM1_OUT | MUX_PAD_CTRL(PWM1_PAD_CTRL),
76};
77
Adam Ford02448f52022-10-22 08:43:44 -050078static int power_init_board(void)
79{
80 struct udevice *dev;
81 int ret;
82
83 ret = pmic_get("pmic@4b", &dev);
84 if (ret == -ENODEV) {
85 puts("No pmic\n");
86 return 0;
87 }
88
89 if (ret != 0)
90 return ret;
91
92 /* decrease RESET key long push time from the default 10s to 10ms */
93 pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0);
94
95 /* unlock the PMIC regs */
96 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
97
98 /* increase VDD_SOC to typical value 0.85v before first DRAM access */
99 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
100
101 /* increase VDD_DRAM to 0.975v for 3Ghz DDR */
102 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
103
104 /* lock the PMIC regs */
105 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
106
107 return 0;
108}
109
Adam Fordd42247d2020-12-11 06:01:46 -0600110int board_early_init_f(void)
111{
Adam Fordd42247d2020-12-11 06:01:46 -0600112 /* Claiming pwm pins prevents LCD flicker during startup*/
113 imx_iomux_v3_setup_multiple_pads(pwm_pads, ARRAY_SIZE(pwm_pads));
114
Adam Fordd42247d2020-12-11 06:01:46 -0600115 init_uart_clk(1);
116
117 return 0;
118}
119
120void board_init_f(ulong dummy)
121{
122 int ret;
123
124 /* Clear the BSS. */
125 memset(__bss_start, 0, __bss_end - __bss_start);
126
127 arch_cpu_init();
128
129 board_early_init_f();
130
131 timer_init();
132
Adam Fordd42247d2020-12-11 06:01:46 -0600133 ret = spl_init();
134 if (ret) {
135 debug("spl_init() failed: %d\n", ret);
136 hang();
137 }
138
Peng Fana9ed59c2022-06-11 20:20:55 +0800139 preloader_console_init();
140
Adam Fordf026e132022-01-24 09:24:17 -0600141 enable_tzc380();
142
Adam Ford02448f52022-10-22 08:43:44 -0500143 /* LPDDR4 at 1.6GHz requires a voltage adjustment on the PMIC */
144 power_init_board();
145
Adam Fordd42247d2020-12-11 06:01:46 -0600146 /* DDR initialization */
147 spl_dram_init();
148
149 board_init_r(NULL, 0);
150}