Skip to contentSkip to conversation

rockchip: Add initial RK3582 support

PATCH Superseded Jonas Karlman 2 participants 8 messages Aug 4, 2025 – Aug 11, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover rockchip: Add initial RK3582 support

This series add initial support for RK3582 support. The RK3582 is a variant of the RK3588S with a few ip blocks disabled. What blocks are disabled/non-working is indicated by the ip-state in OTP.

Compared to the vendor U-Boot variant, this mark cpu and gpu with status=fail instead of removing nodes during DT fixup. Linux skip cpu cores marked as failed staring from v5.17-rc1, however the GIC driver will generate a harmless WARN_ON that safely can be ignored. A patch for Linux will be sent to skip the WARN_ON for failed/disabled cpu cores.

Changes in v2:
- Refactor code to first apply policy to ip-state and then fail cores based on the updated ip-state
- Add support for failing rkvdec and rkvenc cores
- Append soc compatible to board model
- Add patch to add support for ROCK 5C Lite variant

Jonas Karlman (3):
rockchip: Add initial RK3582 support
rockchip: rk3588-generic: Enable support for RK3582
rockchip: rk3588s-rock-5c: Add support for ROCK 5C Lite variant

 arch/arm/dts/rk3588-generic.dts        |   4 +-
 arch/arm/mach-rockchip/rk3588/Kconfig  |   9 +-
 arch/arm/mach-rockchip/rk3588/rk3588.c | 221 +++++++++++++++++++++++++
 configs/generic-rk3588_defconfig       |   1 +
 configs/rock-5c-rk3588s_defconfig      |   1 +
 doc/board/rockchip/rockchip.rst        |   4 +-
 6 files changed, 232 insertions(+), 8 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/3 rockchip: Add initial RK3582 support

The RK3582 SoC is a variant of the RK3588S with some IP blocks disabled. What blocks are disabled/non-working is indicated by ip-state in OTP.

This add initial support for RK3582 by using ft_system_setup() to mark any cpu and/or gpu node with status=fail as indicated by ip-state.

This apply same policy as vendor U-Boot for RK3582, i.e. two big cpu cores and the gpu is always failed/disabled.

Enable Kconfig option OF_SYSTEM_SETUP in board defconfig to make use of the required DT fixups for RK3582 board variants.

---
Changes in v2:
- Refactor code to first apply policy to ip-state and then fail cores based on the updated ip-state
- Add support for failing rkvdec and rkvenc cores
- Append soc compatible to board model
- Not picking up t-b tag due to significant changes to patch

---
 arch/arm/mach-rockchip/rk3588/rk3588.c | 221 +++++++++++++++++++++++++
 1 file changed, 221 insertions(+)
arch/arm/mach-rockchip/rk3588/rk3588.c +221 -0
index c01a40020896..3ab0afe0979e 100644
@@ -7,6 +7,7 @@
 #define LOG_CATEGORY LOGC_ARCH
 
 #include <dm.h>
+#include <fdt_support.h>
 #include <misc.h>
 #include <spl.h>
 #include <asm/armv8/mmu.h>
@@ -200,6 +201,16 @@ int arch_cpu_init(void)
 
 #define RK3588_OTP_CPU_CODE_OFFSET		0x02
 #define RK3588_OTP_SPECIFICATION_OFFSET		0x06
+#define RK3588_OTP_IP_STATE_OFFSET		0x1d
+
+#define FAIL_CPU_CLUSTER0		GENMASK(3, 0)
+#define FAIL_CPU_CLUSTER1		GENMASK(5, 4)
+#define FAIL_CPU_CLUSTER2		GENMASK(7, 6)
+#define FAIL_GPU				GENMASK(4, 1)
+#define FAIL_RKVDEC0			BIT(6)
+#define FAIL_RKVDEC1			BIT(7)
+#define FAIL_RKVENC0			BIT(0)
+#define FAIL_RKVENC1			BIT(2)
 
 int checkboard(void)
 {
@@ -245,3 +256,213 @@ int checkboard(void)
 
 	return 0;
 }
+
+static int fdt_path_del_node(void *fdt, const char *path)
+{
+	int nodeoffset;
+
+	nodeoffset = fdt_path_offset(fdt, path);
+	if (nodeoffset < 0)
+		return nodeoffset;
+
+	return fdt_del_node(fdt, nodeoffset);
+}
+
+static int fdt_path_set_name(void *fdt, const char *path, const char *name)
+{
+	int nodeoffset;
+
+	nodeoffset = fdt_path_offset(fdt, path);
+	if (nodeoffset < 0)
+		return nodeoffset;
+
+	return fdt_set_name(fdt, nodeoffset, name);
+}
+
+/*
+ * RK3582 is a variant of the RK3588S with some IP blocks disabled. What blocks
+ * are disabled/non-working is indicated by ip-state in OTP. ft_system_setup()
+ * is used to mark any cpu and/or gpu node with status=fail as indicated by
+ * ip-state. Apply same policy as vendor U-Boot for RK3582, i.e. two big cpu
+ * cores and the gpu is always failed/disabled. Enable OF_SYSTEM_SETUP to make
+ * use of the required DT fixups for RK3582 board variants.
+ */
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+	static const char * const cpu_node_names[] = {
+		"cpu@0", "cpu@100", "cpu@200", "cpu@300",
+		"cpu@400", "cpu@500", "cpu@600", "cpu@700",
+	};
+	int parent, node, i, comp_len, len, ret;
+	bool cluster1_removed = false;
+	u8 cpu_code[2], ip_state[3];
+	struct udevice *dev;
+	char soc_comp[16];
+	const char *comp;
+	void *data;
+
+	if (!IS_ENABLED(CONFIG_OF_SYSTEM_SETUP))
+		return 0;
+
+	if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC))
+		return -ENOSYS;
+
+	ret = uclass_get_device_by_driver(UCLASS_MISC,
+					  DM_DRIVER_GET(rockchip_otp), &dev);
+	if (ret) {
+		log_debug("Could not find otp device, ret=%d\n", ret);
+		return ret;
+	}
+
+	/* cpu-code: SoC model, e.g. 0x35 0x82 or 0x35 0x88 */
+	ret = misc_read(dev, RK3588_OTP_CPU_CODE_OFFSET, cpu_code, 2);
+	if (ret < 0) {
+		log_debug("Could not read cpu-code, ret=%d\n", ret);
+		return ret;
+	}
+
+	log_debug("cpu-code: %02x %02x\n", cpu_code[0], cpu_code[1]);
+
+	/* only fail devices on rk3582/rk3583 */
+	if (!(cpu_code[0] == 0x35 && cpu_code[1] == 0x82) &&
+	    !(cpu_code[0] == 0x35 && cpu_code[1] == 0x83))
+		return 0;
+
+	ret = misc_read(dev, RK3588_OTP_IP_STATE_OFFSET, &ip_state, 3);
+	if (ret < 0) {
+		log_err("Could not read ip-state, ret=%d\n", ret);
+		return ret;
+	}
+
+	log_debug("ip-state: %02x %02x %02x (otp)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* policy: fail entire big core cluster when one or more core is bad */
+	if (ip_state[0] & FAIL_CPU_CLUSTER1)
+		ip_state[0] |= FAIL_CPU_CLUSTER1;
+	if (ip_state[0] & FAIL_CPU_CLUSTER2)
+		ip_state[0] |= FAIL_CPU_CLUSTER2;
+
+	/* policy: always fail one big core cluster on rk3582/rk3583 */
+	if (!(ip_state[0] & (FAIL_CPU_CLUSTER1 | FAIL_CPU_CLUSTER2)))
+		ip_state[0] |= FAIL_CPU_CLUSTER2;
+
+	if (cpu_code[0] == 0x35 && cpu_code[1] == 0x82) {
+		/* policy: always fail gpu on rk3582 */
+		ip_state[1] |= FAIL_GPU;
+
+		/* policy: always fail rkvdec on rk3582 */
+		ip_state[1] |= FAIL_RKVDEC0 | FAIL_RKVDEC1;
+	} else if (cpu_code[0] == 0x35 && cpu_code[1] == 0x83) {
+		/* policy: always fail one rkvdec core on rk3583 */
+		if (!(ip_state[1] & (FAIL_RKVDEC0 | FAIL_RKVDEC1)))
+			ip_state[1] |= FAIL_RKVDEC1;
+	}
+
+	/* policy: always fail one rkvenc core on rk3582/rk3583 */
+	if (!(ip_state[2] & (FAIL_RKVENC0 | FAIL_RKVENC1)))
+		ip_state[2] |= FAIL_RKVENC1;
+
+	log_debug("ip-state: %02x %02x %02x (policy)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* cpu cluster1: ip_state[0]: bit4~5 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER1) == FAIL_CPU_CLUSTER1) {
+		log_debug("remove cpu-map cluster1\n");
+		fdt_path_del_node(blob, "/cpus/cpu-map/cluster1");
+		cluster1_removed = true;
+	}
+
+	/* cpu cluster2: ip_state[0]: bit6~7 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER2) == FAIL_CPU_CLUSTER2) {
+		log_debug("remove cpu-map cluster2\n");
+		fdt_path_del_node(blob, "/cpus/cpu-map/cluster2");
+	} else if (cluster1_removed) {
+		/* cluster nodes must be named in a continuous series */
+		log_debug("rename cpu-map cluster2\n");
+		fdt_path_set_name(blob, "/cpus/cpu-map/cluster2", "cluster1");
+	}
+
+	/* gpu: ip_state[1]: bit1~4 */
+	if (ip_state[1] & FAIL_GPU) {
+		log_debug("fail gpu\n");
+		fdt_status_fail_by_pathf(blob, "/gpu@fb000000");
+	}
+
+	/* rkvdec: ip_state[1]: bit6,7 */
+	if (ip_state[1] & FAIL_RKVDEC0) {
+		log_debug("fail rkvdec0\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdc38000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdc38700");
+	}
+	if (ip_state[1] & FAIL_RKVDEC1) {
+		log_debug("fail rkvdec1\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdc40000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdc40700");
+	}
+
+	/* rkvenc: ip_state[2]: bit0,2 */
+	if (ip_state[2] & FAIL_RKVENC0) {
+		log_debug("fail rkvenc0\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdbd0000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdbdf000");
+	}
+	if (ip_state[2] & FAIL_RKVENC1) {
+		log_debug("fail rkvenc1\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdbe0000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdbef000");
+	}
+
+	parent = fdt_path_offset(blob, "/cpus");
+	if (parent < 0) {
+		log_err("Could not find /cpus, parent=%d\n", parent);
+		return parent;
+	}
+
+	/* cpu: ip_state[0]: bit0~7 */
+	for (i = 0; i < 8; i++) {
+		/* fail any bad cpu core */
+		if (!(ip_state[0] & BIT(i)))
+			continue;
+
+		node = fdt_subnode_offset(blob, parent, cpu_node_names[i]);
+		if (node >= 0) {
+			log_debug("fail cpu %s\n", cpu_node_names[i]);
+			fdt_status_fail(blob, node);
+		} else {
+			log_err("Could not find %s, node=%d\n",
+				cpu_node_names[i], node);
+			return node;
+		}
+	}
+
+	node = fdt_path_offset(blob, "/");
+	if (node < 0) {
+		log_err("Could not find /, node=%d\n", node);
+		return node;
+	}
+
+	snprintf(soc_comp, sizeof(soc_comp), "rockchip,rk35%x", cpu_code[1]);
+
+	for (i = 0, comp_len = 0;
+	     (comp = fdt_stringlist_get(blob, node, "compatible", i, &len));
+	     i++) {
+		/* stop at soc compatible */
+		if (!strcmp(comp, soc_comp) ||
+		    !strcmp(comp, "rockchip,rk3588s") ||
+		    !strcmp(comp, "rockchip,rk3588"))
+			break;
+
+		log_debug("compatible[%d]: %s\n", i, comp);
+		comp_len += len + 1;
+	}
+
+	/* truncate to only include board compatible */
+	fdt_setprop_placeholder(blob, node, "compatible", comp_len, &data);
+
+	/* append soc compatible */
+	fdt_appendprop_string(blob, node, "compatible", soc_comp);
+	fdt_appendprop_string(blob, node, "compatible", "rockchip,rk3588s");
+
+	return 0;
+}
Signature · 1 line
2.50.1
#2 lore raw

Hi Jonas,

Quoted 70 lines · Jonas Karlman

The RK3582 SoC is a variant of the RK3588S with some IP blocks disabled. What blocks are disabled/non-working is indicated by ip-state in OTP.

This add initial support for RK3582 by using ft_system_setup() to mark any cpu and/or gpu node with status=fail as indicated by ip-state.

This apply same policy as vendor U-Boot for RK3582, i.e. two big cpu cores and the gpu is always failed/disabled.

Enable Kconfig option OF_SYSTEM_SETUP in board defconfig to make use of the required DT fixups for RK3582 board variants.

---
Changes in v2:
- Refactor code to first apply policy to ip-state and then fail cores based on the updated ip-state
- Add support for failing rkvdec and rkvenc cores
- Append soc compatible to board model
- Not picking up t-b tag due to significant changes to patch

---
  arch/arm/mach-rockchip/rk3588/rk3588.c | 221 +++++++++++++++++++++++++
  1 file changed, 221 insertions(+)
arch/arm/mach-rockchip/rk3588/rk3588.c +24 -0
index c01a40020896..3ab0afe0979e 100644
@@ -7,6 +7,7 @@
  #define LOG_CATEGORY LOGC_ARCH
 
  #include <dm.h>
+#include <fdt_support.h>
  #include <misc.h>
  #include <spl.h>
  #include <asm/armv8/mmu.h>
@@ -200,6 +201,16 @@ int arch_cpu_init(void)
 
  #define RK3588_OTP_CPU_CODE_OFFSET		0x02
  #define RK3588_OTP_SPECIFICATION_OFFSET		0x06
+#define RK3588_OTP_IP_STATE_OFFSET		0x1d
+
+#define FAIL_CPU_CLUSTER0		GENMASK(3, 0)
+#define FAIL_CPU_CLUSTER1		GENMASK(5, 4)
+#define FAIL_CPU_CLUSTER2		GENMASK(7, 6)
+#define FAIL_GPU				GENMASK(4, 1)
+#define FAIL_RKVDEC0			BIT(6)
+#define FAIL_RKVDEC1			BIT(7)
+#define FAIL_RKVENC0			BIT(0)
+#define FAIL_RKVENC1			BIT(2)
 
  int checkboard(void)
  {
@@ -245,3 +256,213 @@ int checkboard(void)
 
  	return 0;
  }
+
+static int fdt_path_del_node(void *fdt, const char *path)
+{
+	int nodeoffset;
+
+	nodeoffset = fdt_path_offset(fdt, path);
+	if (nodeoffset < 0)
+		return nodeoffset;
+
+	return fdt_del_node(fdt, nodeoffset);
+}
+
+static int fdt_path_set_name(void *fdt, const char *path, const char *name)

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 281

Quoted 10 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +10 -0
+{
+	int nodeoffset;
+
+	nodeoffset = fdt_path_offset(fdt, path);
+	if (nodeoffset < 0)
+		return nodeoffset;
+
+	return fdt_set_name(fdt, nodeoffset, name);
+}
+

Wondering if this shouldn't be something to add to the fdt "subsystem"?

With tests and all?

Quoted 16 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +16 -0
+/*
+ * RK3582 is a variant of the RK3588S with some IP blocks disabled. What blocks
+ * are disabled/non-working is indicated by ip-state in OTP. ft_system_setup()
+ * is used to mark any cpu and/or gpu node with status=fail as indicated by
+ * ip-state. Apply same policy as vendor U-Boot for RK3582, i.e. two big cpu
+ * cores and the gpu is always failed/disabled. Enable OF_SYSTEM_SETUP to make
+ * use of the required DT fixups for RK3582 board variants.
+ */
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+	static const char * const cpu_node_names[] = {
+		"cpu@0", "cpu@100", "cpu@200", "cpu@300",
+		"cpu@400", "cpu@500", "cpu@600", "cpu@700",
+	};
+	int parent, node, i, comp_len, len, ret;
+	bool cluster1_removed = false;

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 307

Quoted 10 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +10 -0
+	u8 cpu_code[2], ip_state[3];
+	struct udevice *dev;
+	char soc_comp[16];
+	const char *comp;
+	void *data;
+
+	if (!IS_ENABLED(CONFIG_OF_SYSTEM_SETUP))
+		return 0;
+
+	if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC))

Mmmmm we should probably think about adding xPL symbols for ROCKCHIP_OTP. No required for this patch as we already have code doing that same check.

Quoted 39 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +39 -0
+		return -ENOSYS;
+
+	ret = uclass_get_device_by_driver(UCLASS_MISC,
+					  DM_DRIVER_GET(rockchip_otp), &dev);
+	if (ret) {
+		log_debug("Could not find otp device, ret=%d\n", ret);
+		return ret;
+	}
+
+	/* cpu-code: SoC model, e.g. 0x35 0x82 or 0x35 0x88 */
+	ret = misc_read(dev, RK3588_OTP_CPU_CODE_OFFSET, cpu_code, 2);
+	if (ret < 0) {
+		log_debug("Could not read cpu-code, ret=%d\n", ret);
+		return ret;
+	}
+
+	log_debug("cpu-code: %02x %02x\n", cpu_code[0], cpu_code[1]);
+
+	/* only fail devices on rk3582/rk3583 */
+	if (!(cpu_code[0] == 0x35 && cpu_code[1] == 0x82) &&
+	    !(cpu_code[0] == 0x35 && cpu_code[1] == 0x83))
+		return 0;
+
+	ret = misc_read(dev, RK3588_OTP_IP_STATE_OFFSET, &ip_state, 3);
+	if (ret < 0) {
+		log_err("Could not read ip-state, ret=%d\n", ret);
+		return ret;
+	}
+
+	log_debug("ip-state: %02x %02x %02x (otp)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* policy: fail entire big core cluster when one or more core is bad */
+	if (ip_state[0] & FAIL_CPU_CLUSTER1)
+		ip_state[0] |= FAIL_CPU_CLUSTER1;
+	if (ip_state[0] & FAIL_CPU_CLUSTER2)
+		ip_state[0] |= FAIL_CPU_CLUSTER2;
+
+	/* policy: always fail one big core cluster on rk3582/rk3583 */

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 356

Quoted 10 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +10 -0
+	if (!(ip_state[0] & (FAIL_CPU_CLUSTER1 | FAIL_CPU_CLUSTER2)))
+		ip_state[0] |= FAIL_CPU_CLUSTER2;
+
+	if (cpu_code[0] == 0x35 && cpu_code[1] == 0x82) {
+		/* policy: always fail gpu on rk3582 */
+		ip_state[1] |= FAIL_GPU;
+
+		/* policy: always fail rkvdec on rk3582 */
+		ip_state[1] |= FAIL_RKVDEC0 | FAIL_RKVDEC1;
+	} else if (cpu_code[0] == 0x35 && cpu_code[1] == 0x83) {

Technically, we could have a simple else here as the code path before the if is guaranteed to only be reached in two cases, 0x8235 and 0x8335, so if you test the former and it doesn't match, it's necessarily the latter. No strong opinion.

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 358

Quoted 2 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +2 -0
+		/* policy: always fail one rkvdec core on rk3583 */
+		if (!(ip_state[1] & (FAIL_RKVDEC0 | FAIL_RKVDEC1)))

You could want to only check FAIL_RKVDEC0 as FAIL_RKVDEC1 is a bit (and not a bitfield so we don't need to set the whole bitfield in the event it's only partially set like for CPU clusters). No strong opinion.

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 370

Quoted 12 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +12 -0
+			ip_state[1] |= FAIL_RKVDEC1;
+	}
+
+	/* policy: always fail one rkvenc core on rk3582/rk3583 */
+	if (!(ip_state[2] & (FAIL_RKVENC0 | FAIL_RKVENC1)))
+		ip_state[2] |= FAIL_RKVENC1;
+
+	log_debug("ip-state: %02x %02x %02x (policy)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* cpu cluster1: ip_state[0]: bit4~5 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER1) == FAIL_CPU_CLUSTER1) {

No need for the == FAIL_CPU_CLUSTER1 check as you'll have set the whole bitfield earlier even if only one is set in the original ip_state from the register. No strong opinion.

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 377

Quoted 7 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +7 -0
+		log_debug("remove cpu-map cluster1\n");
+		fdt_path_del_node(blob, "/cpus/cpu-map/cluster1");
+		cluster1_removed = true;
+	}
+
+	/* cpu cluster2: ip_state[0]: bit6~7 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER2) == FAIL_CPU_CLUSTER2) {

Ditto. No strong opinion.

Quoted 50 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +50 -0
+		log_debug("remove cpu-map cluster2\n");
+		fdt_path_del_node(blob, "/cpus/cpu-map/cluster2");
+	} else if (cluster1_removed) {
+		/* cluster nodes must be named in a continuous series */
+		log_debug("rename cpu-map cluster2\n");
+		fdt_path_set_name(blob, "/cpus/cpu-map/cluster2", "cluster1");
+	}
+
+	/* gpu: ip_state[1]: bit1~4 */
+	if (ip_state[1] & FAIL_GPU) {
+		log_debug("fail gpu\n");
+		fdt_status_fail_by_pathf(blob, "/gpu@fb000000");
+	}
+
+	/* rkvdec: ip_state[1]: bit6,7 */
+	if (ip_state[1] & FAIL_RKVDEC0) {
+		log_debug("fail rkvdec0\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdc38000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdc38700");
+	}
+	if (ip_state[1] & FAIL_RKVDEC1) {
+		log_debug("fail rkvdec1\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdc40000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdc40700");
+	}
+
+	/* rkvenc: ip_state[2]: bit0,2 */
+	if (ip_state[2] & FAIL_RKVENC0) {
+		log_debug("fail rkvenc0\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdbd0000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdbdf000");
+	}
+	if (ip_state[2] & FAIL_RKVENC1) {
+		log_debug("fail rkvenc1\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdbe0000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdbef000");
+	}
+
+	parent = fdt_path_offset(blob, "/cpus");
+	if (parent < 0) {
+		log_err("Could not find /cpus, parent=%d\n", parent);
+		return parent;
+	}
+
+	/* cpu: ip_state[0]: bit0~7 */
+	for (i = 0; i < 8; i++) {
+		/* fail any bad cpu core */
+		if (!(ip_state[0] & BIT(i)))
+			continue;
+

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 437

Quoted 10 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +10 -0
+		node = fdt_subnode_offset(blob, parent, cpu_node_names[i]);
+		if (node >= 0) {
+			log_debug("fail cpu %s\n", cpu_node_names[i]);
+			fdt_status_fail(blob, node);
+		} else {
+			log_err("Could not find %s, node=%d\n",
+				cpu_node_names[i], node);
+			return node;
+		}
+	}

I would move this closer to the renaming/removing of cpu-map. No strong opinion though.

I'm wondering why you aren't using a direct path like for other controllers, e.g. fdt_status_fail_by_pathf(blob, cpu_node_names[i]) by simply prefixing each node_name with /cpus/ ?

Quoted 12 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +12 -0
+
+	node = fdt_path_offset(blob, "/");
+	if (node < 0) {
+		log_err("Could not find /, node=%d\n", node);
+		return node;
+	}
+
+	snprintf(soc_comp, sizeof(soc_comp), "rockchip,rk35%x", cpu_code[1]);
+
+	for (i = 0, comp_len = 0;
+	     (comp = fdt_stringlist_get(blob, node, "compatible", i, &len));
+	     i++) {

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 459

Quoted 10 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +10 -0
+		/* stop at soc compatible */
+		if (!strcmp(comp, soc_comp) ||
+		    !strcmp(comp, "rockchip,rk3588s") ||
+		    !strcmp(comp, "rockchip,rk3588"))
+			break;
+
+		log_debug("compatible[%d]: %s\n", i, comp);
+		comp_len += len + 1;
+	}
+

If it happens that none of the expected strings are found in the compatible property, we should probably return early.

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 465

Quoted 6 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +6 -0
+	/* truncate to only include board compatible */
+	fdt_setprop_placeholder(blob, node, "compatible", comp_len, &data);
+
+	/* append soc compatible */
+	fdt_appendprop_string(blob, node, "compatible", soc_comp);
+	fdt_appendprop_string(blob, node, "compatible", "rockchip,rk3588s");

I would rather insert rk3582/rk3583 before the rk3588/rk3588s and keep the rest untouched instead of truncating to rockchip,rk3588/rk3588s and then adding rockchip,rk3588s back only. I wouldn't want my device tree to be modified too much and we don't know what we'll get from downstream )I'm not necessarily talking about Rockchip's vendor kernel here) DTBs for example, so truncating doesn't seem to be the best plan? What do you think?

Logic-wise aside from the "compatible" changes, this seems fine. I do not own any RK3582/RK3583 so cannot test this.

Cheers,
Quentin

#3 lore raw

Hi Quentin,

Quoted 87 lines · Quentin Schulz

Hi Jonas,

Quoted 70 lines · Jonas Karlman

The RK3582 SoC is a variant of the RK3588S with some IP blocks disabled. What blocks are disabled/non-working is indicated by ip-state in OTP.

This add initial support for RK3582 by using ft_system_setup() to mark any cpu and/or gpu node with status=fail as indicated by ip-state.

This apply same policy as vendor U-Boot for RK3582, i.e. two big cpu cores and the gpu is always failed/disabled.

Enable Kconfig option OF_SYSTEM_SETUP in board defconfig to make use of the required DT fixups for RK3582 board variants.

---
Changes in v2:
- Refactor code to first apply policy to ip-state and then fail cores based on the updated ip-state
- Add support for failing rkvdec and rkvenc cores
- Append soc compatible to board model
- Not picking up t-b tag due to significant changes to patch

---
  arch/arm/mach-rockchip/rk3588/rk3588.c | 221 +++++++++++++++++++++++++
  1 file changed, 221 insertions(+)
arch/arm/mach-rockchip/rk3588/rk3588.c +24 -0
index c01a40020896..3ab0afe0979e 100644
@@ -7,6 +7,7 @@
  #define LOG_CATEGORY LOGC_ARCH
 
  #include <dm.h>
+#include <fdt_support.h>
  #include <misc.h>
  #include <spl.h>
  #include <asm/armv8/mmu.h>
@@ -200,6 +201,16 @@ int arch_cpu_init(void)
 
  #define RK3588_OTP_CPU_CODE_OFFSET		0x02
  #define RK3588_OTP_SPECIFICATION_OFFSET		0x06
+#define RK3588_OTP_IP_STATE_OFFSET		0x1d
+
+#define FAIL_CPU_CLUSTER0		GENMASK(3, 0)
+#define FAIL_CPU_CLUSTER1		GENMASK(5, 4)
+#define FAIL_CPU_CLUSTER2		GENMASK(7, 6)
+#define FAIL_GPU				GENMASK(4, 1)
+#define FAIL_RKVDEC0			BIT(6)
+#define FAIL_RKVDEC1			BIT(7)
+#define FAIL_RKVENC0			BIT(0)
+#define FAIL_RKVENC1			BIT(2)
 
  int checkboard(void)
  {
@@ -245,3 +256,213 @@ int checkboard(void)
 
  	return 0;
  }
+
+static int fdt_path_del_node(void *fdt, const char *path)
+{
+	int nodeoffset;
+
+	nodeoffset = fdt_path_offset(fdt, path);
+	if (nodeoffset < 0)
+		return nodeoffset;
+
+	return fdt_del_node(fdt, nodeoffset);
+}
+
+static int fdt_path_set_name(void *fdt, const char *path, const char *name)

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 281

Quoted 10 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +10 -0
+{
+	int nodeoffset;
+
+	nodeoffset = fdt_path_offset(fdt, path);
+	if (nodeoffset < 0)
+		return nodeoffset;
+
+	return fdt_set_name(fdt, nodeoffset, name);
+}
+

Wondering if this shouldn't be something to add to the fdt "subsystem"?

Quoted 1 line

With tests and all?

I have no idea if there is any other use for these functions, only wanted to simplify the code below as much as possible.

Quoted 23 lines
Quoted 23 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +22 -0
+/*
+ * RK3582 is a variant of the RK3588S with some IP blocks disabled. What blocks
+ * are disabled/non-working is indicated by ip-state in OTP. ft_system_setup()
+ * is used to mark any cpu and/or gpu node with status=fail as indicated by
+ * ip-state. Apply same policy as vendor U-Boot for RK3582, i.e. two big cpu
+ * cores and the gpu is always failed/disabled. Enable OF_SYSTEM_SETUP to make
+ * use of the required DT fixups for RK3582 board variants.
+ */
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+	static const char * const cpu_node_names[] = {
+		"cpu@0", "cpu@100", "cpu@200", "cpu@300",
+		"cpu@400", "cpu@500", "cpu@600", "cpu@700",
+	};
+	int parent, node, i, comp_len, len, ret;
+	bool cluster1_removed = false;
+	u8 cpu_code[2], ip_state[3];
+	struct udevice *dev;
+	char soc_comp[16];
+	const char *comp;
+	void *data;
+
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 307

Quoted 4 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +4 -0
+	if (!IS_ENABLED(CONFIG_OF_SYSTEM_SETUP))
+		return 0;
+
+	if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC))

Mmmmm we should probably think about adding xPL symbols for ROCKCHIP_OTP. No required for this patch as we already have code doing that same check.

Agree, both ROCKCHIP_OTP and ROCKCHIP_EFUSE could have use for xPL variants, something for a different series.

Quoted 47 lines
Quoted 47 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +46 -0
+		return -ENOSYS;
+
+	ret = uclass_get_device_by_driver(UCLASS_MISC,
+					  DM_DRIVER_GET(rockchip_otp), &dev);
+	if (ret) {
+		log_debug("Could not find otp device, ret=%d\n", ret);
+		return ret;
+	}
+
+	/* cpu-code: SoC model, e.g. 0x35 0x82 or 0x35 0x88 */
+	ret = misc_read(dev, RK3588_OTP_CPU_CODE_OFFSET, cpu_code, 2);
+	if (ret < 0) {
+		log_debug("Could not read cpu-code, ret=%d\n", ret);
+		return ret;
+	}
+
+	log_debug("cpu-code: %02x %02x\n", cpu_code[0], cpu_code[1]);
+
+	/* only fail devices on rk3582/rk3583 */
+	if (!(cpu_code[0] == 0x35 && cpu_code[1] == 0x82) &&
+	    !(cpu_code[0] == 0x35 && cpu_code[1] == 0x83))
+		return 0;
+
+	ret = misc_read(dev, RK3588_OTP_IP_STATE_OFFSET, &ip_state, 3);
+	if (ret < 0) {
+		log_err("Could not read ip-state, ret=%d\n", ret);
+		return ret;
+	}
+
+	log_debug("ip-state: %02x %02x %02x (otp)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* policy: fail entire big core cluster when one or more core is bad */
+	if (ip_state[0] & FAIL_CPU_CLUSTER1)
+		ip_state[0] |= FAIL_CPU_CLUSTER1;
+	if (ip_state[0] & FAIL_CPU_CLUSTER2)
+		ip_state[0] |= FAIL_CPU_CLUSTER2;
+
+	/* policy: always fail one big core cluster on rk3582/rk3583 */
+	if (!(ip_state[0] & (FAIL_CPU_CLUSTER1 | FAIL_CPU_CLUSTER2)))
+		ip_state[0] |= FAIL_CPU_CLUSTER2;
+
+	if (cpu_code[0] == 0x35 && cpu_code[1] == 0x82) {
+		/* policy: always fail gpu on rk3582 */
+		ip_state[1] |= FAIL_GPU;
+
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 356

Quoted 3 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +3 -0
+		/* policy: always fail rkvdec on rk3582 */
+		ip_state[1] |= FAIL_RKVDEC0 | FAIL_RKVDEC1;
+	} else if (cpu_code[0] == 0x35 && cpu_code[1] == 0x83) {

Technically, we could have a simple else here as the code path before the if is guaranteed to only be reached in two cases, 0x8235 and 0x8335, so if you test the former and it doesn't match, it's necessarily the latter. No strong opinion.

I sent a v3 of this series yesterday where both the rk3582 and rk3583 policy have been merged into a single policy to match upstream commit from linux-6.1-stan-rkr6, so this has already been changed.

https://github.com/Kwiboo/u-boot-rockchip/commit/5566d7d920d20932d2188c0cec57cb9036a9eefd

Quoted 7 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 358

Quoted 3 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +2 -0
+		/* policy: always fail one rkvdec core on rk3583 */
+		if (!(ip_state[1] & (FAIL_RKVDEC0 | FAIL_RKVDEC1)))

You could want to only check FAIL_RKVDEC0 as FAIL_RKVDEC1 is a bit (and not a bitfield so we don't need to set the whole bitfield in the event it's only partially set like for CPU clusters). No strong opinion.

Main reason for this is to keep all policy logic more consistent.

Quoted 17 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 370

Quoted 13 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +12 -0
+			ip_state[1] |= FAIL_RKVDEC1;
+	}
+
+	/* policy: always fail one rkvenc core on rk3582/rk3583 */
+	if (!(ip_state[2] & (FAIL_RKVENC0 | FAIL_RKVENC1)))
+		ip_state[2] |= FAIL_RKVENC1;
+
+	log_debug("ip-state: %02x %02x %02x (policy)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* cpu cluster1: ip_state[0]: bit4~5 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER1) == FAIL_CPU_CLUSTER1) {

No need for the == FAIL_CPU_CLUSTER1 check as you'll have set the whole bitfield earlier even if only one is set in the original ip_state from the register. No strong opinion.

Main reason for keeping this is that if you comment out the policy part above, you could end up with a single core removed, so this extra check ensure that we only remove the cpu-map node when all cores in the cluster will be marked as fail.

Quoted 66 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 377

Quoted 8 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +7 -0
+		log_debug("remove cpu-map cluster1\n");
+		fdt_path_del_node(blob, "/cpus/cpu-map/cluster1");
+		cluster1_removed = true;
+	}
+
+	/* cpu cluster2: ip_state[0]: bit6~7 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER2) == FAIL_CPU_CLUSTER2) {

Ditto. No strong opinion.

Quoted 55 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +55 -0
+		log_debug("remove cpu-map cluster2\n");
+		fdt_path_del_node(blob, "/cpus/cpu-map/cluster2");
+	} else if (cluster1_removed) {
+		/* cluster nodes must be named in a continuous series */
+		log_debug("rename cpu-map cluster2\n");
+		fdt_path_set_name(blob, "/cpus/cpu-map/cluster2", "cluster1");
+	}
+
+	/* gpu: ip_state[1]: bit1~4 */
+	if (ip_state[1] & FAIL_GPU) {
+		log_debug("fail gpu\n");
+		fdt_status_fail_by_pathf(blob, "/gpu@fb000000");
+	}
+
+	/* rkvdec: ip_state[1]: bit6,7 */
+	if (ip_state[1] & FAIL_RKVDEC0) {
+		log_debug("fail rkvdec0\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdc38000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdc38700");
+	}
+	if (ip_state[1] & FAIL_RKVDEC1) {
+		log_debug("fail rkvdec1\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdc40000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdc40700");
+	}
+
+	/* rkvenc: ip_state[2]: bit0,2 */
+	if (ip_state[2] & FAIL_RKVENC0) {
+		log_debug("fail rkvenc0\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdbd0000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdbdf000");
+	}
+	if (ip_state[2] & FAIL_RKVENC1) {
+		log_debug("fail rkvenc1\n");
+		fdt_status_fail_by_pathf(blob, "/video-codec@fdbe0000");
+		fdt_status_fail_by_pathf(blob, "/iommu@fdbef000");
+	}
+
+	parent = fdt_path_offset(blob, "/cpus");
+	if (parent < 0) {
+		log_err("Could not find /cpus, parent=%d\n", parent);
+		return parent;
+	}
+
+	/* cpu: ip_state[0]: bit0~7 */
+	for (i = 0; i < 8; i++) {
+		/* fail any bad cpu core */
+		if (!(ip_state[0] & BIT(i)))
+			continue;
+
+		node = fdt_subnode_offset(blob, parent, cpu_node_names[i]);
+		if (node >= 0) {
+			log_debug("fail cpu %s\n", cpu_node_names[i]);
+			fdt_status_fail(blob, node);
+		} else {
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 437

Quoted 5 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +5 -0
+			log_err("Could not find %s, node=%d\n",
+				cpu_node_names[i], node);
+			return node;
+		}
+	}

I would move this closer to the renaming/removing of cpu-map. No strong opinion though.

Sounds good, I think this is just leftover from thinking we should continue to load Linux in case of an error, and just trying to fail as much as possible before there is a chance of an early return.

Quoted 4 lines

I'm wondering why you aren't using a direct path like for other controllers, e.g. fdt_status_fail_by_pathf(blob, cpu_node_names[i]) by simply prefixing each node_name with /cpus/ ?

Good question, I think it may initially have been that I updated the ppi-partitions affinity using phandles to the cpu nodes. However, that part was removed before sending this out, will rework this for a v4.

Quoted 18 lines
Quoted 18 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +17 -0
+
+	node = fdt_path_offset(blob, "/");
+	if (node < 0) {
+		log_err("Could not find /, node=%d\n", node);
+		return node;
+	}
+
+	snprintf(soc_comp, sizeof(soc_comp), "rockchip,rk35%x", cpu_code[1]);
+
+	for (i = 0, comp_len = 0;
+	     (comp = fdt_stringlist_get(blob, node, "compatible", i, &len));
+	     i++) {
+		/* stop at soc compatible */
+		if (!strcmp(comp, soc_comp) ||
+		    !strcmp(comp, "rockchip,rk3588s") ||
+		    !strcmp(comp, "rockchip,rk3588"))
+			break;
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 459

Quoted 5 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +5 -0
+
+		log_debug("compatible[%d]: %s\n", i, comp);
+		comp_len += len + 1;
+	}
+

If it happens that none of the expected strings are found in the compatible property, we should probably return early.

If none of them is found this logic will just try to append the two compatibles at the end of any existing compatible. Should be safe?

The four main scenarios I try to anticipate is:
- rk3582 boards: <board>, rockchip,rk3582, rockchip,rk3588s (do nothing)
- rk3588s boards: <board>, rockchip,rk3588s (inject)
- rk3588-generic: rockchip,rk3588 (replace)
- other: <board>, <wrong soc> (append)

Quoted 11 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 465

Quoted 7 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +6 -0
+	/* truncate to only include board compatible */
+	fdt_setprop_placeholder(blob, node, "compatible", comp_len, &data);
+
+	/* append soc compatible */
+	fdt_appendprop_string(blob, node, "compatible", soc_comp);
+	fdt_appendprop_string(blob, node, "compatible", "rockchip,rk3588s");

I would rather insert rk3582/rk3583 before the rk3588/rk3588s and keep the rest untouched instead of truncating to rockchip,rk3588/rk3588s and then adding rockchip,rk3588s back only.

That is what this is trying to do without having to add too complex code.

We can only replace the full nil separated string array, and adding logic to re-construct a single working string became too complex. We already had helper functions that could be used even if they are a little bit inefficient by causing three fdt prop value replace.

The truncating changes the string length to where first (or none) soc compatible is found to then insert correct soc compatible.

Quoted 5 lines

I wouldn't want my device tree
to be modified too much and we don't know what we'll get from downstream )I'm not necessarily talking about Rockchip's vendor kernel here) DTBs for example, so truncating doesn't seem to be the best plan? What do you think?

We could possible make this very simple by just appending soc compatible when it is missing and not care about the compatible order.

My intention was to ensure that we always end up with:

<board>, [<...>, *] rockchip,rk3582, rockchip,rk3588s

With a simplified append it may instead end up as:

<board>, [<...>, *] rockchip,rk3588s, rockchip,rk3582

Does the order matter or should I just drop all this and replace with something simple like:

  ret = fdt_stringlist_search(blob, node, "compatible", soc_comp);
  if (ret == -FDT_ERR_NOTFOUND)
  	fdt_appendprop_string(blob, node, "compatible", soc_comp);

Regards,
Jonas

Quoted 6 lines

Logic-wise aside from the "compatible" changes, this seems fine. I do not own any RK3582/RK3583 so cannot test this.

Cheers,
Quentin

#4 lore raw

Hi Jonas,

Quoted 6 lines · Jonas Karlman

Hi Quentin,

Quoted 3 lines · Quentin Schulz

Hi Jonas,

On 8/4/25 8:16 PM, Jonas Karlman wrote:

[...]

Quoted 9 lines
Quoted 6 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 358

Quoted 2 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +2 -0
+		/* policy: always fail one rkvdec core on rk3583 */
+		if (!(ip_state[1] & (FAIL_RKVDEC0 | FAIL_RKVDEC1)))

You could want to only check FAIL_RKVDEC0 as FAIL_RKVDEC1 is a bit (and not a bitfield so we don't need to set the whole bitfield in the event it's only partially set like for CPU clusters). No strong opinion.

Main reason for this is to keep all policy logic more consistent.

Fair enough.

Quoted 18 lines
Quoted 17 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 370

Quoted 13 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +12 -0
+			ip_state[1] |= FAIL_RKVDEC1;
+	}
+
+	/* policy: always fail one rkvenc core on rk3582/rk3583 */
+	if (!(ip_state[2] & (FAIL_RKVENC0 | FAIL_RKVENC1)))
+		ip_state[2] |= FAIL_RKVENC1;
+
+	log_debug("ip-state: %02x %02x %02x (policy)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* cpu cluster1: ip_state[0]: bit4~5 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER1) == FAIL_CPU_CLUSTER1) {

No need for the == FAIL_CPU_CLUSTER1 check as you'll have set the whole bitfield earlier even if only one is set in the original ip_state from the register. No strong opinion.

Quoted 2 lines

Main reason for keeping this is that if you comment out the policy part above, you could end up with a single core removed, so this extra check

No you cannot at this point in the code :)

Earlier you do:

+ /* policy: fail entire big core cluster when one or more core is bad */
+ if (ip_state[0] & FAIL_CPU_CLUSTER1)
+ ip_state[0] |= FAIL_CPU_CLUSTER1;

This means that all bits in FAIL_CPU_CLUSTER1 bitfield are set if one is set.

This means that if you check

+ if (ip_state[0] & FAIL_CPU_CLUSTER1)

later on in the code, necessarily if it matches it means all CPUs are disabled in the cluster.

The only benefit is if you are anticipating removing this policy in the future where then the cpu-map shouldn't be removed if not all cores aren't failed. As it is today, it is not a necessary check (but I guess it doesn't hurt, so keep it if you feel more comfortable with it, this is really just me nitpicking).

[...]

Quoted 31 lines
Quoted 17 lines
Quoted 17 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +17 -0
+	parent = fdt_path_offset(blob, "/cpus");
+	if (parent < 0) {
+		log_err("Could not find /cpus, parent=%d\n", parent);
+		return parent;
+	}
+
+	/* cpu: ip_state[0]: bit0~7 */
+	for (i = 0; i < 8; i++) {
+		/* fail any bad cpu core */
+		if (!(ip_state[0] & BIT(i)))
+			continue;
+
+		node = fdt_subnode_offset(blob, parent, cpu_node_names[i]);
+		if (node >= 0) {
+			log_debug("fail cpu %s\n", cpu_node_names[i]);
+			fdt_status_fail(blob, node);
+		} else {
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 437

Quoted 5 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +5 -0
+			log_err("Could not find %s, node=%d\n",
+				cpu_node_names[i], node);
+			return node;
+		}
+	}

I would move this closer to the renaming/removing of cpu-map. No strong opinion though.

Sounds good, I think this is just leftover from thinking we should continue to load Linux in case of an error, and just trying to fail as much as possible before there is a chance of an early return.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

I'm wondering why you aren't using a direct path like for other controllers, e.g. fdt_status_fail_by_pathf(blob, cpu_node_names[i]) by simply prefixing each node_name with /cpus/ ?

Good question, I think it may initially have been that I updated the ppi-partitions affinity using phandles to the cpu nodes. However, that part was removed before sending this out, will rework this for a v4.

Then you would be matching the same workflow as other removals earlier in the code and won't have to mind about the return-early scenario you were concerned about just above.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +17 -0
+
+	node = fdt_path_offset(blob, "/");
+	if (node < 0) {
+		log_err("Could not find /, node=%d\n", node);
+		return node;
+	}
+
+	snprintf(soc_comp, sizeof(soc_comp), "rockchip,rk35%x", cpu_code[1]);
+
+	for (i = 0, comp_len = 0;
+	     (comp = fdt_stringlist_get(blob, node, "compatible", i, &len));
+	     i++) {
+		/* stop at soc compatible */
+		if (!strcmp(comp, soc_comp) ||
+		    !strcmp(comp, "rockchip,rk3588s") ||
+		    !strcmp(comp, "rockchip,rk3588"))
+			break;
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 459

Quoted 5 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +5 -0
+
+		log_debug("compatible[%d]: %s\n", i, comp);
+		comp_len += len + 1;
+	}
+

If it happens that none of the expected strings are found in the compatible property, we should probably return early.

Quoted 3 lines

If none of them is found this logic will just try to append the two compatibles at the end of any existing compatible. Should be safe?

Mmmmmm, you're right, it should be fine I think, but maybe we don't want to add rockchip,rk3588s if the DT only has e.g. myvendor,rk3582-myboard?

Quoted 2 lines

The four main scenarios I try to anticipate is:
- rk3582 boards: <board>, rockchip,rk3582, rockchip,rk3588s (do nothing)

This you aren't doing at the moment, maybe we should return early if soc_comp is found in the compatible list?

Quoted 18 lines

- rk3588s boards: <board>, rockchip,rk3588s (inject)
- rk3588-generic: rockchip,rk3588 (replace)
- other: <board>, <wrong soc> (append)

Quoted 11 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 465

Quoted 7 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +6 -0
+	/* truncate to only include board compatible */
+	fdt_setprop_placeholder(blob, node, "compatible", comp_len, &data);
+
+	/* append soc compatible */
+	fdt_appendprop_string(blob, node, "compatible", soc_comp);
+	fdt_appendprop_string(blob, node, "compatible", "rockchip,rk3588s");

I would rather insert rk3582/rk3583 before the rk3588/rk3588s and keep the rest untouched instead of truncating to rockchip,rk3588/rk3588s and then adding rockchip,rk3588s back only.

That is what this is trying to do without having to add too complex code.

Quoted 8 lines

We can only replace the full nil separated string array, and adding logic to re-construct a single working string became too complex. We already had helper functions that could be used even if they are a little bit inefficient by causing three fdt prop value replace.

The truncating changes the string length to where first (or none) soc compatible is found to then insert correct soc compatible.

Yes, but if downstream decides to do

rockchip,rk3582, rockchip,rk3588s, <board>

We are screwed :) as we'll return only the first two. Does the user not following the spec deserve to have their DT broken? Maybe /me shrugs

Quoted 15 lines
Quoted 5 lines

I wouldn't want my device tree
to be modified too much and we don't know what we'll get from downstream )I'm not necessarily talking about Rockchip's vendor kernel here) DTBs for example, so truncating doesn't seem to be the best plan? What do you think?

We could possible make this very simple by just appending soc compatible when it is missing and not care about the compatible order.

My intention was to ensure that we always end up with:

   <board>, [<...>, *] rockchip,rk3582, rockchip,rk3588s

With a simplified append it may instead end up as:

Quoted 9 lines
   <board>, [<...>, *] rockchip,rk3588s, rockchip,rk3582

Does the order matter or should I just drop all this and replace with something simple like:

   ret = fdt_stringlist_search(blob, node, "compatible", soc_comp);
   if (ret == -FDT_ERR_NOTFOUND)
   	fdt_appendprop_string(blob, node, "compatible", soc_comp);

Nope, this doesn't follow the DT spec then:

"""
The property
value consists of a concatenated list of null terminated strings, from most specific to most general. """

though this is said for the "compatible" property of a device node. For the root node the following is said:

"""
Specifies a list of platform architectures with which this platform is compatible. This prop- erty can be used by operating systems in select- ing platform specific code. The recommended form of the property value is:
"manufacturer,model"
"""

c.f. https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4/devicetree-specification-v0.4.pdf

Cheers,
Quentin

#5 lore raw

Hi Quentin,

Quoted 58 lines · Quentin Schulz

Hi Jonas,

Quoted 6 lines · Jonas Karlman

Hi Quentin,

Quoted 3 lines · Quentin Schulz

Hi Jonas,

On 8/4/25 8:16 PM, Jonas Karlman wrote:

[...]

Quoted 9 lines
Quoted 6 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 358

Quoted 2 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +2 -0
+		/* policy: always fail one rkvdec core on rk3583 */
+		if (!(ip_state[1] & (FAIL_RKVDEC0 | FAIL_RKVDEC1)))

You could want to only check FAIL_RKVDEC0 as FAIL_RKVDEC1 is a bit (and not a bitfield so we don't need to set the whole bitfield in the event it's only partially set like for CPU clusters). No strong opinion.

Main reason for this is to keep all policy logic more consistent.

Fair enough.

Quoted 18 lines
Quoted 17 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 370

Quoted 13 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +12 -0
+			ip_state[1] |= FAIL_RKVDEC1;
+	}
+
+	/* policy: always fail one rkvenc core on rk3582/rk3583 */
+	if (!(ip_state[2] & (FAIL_RKVENC0 | FAIL_RKVENC1)))
+		ip_state[2] |= FAIL_RKVENC1;
+
+	log_debug("ip-state: %02x %02x %02x (policy)\n",
+		  ip_state[0], ip_state[1], ip_state[2]);
+
+	/* cpu cluster1: ip_state[0]: bit4~5 */
+	if ((ip_state[0] & FAIL_CPU_CLUSTER1) == FAIL_CPU_CLUSTER1) {

No need for the == FAIL_CPU_CLUSTER1 check as you'll have set the whole bitfield earlier even if only one is set in the original ip_state from the register. No strong opinion.

Quoted 2 lines

Main reason for keeping this is that if you comment out the policy part above, you could end up with a single core removed, so this extra check

No you cannot at this point in the code :)

Earlier you do:

arch/arm/mach-rockchip/rk3588/rk3588.c +3 -0
+	/* policy: fail entire big core cluster when one or more core is bad */
+	if (ip_state[0] & FAIL_CPU_CLUSTER1)
+		ip_state[0] |= FAIL_CPU_CLUSTER1;

This means that all bits in FAIL_CPU_CLUSTER1 bitfield are set if one is set.

This means that if you check

+ if (ip_state[0] & FAIL_CPU_CLUSTER1)

Quoted 8 lines

later on in the code, necessarily if it matches it means all CPUs are disabled in the cluster.

The only benefit is if you are anticipating removing this policy in the future where then the cpu-map shouldn't be removed if not all cores aren't failed. As it is today, it is not a necessary check (but I guess it doesn't hurt, so keep it if you feel more comfortable with it, this is really just me nitpicking).

The main reason is that end-users may want to remove the policy and just disable the cores that are marked as bad and not the entire cluster.

E.g. for my personal builds I will be able to just remove or comment out the policy part above, or if there is a policy change in the future the removal part will handle such cases without having to be also changed.

On my RK3582 boards there is typically only one single bad core in cpu, vdec or venc. To get most out of the SoC I may want to skip the policy to run all working cores without too much code modification ;-)

Quoted 77 lines

[...]

Quoted 31 lines
Quoted 17 lines
Quoted 17 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +17 -0
+	parent = fdt_path_offset(blob, "/cpus");
+	if (parent < 0) {
+		log_err("Could not find /cpus, parent=%d\n", parent);
+		return parent;
+	}
+
+	/* cpu: ip_state[0]: bit0~7 */
+	for (i = 0; i < 8; i++) {
+		/* fail any bad cpu core */
+		if (!(ip_state[0] & BIT(i)))
+			continue;
+
+		node = fdt_subnode_offset(blob, parent, cpu_node_names[i]);
+		if (node >= 0) {
+			log_debug("fail cpu %s\n", cpu_node_names[i]);
+			fdt_status_fail(blob, node);
+		} else {
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 437

Quoted 5 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +5 -0
+			log_err("Could not find %s, node=%d\n",
+				cpu_node_names[i], node);
+			return node;
+		}
+	}

I would move this closer to the renaming/removing of cpu-map. No strong opinion though.

Sounds good, I think this is just leftover from thinking we should continue to load Linux in case of an error, and just trying to fail as much as possible before there is a chance of an early return.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

I'm wondering why you aren't using a direct path like for other controllers, e.g. fdt_status_fail_by_pathf(blob, cpu_node_names[i]) by simply prefixing each node_name with /cpus/ ?

Good question, I think it may initially have been that I updated the ppi-partitions affinity using phandles to the cpu nodes. However, that part was removed before sending this out, will rework this for a v4.

Then you would be matching the same workflow as other removals earlier in the code and won't have to mind about the return-early scenario you were concerned about just above.

Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +17 -0
+
+	node = fdt_path_offset(blob, "/");
+	if (node < 0) {
+		log_err("Could not find /, node=%d\n", node);
+		return node;
+	}
+
+	snprintf(soc_comp, sizeof(soc_comp), "rockchip,rk35%x", cpu_code[1]);
+
+	for (i = 0, comp_len = 0;
+	     (comp = fdt_stringlist_get(blob, node, "compatible", i, &len));
+	     i++) {
+		/* stop at soc compatible */
+		if (!strcmp(comp, soc_comp) ||
+		    !strcmp(comp, "rockchip,rk3588s") ||
+		    !strcmp(comp, "rockchip,rk3588"))
+			break;
Quoted 8 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 459

Quoted 5 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +5 -0
+
+		log_debug("compatible[%d]: %s\n", i, comp);
+		comp_len += len + 1;
+	}
+

If it happens that none of the expected strings are found in the compatible property, we should probably return early.

Quoted 3 lines

If none of them is found this logic will just try to append the two compatibles at the end of any existing compatible. Should be safe?

Quoted 8 lines

Mmmmmm, you're right, it should be fine I think, but maybe we don't want to add rockchip,rk3588s if the DT only has e.g. myvendor,rk3582-myboard?

Quoted 2 lines

The four main scenarios I try to anticipate is:
- rk3582 boards: <board>, rockchip,rk3582, rockchip,rk3588s (do nothing)

This you aren't doing at the moment, maybe we should return early if soc_comp is found in the compatible list?

Yes, will fix this for v4.

Quoted 28 lines
Quoted 19 lines

- rk3588s boards: <board>, rockchip,rk3588s (inject)
- rk3588-generic: rockchip,rk3588 (replace)
- other: <board>, <wrong soc> (append)

Quoted 11 lines

arch/arm/mach-rockchip/rk3588/rk3588.c int checkboard(void) · line 465

Quoted 7 lines
arch/arm/mach-rockchip/rk3588/rk3588.c +6 -0
+	/* truncate to only include board compatible */
+	fdt_setprop_placeholder(blob, node, "compatible", comp_len, &data);
+
+	/* append soc compatible */
+	fdt_appendprop_string(blob, node, "compatible", soc_comp);
+	fdt_appendprop_string(blob, node, "compatible", "rockchip,rk3588s");

I would rather insert rk3582/rk3583 before the rk3588/rk3588s and keep the rest untouched instead of truncating to rockchip,rk3588/rk3588s and then adding rockchip,rk3588s back only.

That is what this is trying to do without having to add too complex code.

Quoted 8 lines

We can only replace the full nil separated string array, and adding logic to re-construct a single working string became too complex. We already had helper functions that could be used even if they are a little bit inefficient by causing three fdt prop value replace.

The truncating changes the string length to where first (or none) soc compatible is found to then insert correct soc compatible.

Quoted 6 lines

Yes, but if downstream decides to do

rockchip,rk3582, rockchip,rk3588s, <board>

We are screwed :) as we'll return only the first two. Does the user not following the spec deserve to have their DT broken? Maybe /me shrugs

I guess we could relax the logic to return early if rockchip,rk3582 already exists and only truncate and append if rockchip,rk3588s or rockchip,rk3588 is found last, will try something like that for v4.

Quoted 21 lines
Quoted 21 lines
Quoted 6 lines

I wouldn't want my device tree
to be modified too much and we don't know what we'll get from downstream )I'm not necessarily talking about Rockchip's vendor kernel here) DTBs for example, so truncating doesn't seem to be the best plan? What do you think?

We could possible make this very simple by just appending soc compatible when it is missing and not care about the compatible order.

My intention was to ensure that we always end up with:

   <board>, [<...>, *] rockchip,rk3582, rockchip,rk3588s

With a simplified append it may instead end up as:

   <board>, [<...>, *] rockchip,rk3588s, rockchip,rk3582

Does the order matter or should I just drop all this and replace with something simple like:

Quoted 7 lines
Quoted 4 lines
   ret = fdt_stringlist_search(blob, node, "compatible", soc_comp);
   if (ret == -FDT_ERR_NOTFOUND)
   	fdt_appendprop_string(blob, node, "compatible", soc_comp);

Nope, this doesn't follow the DT spec then:

Agree, and I think that the "radxa,e52c", "rockchip,rk3582", "rockchip,rk3588s" already defined the proper order we should use.

Regards,
Jonas

Quoted 24 lines

"""
The property
value consists of a concatenated list of null terminated strings, from most specific to most general.
"""

though this is said for the "compatible" property of a device node. For the root node the following is said:

"""
Specifies a list of platform architectures with
which this platform is compatible. This prop-
erty can be used by operating systems in select-
ing platform specific code. The recommended
form of the property value is:
"manufacturer,model"
"""

c.f.
https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4/devicetree-specification-v0.4.pdf

Cheers,
Quentin

#6 lore raw

PATCH v2 2/3 rockchip: rk3588-generic: Enable support for RK3582

In reply to Jonas Karlman

Add Kconfig option OF_SYSTEM_SETUP=y to support booting boards with a RK3582 SoC. CPU and GPU cores are failed based on ip-state and policy.

Tested on a ROCK 5C Lite v1.1:

cpu-code: 35 82
ip-state: 10 00 00 (otp)
ip-state: 30 de 04 (policy)
remove cpu-map cluster1
rename cpu-map cluster2
fail gpu
fail rkvdec0
fail rkvdec1
fail rkvenc1
fail cpu cpu@400
fail cpu cpu@500

and on a Radxa E52C:

cpu-code: 35 82
ip-state: 00 04 00 (otp)
ip-state: c0 de 04 (policy)
remove cpu-map cluster2
fail gpu
fail rkvdec0
fail rkvdec1
fail rkvenc1
fail cpu cpu@600
fail cpu cpu@700

---
v2: Mention RK3582 in generic board device tree and documentation

---
 arch/arm/dts/rk3588-generic.dts  | 4 ++--
 configs/generic-rk3588_defconfig | 1 +
 doc/board/rockchip/rockchip.rst  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
arch/arm/dts/rk3588-generic.dts +2 -2
index 6740f9866f17..04144e2ad128 100644
@@ -1,13 +1,13 @@
 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 /*
- * Minimal generic DT for RK3588S/RK3588 with eMMC, SD-card and USB OTG enabled
+ * Minimal generic DT for RK3582/RK3588S/RK3588 with eMMC, SD-card and USB OTG enabled
  */
 
 /dts-v1/;
 #include "rk3588s.dtsi"
 
 / {
-	model = "Generic RK3588S/RK3588";
+	model = "Generic RK3582/RK3588S/RK3588";
 	compatible = "rockchip,rk3588";
 
 	aliases {
configs/generic-rk3588_defconfig +1 -0
index dfa8efabe6be..7a8c176912e1 100644
@@ -16,6 +16,7 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 # CONFIG_BOOTMETH_VBE is not set
 CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-generic.dtb"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_MAX_SIZE=0x40000
doc/board/rockchip/rockchip.rst +1 -1
index 7a1385789c20..726eed4ea45b 100644
@@ -145,7 +145,7 @@ List of mainline supported Rockchip boards:
      - FriendlyElec NanoPC-T6 (nanopc-t6-rk3588)
      - FriendlyElec NanoPi R6C (nanopi-r6c-rk3588s)
      - FriendlyElec NanoPi R6S (nanopi-r6s-rk3588s)
-     - Generic RK3588S/RK3588 (generic-rk3588)
+     - Generic RK3582/RK3588S/RK3588 (generic-rk3588)
      - Hardkernel ODROID-M2 (odroid-m2-rk3588s)
      - Indiedroid Nova (nova-rk3588s)
      - Khadas Edge2 (khadas-edge2-rk3588s)
Signature · 1 line
2.50.1
#7 lore raw

PATCH v2 3/3 rockchip: rk3588s-rock-5c: Add support for ROCK 5C Lite variant

In reply to Jonas Karlman

Add Kconfig option OF_SYSTEM_SETUP=y to support booting ROCK 5C Lite boards with a RK3582 SoC. CPU and GPU cores are failed based on ip-state and policy.

Tested on a ROCK 5C Lite v1.1:

cpu-code: 35 82
ip-state: 00 80 00 (otp)
ip-state: c0 de 04 (policy)
remove cpu-map cluster2
fail gpu
fail rkvdec0
fail rkvdec1
fail rkvenc1
fail cpu cpu@600
fail cpu cpu@700

---
v2: New patch

---
 arch/arm/mach-rockchip/rk3588/Kconfig | 9 +++++----
 configs/rock-5c-rk3588s_defconfig     | 1 +
 doc/board/rockchip/rockchip.rst       | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)
arch/arm/mach-rockchip/rk3588/Kconfig +5 -4
index 4e7942ada875..afc26b0b3c6a 100644
@@ -269,14 +269,15 @@ config TARGET_ROCK_5_ITX_RK3588
 	  Powered by either 12V, ATX power-supply or PoE
 
 config TARGET_ROCK_5C_RK3588S
-	bool "Radxa ROCK 5C RK3588S2 board"
+	bool "Radxa ROCK 5C/5C Lite"
 	help
-	  Radxa ROCK 5C is a Rockchip RK3588S2 based single board computer.
+	  Radxa ROCK 5C/5C Lite is a Rockchip RK3588S2/RK3582 based SBC (Single
+	  Board Computer) by Radxa.
 
 	  Specification:
 
-	  Quad A76 and Quad A55 CPU
-	  6 TOPS NPU
+	  Quad/Dual A76 and Quad A55 CPU
+	  6/5 TOPS NPU
 	  up to 32GB LPDDR4x RAM
 	  eMMC / SPI flash connector
 	  Micro SD Card slot
configs/rock-5c-rk3588s_defconfig +1 -0
index 2748fb488c2d..f83d3f6d6c92 100644
@@ -18,6 +18,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588s-rock-5c.dtb"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SPL_MAX_SIZE=0x40000
doc/board/rockchip/rockchip.rst +1 -1
index 726eed4ea45b..c025191302bc 100644
@@ -153,7 +153,7 @@ List of mainline supported Rockchip boards:
      - Radxa ROCK 5 ITX (rock-5-itx-rk3588)
      - Radxa ROCK 5A (rock5a-rk3588s)
      - Radxa ROCK 5B/5B+ (rock5b-rk3588)
-     - Radxa ROCK 5C (rock-5c-rk3588s)
+     - Radxa ROCK 5C/5C Lite (rock-5c-rk3588s)
      - Rockchip Toybrick TB-RK3588X (toybrick-rk3588)
      - Theobroma Systems RK3588-SBC Jaguar (jaguar-rk3588)
      - Theobroma Systems SOM-RK3588-Q7 - Tiger (tiger-rk3588)
Signature · 1 line
2.50.1