blob: 4563446db196884ee19577dc142db4af0a5fcdad [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>
23#include <fsl_esdhc_imx.h>
24#include <mmc.h>
25#include <linux/delay.h>
26#include <power/pmic.h>
27#include <power/bd71837.h>
28#include <spl.h>
29
30#include <dm/uclass.h>
31#include <dm/device.h>
32#include <dm/uclass-internal.h>
33#include <dm/device-internal.h>
34
35DECLARE_GLOBAL_DATA_PTR;
36
37int spl_board_boot_device(enum boot_device boot_dev_spl)
38{
39 return BOOT_DEVICE_BOOTROM;
40}
41
42void spl_dram_init(void)
43{
44 ddr_init(&dram_timing);
45}
46
47void spl_board_init(void)
48{
49 struct udevice *dev;
50 int ret;
51
52 debug("Normal Boot\n");
53
54 ret = uclass_get_device_by_name(UCLASS_CLK,
55 "clock-controller@30380000",
56 &dev);
57 if (ret < 0)
58 puts("Failed to find clock node. Check device tree\n");
59}
60
61#ifdef CONFIG_SPL_LOAD_FIT
62int board_fit_config_name_match(const char *name)
63{
64 /* Just empty function now - can't decide what to choose */
65 debug("%s: %s\n", __func__, name);
66
67 return 0;
68}
69#endif
70
Adam Fordd42247d2020-12-11 06:01:46 -060071#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
72#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 Fordd42247d2020-12-11 06:01:46 -060078static iomux_v3_cfg_t const wdog_pads[] = {
79 IMX8MN_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
80};
81
82int board_early_init_f(void)
83{
84 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
85
86 /* Claiming pwm pins prevents LCD flicker during startup*/
87 imx_iomux_v3_setup_multiple_pads(pwm_pads, ARRAY_SIZE(pwm_pads));
88
89 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
90 set_wdog_reset(wdog);
91
Adam Fordd42247d2020-12-11 06:01:46 -060092 init_uart_clk(1);
93
94 return 0;
95}
96
97void board_init_f(ulong dummy)
98{
99 int ret;
100
101 /* Clear the BSS. */
102 memset(__bss_start, 0, __bss_end - __bss_start);
103
104 arch_cpu_init();
105
106 board_early_init_f();
107
108 timer_init();
109
Adam Fordd42247d2020-12-11 06:01:46 -0600110 ret = spl_init();
111 if (ret) {
112 debug("spl_init() failed: %d\n", ret);
113 hang();
114 }
115
Peng Fana9ed59c2022-06-11 20:20:55 +0800116 preloader_console_init();
117
Adam Fordf026e132022-01-24 09:24:17 -0600118 enable_tzc380();
119
Adam Fordd42247d2020-12-11 06:01:46 -0600120 /* DDR initialization */
121 spl_dram_init();
122
123 board_init_r(NULL, 0);
124}