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>
32 #include <stdio_dev.h>
34 #include <dwc3-uboot.h>
35 #include <linux/delay.h>
36 #include <samsung/misc.h>
37 #include <dm/pinctrl.h>
40 DECLARE_GLOBAL_DATA_PTR;
42 __weak int exynos_early_init_f(void)
47 __weak int exynos_power_init(void)
53 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
55 static int get_boot_mmc_dev(void)
57 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
60 return 2; /* MMC2: SD */
62 /* MMC0: eMMC or unknown */
66 #if defined CONFIG_EXYNOS_TMU
67 /* Boot Time Thermal Analysis for SoC temperature threshold breach */
68 static void boot_temp_check(void)
72 switch (tmu_monitor(&temp)) {
73 case TMU_STATUS_NORMAL:
75 case TMU_STATUS_TRIPPED:
77 * Status TRIPPED ans WARNING means corresponding threshold
80 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
84 case TMU_STATUS_WARNING:
85 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
89 * TMU_STATUS_INIT means something is wrong with temperature
90 * sensing and TMU status was changed back from NORMAL to INIT.
92 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
95 debug("EXYNOS_TMU: Unknown TMU state\n");
102 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
103 #if defined CONFIG_EXYNOS_TMU
104 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
105 debug("%s: Failed to init TMU\n", __func__);
110 #if CONFIG_VAL(SYS_MEM_TOP_HIDE)
111 /* The last few MB of memory can be reserved for secure firmware */
112 ulong size = CONFIG_SYS_MEM_TOP_HIDE;
114 gd->ram_size -= size;
115 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
117 return exynos_init();
125 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
126 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
127 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
132 int dram_init_banksize(void)
135 unsigned long addr, size;
137 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
138 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
139 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
141 gd->bd->bi_dram[i].start = addr;
142 gd->bd->bi_dram[i].size = size;
148 static int board_uart_init(void)
150 #ifndef CONFIG_PINCTRL_EXYNOS
151 int err, uart_id, ret = 0;
153 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
154 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
156 debug("UART%d not configured\n",
157 (uart_id - PERIPH_ID_UART0));
167 #ifdef CONFIG_BOARD_EARLY_INIT_F
168 int board_early_init_f(void)
171 #ifdef CONFIG_BOARD_TYPES
174 err = board_uart_init();
176 debug("UART init failed\n");
180 #ifdef CONFIG_SYS_I2C_INIT_BOARD
181 board_i2c_init(gd->fdt_blob);
184 return exynos_early_init_f();
188 #if CONFIG_IS_ENABLED(POWER_LEGACY) || CONFIG_IS_ENABLED(DM_PMIC)
189 int power_init_board(void)
193 return exynos_power_init();
197 #if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
200 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
201 const char *board_info;
203 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
205 * Printing type requires having revision, although
206 * this will succeed only if done late.
207 * Otherwise revision will be set in misc_init_r().
209 set_board_revision();
212 board_info = get_board_type();
215 printf("Type: %s\n", board_info);
222 #ifdef CONFIG_BOARD_LATE_INIT
223 int board_late_init(void)
227 int mmcbootdev = get_boot_mmc_dev();
228 char mmcbootdev_str[16];
230 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
231 if (ret && ret != -ENODEV) {
232 /* Force console on */
233 gd->flags &= ~GD_FLG_SILENT;
235 printf("cros-ec communications failure %d\n", ret);
236 puts("\nPlease reset with Power+Refresh\n\n");
237 panic("Cannot init cros-ec device");
241 printf("Boot device: MMC(%u)\n", mmcbootdev);
242 sprintf(mmcbootdev_str, "%u", mmcbootdev);
243 env_set("mmcbootdev", mmcbootdev_str);
249 #ifdef CONFIG_MISC_INIT_R
250 int misc_init_r(void)
252 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
253 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
255 * If revision was not set by late display boardinfo,
256 * set it here. At this point regulators should be already
259 set_board_revision();
262 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
265 #ifdef CONFIG_CMD_BMP
266 if (panel_info.logo_on)
273 void reset_misc(void)
275 struct gpio_desc gpio = {};
278 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
279 "samsung,emmc-reset");
283 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
284 &gpio, GPIOD_IS_OUT);
286 if (dm_gpio_is_valid(&gpio)) {
290 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
291 * required by 'JEDEC Standard No.84-A441' (eMMC)
292 * document but real delay time is expected to greater
295 dm_gpio_set_value(&gpio, 0);
297 dm_gpio_set_value(&gpio, 1);
301 int board_usb_cleanup(int index, enum usb_init_type init)
303 #ifdef CONFIG_USB_DWC3
304 dwc3_uboot_exit(index);
309 int mmc_get_env_dev(void)
311 return get_boot_mmc_dev();