Skip to contentSkip to conversation

ufs: amd-versal2: Cleanup firmware interface

PATCH Applied Michal Simek 1 participant 5 messages Jul 30 – Aug 11

Subsystems (4)
lore
Share & tools
lore

Michal Simek

author maintainer
#0 lore raw

cover ufs: amd-versal2: Cleanup firmware interface

Hi,

the first patch mainly alignment with Linux kernel version. Issue was related to IRQ handling which is not valid reason for U-Boot but still correcting sequence make sense.

The second patch is moving firmware handling out of UFS driver. UFS driver cares about delivering functionality. And doesn't really matter how exactly it is done. If it is done via firmware interface, via IO polling or in a different way. That's why move loops out of UFS driver to be able to use different interfaces for it.

The third patch is just Kconfig update.

The series is based on
https://patchwork.ozlabs.org/project/uboot/patch/6419fe4f6f1f451aee624c7762b7aa690d50e498.1784870711.git.michal.simek@amd.com/

Thanks,
Michal

Michal Simek (3):
ufs: amd-versal2: Perform controller reset in the init callback
xilinx: versal2: Clean UFS firmware interface
ufs: amd-versal2: Remove ZYNQMP_FIRMWARE dependency

 arch/arm/mach-versal2/cpu.c                   |  34 +++--
 arch/arm/mach-versal2/include/mach/hardware.h |   5 +
 .../arm/mach-versal2/include/mach/sys_proto.h |   8 +-
 drivers/firmware/firmware-zynqmp.c            |  72 ++++++----
 drivers/ufs/Kconfig                           |   2 +-
 drivers/ufs/ufs-amd-versal2.c                 | 129 ++++++------------
 6 files changed, 119 insertions(+), 131 deletions(-)

---
base-commit: 7e24149aacb83335fa997e2457144f23ba5e1bda

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/3 ufs: amd-versal2: Perform controller reset in the init callback

Move the controller/PHY reset and SRAM-bypass sequence from hce_enable_notify(PRE_CHANGE) into ufs_versal2_init().
The reset sequence releases the host controller from reset, and the UFS core reads the capability and version registers right after .init() and before ufshcd_hba_enable() (the only caller of hce_enable_notify()). Doing the reset in .init() ensures those registers are read after the controller is out of reset, and keeps the driver aligned with Linux. ufs_versal2_phy_init() stays in POST_CHANGE.

---

 drivers/ufs/ufs-amd-versal2.c | 86 ++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 48 deletions(-)
drivers/ufs/ufs-amd-versal2.c +38 -48
index 25af9dd63cca..986147848bda 100644
@@ -301,7 +301,7 @@ static int ufs_versal2_init(struct ufs_hba *hba)
 	struct ufs_versal2_priv *priv = dev_get_priv(hba->dev);
 	struct clk clk;
 	unsigned long core_clk_rate = 0;
-	u32 cal;
+	u32 cal, sram_csr;
 	int ret = 0;
 
 	priv->phy_mode = UFSHCD_DWC_PHY_MODE_ROM;
@@ -331,6 +331,41 @@ static int ufs_versal2_init(struct ufs_hba *hba)
 		return PTR_ERR(priv->rstphy);
 	}
 
+	/* Assert RST_UFS Reset for UFS block in PMX_IOU */
+	ret = reset_assert(priv->rstc);
+	if (ret) {
+		dev_err(hba->dev, "host reset assert failed, err = %d\n", ret);
+		return ret;
+	}
+
+	/* Assert PHY reset */
+	ret = reset_assert(priv->rstphy);
+	if (ret) {
+		dev_err(hba->dev, "phy reset assert failed, err = %d\n", ret);
+		return ret;
+	}
+
+	ret = zynqmp_pm_ufs_sram_csr_read(&sram_csr);
+	if (ret)
+		return ret;
+
+	if (!priv->phy_mode) {
+		sram_csr &= ~SRAM_CSR_EXT_LD_DONE_MASK;
+		sram_csr |= SRAM_CSR_BYPASS_MASK;
+	} else {
+		dev_err(hba->dev, "Invalid phy-mode %d.\n", priv->phy_mode);
+		return -EINVAL;
+	}
+
+	ret = zynqmp_pm_ufs_sram_csr_write(&sram_csr);
+	if (ret)
+		return ret;
+
+	/* De Assert RST_UFS Reset for UFS block in PMX_IOU */
+	ret = reset_deassert(priv->rstc);
+	if (ret)
+		dev_err(hba->dev, "host reset deassert failed, err = %d\n", ret);
+
 	ret = zynqmp_pm_ufs_cal_reg(&cal);
 	if (ret)
 		return ret;
@@ -346,57 +381,12 @@ static int ufs_versal2_init(struct ufs_hba *hba)
 static int ufs_versal2_hce_enable_notify(struct ufs_hba *hba,
 					 enum ufs_notify_change_status status)
 {
-	struct ufs_versal2_priv *priv = dev_get_priv(hba->dev);
-	u32 sram_csr;
-	int ret;
-
-	switch (status) {
-	case PRE_CHANGE:
-		/* Assert RST_UFS Reset for UFS block in PMX_IOU */
-		ret = reset_assert(priv->rstc);
-		if (ret) {
-			dev_err(hba->dev, "ufshc reset assert failed, err = %d\n", ret);
-			return ret;
-		}
-
-		/* Assert PHY reset */
-		ret = reset_assert(priv->rstphy);
-		if (ret) {
-			dev_err(hba->dev, "ufsphy reset assert failed, err = %d\n", ret);
-			return ret;
-		}
-
-		ret = zynqmp_pm_ufs_sram_csr_read(&sram_csr);
-		if (ret)
-			return ret;
-
-		if (!priv->phy_mode) {
-			sram_csr &= ~SRAM_CSR_EXT_LD_DONE_MASK;
-			sram_csr |= SRAM_CSR_BYPASS_MASK;
-		} else {
-			dev_err(hba->dev, "Invalid phy-mode %d.\n", priv->phy_mode);
-			return -EINVAL;
-		}
-
-		ret = zynqmp_pm_ufs_sram_csr_write(&sram_csr);
-		if (ret)
-			return ret;
-
-		/* De Assert RST_UFS Reset for UFS block in PMX_IOU */
-		ret = reset_deassert(priv->rstc);
-		if (ret)
-			dev_err(hba->dev, "ufshc reset deassert failed, err = %d\n", ret);
+	int ret = 0;
 
-		break;
-	case POST_CHANGE:
+	if (status == POST_CHANGE) {
 		ret = ufs_versal2_phy_init(hba);
 		if (ret)
 			dev_err(hba->dev, "Phy init failed (%d)\n", ret);
-
-		break;
-	default:
-		ret = -EINVAL;
-		break;
 	}
 
 	return ret;
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/3 xilinx: versal2: Clean UFS firmware interface

In reply to Michal Simek

The M-PHY and SRAM readiness poll loops move out of the UFS controller driver and into the firmware backend, exposed as blocking waits with a caller-owned timeout budget. This keeps the UFS driver backend-agnostic and lets an other backends offload the wait to the platform in a single call instead of round-tripping every poll.

set_sram_bypass() now performs the SRAM_CSR read-modify-write in the firmware layer.

Hook up functions are also update to reflect their usage.

---

 arch/arm/mach-versal2/cpu.c                   | 34 ++++++---
 arch/arm/mach-versal2/include/mach/hardware.h |  5 ++
 .../arm/mach-versal2/include/mach/sys_proto.h |  8 +-
 drivers/firmware/firmware-zynqmp.c            | 72 +++++++++++-------
 drivers/ufs/ufs-amd-versal2.c                 | 73 +++++--------------
 5 files changed, 95 insertions(+), 97 deletions(-)
arch/arm/mach-versal2/cpu.c +25 -9
index 01efa7b79282..d72f66f4fbac 100644
@@ -11,6 +11,7 @@
 #include <malloc.h>
 #include <time.h>
 #include <vsprintf.h>
+#include <wait_bit.h>
 #include <asm/armv8/mmu.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
@@ -160,25 +161,40 @@ u8 __weak versal2_get_bootmode(void)
 	return bootmode;
 }
 
-int __weak zynqmp_pm_ufs_get_txrx_cfgrdy(u32 *value)
+/*
+ * Wait for the M-PHY TX/RX config-ready status to settle (all bits cleared) or
+ * @timeout_us to elapse. The direct-MMIO fallback owns the poll loop, mirroring
+ * the EEMI backend; the timeout budget is owned by the caller.
+ */
+int __weak zynqmp_pm_wait_mphy_tx_rx_config_ready(u32 timeout_us)
 {
-	*value = readl(PMXC_SLCR_BASE_ADDRESS + PMXC_TX_RX_CFG_RDY);
-	return 0;
+	return wait_for_bit_le32((void *)(uintptr_t)(PMXC_SLCR_BASE_ADDRESS +
+						     PMXC_TX_RX_CFG_RDY),
+				 TX_RX_CFG_RDY_MASK, false, timeout_us / 1000,
+				 false);
 }
 
-int __weak zynqmp_pm_ufs_sram_csr_read(u32 *value)
+int __weak zynqmp_pm_wait_sram_init_done(u32 timeout_us)
 {
-	*value = readl(PMXC_SLCR_BASE_ADDRESS + PMXC_SRAM_CSR);
-	return 0;
+	return wait_for_bit_le32((void *)(uintptr_t)(PMXC_SLCR_BASE_ADDRESS +
+						     PMXC_SRAM_CSR),
+				 SRAM_CSR_INIT_DONE_MASK, true, timeout_us / 1000,
+				 false);
 }
 
-int __weak zynqmp_pm_ufs_sram_csr_write(u32 *value)
+int __weak zynqmp_pm_set_sram_bypass(void)
 {
-	writel(*value, PMXC_SLCR_BASE_ADDRESS + PMXC_SRAM_CSR);
+	u32 sram_csr;
+
+	sram_csr = readl(PMXC_SLCR_BASE_ADDRESS + PMXC_SRAM_CSR);
+	sram_csr &= ~SRAM_CSR_EXT_LD_DONE_MASK;
+	sram_csr |= SRAM_CSR_BYPASS_MASK;
+	writel(sram_csr, PMXC_SLCR_BASE_ADDRESS + PMXC_SRAM_CSR);
+
 	return 0;
 }
 
-int __weak zynqmp_pm_ufs_cal_reg(u32 *value)
+int __weak zynqmp_pm_get_ufs_calibration_values(u32 *value)
 {
 	*value = readl(PMXC_EFUSE_CACHE_BASE_ADDRESS + PMXC_UFS_CAL_1_OFFSET);
 	return 0;
arch/arm/mach-versal2/include/mach/hardware.h +5 -0
index 7977529fd6c1..4ff732d660fd 100644
@@ -65,6 +65,11 @@
 #define PMXC_SRAM_CSR			0x4C
 #define PMXC_TX_RX_CFG_RDY		0x54
 
+#define SRAM_CSR_INIT_DONE_MASK		BIT(0)
+#define SRAM_CSR_EXT_LD_DONE_MASK	BIT(1)
+#define SRAM_CSR_BYPASS_MASK		BIT(2)
+#define TX_RX_CFG_RDY_MASK		GENMASK(3, 0)
+
 #define PMC_GLOBAL_PGGS3_REG	0xF111005C
 #define PMC_GLOBAL_PGGS4_REG	0xF1110060
 
arch/arm/mach-versal2/include/mach/sys_proto.h +4 -4
index c1dfd184d865..d678adf9c267 100644
@@ -22,9 +22,9 @@ u8 versal2_get_bootmode(void);
 /* EL3 clock/timer register setup, called from board_early_init_r() */
 void versal2_timer_setup(void);
 
-int zynqmp_pm_ufs_get_txrx_cfgrdy(u32 *value);
-int zynqmp_pm_ufs_sram_csr_read(u32 *value);
-int zynqmp_pm_ufs_sram_csr_write(u32 *value);
-int zynqmp_pm_ufs_cal_reg(u32 *value);
+int zynqmp_pm_wait_mphy_tx_rx_config_ready(u32 timeout_us);
+int zynqmp_pm_wait_sram_init_done(u32 timeout_us);
+int zynqmp_pm_set_sram_bypass(void);
+int zynqmp_pm_get_ufs_calibration_values(u32 *value);
 
 #endif /* _ASM_ARCH_SYS_PROTO_H */
drivers/firmware/firmware-zynqmp.c +44 -28

116 lines not on this page · raw message

drivers/ufs/ufs-amd-versal2.c +17 -56

125 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/3 ufs: amd-versal2: Remove ZYNQMP_FIRMWARE dependency

In reply to Michal Simek

There are EEMI firmware hooks available but they are also IO versions of it that's why remove ZYNQMP_FIRMWARE depency from UFS driver.

---

 drivers/ufs/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ufs/Kconfig +1 -1
index c1b84bd75597..6dffdc00b32e 100644
@@ -10,7 +10,7 @@ config UFS
 
 config UFS_AMD_VERSAL2
 	bool "AMD Versal Gen 2 UFS controller platform driver"
-	depends on UFS && ZYNQMP_FIRMWARE
+	depends on UFS && ARCH_VERSAL2
 	help
 	  This selects the AMD specific additions to UFSHCD platform driver.
 	  UFS host on AMD needs some vendor specific configuration before accessing
Signature · 1 line
2.43.0
author maintainer Applied
#4 lore raw
In reply to Michal Simek
Quoted 34 lines · Michal Simek

Hi,

the first patch mainly alignment with Linux kernel version. Issue was related to IRQ handling which is not valid reason for U-Boot but still correcting sequence make sense.

The second patch is moving firmware handling out of UFS driver. UFS driver cares about delivering functionality. And doesn't really matter how exactly it is done. If it is done via firmware interface, via IO polling or in a different way. That's why move loops out of UFS driver to be able to use different interfaces for it.

The third patch is just Kconfig update.

The series is based on
https://patchwork.ozlabs.org/project/uboot/patch/6419fe4f6f1f451aee624c7762b7aa690d50e498.1784870711.git.michal.simek@amd.com/

Thanks,
Michal

Michal Simek (3):
ufs: amd-versal2: Perform controller reset in the init callback
xilinx: versal2: Clean UFS firmware interface
ufs: amd-versal2: Remove ZYNQMP_FIRMWARE dependency

  arch/arm/mach-versal2/cpu.c                   |  34 +++--
  arch/arm/mach-versal2/include/mach/hardware.h |   5 +
  .../arm/mach-versal2/include/mach/sys_proto.h |   8 +-
  drivers/firmware/firmware-zynqmp.c            |  72 ++++++----
  drivers/ufs/Kconfig                           |   2 +-
  drivers/ufs/ufs-amd-versal2.c                 | 129 ++++++------------
  6 files changed, 119 insertions(+), 131 deletions(-)
Quoted 3 lines

---
base-commit: 7e24149aacb83335fa997e2457144f23ba5e1bda

applied.
M