SPDX: Convert all of our single license tags to Linux Kernel style
[platform/kernel/u-boot.git] / board / sunxi / board.c
index f79bd5c..3d364c6 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net>
  * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
@@ -7,8 +8,6 @@
  * Tom Cubie <tangliang@allwinnertech.com>
  *
  * Some board init for the Allwinner A10-evb board.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #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 +172,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 +232,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);
@@ -266,10 +285,9 @@ static void nand_clock_setup(void)
                (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
 
        setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0));
-#ifdef CONFIG_MACH_SUN9I
-       setbits_le32(&ccm->ahb_gate1, (1 << AHB_GATE_OFFSET_DMA));
-#else
-       setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA));
+#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I || \
+    defined CONFIG_MACH_SUN9I || defined CONFIG_MACH_SUN50I
+       setbits_le32(&ccm->ahb_reset0_cfg, (1 << AHB_GATE_OFFSET_NAND0));
 #endif
        setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1);
 }
@@ -490,20 +508,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
@@ -601,7 +605,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);
@@ -645,7 +649,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);
 }
 
 /*
@@ -693,7 +697,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 */
@@ -704,14 +708,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);
                }
        }
 }
@@ -719,13 +723,22 @@ static void setup_environment(const void *fdt)
 int misc_init_r(void)
 {
        __maybe_unused int ret;
+       uint boot;
+
+       env_set("fel_booted", NULL);
+       env_set("fel_scriptaddr", NULL);
+       env_set("mmc_bootdev", NULL);
 
-       setenv("fel_booted", NULL);
-       setenv("fel_scriptaddr", 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);
@@ -735,7 +748,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;
 }