dm: gpio: Add live tree support
[oweals/u-boot.git] / board / samsung / common / board.c
index 5c3c5bb9254b0bc427ab493033844f5fb1083086..88299f17e37dde596b70c7302c32013bd0f0cf6a 100644 (file)
 #include <tmu.h>
 #include <netdev.h>
 #include <asm/io.h>
+#include <asm/gpio.h>
 #include <asm/arch/board.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/dwmmc.h>
-#include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/pinmux.h>
 #include <asm/arch/power.h>
 #include <asm/arch/system.h>
-#include <power/pmic.h>
 #include <asm/arch/sromc.h>
 #include <lcd.h>
+#include <i2c.h>
+#include <usb.h>
+#include <dwc3-uboot.h>
 #include <samsung/misc.h>
+#include <dm/pinctrl.h>
+#include <dm.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-int __exynos_early_init_f(void)
+__weak int exynos_early_init_f(void)
 {
        return 0;
 }
-int exynos_early_init_f(void)
-       __attribute__((weak, alias("__exynos_early_init_f")));
 
-int __exynos_power_init(void)
+__weak int exynos_power_init(void)
 {
        return 0;
 }
-int exynos_power_init(void)
-       __attribute__((weak, alias("__exynos_power_init")));
 
 #if defined CONFIG_EXYNOS_TMU
 /* Boot Time Thermal Analysis for SoC temperature threshold breach */
@@ -86,17 +86,20 @@ int board_init(void)
        }
        boot_temp_check();
 #endif
+#ifdef CONFIG_TZSW_RESERVED_DRAM_SIZE
+       /* The last few MB of memory can be reserved for secure firmware */
+       ulong size = CONFIG_TZSW_RESERVED_DRAM_SIZE;
 
-#ifdef CONFIG_EXYNOS_SPI
-       spi_init();
+       gd->ram_size -= size;
+       gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
 #endif
        return exynos_init();
 }
 
 int dram_init(void)
 {
-       int i;
-       u32 addr;
+       unsigned int i;
+       unsigned long addr;
 
        for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
                addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
@@ -105,10 +108,10 @@ int dram_init(void)
        return 0;
 }
 
-void dram_init_banksize(void)
+int dram_init_banksize(void)
 {
-       int i;
-       u32 addr, size;
+       unsigned int i;
+       unsigned long addr, size;
 
        for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
                addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
@@ -117,10 +120,13 @@ void dram_init_banksize(void)
                gd->bd->bi_dram[i].start = addr;
                gd->bd->bi_dram[i].size = size;
        }
+
+       return 0;
 }
 
 static int board_uart_init(void)
 {
+#ifndef CONFIG_PINCTRL_EXYNOS
        int err, uart_id, ret = 0;
 
        for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
@@ -132,6 +138,9 @@ static int board_uart_init(void)
                }
        }
        return ret;
+#else
+       return 0;
+#endif
 }
 
 #ifdef CONFIG_BOARD_EARLY_INIT_F
@@ -151,25 +160,11 @@ int board_early_init_f(void)
        board_i2c_init(gd->fdt_blob);
 #endif
 
-#if defined(CONFIG_OF_CONTROL) && defined(CONFIG_EXYNOS_FB)
-/*
- * board_init_f(arch/arm/lib/board.c) calls lcd_setmem() which needs
- * panel_info.vl_col, panel_info.vl_row and panel_info.vl_bpix, to reserve
- * FB memory at a very early stage. So, we need to fill panel_info.vl_col,
- * panel_info.vl_row and panel_info.vl_bpix before lcd_setmem() is called.
- */
-       err = exynos_lcd_early_init(gd->fdt_blob);
-       if (err) {
-               debug("LCD early init failed\n");
-               return err;
-       }
-#endif
-
        return exynos_early_init_f();
 }
 #endif
 
-#if defined(CONFIG_POWER)
+#if defined(CONFIG_POWER) || defined(CONFIG_DM_PMIC)
 int power_init_board(void)
 {
        set_ps_hold_ctrl();
@@ -178,7 +173,6 @@ int power_init_board(void)
 }
 #endif
 
-#ifdef CONFIG_OF_CONTROL
 #ifdef CONFIG_SMC911X
 static int decode_sromc(const void *blob, struct fdt_sromc *config)
 {
@@ -256,10 +250,10 @@ int board_eth_init(bd_t *bis)
        return 0;
 }
 
-#ifdef CONFIG_GENERIC_MMC
+#ifdef CONFIG_MMC
 static int init_mmc(void)
 {
-#ifdef CONFIG_SDHCI
+#ifdef CONFIG_MMC_SDHCI
        return exynos_mmc_init(gd->fdt_blob);
 #else
        return 0;
@@ -268,7 +262,7 @@ static int init_mmc(void)
 
 static int init_dwmmc(void)
 {
-#ifdef CONFIG_DWMMC
+#ifdef CONFIG_MMC_DW
        return exynos_dwmmc_init(gd->fdt_blob);
 #else
        return 0;
@@ -303,13 +297,12 @@ int checkboard(void)
        printf("Board: %s\n", board_info ? board_info : "unknown");
 #ifdef CONFIG_BOARD_TYPES
        board_info = get_board_type();
-
-       printf("Model: %s\n", board_info ? board_info : "unknown");
+       if (board_info)
+               printf("Type:  %s\n", board_info);
 #endif
        return 0;
 }
 #endif
-#endif /* CONFIG_OF_CONTROL */
 
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
@@ -330,24 +323,9 @@ int board_late_init(void)
 }
 #endif
 
-int arch_early_init_r(void)
-{
-#ifdef CONFIG_CROS_EC
-       if (cros_ec_board_init()) {
-               printf("%s: Failed to init EC\n", __func__);
-               return 0;
-       }
-#endif
-
-       return 0;
-}
-
 #ifdef CONFIG_MISC_INIT_R
 int misc_init_r(void)
 {
-#ifdef CONFIG_SET_DFU_ALT_INFO
-       set_dfu_alt_info();
-#endif
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
        set_board_info();
 #endif
@@ -362,3 +340,39 @@ int misc_init_r(void)
        return 0;
 }
 #endif
+
+void reset_misc(void)
+{
+       struct gpio_desc gpio = {};
+       int node;
+
+       node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
+                       "samsung,emmc-reset");
+       if (node < 0)
+               return;
+
+       gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
+                                  &gpio, GPIOD_IS_OUT);
+
+       if (dm_gpio_is_valid(&gpio)) {
+               /*
+                * Reset eMMC
+                *
+                * FIXME: Need to optimize delay time. Minimum 1usec pulse is
+                *        required by 'JEDEC Standard No.84-A441' (eMMC)
+                *        document but real delay time is expected to greater
+                *        than 1usec.
+                */
+               dm_gpio_set_value(&gpio, 0);
+               mdelay(10);
+               dm_gpio_set_value(&gpio, 1);
+       }
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+#ifdef CONFIG_USB_DWC3
+       dwc3_uboot_exit(index);
+#endif
+       return 0;
+}