public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH V2 0/4] Add Additional Boards and Features to RGxx3
@ 2023-11-17 21:15 Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code Chris Morgan
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Chris Morgan @ 2023-11-17 21:15 UTC (permalink / raw)
  To: u-boot; +Cc: kever.yang, philipp.tomsich, sjg, Chris Morgan

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 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 (4):
  board: rockchip: Refactor panel auto-detect code
  board: rockchip: Add Recovery Button for Anbernic RGxx3
  board: rockchip: Add support for RGB30 and RK2023 to RGxx3
  doc: board: anbernic: Update rgxx3 to add new boards

 board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 195 ++++++++++++++++-----
 doc/board/anbernic/rgxx3.rst               |  18 +-
 2 files changed, 166 insertions(+), 47 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code
  2023-11-17 21:15 [PATCH V2 0/4] Add Additional Boards and Features to RGxx3 Chris Morgan
@ 2023-11-17 21:15 ` Chris Morgan
  2023-11-18 17:10   ` Simon Glass
  2024-01-17  9:18   ` Kever Yang
  2023-11-17 21:15 ` [PATCH V2 2/4] board: rockchip: Add Recovery Button for Anbernic RGxx3 Chris Morgan
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Chris Morgan @ 2023-11-17 21:15 UTC (permalink / raw)
  To: u-boot; +Cc: kever.yang, philipp.tomsich, sjg, Chris Morgan

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;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V2 2/4] board: rockchip: Add Recovery Button for Anbernic RGxx3
  2023-11-17 21:15 [PATCH V2 0/4] Add Additional Boards and Features to RGxx3 Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code Chris Morgan
@ 2023-11-17 21:15 ` Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 3/4] board: rockchip: Add support for RGB30 and RK2023 to RGxx3 Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 4/4] doc: board: anbernic: Update rgxx3 to add new boards Chris Morgan
  3 siblings, 0 replies; 8+ messages in thread
From: Chris Morgan @ 2023-11-17 21:15 UTC (permalink / raw)
  To: u-boot; +Cc: kever.yang, philipp.tomsich, sjg, Chris Morgan

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.

Ideally, once we have an open source TPL stage we can move this to
the TPL stage, so it will run even earlier. It may also be possible
to make this code "more portable", but at the tradeoff of requiring
to be run later in the boot process. For now it's done in a board
specific way to err on the side of "do it early".

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
 board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 64 ++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c
index 3d0c614623..a93b11cd47 100644
--- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c
+++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c
@@ -6,12 +6,14 @@
 #include <abuf.h>
 #include <adc.h>
 #include <asm/io.h>
+#include <command.h>
 #include <display.h>
 #include <dm.h>
 #include <dm/lists.h>
 #include <env.h>
 #include <fdt_support.h>
 #include <linux/delay.h>
+#include <linux/iopoll.h>
 #include <mipi_dsi.h>
 #include <mmc.h>
 #include <panel.h>
@@ -20,6 +22,8 @@
 #include <stdlib.h>
 #include <video_bridge.h>
 
+#define BOOT_BROM_DOWNLOAD	0xef08a53c
+
 #define GPIO0_BASE		0xfdd60000
 #define GPIO4_BASE		0xfe770000
 #define GPIO_SWPORT_DR_L	0x0000
@@ -33,6 +37,14 @@
 
 #define GPIO_WRITEMASK(bits)	((bits) << 16)
 
+#define SARADC_BASE		0xfe720000
+#define SARADC_DATA		0x0000
+#define SARADC_STAS		0x0004
+#define SARADC_ADC_STATUS	BIT(0)
+#define SARADC_CTRL		0x0008
+#define SARADC_INPUT_SRC_MSK	0x7
+#define SARADC_POWER_CTRL	BIT(3)
+
 #define DTB_DIR			"rockchip/"
 
 struct rg3xx_model {
@@ -118,12 +130,64 @@ static const struct rg353_panel rg353_panel_details[] = {
 	},
 };
 
+/*
+ * The device has internal eMMC, and while some devices have an exposed
+ * clk pin you can ground to force a bypass not all devices do. As a
+ * result it may be possible for some devices to become a perma-brick
+ * if a corrupted TPL or SPL stage with a valid header is flashed to
+ * the internal eMMC. Add functionality to read ADC channel 0 (the func
+ * button) as early as possible in the boot process to provide some
+ * protection against this. If we ever get an open TPL stage, we should
+ * consider moving this function there.
+ */
+void read_func_button(void)
+{
+	int ret;
+	u32 reg;
+
+	/* Turn off SARADC to reset it. */
+	writel(0, (SARADC_BASE + SARADC_CTRL));
+
+	/* Enable channel 0 and power on SARADC. */
+	writel(((0 & SARADC_INPUT_SRC_MSK) | SARADC_POWER_CTRL),
+	       (SARADC_BASE + SARADC_CTRL));
+
+	/*
+	 * Wait for data to be ready. Use timeout of 20000us from
+	 * rockchip_saradc driver.
+	 */
+	ret = readl_poll_timeout((SARADC_BASE + SARADC_STAS), reg,
+				 !(reg & SARADC_ADC_STATUS), 20000);
+	if (ret) {
+		printf("ADC Timeout");
+		return;
+	}
+
+	/* Read the data from the SARADC. */
+	reg = readl((SARADC_BASE + SARADC_DATA));
+
+	/* Turn the SARADC back off so it's ready to be used again. */
+	writel(0, (SARADC_BASE + SARADC_CTRL));
+
+	/*
+	 * If the value is less than 30 the button is being pressed.
+	 * Reset the device back into Rockchip download mode.
+	 */
+	if (reg <= 30) {
+		printf("download key pressed, entering download mode...");
+		writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+		do_reset(NULL, 0, 0, NULL);
+	}
+};
+
 /*
  * Start LED very early so user knows device is on. Set color
  * to red.
  */
 void spl_board_init(void)
 {
+	read_func_button();
+
 	/* 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),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V2 3/4] board: rockchip: Add support for RGB30 and RK2023 to RGxx3
  2023-11-17 21:15 [PATCH V2 0/4] Add Additional Boards and Features to RGxx3 Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 2/4] board: rockchip: Add Recovery Button for Anbernic RGxx3 Chris Morgan
@ 2023-11-17 21:15 ` Chris Morgan
  2023-11-17 21:15 ` [PATCH V2 4/4] doc: board: anbernic: Update rgxx3 to add new boards Chris Morgan
  3 siblings, 0 replies; 8+ messages in thread
From: Chris Morgan @ 2023-11-17 21:15 UTC (permalink / raw)
  To: u-boot; +Cc: kever.yang, philipp.tomsich, sjg, Chris Morgan

From: Chris Morgan <macromorgan@hotmail.com>

Add support for the Powkiddy RK2023 and RGB30 to the Anbernic RGxx3.
While these 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>
---
 board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c
index a93b11cd47..dae9dc87c2 100644
--- a/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c
+++ b/board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c
@@ -60,6 +60,8 @@ enum rgxx3_device_id {
 	RG353P,
 	RG353V,
 	RG503,
+	RGB30,
+	RK2023,
 	/* Devices with duplicate ADC value */
 	RG353PS,
 	RG353VS,
@@ -95,6 +97,20 @@ 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,
+	},
 	/* Devices with duplicate ADC value */
 	[RG353PS] = {
 		.adc_value = 860, /* Observed average from device */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V2 4/4] doc: board: anbernic: Update rgxx3 to add new boards
  2023-11-17 21:15 [PATCH V2 0/4] Add Additional Boards and Features to RGxx3 Chris Morgan
                   ` (2 preceding siblings ...)
  2023-11-17 21:15 ` [PATCH V2 3/4] board: rockchip: Add support for RGB30 and RK2023 to RGxx3 Chris Morgan
@ 2023-11-17 21:15 ` Chris Morgan
  3 siblings, 0 replies; 8+ messages in thread
From: Chris Morgan @ 2023-11-17 21:15 UTC (permalink / raw)
  To: u-boot; +Cc: kever.yang, philipp.tomsich, sjg, Chris Morgan

From: Chris Morgan <macromorgan@hotmail.com>

Update the RGxx3 documentation to note that it now supports two new
non-Anbernic boards. 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 | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/doc/board/anbernic/rgxx3.rst b/doc/board/anbernic/rgxx3.rst
index 7d1beb423c..89cc4ee560 100644
--- a/doc/board/anbernic/rgxx3.rst
+++ b/doc/board/anbernic/rgxx3.rst
@@ -12,18 +12,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.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code
  2023-11-17 21:15 ` [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code Chris Morgan
@ 2023-11-18 17:10   ` Simon Glass
  2023-11-19  5:00     ` Chris Morgan
  2024-01-17  9:18   ` Kever Yang
  1 sibling, 1 reply; 8+ messages in thread
From: Simon Glass @ 2023-11-18 17:10 UTC (permalink / raw)
  To: Chris Morgan; +Cc: u-boot, kever.yang, philipp.tomsich, Chris Morgan

Hi Chris,

On Fri, 17 Nov 2023 at 14:15, Chris Morgan <macroalpha82@gmail.com> 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>
> ---
>  board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 115 +++++++++++++--------
>  1 file changed, 74 insertions(+), 41 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

This seems similar to the extension_board command in some ways.

Raspberry Pi has some vaguely similar logic.

I wonder if we could figure out a generic way of handling this?

Regards,
Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code
  2023-11-18 17:10   ` Simon Glass
@ 2023-11-19  5:00     ` Chris Morgan
  0 siblings, 0 replies; 8+ messages in thread
From: Chris Morgan @ 2023-11-19  5:00 UTC (permalink / raw)
  To: Simon Glass; +Cc: u-boot, kever.yang, philipp.tomsich, Chris Morgan

On Sat, Nov 18, 2023 at 10:10:04AM -0700, Simon Glass wrote:
> Hi Chris,
> 
> On Fri, 17 Nov 2023 at 14:15, Chris Morgan <macroalpha82@gmail.com> 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>
> > ---
> >  board/anbernic/rgxx3_rk3566/rgxx3-rk3566.c | 115 +++++++++++++--------
> >  1 file changed, 74 insertions(+), 41 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> This seems similar to the extension_board command in some ways.
> 
> Raspberry Pi has some vaguely similar logic.
> 
> I wonder if we could figure out a generic way of handling this?

I was thinking about that. Given I need it to run so early and with as
few dependencies as possible, for my specific use case I think this way
makes the most sense. However, a quick way to get into recovery mode
for other devices would be desirable, and I think the best way to
accomplish that would be to have a way to set the ADC channel for the
rockchip_dnl_key_pressed() routine via a config option or a board
specific define of some kind instead of setting it permanently at
channel 1 (for all but one of the rk3566 boards I've messed with so far
it would be ADC channel 0 for such a button; ADC channel 1 is used for
board identification).

Thank you,
Chris

> 
> Regards,
> Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code
  2023-11-17 21:15 ` [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code Chris Morgan
  2023-11-18 17:10   ` Simon Glass
@ 2024-01-17  9:18   ` Kever Yang
  1 sibling, 0 replies; 8+ messages in thread
From: Kever Yang @ 2024-01-17  9:18 UTC (permalink / raw)
  To: Chris Morgan, u-boot; +Cc: philipp.tomsich, sjg, Chris Morgan


On 2023/11/18 05:15, 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",
> +		.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;
>   }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-17  9:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 21:15 [PATCH V2 0/4] Add Additional Boards and Features to RGxx3 Chris Morgan
2023-11-17 21:15 ` [PATCH V2 1/4] board: rockchip: Refactor panel auto-detect code Chris Morgan
2023-11-18 17:10   ` Simon Glass
2023-11-19  5:00     ` Chris Morgan
2024-01-17  9:18   ` Kever Yang
2023-11-17 21:15 ` [PATCH V2 2/4] board: rockchip: Add Recovery Button for Anbernic RGxx3 Chris Morgan
2023-11-17 21:15 ` [PATCH V2 3/4] board: rockchip: Add support for RGB30 and RK2023 to RGxx3 Chris Morgan
2023-11-17 21:15 ` [PATCH V2 4/4] doc: board: anbernic: Update rgxx3 to add new boards Chris Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox