[PATCH V4 0/7] Add Additional Boards and Features to RGxx3

From: Chris Morgan macromorgan@hotmail.com
The RGxx3 is a pseudo-device for U-Boot that works for every Anbernic RGxx3 series device on the market. Add support for another series of very similar devices from Powkiddy.
Changes since V3: - Fixed a bug with else/else if logic for board detection (changed a second incorrect "if" to the proper "else if").
Changes since V2: - Modify the mach-rockchip level rockchip_dnl_key_pressed() so that we can also call it in SPL mode and eliminate the board specific function. This requires adding ADC support to SPL. Additionally, I had to change the regulator for the saradc to a fixed regulator and add GPIO and regulator support to SPL. - Move the board specific board_rng_seed to the mach-rockchip level board file so that other rockchip boards with a hardware RNG can benefit. This should only be called if both the Rockchip hardware RNG as well as the rng seed functions are enabled. - Add two new boards (the RG-ARC-D and RG-ARC-S). I removed the previous code review due to the extensive changes made.
Changes since V1: - Update verbiage around function button to say "recovery" mode instead of calling it "maskrom" mode, which has a specific meaning. Also note that recovery function was done in a board specific manner to ensure it can run early. - Update board level documentation for the RGxx3.
Chris Morgan (7): board: rockchip: Refactor panel auto-detect code spl: Add Kconfig options for ADC rockchip: boot_mode: Allow rockchip_dnl_key_pressed() in SPL board: rockchip: Add Recovery Button for Anbernic RGxx3 rockchip: board: Add board_rng_seed() for all Rockchip devices board: rockchip: Add support for new boards to RGxx3 doc: board: anbernic: Update rgxx3 to add new boards
.../arm/dts/rk3566-anbernic-rgxx3-u-boot.dtsi | 11 + arch/arm/mach-rockchip/Makefile | 4 +- arch/arm/mach-rockchip/board.c | 32 +++ arch/arm/mach-rockchip/boot_mode.c | 11 +- board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 194 +++++++++++------- common/spl/Kconfig | 7 + configs/anbernic-rgxx3-rk3566_defconfig | 16 +- doc/board/anbernic/rgxx3.rst | 20 +- drivers/Makefile | 1 + drivers/adc/Makefile | 2 +- include/configs/anbernic-rgxx3-rk3566.h | 2 + 11 files changed, 210 insertions(+), 90 deletions(-)

From: Chris Morgan macromorgan@hotmail.com
Make the inability to detect a panel using the auto detection code not fail the entire boot process. This means that if the panel ID cannot be read we don't set an environment variable for the panel, and if an environment variable for the panel is not set we don't attempt to update the compatible string. Changes to the code also ensure that when there are multiple compatible strings required for the panel we use them both, which solves some issues that will pop up soon for the Linux driver.
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 115 +++++++++++++-------- 1 file changed, 74 insertions(+), 41 deletions(-)
diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 3f1a42d184..3d0c614623 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -40,6 +40,7 @@ struct rg3xx_model { const char *board; const char *board_name; const char *fdtfile; + const bool detect_panel; };
enum rgxx3_device_id { @@ -54,52 +55,67 @@ enum rgxx3_device_id {
static const struct rg3xx_model rg3xx_model_details[] = { [RG353M] = { - 517, /* Observed average from device */ - "rk3566-anbernic-rg353m", - "RG353M", - DTB_DIR "rk3566-anbernic-rg353p.dtb", /* Identical devices */ + .adc_value = 517, /* Observed average from device */ + .board = "rk3566-anbernic-rg353m", + .board_name = "RG353M", + /* Device is identical to RG353P. */ + .fdtfile = DTB_DIR "rk3566-anbernic-rg353p.dtb", + .detect_panel = 1, }, [RG353P] = { - 860, /* Documented value of 860 */ - "rk3566-anbernic-rg353p", - "RG353P", - DTB_DIR "rk3566-anbernic-rg353p.dtb", + .adc_value = 860, /* Documented value of 860 */ + .board = "rk3566-anbernic-rg353p", + .board_name = "RG353P", + .fdtfile = DTB_DIR "rk3566-anbernic-rg353p.dtb", + .detect_panel = 1, }, [RG353V] = { - 695, /* Observed average from device */ - "rk3566-anbernic-rg353v", - "RG353V", - DTB_DIR "rk3566-anbernic-rg353v.dtb", + .adc_value = 695, /* Observed average from device */ + .board = "rk3566-anbernic-rg353v", + .board_name = "RG353V", + .fdtfile = DTB_DIR "rk3566-anbernic-rg353v.dtb", + .detect_panel = 1, }, [RG503] = { - 1023, /* Observed average from device */ - "rk3566-anbernic-rg503", - "RG503", - DTB_DIR "rk3566-anbernic-rg503.dtb", + .adc_value = 1023, /* Observed average from device */ + .board = "rk3566-anbernic-rg503", + .board_name = "RG503", + .fdtfile = DTB_DIR "rk3566-anbernic-rg503.dtb", + .detect_panel = 0, }, /* Devices with duplicate ADC value */ [RG353PS] = { - 860, /* Observed average from device */ - "rk3566-anbernic-rg353ps", - "RG353PS", - DTB_DIR "rk3566-anbernic-rg353ps.dtb", + .adc_value = 860, /* Observed average from device */ + .board = "rk3566-anbernic-rg353ps", + .board_name = "RG353PS", + .fdtfile = DTB_DIR "rk3566-anbernic-rg353ps.dtb", + .detect_panel = 1, }, [RG353VS] = { - 695, /* Gathered from second hand information */ - "rk3566-anbernic-rg353vs", - "RG353VS", - DTB_DIR "rk3566-anbernic-rg353vs.dtb", + .adc_value = 695, /* Gathered from second hand information */ + .board = "rk3566-anbernic-rg353vs", + .board_name = "RG353VS", + .fdtfile = DTB_DIR "rk3566-anbernic-rg353vs.dtb", + .detect_panel = 1, }, };
struct rg353_panel { const u16 id; - const char *panel_compat; + const char *panel_compat[2]; };
static const struct rg353_panel rg353_panel_details[] = { - { .id = 0x3052, .panel_compat = "newvision,nv3051d"}, - { .id = 0x3821, .panel_compat = "anbernic,rg353v-panel-v2"}, + { + .id = 0x3052, + .panel_compat[0] = "anbernic,rg353p-panel", + .panel_compat[1] = "newvision,nv3051d", + }, + { + .id = 0x3821, + .panel_compat[0] = "anbernic,rg353v-panel-v2", + .panel_compat[1] = NULL, + }, };
/* @@ -298,11 +314,10 @@ int rgxx3_detect_display(void) if (!panel) { printf("Unable to identify panel_id %x\n", (panel_id[0] << 8) | panel_id[1]); - env_set("panel", "unknown"); return -EINVAL; }
- env_set("panel", panel->panel_compat); + env_set("panel", panel->panel_compat[0]);
return 0; } @@ -367,13 +382,14 @@ int rgxx3_detect_device(void) rg3xx_model_details[board_id].board_name); env_set("fdtfile", rg3xx_model_details[board_id].fdtfile);
- /* Detect the panel type for any device that isn't a 503. */ - if (board_id == RG503) + /* Skip panel detection for when it is not needed. */ + if (!rg3xx_model_details[board_id].detect_panel) return 0;
+ /* Warn but don't fail for errors in auto-detection of the panel. */ ret = rgxx3_detect_display(); if (ret) - return ret; + printf("Failed to detect panel type\n");
return 0; } @@ -400,7 +416,8 @@ int rk_board_late_init(void)
int ft_board_setup(void *blob, struct bd_info *bd) { - int node, ret; + const struct rg353_panel *panel = NULL; + int node, ret, i; char *env;
/* No fixups necessary for the RG503 */ @@ -414,6 +431,12 @@ int ft_board_setup(void *blob, struct bd_info *bd) rg3xx_model_details[RG353M].board_name, sizeof(rg3xx_model_details[RG353M].board_name));
+ env = env_get("panel"); + if (!env) { + printf("Can't get panel env\n"); + return 0; + } + /* * Check if the environment variable doesn't equal the panel. * If it doesn't, update the devicetree to the correct panel. @@ -424,12 +447,6 @@ int ft_board_setup(void *blob, struct bd_info *bd) return -ENODEV; }
- env = env_get("panel"); - if (!env) { - printf("Can't get panel env\n"); - return -ENODEV; - } - ret = fdt_node_check_compatible(blob, node, env); if (ret < 0) return -ENODEV; @@ -438,8 +455,24 @@ int ft_board_setup(void *blob, struct bd_info *bd) if (!ret) return 0;
- do_fixup_by_path_string(blob, "/dsi@fe060000/panel@0", - "compatible", env); + /* Panels don't match, search by first compatible value. */ + for (i = 0; i < ARRAY_SIZE(rg353_panel_details); i++) { + if (!strcmp(env, rg353_panel_details[i].panel_compat[0])) { + panel = &rg353_panel_details[i]; + break; + } + } + + if (!panel) { + printf("Unable to identify panel by compat string\n"); + return -ENODEV; + } + + /* Set the compatible with the auto-detected values */ + fdt_setprop_string(blob, node, "compatible", panel->panel_compat[0]); + if (panel->panel_compat[1]) + fdt_appendprop_string(blob, node, "compatible", + panel->panel_compat[1]);
return 0; }

On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morgan macromorgan@hotmail.com
Make the inability to detect a panel using the auto detection code not fail the entire boot process. This means that if the panel ID cannot be read we don't set an environment variable for the panel, and if an environment variable for the panel is not set we don't attempt to update the compatible string. Changes to the code also ensure that when there are multiple compatible strings required for the panel we use them both, which solves some issues that will pop up soon for the Linux driver.
Signed-off-by: Chris Morgan macromorgan@hotmail.com
Reviewed-by: Kever Yang kever.yang@rock-chips.com
Thanks, - Kever
board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 115 +++++++++++++-------- 1 file changed, 74 insertions(+), 41 deletions(-)
diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 3f1a42d184..3d0c614623 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -40,6 +40,7 @@ struct rg3xx_model { const char *board; const char *board_name; const char *fdtfile;
const bool detect_panel; };
enum rgxx3_device_id {
@@ -54,52 +55,67 @@ enum rgxx3_device_id {
static const struct rg3xx_model rg3xx_model_details[] = { [RG353M] = {
517, /* Observed average from device */
"rk3566-anbernic-rg353m",
"RG353M",
DTB_DIR "rk3566-anbernic-rg353p.dtb", /* Identical devices */
.adc_value = 517, /* Observed average from device */
.board = "rk3566-anbernic-rg353m",
.board_name = "RG353M",
/* Device is identical to RG353P. */
.fdtfile = DTB_DIR "rk3566-anbernic-rg353p.dtb",
}, [RG353P] = {.detect_panel = 1,
860, /* Documented value of 860 */
"rk3566-anbernic-rg353p",
"RG353P",
DTB_DIR "rk3566-anbernic-rg353p.dtb",
.adc_value = 860, /* Documented value of 860 */
.board = "rk3566-anbernic-rg353p",
.board_name = "RG353P",
.fdtfile = DTB_DIR "rk3566-anbernic-rg353p.dtb",
}, [RG353V] = {.detect_panel = 1,
695, /* Observed average from device */
"rk3566-anbernic-rg353v",
"RG353V",
DTB_DIR "rk3566-anbernic-rg353v.dtb",
.adc_value = 695, /* Observed average from device */
.board = "rk3566-anbernic-rg353v",
.board_name = "RG353V",
.fdtfile = DTB_DIR "rk3566-anbernic-rg353v.dtb",
}, [RG503] = {.detect_panel = 1,
1023, /* Observed average from device */
"rk3566-anbernic-rg503",
"RG503",
DTB_DIR "rk3566-anbernic-rg503.dtb",
.adc_value = 1023, /* Observed average from device */
.board = "rk3566-anbernic-rg503",
.board_name = "RG503",
.fdtfile = DTB_DIR "rk3566-anbernic-rg503.dtb",
}, /* Devices with duplicate ADC value */ [RG353PS] = {.detect_panel = 0,
860, /* Observed average from device */
"rk3566-anbernic-rg353ps",
"RG353PS",
DTB_DIR "rk3566-anbernic-rg353ps.dtb",
.adc_value = 860, /* Observed average from device */
.board = "rk3566-anbernic-rg353ps",
.board_name = "RG353PS",
.fdtfile = DTB_DIR "rk3566-anbernic-rg353ps.dtb",
}, [RG353VS] = {.detect_panel = 1,
695, /* Gathered from second hand information */
"rk3566-anbernic-rg353vs",
"RG353VS",
DTB_DIR "rk3566-anbernic-rg353vs.dtb",
.adc_value = 695, /* Gathered from second hand information */
.board = "rk3566-anbernic-rg353vs",
.board_name = "RG353VS",
.fdtfile = DTB_DIR "rk3566-anbernic-rg353vs.dtb",
.detect_panel = 1,
}, };
struct rg353_panel { const u16 id;
- const char *panel_compat;
const char *panel_compat[2]; };
static const struct rg353_panel rg353_panel_details[] = {
- { .id = 0x3052, .panel_compat = "newvision,nv3051d"},
- { .id = 0x3821, .panel_compat = "anbernic,rg353v-panel-v2"},
{
.id = 0x3052,
.panel_compat[0] = "anbernic,rg353p-panel",
.panel_compat[1] = "newvision,nv3051d",
},
{
.id = 0x3821,
.panel_compat[0] = "anbernic,rg353v-panel-v2",
.panel_compat[1] = NULL,
}, };
/*
@@ -298,11 +314,10 @@ int rgxx3_detect_display(void) if (!panel) { printf("Unable to identify panel_id %x\n", (panel_id[0] << 8) | panel_id[1]);
env_set("panel", "unknown");
return -EINVAL; }
env_set("panel", panel->panel_compat);
env_set("panel", panel->panel_compat[0]);
return 0; }
@@ -367,13 +382,14 @@ int rgxx3_detect_device(void) rg3xx_model_details[board_id].board_name); env_set("fdtfile", rg3xx_model_details[board_id].fdtfile);
- /* Detect the panel type for any device that isn't a 503. */
- if (board_id == RG503)
/* Skip panel detection for when it is not needed. */
if (!rg3xx_model_details[board_id].detect_panel) return 0;
/* Warn but don't fail for errors in auto-detection of the panel. */ ret = rgxx3_detect_display(); if (ret)
return ret;
printf("Failed to detect panel type\n");
return 0; }
@@ -400,7 +416,8 @@ int rk_board_late_init(void)
int ft_board_setup(void *blob, struct bd_info *bd) {
- int node, ret;
const struct rg353_panel *panel = NULL;
int node, ret, i; char *env;
/* No fixups necessary for the RG503 */
@@ -414,6 +431,12 @@ int ft_board_setup(void *blob, struct bd_info *bd) rg3xx_model_details[RG353M].board_name, sizeof(rg3xx_model_details[RG353M].board_name));
- env = env_get("panel");
- if (!env) {
printf("Can't get panel env\n");
return 0;
- }
- /*
- Check if the environment variable doesn't equal the panel.
- If it doesn't, update the devicetree to the correct panel.
@@ -424,12 +447,6 @@ int ft_board_setup(void *blob, struct bd_info *bd) return -ENODEV; }
- env = env_get("panel");
- if (!env) {
printf("Can't get panel env\n");
return -ENODEV;
- }
- ret = fdt_node_check_compatible(blob, node, env); if (ret < 0) return -ENODEV;
@@ -438,8 +455,24 @@ int ft_board_setup(void *blob, struct bd_info *bd) if (!ret) return 0;
- do_fixup_by_path_string(blob, "/dsi@fe060000/panel@0",
"compatible", env);
/* Panels don't match, search by first compatible value. */
for (i = 0; i < ARRAY_SIZE(rg353_panel_details); i++) {
if (!strcmp(env, rg353_panel_details[i].panel_compat[0])) {
panel = &rg353_panel_details[i];
break;
}
}
if (!panel) {
printf("Unable to identify panel by compat string\n");
return -ENODEV;
}
/* Set the compatible with the auto-detected values */
fdt_setprop_string(blob, node, "compatible", panel->panel_compat[0]);
if (panel->panel_compat[1])
fdt_appendprop_string(blob, node, "compatible",
panel->panel_compat[1]);
return 0; }

From: Chris Morgan macromorgan@hotmail.com
Add kconfig options to enable ADC in SPL
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- common/spl/Kconfig | 7 +++++++ drivers/Makefile | 1 + drivers/adc/Makefile | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig index c521b02f4a..ada9dcea5c 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -579,6 +579,13 @@ config SPL_FIT_IMAGE_TINY ensure this information is available to the next image invoked).
+config SPL_ADC + bool "Support ADC drivers" + help + Enable ADC drivers in SPL. These drivers can allow the reading of + analog values from one or more channels. Enable this option to + build the drivers in drivers/adc as part of an SPL build. + config SPL_CACHE bool "Support CACHE drivers" help diff --git a/drivers/Makefile b/drivers/Makefile index bf73b7718c..81ba2c534e 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+
+obj-$(CONFIG_$(SPL_)ADC) += adc/ obj-$(CONFIG_$(SPL_TPL_)BIOSEMU) += bios_emulator/ obj-$(CONFIG_$(SPL_TPL_)BLK) += block/ obj-$(CONFIG_$(SPL_TPL_)BOOTCOUNT_LIMIT) += bootcount/ diff --git a/drivers/adc/Makefile b/drivers/adc/Makefile index 5336c82097..9eb07769b0 100644 --- a/drivers/adc/Makefile +++ b/drivers/adc/Makefile @@ -4,7 +4,7 @@ # Przemyslaw Marczak p.marczak@samsung.com #
-obj-$(CONFIG_ADC) += adc-uclass.o +obj-$(CONFIG_$(SPL_)ADC) += adc-uclass.o obj-$(CONFIG_ADC_EXYNOS) += exynos-adc.o obj-$(CONFIG_ADC_SANDBOX) += sandbox.o obj-$(CONFIG_SARADC_ROCKCHIP) += rockchip-saradc.o

From: Chris Morgan macromorgan@hotmail.com
Update the rockchip_dnl_key_pressed() so that it can run in SPL. Also change the ADC channel to a define that can be overridden by a board specific option.
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- arch/arm/mach-rockchip/Makefile | 4 ++-- arch/arm/mach-rockchip/boot_mode.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 1dc92066bb..ff089ae949 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -15,13 +15,13 @@ obj-tpl-$(CONFIG_ROCKCHIP_PX30) += px30-board-tpl.o
obj-spl-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board-spl.o
-ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) - # Always include boot_mode.o, as we bypass it (i.e. turn it off) # inside of boot_mode.c when CONFIG_ROCKCHIP_BOOT_MODE_REG is 0. This way, # we can have the preprocessor correctly recognise both 0x0 and 0 # meaning "turn it off". obj-y += boot_mode.o + +ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o obj-$(CONFIG_MISC_INIT_R) += misc.o endif diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index eb8f65ae4e..d2308768be 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -38,6 +38,10 @@ void set_back_to_bootrom_dnl_flag(void) #define KEY_DOWN_MIN_VAL 0 #define KEY_DOWN_MAX_VAL 30
+#ifndef RK_DNL_ADC_CHAN +#define RK_DNL_ADC_CHAN 1 +#endif + __weak int rockchip_dnl_key_pressed(void) { unsigned int val; @@ -52,7 +56,8 @@ __weak int rockchip_dnl_key_pressed(void) ret = -ENODEV; uclass_foreach_dev(dev, uc) { if (!strncmp(dev->name, "saradc", 6)) { - ret = adc_channel_single_shot(dev->name, 1, &val); + ret = adc_channel_single_shot(dev->name, + RK_DNL_ADC_CHAN, &val); break; } } @@ -73,11 +78,13 @@ __weak int rockchip_dnl_key_pressed(void)
void rockchip_dnl_mode_check(void) { +#if CONFIG_IS_ENABLED(ADC) if (rockchip_dnl_key_pressed()) { printf("download key pressed, entering download mode..."); set_back_to_bootrom_dnl_flag(); do_reset(NULL, 0, 0, NULL); } +#endif }
int setup_boot_mode(void) @@ -90,6 +97,7 @@ int setup_boot_mode(void) boot_mode = readl(reg); debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
+#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) /* Clear boot mode */ writel(BOOT_NORMAL, reg);
@@ -103,6 +111,7 @@ int setup_boot_mode(void) env_set("preboot", "setenv preboot; ums mmc 0"); break; } +#endif
return 0; }

Hi Chris,
On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morgan macromorgan@hotmail.com
Update the rockchip_dnl_key_pressed() so that it can run in SPL. Also change the ADC channel to a define that can be overridden by a board specific option.
I should ask this earlier.
Why you have to enable the download key in SPL?
This works for a long time in U-Boot proper, both mainline and downstream vendor U-Boot,
no one is detect this download key in SPL.
In theory the SPL can implement all the feature which is available in U-Boot proper,
but it would be better to make the SPL focus on the job it should be done and keep as small as possible.
Thanks,
- Kever
Signed-off-by: Chris Morgan macromorgan@hotmail.com
arch/arm/mach-rockchip/Makefile | 4 ++-- arch/arm/mach-rockchip/boot_mode.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 1dc92066bb..ff089ae949 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -15,13 +15,13 @@ obj-tpl-$(CONFIG_ROCKCHIP_PX30) += px30-board-tpl.o
obj-spl-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board-spl.o
-ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
- # Always include boot_mode.o, as we bypass it (i.e. turn it off) # inside of boot_mode.c when CONFIG_ROCKCHIP_BOOT_MODE_REG is 0. This way, # we can have the preprocessor correctly recognise both 0x0 and 0 # meaning "turn it off". obj-y += boot_mode.o
+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o obj-$(CONFIG_MISC_INIT_R) += misc.o endif diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index eb8f65ae4e..d2308768be 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -38,6 +38,10 @@ void set_back_to_bootrom_dnl_flag(void) #define KEY_DOWN_MIN_VAL 0 #define KEY_DOWN_MAX_VAL 30
+#ifndef RK_DNL_ADC_CHAN +#define RK_DNL_ADC_CHAN 1 +#endif
- __weak int rockchip_dnl_key_pressed(void) { unsigned int val;
@@ -52,7 +56,8 @@ __weak int rockchip_dnl_key_pressed(void) ret = -ENODEV; uclass_foreach_dev(dev, uc) { if (!strncmp(dev->name, "saradc", 6)) {
ret = adc_channel_single_shot(dev->name, 1, &val);
ret = adc_channel_single_shot(dev->name,
} }RK_DNL_ADC_CHAN, &val); break;
@@ -73,11 +78,13 @@ __weak int rockchip_dnl_key_pressed(void)
void rockchip_dnl_mode_check(void) { +#if CONFIG_IS_ENABLED(ADC) if (rockchip_dnl_key_pressed()) { printf("download key pressed, entering download mode..."); set_back_to_bootrom_dnl_flag(); do_reset(NULL, 0, 0, NULL); } +#endif }
int setup_boot_mode(void) @@ -90,6 +97,7 @@ int setup_boot_mode(void) boot_mode = readl(reg); debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
+#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) /* Clear boot mode */ writel(BOOT_NORMAL, reg);
@@ -103,6 +111,7 @@ int setup_boot_mode(void) env_set("preboot", "setenv preboot; ums mmc 0"); break; } +#endif
return 0; }

On Thu, Jan 18, 2024 at 03:20:52PM +0800, Kever Yang wrote:
Hi Chris,
On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morgan macromorgan@hotmail.com
Update the rockchip_dnl_key_pressed() so that it can run in SPL. Also change the ADC channel to a define that can be overridden by a board specific option.
I should ask this earlier.
Why you have to enable the download key in SPL?
This works for a long time in U-Boot proper, both mainline and downstream vendor U-Boot,
no one is detect this download key in SPL.
In theory the SPL can implement all the feature which is available in U-Boot proper,
but it would be better to make the SPL focus on the job it should be done and keep as small as possible.
I wanted this code to run as soon as possible in the event of a bad write. I have some devices which lack a way to bypass the eMMC in the boot path; the fear is that if an SPL stage is written with a good header but a bad payload (or if the A-TF does something wrong) the device will become unbootable. If we can't do it this way for all Rockchip boards that's fine, but I REALLY want to at least do it this way for the Powkiddy X55 board and the Anbernic RGxx3 board.
While I have you, I have a related question I hope you can help with. Is there any way to utilize the boot partitions of an eMMC device? I don't know if the BROM of an RK3568 or RK3588 is capable, but I'd love to have the SPL and U-Boot stages written to the eMMC boot partitions instead of the user partition if I can.
Thank you.
Thanks,
- Kever
Signed-off-by: Chris Morgan macromorgan@hotmail.com
arch/arm/mach-rockchip/Makefile | 4 ++-- arch/arm/mach-rockchip/boot_mode.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 1dc92066bb..ff089ae949 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -15,13 +15,13 @@ obj-tpl-$(CONFIG_ROCKCHIP_PX30) += px30-board-tpl.o obj-spl-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board-spl.o -ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
- # Always include boot_mode.o, as we bypass it (i.e. turn it off) # inside of boot_mode.c when CONFIG_ROCKCHIP_BOOT_MODE_REG is 0. This way, # we can have the preprocessor correctly recognise both 0x0 and 0 # meaning "turn it off". obj-y += boot_mode.o
+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o obj-$(CONFIG_MISC_INIT_R) += misc.o endif diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index eb8f65ae4e..d2308768be 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -38,6 +38,10 @@ void set_back_to_bootrom_dnl_flag(void) #define KEY_DOWN_MIN_VAL 0 #define KEY_DOWN_MAX_VAL 30 +#ifndef RK_DNL_ADC_CHAN +#define RK_DNL_ADC_CHAN 1 +#endif
- __weak int rockchip_dnl_key_pressed(void) { unsigned int val;
@@ -52,7 +56,8 @@ __weak int rockchip_dnl_key_pressed(void) ret = -ENODEV; uclass_foreach_dev(dev, uc) { if (!strncmp(dev->name, "saradc", 6)) {
ret = adc_channel_single_shot(dev->name, 1, &val);
ret = adc_channel_single_shot(dev->name,
} }RK_DNL_ADC_CHAN, &val); break;
@@ -73,11 +78,13 @@ __weak int rockchip_dnl_key_pressed(void) void rockchip_dnl_mode_check(void) { +#if CONFIG_IS_ENABLED(ADC) if (rockchip_dnl_key_pressed()) { printf("download key pressed, entering download mode..."); set_back_to_bootrom_dnl_flag(); do_reset(NULL, 0, 0, NULL); } +#endif } int setup_boot_mode(void) @@ -90,6 +97,7 @@ int setup_boot_mode(void) boot_mode = readl(reg); debug("%s: boot mode 0x%08x\n", __func__, boot_mode); +#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) /* Clear boot mode */ writel(BOOT_NORMAL, reg); @@ -103,6 +111,7 @@ int setup_boot_mode(void) env_set("preboot", "setenv preboot; ums mmc 0"); break; } +#endif return 0; }

Hi Chris,
On 2024/1/18 23:06, Chris Morgan wrote:
On Thu, Jan 18, 2024 at 03:20:52PM +0800, Kever Yang wrote:
Hi Chris,
On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morganmacromorgan@hotmail.com
Update the rockchip_dnl_key_pressed() so that it can run in SPL. Also change the ADC channel to a define that can be overridden by a board specific option.
I should ask this earlier.
Why you have to enable the download key in SPL?
This works for a long time in U-Boot proper, both mainline and downstream vendor U-Boot,
no one is detect this download key in SPL.
In theory the SPL can implement all the feature which is available in U-Boot proper,
but it would be better to make the SPL focus on the job it should be done and keep as small as possible.
I wanted this code to run as soon as possible in the event of a bad write. I have some devices which lack a way to bypass the eMMC in the boot path; the fear is that if an SPL stage is written with a good header but a bad payload (or if the A-TF does something wrong) the device will become unbootable. If we can't do it this way for all Rockchip boards that's fine, but I REALLY want to at least do it this way for the Powkiddy X55 board and the Anbernic RGxx3 board.
That's why rockchip platform has two download mode, loader mode(in U-Boot)
and maskRom mode, any error happen before U-Boot should get into maksRom mode.
Most of user/developer only use loader mode because the modules before U-Boot should
be more stable and have very little chance to update, for the module owners before U-Boot,
they are the users of maskRom mode.
If you enable this feature in SPL, the error still have chance to happen during dram init to SPL key detect.
Does these two board has no way to get into eMMC event with hardware rework? any hardware
signal of eMMC CMD/CLK/DATA is OK.
And another way to bypass eMMC is to use SDcard which has higher priority then eMMC in BootRom.
For SPL itself debug, I would suggest to RESET into bootrom download mode if any error happen
and a reset will need.
I pick up patches other than 2,3,4 in this patchset for now.
While I have you, I have a related question I hope you can help with. Is there any way to utilize the boot partitions of an eMMC device? I don't know if the BROM of an RK3568 or RK3588 is capable, but I'd love to have the SPL and U-Boot stages written to the eMMC boot partitions instead of the user partition if I can.
No, Rockchip SoCs does not use the boot partitions of eMMC, only use the user data partition.
Thanks,
- Kever
Thank you.
Thanks,
- Kever
Signed-off-by: Chris Morganmacromorgan@hotmail.com
arch/arm/mach-rockchip/Makefile | 4 ++-- arch/arm/mach-rockchip/boot_mode.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 1dc92066bb..ff089ae949 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -15,13 +15,13 @@ obj-tpl-$(CONFIG_ROCKCHIP_PX30) += px30-board-tpl.o obj-spl-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board-spl.o -ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
- # Always include boot_mode.o, as we bypass it (i.e. turn it off) # inside of boot_mode.c when CONFIG_ROCKCHIP_BOOT_MODE_REG is 0. This way, # we can have the preprocessor correctly recognise both 0x0 and 0 # meaning "turn it off". obj-y += boot_mode.o
+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o obj-$(CONFIG_MISC_INIT_R) += misc.o endif diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index eb8f65ae4e..d2308768be 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -38,6 +38,10 @@ void set_back_to_bootrom_dnl_flag(void) #define KEY_DOWN_MIN_VAL 0 #define KEY_DOWN_MAX_VAL 30 +#ifndef RK_DNL_ADC_CHAN +#define RK_DNL_ADC_CHAN 1 +#endif
- __weak int rockchip_dnl_key_pressed(void) { unsigned int val;
@@ -52,7 +56,8 @@ __weak int rockchip_dnl_key_pressed(void) ret = -ENODEV; uclass_foreach_dev(dev, uc) { if (!strncmp(dev->name, "saradc", 6)) {
ret = adc_channel_single_shot(dev->name, 1, &val);
ret = adc_channel_single_shot(dev->name,
}RK_DNL_ADC_CHAN, &val); break; }
@@ -73,11 +78,13 @@ __weak int rockchip_dnl_key_pressed(void) void rockchip_dnl_mode_check(void) { +#if CONFIG_IS_ENABLED(ADC) if (rockchip_dnl_key_pressed()) { printf("download key pressed, entering download mode..."); set_back_to_bootrom_dnl_flag(); do_reset(NULL, 0, 0, NULL); } +#endif } int setup_boot_mode(void) @@ -90,6 +97,7 @@ int setup_boot_mode(void) boot_mode = readl(reg); debug("%s: boot mode 0x%08x\n", __func__, boot_mode); +#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) /* Clear boot mode */ writel(BOOT_NORMAL, reg); @@ -103,6 +111,7 @@ int setup_boot_mode(void) env_set("preboot", "setenv preboot; ums mmc 0"); break; } +#endif return 0; }

On Fri, Jan 19, 2024 at 05:01:38PM +0800, Kever Yang wrote:
Hi Chris,
On 2024/1/18 23:06, Chris Morgan wrote:
On Thu, Jan 18, 2024 at 03:20:52PM +0800, Kever Yang wrote:
Hi Chris,
On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morganmacromorgan@hotmail.com
Update the rockchip_dnl_key_pressed() so that it can run in SPL. Also change the ADC channel to a define that can be overridden by a board specific option.
I should ask this earlier.
Why you have to enable the download key in SPL?
This works for a long time in U-Boot proper, both mainline and downstream vendor U-Boot,
no one is detect this download key in SPL.
In theory the SPL can implement all the feature which is available in U-Boot proper,
but it would be better to make the SPL focus on the job it should be done and keep as small as possible.
I wanted this code to run as soon as possible in the event of a bad write. I have some devices which lack a way to bypass the eMMC in the boot path; the fear is that if an SPL stage is written with a good header but a bad payload (or if the A-TF does something wrong) the device will become unbootable. If we can't do it this way for all Rockchip boards that's fine, but I REALLY want to at least do it this way for the Powkiddy X55 board and the Anbernic RGxx3 board.
That's why rockchip platform has two download mode, loader mode(in U-Boot)
and maskRom mode, any error happen before U-Boot should get into maksRom mode.
Most of user/developer only use loader mode because the modules before U-Boot should
be more stable and have very little chance to update, for the module owners before U-Boot,
they are the users of maskRom mode.
If you enable this feature in SPL, the error still have chance to happen during dram init to SPL key detect.
Does these two board has no way to get into eMMC event with hardware rework? any hardware
signal of eMMC CMD/CLK/DATA is OK.
A few do not. The error is less likely to occur between RAM init and SPL key detect, but yes it's even possible at this stage.
From my testing using the latest BL31 file from the
rockchip-linux/rkbin github repository I was unable to reboot into maskrom mode after A-TF loaded, the device would just straight reboot. Do you know if A-TF does something that makes reboot into maskrom mode no longer work?
And another way to bypass eMMC is to use SDcard which has higher priority then eMMC in BootRom.
I see in the TRM under section 1.2 that the eMMC is higher in the boot path than SDMMC, and that matches my experience as well. So this wouldn't be a solution sadly.
For SPL itself debug, I would suggest to RESET into bootrom download mode if any error happen
and a reset will need.
I pick up patches other than 2,3,4 in this patchset for now.
While I have you, I have a related question I hope you can help with. Is there any way to utilize the boot partitions of an eMMC device? I don't know if the BROM of an RK3568 or RK3588 is capable, but I'd love to have the SPL and U-Boot stages written to the eMMC boot partitions instead of the user partition if I can.
No, Rockchip SoCs does not use the boot partitions of eMMC, only use the user data partition.
That's unfortunate, but I appreciate the feedback.
Thank you, Chris
Thanks,
- Kever
Thank you.
Thanks,
- Kever
Signed-off-by: Chris Morganmacromorgan@hotmail.com
arch/arm/mach-rockchip/Makefile | 4 ++-- arch/arm/mach-rockchip/boot_mode.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 1dc92066bb..ff089ae949 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -15,13 +15,13 @@ obj-tpl-$(CONFIG_ROCKCHIP_PX30) += px30-board-tpl.o obj-spl-$(CONFIG_ROCKCHIP_RK3036) += rk3036-board-spl.o -ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
- # Always include boot_mode.o, as we bypass it (i.e. turn it off) # inside of boot_mode.c when CONFIG_ROCKCHIP_BOOT_MODE_REG is 0. This way, # we can have the preprocessor correctly recognise both 0x0 and 0 # meaning "turn it off". obj-y += boot_mode.o
+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),) obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o obj-$(CONFIG_MISC_INIT_R) += misc.o endif diff --git a/arch/arm/mach-rockchip/boot_mode.c b/arch/arm/mach-rockchip/boot_mode.c index eb8f65ae4e..d2308768be 100644 --- a/arch/arm/mach-rockchip/boot_mode.c +++ b/arch/arm/mach-rockchip/boot_mode.c @@ -38,6 +38,10 @@ void set_back_to_bootrom_dnl_flag(void) #define KEY_DOWN_MIN_VAL 0 #define KEY_DOWN_MAX_VAL 30 +#ifndef RK_DNL_ADC_CHAN +#define RK_DNL_ADC_CHAN 1 +#endif
- __weak int rockchip_dnl_key_pressed(void) { unsigned int val;
@@ -52,7 +56,8 @@ __weak int rockchip_dnl_key_pressed(void) ret = -ENODEV; uclass_foreach_dev(dev, uc) { if (!strncmp(dev->name, "saradc", 6)) {
ret = adc_channel_single_shot(dev->name, 1, &val);
ret = adc_channel_single_shot(dev->name,
}RK_DNL_ADC_CHAN, &val); break; }
@@ -73,11 +78,13 @@ __weak int rockchip_dnl_key_pressed(void) void rockchip_dnl_mode_check(void) { +#if CONFIG_IS_ENABLED(ADC) if (rockchip_dnl_key_pressed()) { printf("download key pressed, entering download mode..."); set_back_to_bootrom_dnl_flag(); do_reset(NULL, 0, 0, NULL); } +#endif } int setup_boot_mode(void) @@ -90,6 +97,7 @@ int setup_boot_mode(void) boot_mode = readl(reg); debug("%s: boot mode 0x%08x\n", __func__, boot_mode); +#if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) /* Clear boot mode */ writel(BOOT_NORMAL, reg); @@ -103,6 +111,7 @@ int setup_boot_mode(void) env_set("preboot", "setenv preboot; ums mmc 0"); break; } +#endif return 0; }

From: Chris Morgan macromorgan@hotmail.com
Add support for users to enter recovery mode by holding the function button when they power up the device.
Since the device has soldered eMMC and sometimes does not expose a clk pin on the mainboard there is a small chance that a user who flashes a bad bootloader may not be able to recover if the headers themselves are valid. As a result this check is done during spl_early_init() to ensure that it runs as early as possible, and it does so by directly manipulating the ADC hardware in lieu of loading the ADC driver.
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- arch/arm/dts/rk3566-anbernic-rgxx3-u-boot.dtsi | 11 +++++++++++ board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 6 +++++- configs/anbernic-rgxx3-rk3566_defconfig | 16 ++++++++++++---- include/configs/anbernic-rgxx3-rk3566.h | 2 ++ 4 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/arch/arm/dts/rk3566-anbernic-rgxx3-u-boot.dtsi b/arch/arm/dts/rk3566-anbernic-rgxx3-u-boot.dtsi index f986e1941e..e3ab196d22 100644 --- a/arch/arm/dts/rk3566-anbernic-rgxx3-u-boot.dtsi +++ b/arch/arm/dts/rk3566-anbernic-rgxx3-u-boot.dtsi @@ -76,6 +76,12 @@ /delete-property/ clock-names; };
+&saradc { + bootph-all; + vref-supply = <&vcc_sys>; + status = "okay"; +}; + &sdhci { pinctrl-0 = <&emmc_bus8>, <&emmc_clk>, <&emmc_cmd>, <&emmc_datastrobe>, <&emmc_rstnout>; @@ -94,3 +100,8 @@ bootph-all; status = "okay"; }; + +&vcc_sys { + bootph-all; + status = "okay"; +}; diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 3d0c614623..45854709f5 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -5,6 +5,7 @@
#include <abuf.h> #include <adc.h> +#include <asm/arch-rockchip/boot_mode.h> #include <asm/io.h> #include <display.h> #include <dm.h> @@ -119,11 +120,14 @@ static const struct rg353_panel rg353_panel_details[] = { };
/* - * Start LED very early so user knows device is on. Set color + * Check if rockchip_dnl button is pressed and reboot into rockusb if + * true. Start LED very early so user knows device is on. Set color * to red. */ void spl_board_init(void) { + setup_boot_mode(); + /* Set GPIO0_C5, GPIO0_C6, and GPIO0_C7 to output. */ writel(GPIO_WRITEMASK(GPIO_C7 | GPIO_C6 | GPIO_C5) | \ (GPIO_C7 | GPIO_C6 | GPIO_C5), diff --git a/configs/anbernic-rgxx3-rk3566_defconfig b/configs/anbernic-rgxx3-rk3566_defconfig index ed6643d9d4..4e72f75815 100644 --- a/configs/anbernic-rgxx3-rk3566_defconfig +++ b/configs/anbernic-rgxx3-rk3566_defconfig @@ -3,6 +3,7 @@ CONFIG_SKIP_LOWLEVEL_INIT=y CONFIG_COUNTER_FREQUENCY=24000000 CONFIG_ARCH_ROCKCHIP=y CONFIG_TEXT_BASE=0x00a00000 +CONFIG_SPL_GPIO=y CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_NR_DRAM_BANKS=2 @@ -24,7 +25,9 @@ CONFIG_SYS_LOAD_ADDR=0xc00800 CONFIG_DEBUG_UART=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y +CONFIG_SPL_FIT_SIGNATURE=y CONFIG_SPL_LOAD_FIT=y +CONFIG_LEGACY_IMAGE_FORMAT=y CONFIG_OF_BOARD_SETUP=y CONFIG_OF_STDOUT_VIA_ALIAS=y CONFIG_DEFAULT_FDT_FILE="rockchip/rk3566-anbernic-rgxx3.dtb" @@ -32,7 +35,7 @@ CONFIG_DEFAULT_FDT_FILE="rockchip/rk3566-anbernic-rgxx3.dtb" # CONFIG_DISPLAY_CPUINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_BOARD_RNG_SEED=y -CONFIG_SPL_MAX_SIZE=0x20000 +CONFIG_SPL_MAX_SIZE=0x40000 CONFIG_SPL_PAD_TO=0x7f8000 CONFIG_SPL_HAS_BSS_LINKER_SECTION=y CONFIG_SPL_BSS_START_ADDR=0x4000000 @@ -41,6 +44,8 @@ CONFIG_SPL_BOARD_INIT=y # CONFIG_SPL_RAW_IMAGE_SUPPORT is not set # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set CONFIG_SPL_STACK_R=y +CONFIG_SPL_ADC=y +CONFIG_SPL_POWER=y CONFIG_SPL_ATF=y CONFIG_CMD_PWM=y CONFIG_CMD_GPT=y @@ -50,8 +55,10 @@ CONFIG_CMD_MMC=y # CONFIG_SPL_DOS_PARTITION is not set CONFIG_SPL_OF_CONTROL=y CONFIG_OF_LIVE=y +CONFIG_OF_SPL_REMOVE_PROPS="clock-names interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents" CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y # CONFIG_NET is not set +CONFIG_SPL_DM_SEQ_ALIAS=y CONFIG_SPL_REGMAP=y CONFIG_SPL_SYSCON=y CONFIG_SPL_CLK=y @@ -67,13 +74,13 @@ CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y CONFIG_MMC_SDHCI_ROCKCHIP=y CONFIG_PHY_ROCKCHIP_INNO_DSIDPHY=y +CONFIG_SPL_PINCTRL=y CONFIG_DM_PMIC=y CONFIG_DM_PMIC_FAN53555=y CONFIG_PMIC_RK8XX=y -CONFIG_REGULATOR_PWM=y -CONFIG_DM_REGULATOR_GPIO=y +CONFIG_SPL_DM_REGULATOR=y +CONFIG_SPL_DM_REGULATOR_FIXED=y CONFIG_REGULATOR_RK8XX=y -CONFIG_DM_REGULATOR_SCMI=y CONFIG_PWM_ROCKCHIP=y CONFIG_SPL_RAM=y # CONFIG_RAM_ROCKCHIP_DEBUG is not set @@ -89,5 +96,6 @@ CONFIG_VIDEO_ROCKCHIP=y CONFIG_DISPLAY_ROCKCHIP_DW_MIPI=y CONFIG_VIDEO_BRIDGE=y CONFIG_REGEX=y +# CONFIG_RSA is not set CONFIG_ERRNO_STR=y # CONFIG_EFI_LOADER is not set diff --git a/include/configs/anbernic-rgxx3-rk3566.h b/include/configs/anbernic-rgxx3-rk3566.h index 3c4ea4e7d8..2aaac55c06 100644 --- a/include/configs/anbernic-rgxx3-rk3566.h +++ b/include/configs/anbernic-rgxx3-rk3566.h @@ -9,4 +9,6 @@ "stdout=serial,vidconsole\0" \ "stderr=serial,vidconsole\0"
+#define RK_DNL_ADC_CHAN 0 + #endif

From: Chris Morgan macromorgan@hotmail.com
Allow all rockchip devices to use the hardware RNG to seed Linux RNG.
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- arch/arm/mach-rockchip/board.c | 32 ++++++++++++++++++++++ board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 29 -------------------- 2 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c index 57f08e0be0..77145524ea 100644 --- a/arch/arm/mach-rockchip/board.c +++ b/arch/arm/mach-rockchip/board.c @@ -348,3 +348,35 @@ __weak int misc_init_r(void) return ret; } #endif + +#if IS_ENABLED(CONFIG_BOARD_RNG_SEED) && IS_ENABLED(CONFIG_RNG_ROCKCHIP) +#include <rng.h> + +/* Use hardware rng to seed Linux random. */ +__weak int board_rng_seed(struct abuf *buf) +{ + struct udevice *dev; + size_t len = 0x8; + u64 *data; + + data = malloc(len); + if (!data) { + printf("Out of memory\n"); + return -ENOMEM; + } + + if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { + printf("No RNG device\n"); + return -ENODEV; + } + + if (dm_rng_read(dev, data, len)) { + printf("Reading RNG failed\n"); + return -EIO; + } + + abuf_init_set(buf, data, len); + + return 0; +} +#endif diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 45854709f5..7bef5a53f0 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -17,7 +17,6 @@ #include <mmc.h> #include <panel.h> #include <pwm.h> -#include <rng.h> #include <stdlib.h> #include <video_bridge.h>
@@ -137,34 +136,6 @@ void spl_board_init(void) (GPIO0_BASE + GPIO_SWPORT_DR_H)); }
-/* Use hardware rng to seed Linux random. */ -int board_rng_seed(struct abuf *buf) -{ - struct udevice *dev; - size_t len = 0x8; - u64 *data; - - data = malloc(len); - if (!data) { - printf("Out of memory\n"); - return -ENOMEM; - } - - if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { - printf("No RNG device\n"); - return -ENODEV; - } - - if (dm_rng_read(dev, data, len)) { - printf("Reading RNG failed\n"); - return -EIO; - } - - abuf_init_set(buf, data, len); - - return 0; -} - /* * Buzz the buzzer so the user knows something is going on. Make it * optional in case PWM is disabled.

On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morgan macromorgan@hotmail.com
Allow all rockchip devices to use the hardware RNG to seed Linux RNG.
Signed-off-by: Chris Morgan macromorgan@hotmail.com
Reviewed-by: Kever Yang kever.yang@rock-chips.com
Thanks, - Kever
arch/arm/mach-rockchip/board.c | 32 ++++++++++++++++++++++ board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 29 -------------------- 2 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c index 57f08e0be0..77145524ea 100644 --- a/arch/arm/mach-rockchip/board.c +++ b/arch/arm/mach-rockchip/board.c @@ -348,3 +348,35 @@ __weak int misc_init_r(void) return ret; } #endif
+#if IS_ENABLED(CONFIG_BOARD_RNG_SEED) && IS_ENABLED(CONFIG_RNG_ROCKCHIP) +#include <rng.h>
+/* Use hardware rng to seed Linux random. */ +__weak int board_rng_seed(struct abuf *buf) +{
- struct udevice *dev;
- size_t len = 0x8;
- u64 *data;
- data = malloc(len);
- if (!data) {
printf("Out of memory\n");
return -ENOMEM;
- }
- if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
printf("No RNG device\n");
return -ENODEV;
- }
- if (dm_rng_read(dev, data, len)) {
printf("Reading RNG failed\n");
return -EIO;
- }
- abuf_init_set(buf, data, len);
- return 0;
+} +#endif diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 45854709f5..7bef5a53f0 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -17,7 +17,6 @@ #include <mmc.h> #include <panel.h> #include <pwm.h> -#include <rng.h> #include <stdlib.h> #include <video_bridge.h>
@@ -137,34 +136,6 @@ void spl_board_init(void) (GPIO0_BASE + GPIO_SWPORT_DR_H)); }
-/* Use hardware rng to seed Linux random. */ -int board_rng_seed(struct abuf *buf) -{
- struct udevice *dev;
- size_t len = 0x8;
- u64 *data;
- data = malloc(len);
- if (!data) {
printf("Out of memory\n");
return -ENOMEM;
- }
- if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
printf("No RNG device\n");
return -ENODEV;
- }
- if (dm_rng_read(dev, data, len)) {
printf("Reading RNG failed\n");
return -EIO;
- }
- abuf_init_set(buf, data, len);
- return 0;
-}
- /*
- Buzz the buzzer so the user knows something is going on. Make it
- optional in case PWM is disabled.

From: Chris Morgan macromorgan@hotmail.com
Add support for the Anbernic RG-ARC-D, Anbernic RG-ARC-S, Powkiddy RK2023, and Powkiddy RGB30 to the Anbernic RGxx3. While the Powkiddy devices are manufactured by Powkiddy instead of Anbernic, the hardware is so similar they can all use the same bootloader.
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 44 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 7bef5a53f0..e12a85a02a 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -48,9 +48,13 @@ enum rgxx3_device_id { RG353P, RG353V, RG503, + RGB30, + RK2023, + RGARCD, /* Devices with duplicate ADC value */ RG353PS, RG353VS, + RGARCS, };
static const struct rg3xx_model rg3xx_model_details[] = { @@ -83,6 +87,27 @@ static const struct rg3xx_model rg3xx_model_details[] = { .fdtfile = DTB_DIR "rk3566-anbernic-rg503.dtb", .detect_panel = 0, }, + [RGB30] = { + .adc_value = 383, /* Gathered from second hand information */ + .board = "rk3566-powkiddy-rgb30", + .board_name = "RGB30", + .fdtfile = DTB_DIR "rk3566-powkiddy-rgb30.dtb", + .detect_panel = 0, + }, + [RK2023] = { + .adc_value = 635, /* Observed average from device */ + .board = "rk3566-powkiddy-rk2023", + .board_name = "RK2023", + .fdtfile = DTB_DIR "rk3566-powkiddy-rk2023.dtb", + .detect_panel = 0, + }, + [RGARCD] = { + .adc_value = 183, /* Observed average from device */ + .board = "rk3566-anbernic-rg-arc-d", + .board_name = "Anbernic RG ARC-D", + .fdtfile = DTB_DIR "rk3566-anbernic-rg-arc-d.dtb", + .detect_panel = 0, + }, /* Devices with duplicate ADC value */ [RG353PS] = { .adc_value = 860, /* Observed average from device */ @@ -98,6 +123,13 @@ static const struct rg3xx_model rg3xx_model_details[] = { .fdtfile = DTB_DIR "rk3566-anbernic-rg353vs.dtb", .detect_panel = 1, }, + [RGARCS] = { + .adc_value = 183, /* Observed average from device */ + .board = "rk3566-anbernic-rg-arc-s", + .board_name = "Anbernic RG ARC-S", + .fdtfile = DTB_DIR "rk3566-anbernic-rg-arc-s.dtb", + .detect_panel = 0, + }, };
struct rg353_panel { @@ -332,19 +364,21 @@ int rgxx3_detect_device(void) }
/* - * Try to access the eMMC on an RG353V or RG353P. If it's - * missing, it's an RG353VS or RG353PS. Note we could also - * check for a touchscreen at 0x1a on i2c2. + * Try to access the eMMC on an RG353V, RG353P, or RG Arc D. + * If it's missing, it's an RG353VS, RG353PS, or RG Arc S. + * Note we could also check for a touchscreen at 0x1a on i2c2. */ - if (board_id == RG353V || board_id == RG353P) { + if (board_id == RG353V || board_id == RG353P || board_id == RGARCD) { mmc = find_mmc_device(0); if (mmc) { ret = mmc_init(mmc); if (ret) { if (board_id == RG353V) board_id = RG353VS; - else + else if (board_id == RG353P) board_id = RG353PS; + else + board_id = RGARCS; } } }

On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morgan macromorgan@hotmail.com
Add support for the Anbernic RG-ARC-D, Anbernic RG-ARC-S, Powkiddy RK2023, and Powkiddy RGB30 to the Anbernic RGxx3. While the Powkiddy devices are manufactured by Powkiddy instead of Anbernic, the hardware is so similar they can all use the same bootloader.
Signed-off-by: Chris Morgan macromorgan@hotmail.com
Reviewed-by: Kever Yang kever.yang@rock-chips.com
Thanks, - Kever
board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 44 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c index 7bef5a53f0..e12a85a02a 100644 --- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c +++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c @@ -48,9 +48,13 @@ enum rgxx3_device_id { RG353P, RG353V, RG503,
RGB30,
RK2023,
RGARCD, /* Devices with duplicate ADC value */ RG353PS, RG353VS,
RGARCS, };
static const struct rg3xx_model rg3xx_model_details[] = {
@@ -83,6 +87,27 @@ static const struct rg3xx_model rg3xx_model_details[] = { .fdtfile = DTB_DIR "rk3566-anbernic-rg503.dtb", .detect_panel = 0, },
- [RGB30] = {
.adc_value = 383, /* Gathered from second hand information */
.board = "rk3566-powkiddy-rgb30",
.board_name = "RGB30",
.fdtfile = DTB_DIR "rk3566-powkiddy-rgb30.dtb",
.detect_panel = 0,
- },
- [RK2023] = {
.adc_value = 635, /* Observed average from device */
.board = "rk3566-powkiddy-rk2023",
.board_name = "RK2023",
.fdtfile = DTB_DIR "rk3566-powkiddy-rk2023.dtb",
.detect_panel = 0,
- },
- [RGARCD] = {
.adc_value = 183, /* Observed average from device */
.board = "rk3566-anbernic-rg-arc-d",
.board_name = "Anbernic RG ARC-D",
.fdtfile = DTB_DIR "rk3566-anbernic-rg-arc-d.dtb",
.detect_panel = 0,
- }, /* Devices with duplicate ADC value */ [RG353PS] = { .adc_value = 860, /* Observed average from device */
@@ -98,6 +123,13 @@ static const struct rg3xx_model rg3xx_model_details[] = { .fdtfile = DTB_DIR "rk3566-anbernic-rg353vs.dtb", .detect_panel = 1, },
[RGARCS] = {
.adc_value = 183, /* Observed average from device */
.board = "rk3566-anbernic-rg-arc-s",
.board_name = "Anbernic RG ARC-S",
.fdtfile = DTB_DIR "rk3566-anbernic-rg-arc-s.dtb",
.detect_panel = 0,
}, };
struct rg353_panel {
@@ -332,19 +364,21 @@ int rgxx3_detect_device(void) }
/*
* Try to access the eMMC on an RG353V or RG353P. If it's
* missing, it's an RG353VS or RG353PS. Note we could also
* check for a touchscreen at 0x1a on i2c2.
* Try to access the eMMC on an RG353V, RG353P, or RG Arc D.
* If it's missing, it's an RG353VS, RG353PS, or RG Arc S.
*/* Note we could also check for a touchscreen at 0x1a on i2c2.
- if (board_id == RG353V || board_id == RG353P) {
- if (board_id == RG353V || board_id == RG353P || board_id == RGARCD) { mmc = find_mmc_device(0); if (mmc) { ret = mmc_init(mmc); if (ret) { if (board_id == RG353V) board_id = RG353VS;
else
else if (board_id == RG353P) board_id = RG353PS;
else
} }board_id = RGARCS; }

From: Chris Morgan macromorgan@hotmail.com
Update the RGxx3 documentation to note that it now supports the RG-ARC-D, RG-ARC-S, Powkiddy RK2023, and Powkiddy RGB30. Also update verbiage around panel detection to note that it is no longer hard coded to the RG503.
Signed-off-by: Chris Morgan macromorgan@hotmail.com --- doc/board/anbernic/rgxx3.rst | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/doc/board/anbernic/rgxx3.rst b/doc/board/anbernic/rgxx3.rst index 7d1beb423c..d159ed2f76 100644 --- a/doc/board/anbernic/rgxx3.rst +++ b/doc/board/anbernic/rgxx3.rst @@ -5,6 +5,8 @@ U-Boot for Anbernic RGxx3 Devices
This allows U-Boot to boot the following Anbernic devices:
+ - Anbernic RG-ARC-D + - Anbernic RG-ARC-S - Anbernic RG353M - Anbernic RG353P - Anbernic RG353PS @@ -12,18 +14,24 @@ This allows U-Boot to boot the following Anbernic devices: - Anbernic RG353VS - Anbernic RG503
+Additionally, the following very similar non-Anbernic devices are also +supported: + + - Powkiddy RGB30 + - Powkiddy RK2023 + The correct device is detected automatically by comparing ADC values from ADC channel 1. In the event of an RG353V or RG353P, an attempt is then made to probe for an eMMC and if it fails the device is assumed to be an RG353VS or RG353PS. Based on the detected device, the environment variables "board", "board_name", and "fdtfile" are set to the correct values corresponding to the board which can be read by a -boot script to boot with the correct device tree. If the board detected -is not of type RG503 (which currently has only 1 panel revision) a -panel detect is then performed by probing a "dummy" display on the DSI -bus and then querying the display ID. The display ID is then compared -to a table to get the known compatible string for use in Linux, and -this string is saved as an environment variable of "panel". +boot script to boot with the correct device tree. If a board is defined +as requiring panel detection, a panel detect is then performed by +probing a "dummy" display on the DSI bus and then querying the display +ID. The display ID is then compared to a table to get the known +compatible string for use in Linux, and this string is saved as an +environment variable of "panel".
FDT fixups are performed in the event of an RG353M to change the device name, or in the event the panel detected does not match the devicetree.

On 2024/1/2 23:46, Chris Morgan wrote:
From: Chris Morgan macromorgan@hotmail.com
Update the RGxx3 documentation to note that it now supports the RG-ARC-D, RG-ARC-S, Powkiddy RK2023, and Powkiddy RGB30. Also update verbiage around panel detection to note that it is no longer hard coded to the RG503.
Signed-off-by: Chris Morgan macromorgan@hotmail.com
Reviewed-by: Kever Yang kever.yang@rock-chips.com
Thanks, - Kever
doc/board/anbernic/rgxx3.rst | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/doc/board/anbernic/rgxx3.rst b/doc/board/anbernic/rgxx3.rst index 7d1beb423c..d159ed2f76 100644 --- a/doc/board/anbernic/rgxx3.rst +++ b/doc/board/anbernic/rgxx3.rst @@ -5,6 +5,8 @@ U-Boot for Anbernic RGxx3 Devices
This allows U-Boot to boot the following Anbernic devices:
- Anbernic RG-ARC-D
- Anbernic RG-ARC-S
- Anbernic RG353M
- Anbernic RG353P
- Anbernic RG353PS
@@ -12,18 +14,24 @@ This allows U-Boot to boot the following Anbernic devices:
- Anbernic RG353VS
- Anbernic RG503
+Additionally, the following very similar non-Anbernic devices are also +supported:
- Powkiddy RGB30
- Powkiddy RK2023
- The correct device is detected automatically by comparing ADC values from ADC channel 1. In the event of an RG353V or RG353P, an attempt is then made to probe for an eMMC and if it fails the device is assumed to be an RG353VS or RG353PS. Based on the detected device, the environment variables "board", "board_name", and "fdtfile" are set to the correct values corresponding to the board which can be read by a
-boot script to boot with the correct device tree. If the board detected -is not of type RG503 (which currently has only 1 panel revision) a -panel detect is then performed by probing a "dummy" display on the DSI -bus and then querying the display ID. The display ID is then compared -to a table to get the known compatible string for use in Linux, and -this string is saved as an environment variable of "panel". +boot script to boot with the correct device tree. If a board is defined +as requiring panel detection, a panel detect is then performed by +probing a "dummy" display on the DSI bus and then querying the display +ID. The display ID is then compared to a table to get the known +compatible string for use in Linux, and this string is saved as an +environment variable of "panel".
FDT fixups are performed in the event of an RG353M to change the device name, or in the event the panel detected does not match the devicetree.
participants (3)
-
Chris Morgan
-
Chris Morgan
-
Kever Yang