Skip to contentSkip to conversation

Improve usability of TH1520 with mainline SPL

PATCH In review Yao Zi 2 participants 9 messages May 16, 2025 – May 21, 2025

Subsystems (3)
lore
Share & tools
lore

Yao Zi

author
#0 lore raw

cover Improve usability of TH1520 with mainline SPL

Depending on the previous SPL support series of TH1520[1], this series further improves usability of TH1520 SoC when booting with mainline SPL.

The T-Head customized IOPMPs are initialized in SPL and a clock driver is ported from Linux kernel to support operation of various peripherals.

With this series, it's possible to properly initialize GPIO and eMMC when booting with mainline SPL on the 16GiB variant of Lichee Pi 4A. SDIO controller fails to initialize the SD card sometimes, which may be related to incorrect pin configuration.

A bootlog with eMMC/SD information shown could be obtained here[2]. Thanks for your time and review.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://gist.github.com/ziyao233/75ff1e5b2cf9161093fcc12ed0a62395

Yao Zi (4):
riscv: cpu: th1520: Initialize IOPMPs in SPL
clk: thead: Port clock controller driver of TH1520 SoC
riscv: cpu: th1520: Select clock driver
riscv: dts: th1520: Complete clock tree

 arch/riscv/cpu/th1520/Kconfig               |    1 +
 arch/riscv/cpu/th1520/spl.c                 |   65 ++
 arch/riscv/dts/th1520-lichee-module-4a.dtsi |    8 -
 arch/riscv/dts/th1520.dtsi                  |   75 +-
 arch/riscv/include/asm/arch-th1520/iopmp.h  |   42 +
 drivers/clk/Kconfig                         |    1 +
 drivers/clk/Makefile                        |    1 +
 drivers/clk/thead/Kconfig                   |   19 +
 drivers/clk/thead/Makefile                  |    5 +
 drivers/clk/thead/clk-th1520-ap.c           | 1031 +++++++++++++++++++
 10 files changed, 1204 insertions(+), 44 deletions(-)
 create mode 100644 arch/riscv/include/asm/arch-th1520/iopmp.h
 create mode 100644 drivers/clk/thead/Kconfig
 create mode 100644 drivers/clk/thead/Makefile
 create mode 100644 drivers/clk/thead/clk-th1520-ap.c
Signature · 1 line
2.49.0
author
#1 lore raw

PATCH 1/4 riscv: cpu: th1520: Initialize IOPMPs in SPL

TH1520 SoC ships several IOPMPs protecting various on-chip peripherals. They must be configured before accessing the peripherals. Let's initialize them in SPL harts_early_init().

---
 arch/riscv/cpu/th1520/spl.c                | 65 ++++++++++++++++++++++
 arch/riscv/include/asm/arch-th1520/iopmp.h | 42 ++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 arch/riscv/include/asm/arch-th1520/iopmp.h
arch/riscv/cpu/th1520/spl.c +65 -0
index aec398528d1..362fe895f86 100644
@@ -2,6 +2,8 @@
 /*
  * Copyright (C) 2025 Yao Zi <[email protected]>
  */
+#include <asm/arch/iopmp.h>
+#include <asm/io.h>
 #include <dm.h>
 #include <linux/sizes.h>
 #include <log.h>
@@ -9,6 +11,16 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#define TH1520_SUBSYS_CLK		(void __iomem *)(0xffff011000 + 0x220)
+#define  TH1520_SUBSYS_CLK_VO_EN	BIT(2)
+#define  TH1520_SUBSYS_CLK_VI_EN	BIT(1)
+#define  TH1520_SUBSYS_CLK_DSP_EN	BIT(0)
+#define TH1520_SUBSYS_RST		(void __iomem *)(0xffff015000 + 0x220)
+#define  TH1520_SUBSYS_RST_VP_N		BIT(3)
+#define  TH1520_SUBSYS_RST_VO_N		BIT(2)
+#define  TH1520_SUBSYS_RST_VI_N		BIT(1)
+#define  TH1520_SUBSYS_RST_DSP_N	BIT(0)
+
 int spl_dram_init(void)
 {
 	int ret;
@@ -29,3 +41,56 @@ int spl_dram_init(void)
 
 	return 0;
 }
+
+static void __iomem *th1520_iopmp_regs[] = {
+	TH1520_IOPMP_EMMC,
+	TH1520_IOPMP_SDIO0,
+	TH1520_IOPMP_SDIO1,
+	TH1520_IOPMP_USB0,
+	TH1520_IOPMP_AO,
+	TH1520_IOPMP_AUD,
+	TH1520_IOPMP_CHIP_DBG,
+	TH1520_IOPMP_EIP120I,
+	TH1520_IOPMP_EIP120II,
+	TH1520_IOPMP_EIP120III,
+	TH1520_IOPMP_ISP0,
+	TH1520_IOPMP_ISP1,
+	TH1520_IOPMP_DW200,
+	TH1520_IOPMP_VIPRE,
+	TH1520_IOPMP_VENC,
+	TH1520_IOPMP_VDEC,
+	TH1520_IOPMP_G2D,
+	TH1520_IOPMP_FCE,
+	TH1520_IOPMP_NPU,
+	TH1520_IOPMP_DPU0,
+	TH1520_IOPMP_DPU1,
+	TH1520_IOPMP_GPU,
+	TH1520_IOPMP_GMAC1,
+	TH1520_IOPMP_GMAC2,
+	TH1520_IOPMP_DMAC,
+	TH1520_IOPMP_TEE_DMAC,
+	TH1520_IOPMP_DSP0,
+	TH1520_IOPMP_DSP1,
+};
+
+void harts_early_init(void)
+{
+	int i;
+
+	/*
+	 * Set IOPMPs to the default attribute, allowing the application
+	 * processor to access various peripherals. Subsystem clocks should be
+	 * enabled and resets should be deasserted ahead of time, or the HART
+	 * will hang when configuring corresponding IOPMP entries.
+	 */
+	setbits_le32(TH1520_SUBSYS_CLK, TH1520_SUBSYS_CLK_VO_EN |
+					TH1520_SUBSYS_CLK_VI_EN |
+					TH1520_SUBSYS_CLK_DSP_EN);
+	setbits_le32(TH1520_SUBSYS_RST, TH1520_SUBSYS_RST_VP_N |
+					TH1520_SUBSYS_RST_VO_N |
+					TH1520_SUBSYS_RST_VI_N |
+					TH1520_SUBSYS_RST_DSP_N);
+
+	for (i = 0; i < ARRAY_SIZE(th1520_iopmp_regs); i++)
+		writel(TH1520_IOPMP_DEFAULT_ATTR, th1520_iopmp_regs[i]);
+}
arch/riscv/include/asm/arch-th1520/iopmp.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] riscv: cpu: th1520: Initialize IOPMPs in SPL

Quoted 10 lines · Yao Zi

TH1520 SoC ships several IOPMPs protecting various on-chip peripherals. They must be configured before accessing the peripherals. Let's initialize them in SPL harts_early_init().

---
 arch/riscv/cpu/th1520/spl.c                | 65 ++++++++++++++++++++++
 arch/riscv/include/asm/arch-th1520/iopmp.h | 42 ++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 arch/riscv/include/asm/arch-th1520/iopmp.h
author
#3 lore raw

PATCH 2/4 clk: thead: Port clock controller driver of TH1520 SoC

In reply to Yao Zi

The driver is adapted from Linux kernel's version of clk-th1520-ap.c, with only output clocks for external sensors, which are barely useful in bootloaders, removed.

Same as the mainline driver, it currently lacks of ability to enable and reconfigure PLLs, which could be implemented later.

---
 drivers/clk/Kconfig               |    1 +
 drivers/clk/Makefile              |    1 +
 drivers/clk/thead/Kconfig         |   19 +
 drivers/clk/thead/Makefile        |    5 +
 drivers/clk/thead/clk-th1520-ap.c | 1031 +++++++++++++++++++++++++++++
 5 files changed, 1057 insertions(+)
 create mode 100644 drivers/clk/thead/Kconfig
 create mode 100644 drivers/clk/thead/Makefile
 create mode 100644 drivers/clk/thead/clk-th1520-ap.c
drivers/clk/Kconfig +1 -0
index 18bd640a68b..19aa2ffa539 100644
@@ -271,6 +271,7 @@ source "drivers/clk/starfive/Kconfig"
 source "drivers/clk/stm32/Kconfig"
 source "drivers/clk/tegra/Kconfig"
 source "drivers/clk/ti/Kconfig"
+source "drivers/clk/thead/Kconfig"
 source "drivers/clk/uniphier/Kconfig"
 
 endmenu
drivers/clk/Makefile +1 -0
index 8411205ee04..5f0c0d8a5c2 100644
@@ -20,6 +20,7 @@ obj-y += imx/
 obj-$(CONFIG_CLK_JH7110) += starfive/
 obj-y += tegra/
 obj-y += ti/
+obj-$(CONFIG_CLK_THEAD) += thead/
 obj-$(CONFIG_$(PHASE_)CLK_INTEL) += intel/
 obj-$(CONFIG_ARCH_ASPEED) += aspeed/
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
drivers/clk/thead/Kconfig new file +19 -0
new file mode 100644
index 00000000000..e815286b085
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (c) 2025, Yao Zi <[email protected]>
+
+config CLK_THEAD
+	bool "Clock support for T-Head SoCs"
+	depends on CLK
+
+if CLK_THEAD
+
+config CLK_THEAD_TH1520_AP
+	bool "T-Head TH1520 AP clock support"
+	select CLK_CCF
+	default THEAD_TH1520
+	help
+	  This enables support clock driver for T-Head TH1520 Application
+	  processor.
+
+endif
drivers/clk/thead/Makefile new file +5 -0
new file mode 100644
index 00000000000..8cc05ed7914
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2025 Yao Zi <[email protected]>
+
+obj-$(CONFIG_CLK_THEAD_TH1520_AP) += clk-th1520-ap.o
drivers/clk/thead/clk-th1520-ap.c new file +1031 -0

1,031 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] clk: thead: Port clock controller driver of TH1520 SoC

Quoted 8 lines · Yao Zi

The driver is adapted from Linux kernel's version of clk-th1520-ap.c, with only output clocks for external sensors, which are barely useful in bootloaders, removed.

Same as the mainline driver, it currently lacks of ability to enable and reconfigure PLLs, which could be implemented later.

Quoted 10 lines
---
 drivers/clk/Kconfig               |    1 +
 drivers/clk/Makefile              |    1 +
 drivers/clk/thead/Kconfig         |   19 +
 drivers/clk/thead/Makefile        |    5 +
 drivers/clk/thead/clk-th1520-ap.c | 1031 +++++++++++++++++++++++++++++
 5 files changed, 1057 insertions(+)
 create mode 100644 drivers/clk/thead/Kconfig
 create mode 100644 drivers/clk/thead/Makefile
 create mode 100644 drivers/clk/thead/clk-th1520-ap.c
author
#5 lore raw

PATCH 3/4 riscv: cpu: th1520: Select clock driver

In reply to Yao Zi

The clock driver is essential for TH1520 SoCs to operate. Select the driver in SoC Kconfig entry.

---
 arch/riscv/cpu/th1520/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/cpu/th1520/Kconfig +1 -0
index a916d364e6c..4d44191bd22 100644
@@ -10,6 +10,7 @@ config THEAD_TH1520
 	select SUPPORT_SPL
 	select BINMAN if SPL
 	select SYS_CACHE_THEAD_CMO
+	select CLK_THEAD
 	imply CPU
 	imply CPU_RISCV
 	imply RISCV_TIMER if (RISCV_SMODE || SPL_RISCV_SMODE)
Signature · 1 line
2.49.0
author
#7 lore raw

PATCH 4/4 riscv: dts: th1520: Complete clock tree

In reply to Yao Zi

Describe the newly-supported clock controller of TH1520 in SoC devicetree, replace dummy clocks with the controller-supplied ones and add correct clocks for GPIO controllers.

---
 arch/riscv/dts/th1520-lichee-module-4a.dtsi |  8 ---
 arch/riscv/dts/th1520.dtsi                  | 75 +++++++++++----------
 2 files changed, 39 insertions(+), 44 deletions(-)
arch/riscv/dts/th1520-lichee-module-4a.dtsi +0 -8
index 20dbc4c7d24..9b255f8243c 100644
@@ -26,14 +26,6 @@
 	clock-frequency = <32768>;
 };
 
-&apb_clk {
-	clock-frequency = <62500000>;
-};
-
-&uart_sclk {
-	clock-frequency = <100000000>;
-};
-
 &emmc {
 	bus-width = <8>;
 	max-frequency = <198000000>;
arch/riscv/dts/th1520.dtsi +39 -36

215 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] riscv: dts: th1520: Complete clock tree

Quoted 9 lines · Yao Zi

Describe the newly-supported clock controller of TH1520 in SoC devicetree, replace dummy clocks with the controller-supplied ones and add correct clocks for GPIO controllers.

---
 arch/riscv/dts/th1520-lichee-module-4a.dtsi |  8 ---
 arch/riscv/dts/th1520.dtsi                  | 75 +++++++++++----------
 2 files changed, 39 insertions(+), 44 deletions(-)