Re: [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails

From: Peter Wang

Date: Thu Nov 19 2026 - 03:36:53 EST


On Thu, 2026-11-19 at 15:16 +0800, Xiangwu Lai wrote:
> In ufs_mtk_mphy_power_on(), the power-off path tears the M-PHY down
> in
> two steps before regulator_disable() is called: phy_power_off() puts
> the PHY PLL and its clocks down, and ufs_mtk_va09_pwr_ctrl() asks the
> firmware to drop the VA09 supply.  If regulator_disable() then fails,
> the M-PHY stays physically off while host->mphy_powered_on is left
> set, so the next power-on attempt bails out through the
> !(on ^ host->mphy_powered_on) check and never powers the M-PHY back
> up, leaving the UFS host with an unpowered PHY (I/O timeouts,
> controller lockups).
>
> Simply forcing mphy_powered_on to false would trade this for two more
> problems.  First, the regulator core drops the consumer enable count
> only after a successful disable, so the count stays at 1, the next
> power-on raises it to 2 and it never returns to zero: va09 is then
> never physically disabled and the devm-acquired regulator would hit
> WARN_ON(enable_count) again on release.  Second, when the power-off
> fails during ufs_mtk_suspend(), the error recovery in
> __ufshcd_wl_suspend() runs ufshcd_host_reset_and_restore() without
> powering the M-PHY back on, which would run against an unpowered PHY.
> (Both points were raised by the Sashiko AI review of v2.)
>
> Since the va09 regulator stays enabled when its disable fails,
> restore
> the M-PHY power state instead: power the PHY back on through
> ufs_mtk_va09_pwr_ctrl() and phy_power_on() and leave mphy_powered_on
> set.  The next power-off attempt then retries the full sequence and
> the enable count stays balanced.
>
> Found by code inspection while reviewing the va09 error paths of the
> driver; the failure has not been observed on real hardware.
>
> Suggested-by: Peter Wang <peter.wang@xxxxxxxxxxxx>
> Link: https://lore.kernel.org/r/sashiko-outbox-220026@xxxxxxxxxx
> Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator
> operations")
> Signed-off-by: Xiangwu Lai <laixiangwu@xxxxxxxxxxxxxxxxxxxx>
> ---

Reviewed-by: Peter Wang <peter.wang@xxxxxxxxxxxx>