diff mbox series

[U-Boot,1/3] rockchip: make boot_mode releated codes reused across all platforms

Message ID 1505224652-29989-1-git-send-email-andy.yan@rock-chips.com
State Superseded
Delegated to: Philipp Tomsich
Headers show
Series support enter download mode on rockchip platform | expand

Commit Message

Andy Yan Sept. 12, 2017, 1:57 p.m. UTC
setup_boot_mode function use the same logic but different
mode register address across all the rockchip platforms,
so it's better to make this function reused across all the
platforms, and let the mode register address setting from
the config file.

Signed-off-by: Andy Yan <andy.yan@rock-chips.com>

---

 arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
 arch/arm/mach-rockchip/Kconfig                 | 14 +++++++++++
 arch/arm/mach-rockchip/Makefile                |  5 +++-
 arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
 arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
 arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
 arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
 8 files changed, 67 insertions(+), 74 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/boot_mode.c
 create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

Comments

Simon Glass Sept. 13, 2017, 4:26 a.m. UTC | #1
On 12 September 2017 at 07:57, Andy Yan <andy.yan@rock-chips.com> wrote:
> setup_boot_mode function use the same logic but different
> mode register address across all the rockchip platforms,
> so it's better to make this function reused across all the
> platforms, and let the mode register address setting from
> the config file.
>
> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
>
> ---
>
>  arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
>  arch/arm/mach-rockchip/Kconfig                 | 14 +++++++++++
>  arch/arm/mach-rockchip/Makefile                |  5 +++-
>  arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
>  arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
>  arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
>  arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
>  arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
>  8 files changed, 67 insertions(+), 74 deletions(-)
>  create mode 100644 arch/arm/mach-rockchip/boot_mode.c
>  create mode 100644 arch/arm/mach-rockchip/rk3399-board.c

Reviewed-by: Simon Glass <sjg@chromium.org>
Heiko Stübner Sept. 21, 2017, 9:02 a.m. UTC | #2
Hi Andy,

Am Dienstag, 12. September 2017, 21:57:32 CEST schrieb Andy Yan:
> setup_boot_mode function use the same logic but different
> mode register address across all the rockchip platforms,
> so it's better to make this function reused across all the
> platforms, and let the mode register address setting from
> the config file.
> 
> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
> 
> ---
> 
>  arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
>  arch/arm/mach-rockchip/Kconfig                 | 14 +++++++++++
>  arch/arm/mach-rockchip/Makefile                |  5 +++-
>  arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
>  arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
>  arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
>  arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
>  arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
>  8 files changed, 67 insertions(+), 74 deletions(-)
>  create mode 100644 arch/arm/mach-rockchip/boot_mode.c
>  create mode 100644 arch/arm/mach-rockchip/rk3399-board.c
> 
> diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h
> index bd65f60..163b2e7 100644
> --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h
> +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h
> @@ -16,4 +16,6 @@
>  /* enter usb mass storage mode */
>  #define BOOT_UMS		(REBOOT_FLAG + 12)
>  
> +int setup_boot_mode(void);
> +
>  #endif
> diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
> index d9b25d5..527ca60 100644
> --- a/arch/arm/mach-rockchip/Kconfig
> +++ b/arch/arm/mach-rockchip/Kconfig
> @@ -114,6 +114,7 @@ config ROCKCHIP_RK3399
>  	select SPL_DRIVERS_MISC_SUPPORT
>  	select ENABLE_ARM_SOC_BOOT0_HOOK
>  	select DEBUG_UART_BOARD_INIT
> +	select BOARD_LATE_INIT
>  	help
>  	  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
>  	  and quad-core Cortex-A53.
> @@ -149,6 +150,19 @@ config TPL_ROCKCHIP_BACK_TO_BROM
>            SPL will return to the boot rom, which will then load the U-Boot
>            binary to keep going on.
>  
> +config ROCKCHIP_BOOT_MODE_REG
> +	hex "Rockchip boot mode flag register address"
> +	default 0x200081c8 if ROCKCHIP_RK3036
> +	default 0x110005d8 if ROCKCHIP_RK322X
> +	default 0xff730094 if ROCKCHIP_RK3288
> +	default 0xff738200 if ROCKCHIP_RK3368
> +	default 0xff320300 if ROCKCHIP_RK3399
> +	default 0x10300580 if ROCKCHIP_RV1108

could you possibly look up if the rk3188 and rk3066 also support
the subsequent boot to maskrom download mode from the later
patches and include the register if possible?


Thanks
Heiko
Andy Yan Sept. 21, 2017, 9:04 a.m. UTC | #3
Hi Heiko:


On 2017年09月21日 17:02, Heiko Stuebner wrote:
> Hi Andy,
>
> Am Dienstag, 12. September 2017, 21:57:32 CEST schrieb Andy Yan:
>> setup_boot_mode function use the same logic but different
>> mode register address across all the rockchip platforms,
>> so it's better to make this function reused across all the
>> platforms, and let the mode register address setting from
>> the config file.
>>
>> Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
>>
>> ---
>>
>>   arch/arm/include/asm/arch-rockchip/boot_mode.h |  2 ++
>>   arch/arm/mach-rockchip/Kconfig                 | 14 +++++++++++
>>   arch/arm/mach-rockchip/Makefile                |  5 +++-
>>   arch/arm/mach-rockchip/boot_mode.c             | 33 ++++++++++++++++++++++++++
>>   arch/arm/mach-rockchip/rk3036-board.c          | 24 -------------------
>>   arch/arm/mach-rockchip/rk322x-board.c          | 24 -------------------
>>   arch/arm/mach-rockchip/rk3288-board.c          | 25 -------------------
>>   arch/arm/mach-rockchip/rk3399-board.c          | 14 +++++++++++
>>   8 files changed, 67 insertions(+), 74 deletions(-)
>>   create mode 100644 arch/arm/mach-rockchip/boot_mode.c
>>   create mode 100644 arch/arm/mach-rockchip/rk3399-board.c
>>
>> diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h
>> index bd65f60..163b2e7 100644
>> --- a/arch/arm/include/asm/arch-rockchip/boot_mode.h
>> +++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h
>> @@ -16,4 +16,6 @@
>>   /* enter usb mass storage mode */
>>   #define BOOT_UMS		(REBOOT_FLAG + 12)
>>   
>> +int setup_boot_mode(void);
>> +
>>   #endif
>> diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
>> index d9b25d5..527ca60 100644
>> --- a/arch/arm/mach-rockchip/Kconfig
>> +++ b/arch/arm/mach-rockchip/Kconfig
>> @@ -114,6 +114,7 @@ config ROCKCHIP_RK3399
>>   	select SPL_DRIVERS_MISC_SUPPORT
>>   	select ENABLE_ARM_SOC_BOOT0_HOOK
>>   	select DEBUG_UART_BOARD_INIT
>> +	select BOARD_LATE_INIT
>>   	help
>>   	  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
>>   	  and quad-core Cortex-A53.
>> @@ -149,6 +150,19 @@ config TPL_ROCKCHIP_BACK_TO_BROM
>>             SPL will return to the boot rom, which will then load the U-Boot
>>             binary to keep going on.
>>   
>> +config ROCKCHIP_BOOT_MODE_REG
>> +	hex "Rockchip boot mode flag register address"
>> +	default 0x200081c8 if ROCKCHIP_RK3036
>> +	default 0x110005d8 if ROCKCHIP_RK322X
>> +	default 0xff730094 if ROCKCHIP_RK3288
>> +	default 0xff738200 if ROCKCHIP_RK3368
>> +	default 0xff320300 if ROCKCHIP_RK3399
>> +	default 0x10300580 if ROCKCHIP_RV1108
> could you possibly look up if the rk3188 and rk3066 also support
> the subsequent boot to maskrom download mode from the later
> patches and include the register if possible?

Okay, I will add support for them in next version.
>
>
> Thanks
> Heiko
>
>
>
>
diff mbox series

Patch

diff --git a/arch/arm/include/asm/arch-rockchip/boot_mode.h b/arch/arm/include/asm/arch-rockchip/boot_mode.h
index bd65f60..163b2e7 100644
--- a/arch/arm/include/asm/arch-rockchip/boot_mode.h
+++ b/arch/arm/include/asm/arch-rockchip/boot_mode.h
@@ -16,4 +16,6 @@ 
 /* enter usb mass storage mode */
 #define BOOT_UMS		(REBOOT_FLAG + 12)
 
+int setup_boot_mode(void);
+
 #endif
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index d9b25d5..527ca60 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -114,6 +114,7 @@  config ROCKCHIP_RK3399
 	select SPL_DRIVERS_MISC_SUPPORT
 	select ENABLE_ARM_SOC_BOOT0_HOOK
 	select DEBUG_UART_BOARD_INIT
+	select BOARD_LATE_INIT
 	help
 	  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
 	  and quad-core Cortex-A53.
@@ -149,6 +150,19 @@  config TPL_ROCKCHIP_BACK_TO_BROM
           SPL will return to the boot rom, which will then load the U-Boot
           binary to keep going on.
 
+config ROCKCHIP_BOOT_MODE_REG
+	hex "Rockchip boot mode flag register address"
+	default 0x200081c8 if ROCKCHIP_RK3036
+	default 0x110005d8 if ROCKCHIP_RK322X
+	default 0xff730094 if ROCKCHIP_RK3288
+	default 0xff738200 if ROCKCHIP_RK3368
+	default 0xff320300 if ROCKCHIP_RK3399
+	default 0x10300580 if ROCKCHIP_RV1108
+	default 0
+	help
+	  The Soc will enter to different boot mode according to different
+	  value of this register.
+
 config ROCKCHIP_SPL_RESERVE_IRAM
 	hex "Size of IRAM reserved in SPL"
 	default 0x4000
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index 79e9704..b7624cb 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -10,7 +10,6 @@ 
 # the stack-pointer is valid before switching to the U-Boot stack).
 obj-spl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o
 obj-tpl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o

 obj-tpl-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board-tpl.o
 obj-tpl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-tpl.o
 
@@ -22,10 +21,14 @@  obj-spl-$(CONFIG_ROCKCHIP_RK3368) += rk3368-board-spl.o spl-boot-order.o
 obj-spl-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board-spl.o spl-boot-order.o
 
 ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
+ifneq ($(CONFIG_ROCKCHIP_BOOT_MODE_REG),0)
+obj-y += boot_mode.o
+endif
 obj-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board.o
 obj-$(CONFIG_ROCKCHIP_RK322X) += rk322x-board.o
 obj-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board.o
 obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board.o
+obj-$(CONFIG_ROCKCHIP_RK3399) += rk3399-board.o
 endif
 
 obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c
new file mode 100644
index 0000000..7b3cbc5
--- /dev/null
+++ b/arch/arm/mach-rockchip/boot_mode.c
@@ -0,0 +1,33 @@ 
+/*
+ * (C) Copyright 2016 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/boot_mode.h>
+
+int setup_boot_mode(void)
+{
+	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
+	int boot_mode = readl(reg);
+
+	debug("boot mode %x.\n", boot_mode);
+
+	/* Clear boot mode */
+	writel(BOOT_NORMAL, reg);
+
+	switch (boot_mode) {
+	case BOOT_FASTBOOT:
+		printf("enter fastboot!\n");
+		env_set("preboot", "setenv preboot; fastboot usb0");
+		break;
+	case BOOT_UMS:
+		printf("enter UMS!\n");
+		env_set("preboot", "setenv preboot; ums mmc 0");
+		break;
+	}
+
+	return 0;
+}
diff --git a/arch/arm/mach-rockchip/rk3036-board.c b/arch/arm/mach-rockchip/rk3036-board.c
index a3457f3..a5d2571 100644
--- a/arch/arm/mach-rockchip/rk3036-board.c
+++ b/arch/arm/mach-rockchip/rk3036-board.c
@@ -19,30 +19,6 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE	0x20008000
-
-static void setup_boot_mode(void)
-{
-	struct rk3036_grf *const grf = (void *)GRF_BASE;
-	int boot_mode = readl(&grf->os_reg[4]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &grf->os_reg[4]);
-
-	switch (boot_mode) {
-	case BOOT_FASTBOOT:
-		printf("enter fastboot!\n");
-		env_set("preboot", "setenv preboot; fastboot usb0");
-		break;
-	case BOOT_UMS:
-		printf("enter UMS!\n");
-		env_set("preboot", "setenv preboot; ums mmc 0");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
diff --git a/arch/arm/mach-rockchip/rk322x-board.c b/arch/arm/mach-rockchip/rk322x-board.c
index c0ac2e9..3af137e 100644
--- a/arch/arm/mach-rockchip/rk322x-board.c
+++ b/arch/arm/mach-rockchip/rk322x-board.c
@@ -15,30 +15,6 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define GRF_BASE	0x11000000
-
-static void setup_boot_mode(void)
-{
-	struct rk322x_grf *const grf = (void *)GRF_BASE;
-	int boot_mode = readl(&grf->os_reg[4]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &grf->os_reg[4]);
-
-	switch (boot_mode) {
-	case BOOT_FASTBOOT:
-		printf("enter fastboot!\n");
-		env_set("preboot", "setenv preboot; fastboot usb0");
-		break;
-	case BOOT_UMS:
-		printf("enter UMS!\n");
-		env_set("preboot", "setenv preboot; ums mmc 0");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
diff --git a/arch/arm/mach-rockchip/rk3288-board.c b/arch/arm/mach-rockchip/rk3288-board.c
index 278bb40..1c53cca 100644
--- a/arch/arm/mach-rockchip/rk3288-board.c
+++ b/arch/arm/mach-rockchip/rk3288-board.c
@@ -23,31 +23,6 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define PMU_BASE	0xff730000
-
-static void setup_boot_mode(void)
-{
-	struct rk3288_pmu *const pmu = (void *)PMU_BASE;
-	int boot_mode = readl(&pmu->sys_reg[0]);
-
-	debug("boot mode %x.\n", boot_mode);
-
-	/* Clear boot mode */
-	writel(BOOT_NORMAL, &pmu->sys_reg[0]);
-
-	switch (boot_mode) {
-	case BOOT_FASTBOOT:
-		printf("enter fastboot!\n");
-		env_set("preboot", "setenv preboot; fastboot usb0");
-		break;
-	case BOOT_UMS:
-		printf("enter UMS!\n");
-		env_set("preboot", "setenv preboot; if mmc dev 0;"
-		       "then ums mmc 0; else ums mmc 1;fi");
-		break;
-	}
-}
-
 __weak int rk_board_late_init(void)
 {
 	return 0;
diff --git a/arch/arm/mach-rockchip/rk3399-board.c b/arch/arm/mach-rockchip/rk3399-board.c
new file mode 100644
index 0000000..9293843
--- /dev/null
+++ b/arch/arm/mach-rockchip/rk3399-board.c
@@ -0,0 +1,14 @@ 
+/*
+ * Copyright (c) 2017 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/arch/boot_mode.h>
+
+int board_late_init(void)
+{
+	setup_boot_mode();
+	return 0;
+}