1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2013 SAMSUNG Electronics
4 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
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 int exynos_power_init(void)
52 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
54 static int get_boot_mmc_dev(void)
56 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
59 return 2; /* MMC2: SD */
61 /* MMC0: eMMC or unknown */
65 #if defined CONFIG_EXYNOS_TMU
66 /* Boot Time Thermal Analysis for SoC temperature threshold breach */
67 static void boot_temp_check(void)
71 switch (tmu_monitor(&temp)) {
72 case TMU_STATUS_NORMAL:
74 case TMU_STATUS_TRIPPED:
76 * Status TRIPPED ans WARNING means corresponding threshold
79 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
83 case TMU_STATUS_WARNING:
84 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
88 * TMU_STATUS_INIT means something is wrong with temperature
89 * sensing and TMU status was changed back from NORMAL to INIT.
91 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
94 debug("EXYNOS_TMU: Unknown TMU state\n");
101 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
102 #if defined CONFIG_EXYNOS_TMU
103 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
104 debug("%s: Failed to init TMU\n", __func__);
109 #if CONFIG_VAL(SYS_MEM_TOP_HIDE)
110 /* The last few MB of memory can be reserved for secure firmware */
111 ulong size = CONFIG_SYS_MEM_TOP_HIDE;
113 gd->ram_size -= size;
114 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
116 return exynos_init();
124 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
125 addr = CFG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
126 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
131 int dram_init_banksize(void)
134 unsigned long addr, size;
136 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
137 addr = CFG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
138 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
140 gd->bd->bi_dram[i].start = addr;
141 gd->bd->bi_dram[i].size = size;
147 static int board_uart_init(void)
149 #ifndef CONFIG_PINCTRL_EXYNOS
150 int err, uart_id, ret = 0;
152 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
153 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
155 debug("UART%d not configured\n",
156 (uart_id - PERIPH_ID_UART0));
166 #ifdef CONFIG_BOARD_EARLY_INIT_F
167 int board_early_init_f(void)
170 #ifdef CONFIG_BOARD_TYPES
173 err = board_uart_init();
175 debug("UART init failed\n");
179 return exynos_early_init_f();
183 #if CONFIG_IS_ENABLED(POWER_LEGACY) || CONFIG_IS_ENABLED(DM_PMIC)
184 int power_init_board(void)
188 return exynos_power_init();
192 #if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
195 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
196 const char *board_info;
198 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
200 * Printing type requires having revision, although
201 * this will succeed only if done late.
202 * Otherwise revision will be set in misc_init_r().
204 set_board_revision();
207 board_info = get_board_type();
210 printf("Type: %s\n", board_info);
217 #ifdef CONFIG_BOARD_LATE_INIT
218 int board_late_init(void)
222 int mmcbootdev = get_boot_mmc_dev();
223 char mmcbootdev_str[16];
225 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
226 if (ret && ret != -ENODEV) {
227 /* Force console on */
228 gd->flags &= ~GD_FLG_SILENT;
230 printf("cros-ec communications failure %d\n", ret);
231 puts("\nPlease reset with Power+Refresh\n\n");
232 panic("Cannot init cros-ec device");
236 printf("Boot device: MMC(%u)\n", mmcbootdev);
237 sprintf(mmcbootdev_str, "%u", mmcbootdev);
238 env_set("mmcbootdev", mmcbootdev_str);
244 #ifdef CONFIG_MISC_INIT_R
245 int misc_init_r(void)
247 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
248 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
250 * If revision was not set by late display boardinfo,
251 * set it here. At this point regulators should be already
254 set_board_revision();
257 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
260 #ifdef CONFIG_CMD_BMP
261 if (panel_info.logo_on)
268 void reset_misc(void)
270 struct gpio_desc gpio = {};
273 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
274 "samsung,emmc-reset");
278 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
279 &gpio, GPIOD_IS_OUT);
281 if (dm_gpio_is_valid(&gpio)) {
285 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
286 * required by 'JEDEC Standard No.84-A441' (eMMC)
287 * document but real delay time is expected to greater
290 dm_gpio_set_value(&gpio, 0);
292 dm_gpio_set_value(&gpio, 1);
296 int board_usb_cleanup(int index, enum usb_init_type init)
298 #ifdef CONFIG_USB_DWC3
299 dwc3_uboot_exit(index);
304 int mmc_get_env_dev(void)
306 return get_boot_mmc_dev();