Merge tag 'u-boot-at91-fixes-2022.04-a' of https://source.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / board / sunxi / board.c
index 418dc0c..82c52b2 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <common.h>
+#include <clock_legacy.h>
 #include <dm.h>
 #include <env.h>
 #include <hang.h>
@@ -25,9 +26,9 @@
 #include <asm/arch/cpu.h>
 #include <asm/arch/display.h>
 #include <asm/arch/dram.h>
-#include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/prcm.h>
+#include <asm/arch/pmic_bus.h>
 #include <asm/arch/spl.h>
 #include <asm/global_data.h>
 #include <linux/delay.h>
 #include <spl.h>
 #include <sy8106a.h>
 #include <asm/setup.h>
-
-#if defined(CONFIG_VIDEO_LCD_PANEL_I2C)
-/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
-int soft_i2c_gpio_sda;
-int soft_i2c_gpio_scl;
-
-static int soft_i2c_board_init(void)
-{
-       int ret;
-
-       soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
-       if (soft_i2c_gpio_sda < 0) {
-               printf("Error invalid soft i2c sda pin: '%s', err %d\n",
-                      CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda);
-               return soft_i2c_gpio_sda;
-       }
-       ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda");
-       if (ret) {
-               printf("Error requesting soft i2c sda pin: '%s', err %d\n",
-                      CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret);
-               return ret;
-       }
-
-       soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
-       if (soft_i2c_gpio_scl < 0) {
-               printf("Error invalid soft i2c scl pin: '%s', err %d\n",
-                      CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl);
-               return soft_i2c_gpio_scl;
-       }
-       ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl");
-       if (ret) {
-               printf("Error requesting soft i2c scl pin: '%s', err %d\n",
-                      CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret);
-               return ret;
-       }
-
-       return 0;
-}
-#else
-static int soft_i2c_board_init(void) { return 0; }
-#endif
+#include <status_led.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -237,7 +198,7 @@ int board_init(void)
 
        gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
 
-#ifndef CONFIG_ARM64
+#if !defined(CONFIG_ARM64) && !defined(CONFIG_MACH_SUNIV)
        asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
        debug("id_pfr1: 0x%08x\n", id_pfr1);
        /* Generic Timer Extension available? */
@@ -264,7 +225,7 @@ int board_init(void)
 #endif
                }
        }
-#endif /* !CONFIG_ARM64 */
+#endif /* !CONFIG_ARM64 && !CONFIG_MACH_SUNIV */
 
        ret = axp_gpio_init();
        if (ret)
@@ -312,8 +273,7 @@ int board_init(void)
 #endif
 #endif /* CONFIG_DM_MMC */
 
-       /* Uses dm gpio code so do this here and not in i2c_init_board() */
-       return soft_i2c_board_init();
+       return 0;
 }
 
 /*
@@ -629,6 +589,11 @@ void sunxi_board_init(void)
 {
        int power_failed = 0;
 
+#ifdef CONFIG_LED_STATUS
+       if (IS_ENABLED(CONFIG_SPL_DRIVERS_MISC))
+               status_led_init();
+#endif
+
 #ifdef CONFIG_SY8106A_POWER
        power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
 #endif
@@ -638,6 +603,16 @@ void sunxi_board_init(void)
        defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
        power_failed = axp_init();
 
+       if (IS_ENABLED(CONFIG_AXP_DISABLE_BOOT_ON_POWERON) && !power_failed) {
+               u8 boot_reason;
+
+               pmic_bus_read(AXP_POWER_STATUS, &boot_reason);
+               if (boot_reason & AXP_POWER_STATUS_ALDO_IN) {
+                       printf("Power on by plug-in, shutting down.\n");
+                       pmic_bus_write(0x32, BIT(7));
+               }
+       }
+
 #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
        defined CONFIG_AXP818_POWER
        power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
@@ -704,7 +679,7 @@ void sunxi_board_init(void)
         * assured it's being powered with suitable core voltage
         */
        if (!power_failed)
-               clock_set_pll1(CONFIG_SYS_CLK_FREQ);
+               clock_set_pll1(get_board_sys_clk());
        else
                printf("Failed to set core voltage! Can't set CPU frequency\n");
 }
@@ -735,13 +710,7 @@ int g_dnl_board_usb_cable_connected(void)
                return ret;
        }
 
-       ret = sun4i_usb_phy_vbus_detect(&phy);
-       if (ret == 1) {
-               pr_err("A charger is plugged into the OTG\n");
-               return -ENODEV;
-       }
-
-       return ret;
+       return sun4i_usb_phy_vbus_detect(&phy);
 }
 #endif
 
@@ -954,10 +923,12 @@ int ft_board_setup(void *blob, struct bd_info *bd)
        int __maybe_unused r;
 
        /*
-        * Call setup_environment again in case the boot fdt has
-        * ethernet aliases the u-boot copy does not have.
+        * Call setup_environment and fdt_fixup_ethernet again
+        * in case the boot fdt has ethernet aliases the u-boot
+        * copy does not have.
         */
        setup_environment(blob);
+       fdt_fixup_ethernet(blob);
 
        bluetooth_dt_fixup(blob);