Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: mediatek: Handle mPHY power-on failures
@ 2026-08-28  9:23 Pengpeng Hou
  2026-08-28  9:40 ` sashiko-bot
  2026-08-30  9:52 ` Stanley Jhu
  0 siblings, 2 replies; 3+ messages in thread
From: Pengpeng Hou @ 2026-08-28  9:23 UTC (permalink / raw)
  To: Peter Wang, Chaotian Jing
  Cc: Pengpeng Hou, Stanley Jhu, James E . J . Bottomley,
	Martin K . Petersen, Matthias Brugger, AngeloGioacchino Del Regno,
	linux-scsi, linux-mediatek, linux-kernel, linux-arm-kernel

ufs_mtk_mphy_power_on() enables the optional VA09 supply before powering
on the mPHY.  The PHY result is ignored, so a failure leaves VA09
enabled and records mphy_powered_on as true, suppressing later retries.
The initialization path also ignores the helper result and continues
setting up the host.

Check phy_power_on(), turn VA09 back off on failure, and leave the state
flag unchanged.  Propagate the helper error from initialization as well
as the existing resume caller.  Keep regulator and mPHY diagnostics on
separate paths so regulator errors are not mislabeled.

The issue was identified via static analysis and manually reviewed.

Fixes: 561e3a8726b2 ("scsi: ufs-mediatek: Fix unbalanced clock on/off")
Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations")

Assisted-by: LLM
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 drivers/ufs/host/ufs-mediatek.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 814c1b7343b9..9d481147ea38 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -509,6 +509,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
 	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
 	struct phy *mphy = host->mphy;
 	struct arm_smccc_res res;
+	int rollback_ret;
 	int ret = 0;
 
 	if (!mphy || !(on ^ host->mphy_powered_on))
@@ -523,7 +524,18 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
 			usleep_range(200, 210);
 			ufs_mtk_va09_pwr_ctrl(res, 1);
 		}
-		phy_power_on(mphy);
+		ret = phy_power_on(mphy);
+		if (ret) {
+			if (ufs_mtk_is_va09_supported(hba)) {
+				ufs_mtk_va09_pwr_ctrl(res, 0);
+				rollback_ret = regulator_disable(host->reg_va09);
+				if (rollback_ret)
+					dev_warn(hba->dev, "failed to disable va09 after mphy failure: %d\n",
+						 rollback_ret);
+			}
+			dev_info(hba->dev, "failed to enable mphy: %d\n", ret);
+			return ret;
+		}
 	} else {
 		phy_power_off(mphy);
 		if (ufs_mtk_is_va09_supported(hba)) {
@@ -1295,7 +1307,9 @@ static int ufs_mtk_init(struct ufs_hba *hba)
 	 *
 	 * Enable phy clocks specifically here.
 	 */
-	ufs_mtk_mphy_power_on(hba, true);
+	err = ufs_mtk_mphy_power_on(hba, true);
+	if (err)
+		goto out_variant_clear;
 
 	if (ufs_mtk_is_rtff_mtcmos(hba)) {
 		/* First Restore here, to avoid backup unexpected value */
-- 
2.43.0


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

end of thread, other threads:[~2026-08-30  9:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28  9:23 [PATCH] scsi: ufs: mediatek: Handle mPHY power-on failures Pengpeng Hou
2026-08-28  9:40 ` sashiko-bot
2026-08-30  9:52 ` Stanley Jhu

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