]> git.sur5r.net Git - u-boot/blobdiff - board/sunxi/board.c
libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>
[u-boot] / board / sunxi / board.c
index f903a5d0a028fb627807572f39aed052f06e0f5b..e08e22f30c0ade2256f69a15e3b7f1db01159677 100644 (file)
 #include <asm/io.h>
 #include <crc.h>
 #include <environment.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
 #include <nand.h>
 #include <net.h>
+#include <spl.h>
 #include <sy8106a.h>
+#include <asm/setup.h>
 
 #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
 /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
@@ -171,6 +173,22 @@ void i2c_init_board(void)
 #endif
 }
 
+#if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT)
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+       switch (prio) {
+       case 0:
+               return ENVL_FAT;
+
+       case 1:
+               return ENVL_MMC;
+
+       default:
+               return ENVL_UNKNOWN;
+       }
+}
+#endif
+
 /* add board specific code here */
 int board_init(void)
 {
@@ -215,6 +233,8 @@ int board_init(void)
        satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
        gpio_request(satapwr_pin, "satapwr");
        gpio_direction_output(satapwr_pin, 1);
+       /* Give attached sata device time to power-up to avoid link timeouts */
+       mdelay(500);
 #endif
 #ifdef CONFIG_MACPWR
        macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
@@ -222,6 +242,14 @@ int board_init(void)
        gpio_direction_output(macpwr_pin, 1);
 #endif
 
+#ifdef CONFIG_DM_I2C
+       /*
+        * Temporary workaround for enabling I2C clocks until proper sunxi DM
+        * clk, reset and pinctrl drivers land.
+        */
+       i2c_init_board();
+#endif
+
        /* Uses dm gpio code so do this here and not in i2c_init_board() */
        return soft_i2c_board_init();
 }
@@ -276,7 +304,7 @@ void board_nand_init(void)
 }
 #endif
 
-#ifdef CONFIG_GENERIC_MMC
+#ifdef CONFIG_MMC
 static void mmc_pinmux_setup(int sdc)
 {
        unsigned int pin;
@@ -482,20 +510,6 @@ int board_mmc_init(bd_t *bis)
                return -1;
 #endif
 
-#if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
-       /*
-        * On systems with an emmc (mmc2), figure out if we are booting from
-        * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc.
-        * are searched there first. Note we only do this for u-boot proper,
-        * not for the SPL, see spl_boot_device().
-        */
-       if (readb(SPL_ADDR + 0x28) == SUNXI_BOOTED_FROM_MMC2) {
-               /* Booting from emmc / mmc2, swap */
-               mmc0->block_dev.devnum = 1;
-               mmc1->block_dev.devnum = 0;
-       }
-#endif
-
        return 0;
 }
 #endif
@@ -504,7 +518,6 @@ int board_mmc_init(bd_t *bis)
 void sunxi_board_init(void)
 {
        int power_failed = 0;
-       unsigned long ramsize;
 
 #ifdef CONFIG_SY8106A_POWER
        power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
@@ -565,9 +578,9 @@ void sunxi_board_init(void)
 #endif
 #endif
        printf("DRAM:");
-       ramsize = sunxi_dram_init();
-       printf(" %d MiB\n", (int)(ramsize >> 20));
-       if (!ramsize)
+       gd->ram_size = sunxi_dram_init();
+       printf(" %d MiB\n", (int)(gd->ram_size >> 20));
+       if (!gd->ram_size)
                hang();
 
        /*
@@ -594,7 +607,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
        char *serial_string;
        unsigned long long serial;
 
-       serial_string = getenv("serial#");
+       serial_string = env_get("serial#");
 
        if (serial_string) {
                serial = simple_strtoull(serial_string, NULL, 16);
@@ -638,7 +651,7 @@ static void parse_spl_header(const uint32_t spl_addr)
                return;
        }
        /* otherwise assume .scr format (mkimage-type script) */
-       setenv_hex("fel_scriptaddr", spl->fel_script_address);
+       env_set_hex("fel_scriptaddr", spl->fel_script_address);
 }
 
 /*
@@ -686,7 +699,7 @@ static void setup_environment(const void *fdt)
                        else
                                sprintf(ethaddr, "eth%daddr", i);
 
-                       if (getenv(ethaddr))
+                       if (env_get(ethaddr))
                                continue;
 
                        /* Non OUI / registered MAC address */
@@ -697,14 +710,14 @@ static void setup_environment(const void *fdt)
                        mac_addr[4] = (sid[3] >>  8) & 0xff;
                        mac_addr[5] = (sid[3] >>  0) & 0xff;
 
-                       eth_setenv_enetaddr(ethaddr, mac_addr);
+                       eth_env_set_enetaddr(ethaddr, mac_addr);
                }
 
-               if (!getenv("serial#")) {
+               if (!env_get("serial#")) {
                        snprintf(serial_string, sizeof(serial_string),
                                "%08x%08x", sid[0], sid[3]);
 
-                       setenv("serial#", serial_string);
+                       env_set("serial#", serial_string);
                }
        }
 }
@@ -712,13 +725,22 @@ static void setup_environment(const void *fdt)
 int misc_init_r(void)
 {
        __maybe_unused int ret;
+       uint boot;
 
-       setenv("fel_booted", NULL);
-       setenv("fel_scriptaddr", NULL);
+       env_set("fel_booted", NULL);
+       env_set("fel_scriptaddr", NULL);
+       env_set("mmc_bootdev", NULL);
+
+       boot = sunxi_get_boot_device();
        /* determine if we are running in FEL mode */
-       if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
-               setenv("fel_booted", "1");
+       if (boot == BOOT_DEVICE_BOARD) {
+               env_set("fel_booted", "1");
                parse_spl_header(SPL_ADDR);
+       /* or if we booted from MMC, and which one */
+       } else if (boot == BOOT_DEVICE_MMC1) {
+               env_set("mmc_bootdev", "0");
+       } else if (boot == BOOT_DEVICE_MMC2) {
+               env_set("mmc_bootdev", "1");
        }
 
        setup_environment(gd->fdt_blob);
@@ -728,7 +750,10 @@ int misc_init_r(void)
        if (ret)
                return ret;
 #endif
-       sunxi_musb_board_init();
+
+#ifdef CONFIG_USB_ETHER
+       usb_ether_init();
+#endif
 
        return 0;
 }
@@ -750,3 +775,32 @@ int ft_board_setup(void *blob, bd_t *bd)
 #endif
        return 0;
 }
+
+#ifdef CONFIG_SPL_LOAD_FIT
+int board_fit_config_name_match(const char *name)
+{
+       struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
+       const char *cmp_str = (void *)(ulong)SPL_ADDR;
+
+       /* Check if there is a DT name stored in the SPL header and use that. */
+       if (spl->dt_name_offset) {
+               cmp_str += spl->dt_name_offset;
+       } else {
+#ifdef CONFIG_DEFAULT_DEVICE_TREE
+               cmp_str = CONFIG_DEFAULT_DEVICE_TREE;
+#else
+               return 0;
+#endif
+       };
+
+/* Differentiate the two Pine64 board DTs by their DRAM size. */
+       if (strstr(name, "-pine64") && strstr(cmp_str, "-pine64")) {
+               if ((gd->ram_size > 512 * 1024 * 1024))
+                       return !strstr(name, "plus");
+               else
+                       return !!strstr(name, "plus");
+       } else {
+               return strcmp(name, cmp_str);
+       }
+}
+#endif