Skip to contentSkip to conversation

Switch to upstream devicetree for TH1520 platform

PATCH In review Yao Zi 2 participants 9 messages Aug 13, 2025 – Sep 18, 2025

Subsystems (4)
lore
Share & tools
lore

Yao Zi

author
#0 lore raw

cover Switch to upstream devicetree for TH1520 platform

This series switches the TH1520 platform along with the only board, th1520_lpi4a, to use upstream devicetree.

The upstream dt specifies pinctrl configuration for the UART, which is probed before proper U-Boot relocation. This means we must make pincontroller, and resource used by the pincontroller available in relocation. too, so here come PATCH 2 and 3.

Making more drivers bind and probe before relocation raises requirement of pre-relocation malloc pool, PATCH 1 increases SYS_MALLOC_F_LEN to 0x10000 to fit drivers' usage.

Tested on Lichee Pi 4A 16GiB variant, and it introduces no functionality regression. Thanks for your time and review.

Yao Zi (4):
configs: th1520_lpi4a: Enlarge SYS_MALLOC_F_LEN to 0x10000
clk: thead: th1520-ap: Mark drivers as DM_FLAG_PRE_RELOC
pinctrl: th1520: Mark driver as DM_FLAG_PRE_RELOC
dts: th1520: Switch to upstream devicetree

 arch/riscv/cpu/th1520/Kconfig                 |   1 +
 arch/riscv/dts/Makefile                       |   1 -
 .../dts/th1520-lichee-module-4a-u-boot.dtsi   |  10 +
 arch/riscv/dts/th1520-lichee-module-4a.dtsi   | 164 ------
 .../riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi |  27 +
 arch/riscv/dts/th1520-lichee-pi-4a.dts        |  33 --
 arch/riscv/dts/th1520-u-boot.dtsi             |  44 ++
 arch/riscv/dts/th1520.dtsi                    | 530 ------------------
 configs/th1520_lpi4a_defconfig                |   4 +-
 drivers/clk/thead/clk-th1520-ap.c             |   3 +
 drivers/pinctrl/pinctrl-th1520.c              |   1 +
 11 files changed, 88 insertions(+), 730 deletions(-)
 create mode 100644 arch/riscv/dts/th1520-lichee-module-4a-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520-lichee-module-4a.dtsi
 create mode 100644 arch/riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520-lichee-pi-4a.dts
 create mode 100644 arch/riscv/dts/th1520-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520.dtsi
Signature · 1 line
2.50.1
author
#1 lore raw

PATCH 1/4 configs: th1520_lpi4a: Enlarge SYS_MALLOC_F_LEN to 0x10000

For TH1520, we want clock and pinctrl drivers to bind before relocation along with the UART which makes use of them, since upstream devicetree specifies pinctrl properties for the UART.

This requires a large malloc pool before relocation, let's enlarge it.

---
 configs/th1520_lpi4a_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configs/th1520_lpi4a_defconfig +1 -1
index 2763cbb428a..731fe378ac8 100644
@@ -1,6 +1,6 @@
 CONFIG_RISCV=y
 CONFIG_SYS_MALLOC_LEN=0x800000
-CONFIG_SYS_MALLOC_F_LEN=0x3000
+CONFIG_SYS_MALLOC_F_LEN=0x10000
 CONFIG_SPL_GPIO=y
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
Signature · 1 line
2.50.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] configs: th1520_lpi4a: Enlarge SYS_MALLOC_F_LEN to 0x10000

Quoted 10 lines · Yao Zi

For TH1520, we want clock and pinctrl drivers to bind before relocation along with the UART which makes use of them, since upstream devicetree specifies pinctrl properties for the UART.

This requires a large malloc pool before relocation, let's enlarge it.

---
 configs/th1520_lpi4a_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
author
#3 lore raw

PATCH 2/4 clk: thead: th1520-ap: Mark drivers as DM_FLAG_PRE_RELOC

In reply to Yao Zi

It's common that UARTs are bound and probed before U-Boot relocation, in which case the clocks of UART and UART's pincontroller must be registered first. Let's apply DM_FLAG_PRE_RELOC to the driver, allowing it to bind before relocation.

---
 drivers/clk/thead/clk-th1520-ap.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clk/thead/clk-th1520-ap.c +3 -0
index 822cf0809d5..6899e1b595a 100644
@@ -235,6 +235,7 @@ U_BOOT_DRIVER(th1520_clk_div) = {
 	.name	= "th1520_clk_div",
 	.id	= UCLASS_CLK,
 	.ops	= &ccu_div_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
 };
 
 static unsigned long th1520_pll_vco_recalc_rate(struct clk *clk,
@@ -302,6 +303,7 @@ U_BOOT_DRIVER(th1520_clk_pll) = {
 	.name	= "th1520_clk_pll",
 	.id	= UCLASS_CLK,
 	.ops	= &clk_pll_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
 };
 
 static struct ccu_pll cpu_pll0_clk = {
@@ -1030,4 +1032,5 @@ U_BOOT_DRIVER(th1520_clk) = {
 	.of_match	= th1520_clk_match,
 	.probe		= th1520_clk_probe,
 	.ops		= &th1520_clk_ops,
+	.flags		= DM_FLAG_PRE_RELOC,
 };
Signature · 1 line
2.50.1
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] clk: thead: th1520-ap: Mark drivers as DM_FLAG_PRE_RELOC

Quoted 9 lines · Yao Zi

It's common that UARTs are bound and probed before U-Boot relocation, in which case the clocks of UART and UART's pincontroller must be registered first. Let's apply DM_FLAG_PRE_RELOC to the driver, allowing it to bind before relocation.

---
 drivers/clk/thead/clk-th1520-ap.c | 3 +++
 1 file changed, 3 insertions(+)
author
#5 lore raw

PATCH 3/4 pinctrl: th1520: Mark driver as DM_FLAG_PRE_RELOC

In reply to Yao Zi

It's common that UARTs are bound and probed before U-Boot relocation, in which case the UART's pincontroller and pinconfig must be probed first. Let's apply DM_FLAG_PRE_RELOC to the driver, allow it to bind before relocation.

---
 drivers/pinctrl/pinctrl-th1520.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pinctrl/pinctrl-th1520.c +1 -0
index be7e508f8a4..4eead0875d8 100644
@@ -697,4 +697,5 @@ U_BOOT_DRIVER(th1520_pinctrl) = {
 	.probe = th1520_pinctrl_probe,
 	.priv_auto = sizeof(struct th1520_pinctrl),
 	.ops = &th1520_pinctrl_ops,
+	.flags = DM_FLAG_PRE_RELOC,
 };
Signature · 1 line
2.50.1
Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] pinctrl: th1520: Mark driver as DM_FLAG_PRE_RELOC

Quoted 9 lines · Yao Zi

It's common that UARTs are bound and probed before U-Boot relocation, in which case the UART's pincontroller and pinconfig must be probed first. Let's apply DM_FLAG_PRE_RELOC to the driver, allow it to bind before relocation.

---
 drivers/pinctrl/pinctrl-th1520.c | 1 +
 1 file changed, 1 insertion(+)
author
#7 lore raw

PATCH 4/4 dts: th1520: Switch to upstream devicetree

In reply to Yao Zi

Imply OF_UPSTREAM in platform Kconfig option and adapt existing boards to use the correct upstream devicetree paths.

---
 arch/riscv/cpu/th1520/Kconfig                 |   1 +
 arch/riscv/dts/Makefile                       |   1 -
 .../dts/th1520-lichee-module-4a-u-boot.dtsi   |  10 +
 arch/riscv/dts/th1520-lichee-module-4a.dtsi   | 164 ------
 .../riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi |  27 +
 arch/riscv/dts/th1520-lichee-pi-4a.dts        |  33 --
 arch/riscv/dts/th1520-u-boot.dtsi             |  44 ++
 arch/riscv/dts/th1520.dtsi                    | 530 ------------------
 configs/th1520_lpi4a_defconfig                |   2 +-
 9 files changed, 83 insertions(+), 729 deletions(-)
 create mode 100644 arch/riscv/dts/th1520-lichee-module-4a-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520-lichee-module-4a.dtsi
 create mode 100644 arch/riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520-lichee-pi-4a.dts
 create mode 100644 arch/riscv/dts/th1520-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520.dtsi
arch/riscv/cpu/th1520/Kconfig +1 -0
index c73462c04b8..a02f5f24906 100644
@@ -21,3 +21,4 @@ config THEAD_TH1520
 	imply SPL_CPU
 	imply SPL_OPENSBI
 	imply SPL_LOAD_FIT
+	imply OF_UPSTREAM
arch/riscv/dts/Makefile +0 -1
index 2b10c2d6c01..1b2e8dd3d4e 100644
@@ -11,7 +11,6 @@ dtb-$(CONFIG_TARGET_OPENPITON_RISCV64) += openpiton-riscv64.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb
 dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
-dtb-$(CONFIG_TARGET_TH1520_LPI4A) += th1520-lichee-pi-4a.dtb
 dtb-$(CONFIG_TARGET_XILINX_MBV) += xilinx-mbv32.dtb
 dtb-$(CONFIG_TARGET_XILINX_MBV) += xilinx-mbv64.dtb
 dtb-$(CONFIG_TARGET_ASPEED_AST2700_IBEX) += ast2700-ibex.dtb
arch/riscv/dts/th1520-lichee-module-4a-u-boot.dtsi new file +10 -0
new file mode 100644
index 00000000000..bbfa3c499cf
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Yao Zi <[email protected]>
+ */
+
+#include "th1520-u-boot.dtsi"
+
+&{/memory@0} {
+	bootph-pre-ram;
+};
arch/riscv/dts/th1520-lichee-module-4a.dtsi deleted +0 -164

164 lines not on this page · raw message

arch/riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi new file +27 -0
new file mode 100644
index 00000000000..06d4a70d1ea
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 Yao Zi <[email protected]>
+ */
+
+#include "th1520-lichee-module-4a-u-boot.dtsi"
+#include "thead-th1520-binman.dtsi"
+
+&clk {
+	bootph-some-ram;
+};
+
+&padctrl0_apsys {
+	bootph-some-ram;
+};
+
+&uart0_pins {
+	bootph-some-ram;
+
+	tx-pins {
+		bootph-some-ram;
+	};
+
+	rx-pins {
+		bootph-some-ram;
+	};
+};
arch/riscv/dts/th1520-lichee-pi-4a.dts deleted +0 -33
deleted file mode 100644
index 49af88b7adf..00000000000
@@ -1,33 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2023 Jisheng Zhang <[email protected]>
- */
-
-#include "th1520-lichee-module-4a.dtsi"
-#include "thead-th1520-binman.dtsi"
-
-/ {
-	model = "Sipeed Lichee Pi 4A";
-	compatible = "sipeed,lichee-pi-4a", "sipeed,lichee-module-4a", "thead,th1520";
-
-	aliases {
-		gpio0 = &gpio0;
-		gpio1 = &gpio1;
-		gpio2 = &gpio2;
-		gpio3 = &gpio3;
-		serial0 = &uart0;
-		serial1 = &uart1;
-		serial2 = &uart2;
-		serial3 = &uart3;
-		serial4 = &uart4;
-		serial5 = &uart5;
-	};
-
-	chosen {
-		stdout-path = "serial0:115200n8";
-	};
-};
-
-&uart0 {
-	status = "okay";
-};
arch/riscv/dts/th1520-u-boot.dtsi new file +44 -0

44 lines not on this page · raw message

arch/riscv/dts/th1520.dtsi deleted +0 -530

530 lines not on this page · raw message

configs/th1520_lpi4a_defconfig +1 -1
index 731fe378ac8..1039c2ac54e 100644
@@ -6,7 +6,7 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x80200000
 CONFIG_DM_GPIO=y
-CONFIG_DEFAULT_DEVICE_TREE="th1520-lichee-pi-4a"
+CONFIG_DEFAULT_DEVICE_TREE="thead/th1520-lichee-pi-4a"
 CONFIG_SPL_STACK=0xffe0170000
 CONFIG_SPL_BSS_START_ADDR=0xffe0160000
 CONFIG_SPL_BSS_MAX_SIZE=0x10000
Signature · 1 line
2.50.1
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] dts: th1520: Switch to upstream devicetree

Quoted 13 lines · Yao Zi

Imply OF_UPSTREAM in platform Kconfig option and adapt existing boards to use the correct upstream devicetree paths.

---
 arch/riscv/cpu/th1520/Kconfig                 |   1 +
 arch/riscv/dts/Makefile                       |   1 -
 .../dts/th1520-lichee-module-4a-u-boot.dtsi   |  10 +
 arch/riscv/dts/th1520-lichee-module-4a.dtsi   | 164 ------
 .../riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi |  27 +
 arch/riscv/dts/th1520-lichee-pi-4a.dts        |  33 --
 arch/riscv/dts/th1520-u-boot.dtsi             |  44 ++
 arch/riscv/dts/th1520.dtsi                    | 530 ------------------
Quoted 8 lines
 configs/th1520_lpi4a_defconfig                |   2 +-
 9 files changed, 83 insertions(+), 729 deletions(-)
 create mode 100644 arch/riscv/dts/th1520-lichee-module-4a-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520-lichee-module-4a.dtsi
 create mode 100644 arch/riscv/dts/th1520-lichee-pi-4a-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520-lichee-pi-4a.dts
 create mode 100644 arch/riscv/dts/th1520-u-boot.dtsi
 delete mode 100644 arch/riscv/dts/th1520.dtsi