Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / board / beacon / imx8mm / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2
3 #include <common.h>
4 #include <cpu_func.h>
5 #include <hang.h>
6 #include <init.h>
7 #include <log.h>
8 #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
22 #include <power/pmic.h>
23 #include <power/bd71837.h>
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 int 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
41 static void spl_dram_init(void)
42 {
43         ddr_init(&dram_timing);
44 }
45
46 void spl_board_init(void)
47 {
48         debug("Normal Boot\n");
49 }
50
51 #ifdef CONFIG_SPL_LOAD_FIT
52 int 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
64 static 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
69 static iomux_v3_cfg_t const wdog_pads[] = {
70         IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B  | MUX_PAD_CTRL(WDOG_PAD_CTRL),
71 };
72
73 int 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
86 static int 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         /* lock the PMIC regs */
112         pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
113
114         return 0;
115 }
116
117 void board_init_f(ulong dummy)
118 {
119         struct udevice *dev;
120         int ret;
121
122         arch_cpu_init();
123
124         init_uart_clk(1);
125
126         board_early_init_f();
127
128         timer_init();
129
130         preloader_console_init();
131
132         /* Clear the BSS. */
133         memset(__bss_start, 0, __bss_end - __bss_start);
134
135         ret = spl_early_init();
136         if (ret) {
137                 debug("spl_early_init() failed: %d\n", ret);
138                 hang();
139         }
140
141         ret = uclass_get_device_by_name(UCLASS_CLK,
142                                         "clock-controller@30380000",
143                                         &dev);
144         if (ret < 0) {
145                 printf("Failed to find clock node. Check device tree\n");
146                 hang();
147         }
148
149         enable_tzc380();
150
151         power_init_board();
152
153         /* DDR initialization */
154         spl_dram_init();
155
156         board_init_r(NULL, 0);
157 }