1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2013 SAMSUNG Electronics
4 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
18 #include <asm/arch/board.h>
19 #include <asm/arch/cpu.h>
20 #include <asm/arch/dwmmc.h>
21 #include <asm/arch/mmc.h>
22 #include <asm/arch/pinmux.h>
23 #include <asm/arch/power.h>
24 #include <asm/arch/system.h>
25 #include <asm/arch/sromc.h>
29 #include <stdio_dev.h>
31 #include <dwc3-uboot.h>
32 #include <samsung/misc.h>
33 #include <dm/pinctrl.h>
36 DECLARE_GLOBAL_DATA_PTR
;
38 __weak
int exynos_early_init_f(void)
43 __weak
int exynos_power_init(void)
49 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
51 static int get_boot_mmc_dev(void)
53 u32 mode
= readl(EXYNOS4_OP_MODE
) & 0x1C;
56 return 2; /* MMC2: SD */
58 /* MMC0: eMMC or unknown */
62 #if defined CONFIG_EXYNOS_TMU
63 /* Boot Time Thermal Analysis for SoC temperature threshold breach */
64 static void boot_temp_check(void)
68 switch (tmu_monitor(&temp
)) {
69 case TMU_STATUS_NORMAL
:
71 case TMU_STATUS_TRIPPED
:
73 * Status TRIPPED ans WARNING means corresponding threshold
76 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
80 case TMU_STATUS_WARNING
:
81 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
85 * TMU_STATUS_INIT means something is wrong with temperature
86 * sensing and TMU status was changed back from NORMAL to INIT.
88 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
91 debug("EXYNOS_TMU: Unknown TMU state\n");
98 gd
->bd
->bi_boot_params
= (PHYS_SDRAM_1
+ 0x100UL
);
99 #if defined CONFIG_EXYNOS_TMU
100 if (tmu_init(gd
->fdt_blob
) != TMU_STATUS_NORMAL
) {
101 debug("%s: Failed to init TMU\n", __func__
);
106 #ifdef CONFIG_TZSW_RESERVED_DRAM_SIZE
107 /* The last few MB of memory can be reserved for secure firmware */
108 ulong size
= CONFIG_TZSW_RESERVED_DRAM_SIZE
;
110 gd
->ram_size
-= size
;
111 gd
->bd
->bi_dram
[CONFIG_NR_DRAM_BANKS
- 1].size
-= size
;
113 return exynos_init();
121 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
122 addr
= CONFIG_SYS_SDRAM_BASE
+ (i
* SDRAM_BANK_SIZE
);
123 gd
->ram_size
+= get_ram_size((long *)addr
, SDRAM_BANK_SIZE
);
128 int dram_init_banksize(void)
131 unsigned long addr
, size
;
133 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
134 addr
= CONFIG_SYS_SDRAM_BASE
+ (i
* SDRAM_BANK_SIZE
);
135 size
= get_ram_size((long *)addr
, SDRAM_BANK_SIZE
);
137 gd
->bd
->bi_dram
[i
].start
= addr
;
138 gd
->bd
->bi_dram
[i
].size
= size
;
144 static int board_uart_init(void)
146 #ifndef CONFIG_PINCTRL_EXYNOS
147 int err
, uart_id
, ret
= 0;
149 for (uart_id
= PERIPH_ID_UART0
; uart_id
<= PERIPH_ID_UART3
; uart_id
++) {
150 err
= exynos_pinmux_config(uart_id
, PINMUX_FLAG_NONE
);
152 debug("UART%d not configured\n",
153 (uart_id
- PERIPH_ID_UART0
));
163 #ifdef CONFIG_BOARD_EARLY_INIT_F
164 int board_early_init_f(void)
167 #ifdef CONFIG_BOARD_TYPES
170 err
= board_uart_init();
172 debug("UART init failed\n");
176 #ifdef CONFIG_SYS_I2C_INIT_BOARD
177 board_i2c_init(gd
->fdt_blob
);
180 return exynos_early_init_f();
184 #if defined(CONFIG_POWER) || defined(CONFIG_DM_PMIC)
185 int power_init_board(void)
189 return exynos_power_init();
193 #ifdef CONFIG_SMC911X
194 static int decode_sromc(const void *blob
, struct fdt_sromc
*config
)
199 node
= fdtdec_next_compatible(blob
, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC
);
201 debug("Could not find SROMC node\n");
205 config
->bank
= fdtdec_get_int(blob
, node
, "bank", 0);
206 config
->width
= fdtdec_get_int(blob
, node
, "width", 2);
208 err
= fdtdec_get_int_array(blob
, node
, "srom-timing", config
->timing
,
209 FDT_SROM_TIMING_COUNT
);
211 debug("Could not decode SROMC configuration Error: %s\n",
213 return -FDT_ERR_NOTFOUND
;
219 int board_eth_init(bd_t
*bis
)
221 #ifdef CONFIG_SMC911X
222 u32 smc_bw_conf
, smc_bc_conf
;
223 struct fdt_sromc config
;
224 fdt_addr_t base_addr
;
227 node
= decode_sromc(gd
->fdt_blob
, &config
);
229 debug("%s: Could not find sromc configuration\n", __func__
);
232 node
= fdtdec_next_compatible(gd
->fdt_blob
, node
, COMPAT_SMSC_LAN9215
);
234 debug("%s: Could not find lan9215 configuration\n", __func__
);
238 /* We now have a node, so any problems from now on are errors */
239 base_addr
= fdtdec_get_addr(gd
->fdt_blob
, node
, "reg");
240 if (base_addr
== FDT_ADDR_T_NONE
) {
241 debug("%s: Could not find lan9215 address\n", __func__
);
245 /* Ethernet needs data bus width of 16 bits */
246 if (config
.width
!= 2) {
247 debug("%s: Unsupported bus width %d\n", __func__
,
251 smc_bw_conf
= SROMC_DATA16_WIDTH(config
.bank
)
252 | SROMC_BYTE_ENABLE(config
.bank
);
254 smc_bc_conf
= SROMC_BC_TACS(config
.timing
[FDT_SROM_TACS
]) |
255 SROMC_BC_TCOS(config
.timing
[FDT_SROM_TCOS
]) |
256 SROMC_BC_TACC(config
.timing
[FDT_SROM_TACC
]) |
257 SROMC_BC_TCOH(config
.timing
[FDT_SROM_TCOH
]) |
258 SROMC_BC_TAH(config
.timing
[FDT_SROM_TAH
]) |
259 SROMC_BC_TACP(config
.timing
[FDT_SROM_TACP
]) |
260 SROMC_BC_PMC(config
.timing
[FDT_SROM_PMC
]);
262 /* Select and configure the SROMC bank */
263 exynos_pinmux_config(PERIPH_ID_SROMC
, config
.bank
);
264 s5p_config_sromc(config
.bank
, smc_bw_conf
, smc_bc_conf
);
265 return smc911x_initialize(0, base_addr
);
270 #if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
273 if (IS_ENABLED(CONFIG_BOARD_TYPES
)) {
274 const char *board_info
;
276 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE
)) {
278 * Printing type requires having revision, although
279 * this will succeed only if done late.
280 * Otherwise revision will be set in misc_init_r().
282 set_board_revision();
285 board_info
= get_board_type();
288 printf("Type: %s\n", board_info
);
295 #ifdef CONFIG_BOARD_LATE_INIT
296 int board_late_init(void)
300 int mmcbootdev
= get_boot_mmc_dev();
301 char mmcbootdev_str
[16];
303 stdio_print_current_devices();
304 ret
= uclass_first_device_err(UCLASS_CROS_EC
, &dev
);
305 if (ret
&& ret
!= -ENODEV
) {
306 /* Force console on */
307 gd
->flags
&= ~GD_FLG_SILENT
;
309 printf("cros-ec communications failure %d\n", ret
);
310 puts("\nPlease reset with Power+Refresh\n\n");
311 panic("Cannot init cros-ec device");
315 printf("Boot device: MMC(%u)\n", mmcbootdev
);
316 sprintf(mmcbootdev_str
, "%u", mmcbootdev
);
317 env_set("mmcbootdev", mmcbootdev_str
);
323 #ifdef CONFIG_MISC_INIT_R
324 int misc_init_r(void)
326 if (IS_ENABLED(CONFIG_BOARD_TYPES
) &&
327 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE
)) {
329 * If revision was not set by late display boardinfo,
330 * set it here. At this point regulators should be already
333 set_board_revision();
336 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
339 #ifdef CONFIG_LCD_MENU
343 #ifdef CONFIG_CMD_BMP
344 if (panel_info
.logo_on
)
351 void reset_misc(void)
353 struct gpio_desc gpio
= {};
356 node
= fdt_node_offset_by_compatible(gd
->fdt_blob
, 0,
357 "samsung,emmc-reset");
361 gpio_request_by_name_nodev(offset_to_ofnode(node
), "reset-gpio", 0,
362 &gpio
, GPIOD_IS_OUT
);
364 if (dm_gpio_is_valid(&gpio
)) {
368 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
369 * required by 'JEDEC Standard No.84-A441' (eMMC)
370 * document but real delay time is expected to greater
373 dm_gpio_set_value(&gpio
, 0);
375 dm_gpio_set_value(&gpio
, 1);
379 int board_usb_cleanup(int index
, enum usb_init_type init
)
381 #ifdef CONFIG_USB_DWC3
382 dwc3_uboot_exit(index
);
387 int mmc_get_env_dev(void)
389 return get_boot_mmc_dev();