blob: 36cad14fc413c862dedf010c3db9214364110886 [file] [log] [blame]
Marek Vasut0b16ba52022-04-12 17:26:01 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 Marek Vasut <marex@denx.de>
4 */
5
6#include <common.h>
7#include <hang.h>
8#include <image.h>
9#include <init.h>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm-generic/gpio.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/imx8mm_pins.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/arch/ddr.h>
17#include <asm/mach-imx/boot_mode.h>
18
19#include <dm/uclass.h>
20#include <dm/device.h>
21#include <dm/uclass-internal.h>
22#include <dm/device-internal.h>
23
24#include <power/pmic.h>
25#include <power/bd71837.h>
26
27#include "lpddr4_timing.h"
28
29DECLARE_GLOBAL_DATA_PTR;
30
31#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
32#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
33
34static const iomux_v3_cfg_t uart_pads[] = {
35 IMX8MM_PAD_UART3_RXD_UART3_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
36 IMX8MM_PAD_UART3_TXD_UART3_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
37};
38
39static const iomux_v3_cfg_t wdog_pads[] = {
40 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
41};
42
43static void data_modul_imx8mm_edm_sbc_early_init_f(void)
44{
45 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
46
47 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
48
49 set_wdog_reset(wdog);
50
51 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
52}
53
54static int data_modul_imx8mm_edm_sbc_board_power_init(void)
55{
56 struct udevice *dev;
57 int ret;
58
59 ret = pmic_get("pmic@4b", &dev);
60 if (ret == -ENODEV) {
61 puts("Failed to get PMIC\n");
62 return 0;
63 }
64 if (ret != 0)
65 return ret;
66
67 /* Unlock the PMIC regs */
68 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
69
70 /* Increase VDD_SOC to typical value 0.85V before first DRAM access */
71 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
72
73 /* Increase VDD_DRAM to 0.975V for 3GHz DDR */
74 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
75
76 /* Lock the PMIC regs */
77 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
78
79 return 0;
80}
81
82int spl_board_boot_device(enum boot_device boot_dev_spl)
83{
84 if (boot_dev_spl == MMC3_BOOT)
85 return BOOT_DEVICE_MMC2; /* eMMC */
86 else
87 return BOOT_DEVICE_MMC1; /* SD */
88}
89
90void board_boot_order(u32 *spl_boot_list)
91{
92 int boot_device = spl_boot_device();
93
94 spl_boot_list[0] = boot_device; /* 1:SD 2:eMMC */
95
96 if (boot_device == BOOT_DEVICE_MMC1)
97 spl_boot_list[1] = BOOT_DEVICE_MMC2; /* eMMC */
98 else
99 spl_boot_list[1] = BOOT_DEVICE_MMC1; /* SD */
100
101 spl_boot_list[2] = BOOT_DEVICE_UART; /* YModem */
102 spl_boot_list[3] = BOOT_DEVICE_NONE;
103}
104
105static struct dram_timing_info *dram_timing_info[8] = {
106 &dmo_imx8mm_sbc_dram_timing_32_32, /* 32 Gbit x32 */
107 NULL, /* 32 Gbit x16 */
108 &dmo_imx8mm_sbc_dram_timing_16_32, /* 16 Gbit x32 */
109 NULL, /* 16 Gbit x16 */
110 NULL, /* 8 Gbit x32 */
111 NULL, /* 8 Gbit x16 */
112 NULL, /* INVALID */
113 NULL, /* INVALID */
114};
115
116static void spl_dram_init(void)
117{
118 u8 memcfg = dmo_get_memcfg();
119 int i;
120
121 printf("DDR: %d GiB x%d [0x%x]\n",
122 /* 0..4 GiB, 1..2 GiB, 0..1 GiB */
123 4 >> ((memcfg >> 1) & 0x3),
124 /* 0..x32, 1..x16 */
125 32 >> (memcfg & BIT(0)),
126 memcfg);
127
128 if (!dram_timing_info[memcfg]) {
129 printf("Unsupported DRAM strapping, trying lowest supported. MEMCFG=0x%x\n",
130 memcfg);
131 for (i = ARRAY_SIZE(dram_timing_info) - 1; i >= 0; i--)
132 if (dram_timing_info[i]) /* Configuration found */
133 break;
134 }
135
136 ddr_init(dram_timing_info[memcfg]);
137}
138
139void board_init_f(ulong dummy)
140{
141 struct udevice *dev;
142 int ret;
143
144 icache_enable();
145
146 arch_cpu_init();
147
148 init_uart_clk(2);
149
150 data_modul_imx8mm_edm_sbc_early_init_f();
151
152 preloader_console_init();
153
154 /* Clear the BSS. */
155 memset(__bss_start, 0, __bss_end - __bss_start);
156
157 ret = spl_early_init();
158 if (ret) {
159 debug("spl_early_init() failed: %d\n", ret);
160 hang();
161 }
162
163 ret = uclass_get_device_by_name(UCLASS_CLK,
164 "clock-controller@30380000",
165 &dev);
166 if (ret < 0) {
167 printf("Failed to find clock node. Check device tree\n");
168 hang();
169 }
170
171 enable_tzc380();
172
173 data_modul_imx8mm_edm_sbc_board_power_init();
174
175 /* DDR initialization */
176 spl_dram_init();
177
178 board_init_r(NULL, 0);
179}