* [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures
@ 2026-09-20 3:49 Pengpeng Hou
2026-09-21 13:02 ` Peter Wang
2026-09-21 14:08 ` Stanley Jhu
0 siblings, 2 replies; 4+ messages in thread
From: Pengpeng Hou @ 2026-09-20 3:49 UTC (permalink / raw)
To: peter.wang
Cc: chaotian.jing, chu.stanley, james.bottomley, mkp, linux-scsi,
linux-mediatek, linux-kernel, martin.petersen, matthias.bgg,
angelogioacchino.delregno, linux-arm-kernel, stanleyjhu,
hppiscas
The MediaTek helper enables VA09 before powering on the mPHY, but
ignores the PHY result. A failure can leave VA09 enabled and publish
mphy_powered_on as true, so a later power-on attempt is skipped.
Check phy_power_on(), attempt to unwind VA09 on failure, and leave the
state flag unchanged. Propagate the helper result from host
initialization as well as its existing resume caller. Keep the original
PHY error if the supply rollback also fails, and report that rollback
separately.
The issue was found by our static-analysis tool.
Fixes: 561e3a8726b2 ("scsi: ufs-mediatek: Fix unbalanced clock on/off")
Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations")
Assisted-by: gpt 5
Signed-off-by: Pengpeng Hou <hppiscas@163.com>
---
Changes since v1:
https://lore.kernel.org/all/20260828092311.10774-1-pengpeng@iscas.ac.cn/
Use err for the rollback result and dev_err() for operation failures, as
Stanley requested.
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..12a6d4138e44 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 err;
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);
+ err = regulator_disable(host->reg_va09);
+ if (err)
+ dev_err(hba->dev,
+ "failed to unwind va09: %d\n", err);
+ }
+ dev_err(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 */
base-commit: 518e5b794c06c0f0eb40df3e202274a66202c137
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures
2026-09-20 3:49 [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures Pengpeng Hou
@ 2026-09-21 13:02 ` Peter Wang
2026-09-21 14:08 ` Stanley Jhu
1 sibling, 0 replies; 4+ messages in thread
From: Peter Wang @ 2026-09-21 13:02 UTC (permalink / raw)
To: Pengpeng Hou
Cc: chaotian.jing, chu.stanley, james.bottomley, mkp, linux-scsi,
linux-mediatek, linux-kernel, martin.petersen, matthias.bgg,
angelogioacchino.delregno, linux-arm-kernel, stanleyjhu
On Sun, 2026-09-20 at 11:49 +0800, Pengpeng Hou wrote:
> The MediaTek helper enables VA09 before powering on the mPHY, but
> ignores the PHY result. A failure can leave VA09 enabled and publish
> mphy_powered_on as true, so a later power-on attempt is skipped.
>
> Check phy_power_on(), attempt to unwind VA09 on failure, and leave
> the
> state flag unchanged. Propagate the helper result from host
> initialization as well as its existing resume caller. Keep the
> original
> PHY error if the supply rollback also fails, and report that rollback
> separately.
>
> The issue was found by our static-analysis tool.
>
> Fixes: 561e3a8726b2 ("scsi: ufs-mediatek: Fix unbalanced clock
> on/off")
> Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator
> operations")
> Assisted-by: gpt 5
> Signed-off-by: Pengpeng Hou <hppiscas@163.com>
> ---
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures
2026-09-20 3:49 [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures Pengpeng Hou
2026-09-21 13:02 ` Peter Wang
@ 2026-09-21 14:08 ` Stanley Jhu
1 sibling, 0 replies; 4+ messages in thread
From: Stanley Jhu @ 2026-09-21 14:08 UTC (permalink / raw)
To: Pengpeng Hou, Peter Wang
Cc: Stanley Jhu, chaotian.jing, chu.stanley, james.bottomley, mkp,
linux-scsi, linux-mediatek, linux-kernel, martin.petersen,
matthias.bgg, angelogioacchino.delregno, linux-arm-kernel
On Sun, 20 Sep 2026 11:49:53 +0800, Pengpeng Hou wrote:
> Check phy_power_on(), attempt to unwind VA09 on failure, and leave the
> state flag unchanged. Propagate the helper result from host
> initialization as well as its existing resume caller. Keep the original
> PHY error if the supply rollback also fails, and report that rollback
> separately.
Reviewed-by: Stanley Jhu <stanleyjhu@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures
@ 2026-09-21 8:09 Peter Wang (王信友)
0 siblings, 0 replies; 4+ messages in thread
From: Peter Wang (王信友) @ 2026-09-21 8:09 UTC (permalink / raw)
To: Pengpeng Hou
Cc: Chaotian Jing (井朝天),
chu.stanley, james.bottomley, mkp, linux-scsi, linux-mediatek,
linux-kernel, martin.petersen, matthias.bgg,
AngeloGioacchino Del Regno, linux-arm-kernel, stanleyjhu
On Sun, 2026-09-20 at 11:49 +0800, Pengpeng Hou wrote:
> The MediaTek helper enables VA09 before powering on the mPHY, but
> ignores the PHY result. A failure can leave VA09 enabled and publish
> mphy_powered_on as true, so a later power-on attempt is skipped.
>
> Check phy_power_on(), attempt to unwind VA09 on failure, and leave
> the
> state flag unchanged. Propagate the helper result from host
> initialization as well as its existing resume caller. Keep the
> original
> PHY error if the supply rollback also fails, and report that rollback
> separately.
>
> The issue was found by our static-analysis tool.
>
> Fixes: 561e3a8726b2 ("scsi: ufs-mediatek: Fix unbalanced clock
> on/off")
> Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator
> operations")
> Assisted-by: gpt 5
> Signed-off-by: Pengpeng Hou <hppiscas@163.com>
> ---
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-21 14:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 3:49 [PATCH v2] scsi: ufs: mediatek: handle mPHY power-on failures Pengpeng Hou
2026-09-21 13:02 ` Peter Wang
2026-09-21 14:08 ` Stanley Jhu
2026-09-21 8:09 Peter Wang (王信友)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®