1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2013 SAMSUNG Electronics
19 #include <asm/global_data.h>
22 #include <asm/arch/board.h>
23 #include <asm/arch/cpu.h>
24 #include <asm/arch/dwmmc.h>
25 #include <asm/arch/mmc.h>
26 #include <asm/arch/pinmux.h>
27 #include <asm/arch/power.h>
28 #include <asm/arch/system.h>
31 #include <stdio_dev.h>
33 #include <dwc3-uboot.h>
34 #include <linux/delay.h>
35 #include <samsung/misc.h>
36 #include <dm/pinctrl.h>
39 DECLARE_GLOBAL_DATA_PTR;
41 __weak int exynos_early_init_f(void)
46 __weak void exynos_init(void)
50 __weak int exynos_power_init(void)
56 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
58 static int get_boot_mmc_dev(void)
60 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
63 return 2; /* MMC2: SD */
65 /* MMC0: eMMC or unknown */
69 #if defined CONFIG_EXYNOS_TMU
70 /* Boot Time Thermal Analysis for SoC temperature threshold breach */
71 static void boot_temp_check(void)
75 switch (tmu_monitor(&temp)) {
76 case TMU_STATUS_NORMAL:
78 case TMU_STATUS_TRIPPED:
80 * Status TRIPPED ans WARNING means corresponding threshold
83 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
87 case TMU_STATUS_WARNING:
88 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
92 * TMU_STATUS_INIT means something is wrong with temperature
93 * sensing and TMU status was changed back from NORMAL to INIT.
95 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
98 debug("EXYNOS_TMU: Unknown TMU state\n");
105 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
106 #if defined CONFIG_EXYNOS_TMU
107 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
108 debug("%s: Failed to init TMU\n", __func__);
113 #if CONFIG_VAL(SYS_MEM_TOP_HIDE)
114 /* The last few MB of memory can be reserved for secure firmware */
115 ulong size = CONFIG_SYS_MEM_TOP_HIDE;
117 gd->ram_size -= size;
118 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
130 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
131 addr = CFG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
132 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
137 int dram_init_banksize(void)
140 unsigned long addr, size;
142 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
143 addr = CFG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
144 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
146 gd->bd->bi_dram[i].start = addr;
147 gd->bd->bi_dram[i].size = size;
153 static int board_uart_init(void)
155 #ifndef CONFIG_PINCTRL_EXYNOS
156 int err, uart_id, ret = 0;
158 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
159 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
161 debug("UART%d not configured\n",
162 (uart_id - PERIPH_ID_UART0));
172 #ifdef CONFIG_BOARD_EARLY_INIT_F
173 int board_early_init_f(void)
176 #ifdef CONFIG_BOARD_TYPES
179 err = board_uart_init();
181 debug("UART init failed\n");
185 return exynos_early_init_f();
189 #if CONFIG_IS_ENABLED(POWER_LEGACY) || CONFIG_IS_ENABLED(DM_PMIC)
190 int power_init_board(void)
194 return exynos_power_init();
198 #if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
201 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
202 const char *board_info;
204 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
206 * Printing type requires having revision, although
207 * this will succeed only if done late.
208 * Otherwise revision will be set in misc_init_r().
210 set_board_revision();
213 board_info = get_board_type();
216 printf("Type: %s\n", board_info);
223 #ifdef CONFIG_BOARD_LATE_INIT
224 int board_late_init(void)
228 int mmcbootdev = get_boot_mmc_dev();
229 char mmcbootdev_str[16];
231 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
232 if (ret && ret != -ENODEV && ret != -EPFNOSUPPORT) {
233 /* Force console on */
234 gd->flags &= ~GD_FLG_SILENT;
236 printf("cros-ec communications failure %d\n", ret);
237 puts("\nPlease reset with Power+Refresh\n\n");
238 panic("Cannot init cros-ec device");
242 printf("Boot device: MMC(%u)\n", mmcbootdev);
243 sprintf(mmcbootdev_str, "%u", mmcbootdev);
244 env_set("mmcbootdev", mmcbootdev_str);
250 #ifdef CONFIG_MISC_INIT_R
251 int misc_init_r(void)
253 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
254 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
256 * If revision was not set by late display boardinfo,
257 * set it here. At this point regulators should be already
260 set_board_revision();
263 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
266 #ifdef CONFIG_CMD_BMP
267 if (panel_info.logo_on)
274 void reset_misc(void)
276 struct gpio_desc gpio = {};
279 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
280 "samsung,emmc-reset");
284 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
285 &gpio, GPIOD_IS_OUT);
287 if (dm_gpio_is_valid(&gpio)) {
291 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
292 * required by 'JEDEC Standard No.84-A441' (eMMC)
293 * document but real delay time is expected to greater
296 dm_gpio_set_value(&gpio, 0);
298 dm_gpio_set_value(&gpio, 1);
302 int board_usb_cleanup(int index, enum usb_init_type init)
304 #ifdef CONFIG_USB_DWC3
305 dwc3_uboot_exit(index);
310 int mmc_get_env_dev(void)
312 return get_boot_mmc_dev();