blob: f5063eb8c1917f38ab39a41e9f2ea554f31a2afc [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
Marek Vasut0b16ba52022-04-12 17:26:01 +020031#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
32
Marek Vasut0b16ba52022-04-12 17:26:01 +020033static const iomux_v3_cfg_t wdog_pads[] = {
34 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
35};
36
37static void data_modul_imx8mm_edm_sbc_early_init_f(void)
38{
39 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
40
41 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
42
43 set_wdog_reset(wdog);
Marek Vasut0b16ba52022-04-12 17:26:01 +020044}
45
46static int data_modul_imx8mm_edm_sbc_board_power_init(void)
47{
48 struct udevice *dev;
49 int ret;
50
51 ret = pmic_get("pmic@4b", &dev);
52 if (ret == -ENODEV) {
53 puts("Failed to get PMIC\n");
54 return 0;
55 }
56 if (ret != 0)
57 return ret;
58
59 /* Unlock the PMIC regs */
60 pmic_reg_write(dev, BD718XX_REGLOCK, 0x1);
61
62 /* Increase VDD_SOC to typical value 0.85V before first DRAM access */
63 pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
64
65 /* Increase VDD_DRAM to 0.975V for 3GHz DDR */
66 pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
67
68 /* Lock the PMIC regs */
69 pmic_reg_write(dev, BD718XX_REGLOCK, 0x11);
70
71 return 0;
72}
73
74int spl_board_boot_device(enum boot_device boot_dev_spl)
75{
76 if (boot_dev_spl == MMC3_BOOT)
77 return BOOT_DEVICE_MMC2; /* eMMC */
78 else
79 return BOOT_DEVICE_MMC1; /* SD */
80}
81
82void board_boot_order(u32 *spl_boot_list)
83{
84 int boot_device = spl_boot_device();
85
86 spl_boot_list[0] = boot_device; /* 1:SD 2:eMMC */
87
88 if (boot_device == BOOT_DEVICE_MMC1)
89 spl_boot_list[1] = BOOT_DEVICE_MMC2; /* eMMC */
90 else
91 spl_boot_list[1] = BOOT_DEVICE_MMC1; /* SD */
92
93 spl_boot_list[2] = BOOT_DEVICE_UART; /* YModem */
94 spl_boot_list[3] = BOOT_DEVICE_NONE;
95}
96
97static struct dram_timing_info *dram_timing_info[8] = {
98 &dmo_imx8mm_sbc_dram_timing_32_32, /* 32 Gbit x32 */
99 NULL, /* 32 Gbit x16 */
100 &dmo_imx8mm_sbc_dram_timing_16_32, /* 16 Gbit x32 */
101 NULL, /* 16 Gbit x16 */
102 NULL, /* 8 Gbit x32 */
103 NULL, /* 8 Gbit x16 */
104 NULL, /* INVALID */
105 NULL, /* INVALID */
106};
107
108static void spl_dram_init(void)
109{
110 u8 memcfg = dmo_get_memcfg();
111 int i;
112
113 printf("DDR: %d GiB x%d [0x%x]\n",
114 /* 0..4 GiB, 1..2 GiB, 0..1 GiB */
115 4 >> ((memcfg >> 1) & 0x3),
116 /* 0..x32, 1..x16 */
117 32 >> (memcfg & BIT(0)),
118 memcfg);
119
120 if (!dram_timing_info[memcfg]) {
121 printf("Unsupported DRAM strapping, trying lowest supported. MEMCFG=0x%x\n",
122 memcfg);
123 for (i = ARRAY_SIZE(dram_timing_info) - 1; i >= 0; i--)
124 if (dram_timing_info[i]) /* Configuration found */
125 break;
126 }
127
128 ddr_init(dram_timing_info[memcfg]);
129}
130
131void board_init_f(ulong dummy)
132{
133 struct udevice *dev;
134 int ret;
135
136 icache_enable();
137
138 arch_cpu_init();
139
140 init_uart_clk(2);
141
142 data_modul_imx8mm_edm_sbc_early_init_f();
143
Marek Vasut0b16ba52022-04-12 17:26:01 +0200144 /* Clear the BSS. */
145 memset(__bss_start, 0, __bss_end - __bss_start);
146
147 ret = spl_early_init();
148 if (ret) {
149 debug("spl_early_init() failed: %d\n", ret);
150 hang();
151 }
152
Peng Fan33e34be2022-05-05 15:43:36 +0800153 preloader_console_init();
154
Marek Vasut0b16ba52022-04-12 17:26:01 +0200155 ret = uclass_get_device_by_name(UCLASS_CLK,
156 "clock-controller@30380000",
157 &dev);
158 if (ret < 0) {
159 printf("Failed to find clock node. Check device tree\n");
160 hang();
161 }
162
163 enable_tzc380();
164
165 data_modul_imx8mm_edm_sbc_board_power_init();
166
167 /* DDR initialization */
168 spl_dram_init();
169
170 board_init_r(NULL, 0);
171}