[2/2] board: roc-rk3399-pc: Add support for onboard LED's and push button

Message ID 1579858438-13035-2-git-send-email-sunil@amarulasolutions.com
State New
Headers show
Series
  • Untitled series #154
Related show

Commit Message

Suniel Mahesh Jan. 24, 2020, 9:33 a.m. UTC
From: Suniel Mahesh <sunil@amarulasolutions.com>

Added support for onboard LED's and push button. When powered board
will be in low power mode(yellow LED), on button press, board enters
full power mode(red LED) and boots u-boot.

Signed-off-by: Suniel Mahesh <sunil@amarulasolutions.com>
---
 arch/arm/mach-rockchip/tpl.c                |  7 +++++++
 board/firefly/roc-rk3399-pc/roc-rk3399-pc.c | 26 ++++++++++++++++++++++++++
 configs/roc-pc-rk3399_defconfig             |  1 +
 3 files changed, 34 insertions(+)

Patch

diff --git a/arch/arm/mach-rockchip/tpl.c b/arch/arm/mach-rockchip/tpl.c
index c3734cb..c6d6596 100644
--- a/arch/arm/mach-rockchip/tpl.c
+++ b/arch/arm/mach-rockchip/tpl.c
@@ -39,11 +39,18 @@  __weak void rockchip_stimer_init(void)
 	       TIMER_CONTROL_REG);
 }
 
+__weak int board_early_init_f(void)
+{
+	return 0;
+}
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
 	int ret;
 
+	board_early_init_f();
+
 #if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL_SUPPORT)
 	/*
 	 * Debug UART can be used from here if required:
diff --git a/board/firefly/roc-rk3399-pc/roc-rk3399-pc.c b/board/firefly/roc-rk3399-pc/roc-rk3399-pc.c
index d47dba8..aedc15e 100644
--- a/board/firefly/roc-rk3399-pc/roc-rk3399-pc.c
+++ b/board/firefly/roc-rk3399-pc/roc-rk3399-pc.c
@@ -7,6 +7,10 @@ 
 #include <dm.h>
 #include <asm/arch-rockchip/periph.h>
 #include <power/regulator.h>
+#include <spl_gpio.h>
+#include <asm/io.h>
+#include <asm/arch-rockchip/gpio.h>
+#include <asm/arch-rockchip/grf_rk3399.h>
 
 #ifndef CONFIG_SPL_BUILD
 int board_early_init_f(void)
@@ -27,3 +31,25 @@  out:
 	return 0;
 }
 #endif
+
+#if defined(CONFIG_TPL_BUILD)
+
+#define PMUGRF_BASE     0xff320000
+#define GPIO0_BASE      0xff720000
+
+int board_early_init_f(void)
+{
+        struct rockchip_gpio_regs * const gpio0 = (void *)GPIO0_BASE;
+        struct rk3399_pmugrf_regs * const pmugrf = (void *)PMUGRF_BASE;
+
+        spl_gpio_output(gpio0, GPIO(BANK_A, 2), 1);
+
+        spl_gpio_set_pull(&pmugrf->gpio0_p, GPIO(BANK_A, 5), GPIO_PULL_NORMAL);
+        while (readl(&gpio0->ext_port) & 0x20);
+
+        spl_gpio_output(gpio0, GPIO(BANK_A, 2), 0);
+        spl_gpio_output(gpio0, GPIO(BANK_B, 5), 1);
+
+        return 0;
+}
+#endif
diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig
index 6ce1bc2..77e162c 100644
--- a/configs/roc-pc-rk3399_defconfig
+++ b/configs/roc-pc-rk3399_defconfig
@@ -63,3 +63,4 @@  CONFIG_VIDEO_BPP32=y
 CONFIG_DISPLAY=y
 CONFIG_VIDEO_ROCKCHIP=y
 CONFIG_DISPLAY_ROCKCHIP_HDMI=y
+CONFIG_TPL_GPIO_SUPPORT=y