From fb7214e7562440aaf65d3ac6edededb4eef858c7 Mon Sep 17 00:00:00 2001
From: orangepi-xunlong <258384131@qq.com>
Date: Mon, 18 Apr 2022 10:43:17 +0800
Subject: [PATCH] sunxi: power led support

---
 arch/arm/mach-sunxi/Kconfig |  8 ++++++++
 board/sunxi/board.c         | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index d91faf9ab13..e5dffd3f571 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -735,6 +735,15 @@ config OLD_SUNXI_KERNEL_COMPAT
 	Set this to enable various workarounds for old kernels, this results in
 	sub-optimal settings for newer kernels, only enable if needed.
 
+config PWRLED
+        string "Power led pin"
+        default "PL10" if MACH_SUNXI_H3_H5
+        default "PL4" if MACH_SUN50I_H6
+        default ""
+        help
+          Set the pin used to power the led. This takes a string in the format
+          understood by sunxi_name_to_gpio, e.g. PC12 for pin 1 of port H.
+
 config MMC1_PINS_PH
 	bool "Pins for mmc1 are on Port H"
 	depends on MACH_SUN4I || MACH_SUN7I || MACH_SUN8I_R40
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index bec14d61058..ec45ed3e05f 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -189,7 +189,7 @@ enum env_location env_get_location(enum env_operation op, int prio)
 /* add board specific code here */
 int board_init(void)
 {
-	__maybe_unused int id_pfr1, ret;
+	__maybe_unused int id_pfr1, ret, pwrled_pin;
 
 	gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
 
@@ -226,6 +226,14 @@ int board_init(void)
 	if (ret)
 		return ret;
 
+	if (CONFIG_PWRLED[0]) {
+		pwrled_pin = sunxi_name_to_gpio(CONFIG_PWRLED);
+		if (pwrled_pin >= 0) {
+			gpio_request(pwrled_pin, "pwrled");
+			gpio_direction_output(pwrled_pin, 1);
+		}
+	}
+
 #if CONFIG_MACH_SUN50I_H616
 	/*
 	 * The bit[16] of register reg[0x03000000] must be zero for the THS
-- 
2.34.1

