* [PATCH v3 0/2] scsi: ufs-mediatek: fix va09 regulator lifecycle
@ 2026-11-19 7:16 Xiangwu Lai
2026-11-19 7:16 ` [PATCH v3 1/2] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator Xiangwu Lai
2026-11-19 7:16 ` [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails Xiangwu Lai
0 siblings, 2 replies; 4+ messages in thread
From: Xiangwu Lai @ 2026-11-19 7:16 UTC (permalink / raw)
To: peter.wang, chaotian.jing
Cc: chu.stanley, alim.akhtar, bvanassche, stanley.chu, sashiko-bot,
linux-scsi, linux-mediatek, linux-kernel, Xiangwu Lai
Two fixes for the va09 regulator handling of the Mediatek UFS variant
driver.
Patch 1 converts the va09 acquisition to devm_regulator_get() and adds
an .exit callback that powers the M-PHY off, so the enable count is
balanced when devm releases the regulator.
Patch 2 fixes the state desynchronization of the power-off error path:
when regulator_disable() fails, the M-PHY is left physically off while
mphy_powered_on stays set, and the next power-on never retries.
Both issues were found by manual code inspection of the va09 error
paths; neither has been observed on real hardware, and no MTK UFS
hardware was available for testing. The affected paths only trigger
when a va09 regulator operation fails, which does not happen on a
working system.
Changes in v3:
- patch 2: restore the M-PHY power state when regulator_disable()
fails (phy_power_on() plus the va09 SMC call) instead of forcing
mphy_powered_on to false, as suggested by Peter Wang. This also
keeps the va09 enable count balanced and leaves the suspend error
recovery running with the M-PHY powered, resolving both findings of
the Sashiko AI review of v2.
- patch 1: no functional change, the Reviewed-by tag received for v2
is kept.
Link: https://lore.kernel.org/r/20261118032015.974-1-laixiangwu@cmss.chinamobile.com/
Xiangwu Lai (2):
scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
scsi: ufs-mediatek: restore the M-PHY power state when va09 disable
fails
drivers/ufs/host/ufs-mediatek.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 1/2] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator
2026-11-19 7:16 [PATCH v3 0/2] scsi: ufs-mediatek: fix va09 regulator lifecycle Xiangwu Lai
@ 2026-11-19 7:16 ` Xiangwu Lai
2026-11-19 7:16 ` [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails Xiangwu Lai
1 sibling, 0 replies; 4+ messages in thread
From: Xiangwu Lai @ 2026-11-19 7:16 UTC (permalink / raw)
To: peter.wang, chaotian.jing
Cc: chu.stanley, alim.akhtar, bvanassche, stanley.chu, sashiko-bot,
linux-scsi, linux-mediatek, linux-kernel, Xiangwu Lai
ufs_mtk_init_va09_pwr_ctrl() obtains the va09 regulator with
regulator_get() but the reference is never released with
regulator_put(), neither on driver unbind nor on probe failure. The
other regulators handled by this driver (dvfsrc-vcore) are already
obtained with devm_regulator_get_optional().
Use devm_regulator_get() so that the reference is released
automatically when the UFS device is detached.
This alone is not enough, though: ufs_mtk_init() powers the M-PHY on,
which enables the va09 regulator, and nothing powers it off again on
the way out -- the variant operations have no .exit callback and
ufshcd_pltfrm_remove() only resumes the device. The devm release
would then hit WARN_ON(regulator->enable_count) in _regulator_put()
and leak the enable reference.
Balance the use count by adding an .exit callback which powers the
M-PHY off, in the same spirit as the .exit callbacks of ufs-exynos
and ufs-qcom. ufshcd_hba_exit() invokes it both on driver unbind and
on ufshcd_init() failure after the variant init, so the enable count
is always balanced by the time devm releases the regulator. It
relies on the state tracking in ufs_mtk_mphy_power_on() and is a
no-op if the M-PHY was never powered on.
Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations")
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
drivers/ufs/host/ufs-mediatek.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
Changes in v3:
- none, the Reviewed-by tag received for v2 is kept.
Link: https://lore.kernel.org/r/20261118032015.974-2-laixiangwu@cmss.chinamobile.com/
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 5b6bff2cf..ebbc017d0 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -692,7 +692,7 @@ static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba)
{
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
- host->reg_va09 = regulator_get(hba->dev, "va09");
+ host->reg_va09 = devm_regulator_get(hba->dev, "va09");
if (IS_ERR(host->reg_va09))
dev_info(hba->dev, "failed to get va09");
else
@@ -1331,6 +1331,14 @@ static int ufs_mtk_init(struct ufs_hba *hba)
return err;
}
+static void ufs_mtk_exit(struct ufs_hba *hba)
+{
+ struct ufs_mtk_host *host = ufshcd_get_variant(hba);
+
+ if (host)
+ ufs_mtk_mphy_power_on(hba, false);
+}
+
static int ufs_mtk_negotiate_pwr_mode(struct ufs_hba *hba,
const struct ufs_pa_layer_attr *dev_max_params,
struct ufs_pa_layer_attr *dev_req_params)
@@ -2353,6 +2361,7 @@ static void ufs_mtk_config_scsi_dev(struct scsi_device *sdev)
static const struct ufs_hba_variant_ops ufs_hba_mtk_vops = {
.name = "mediatek.ufshci",
.init = ufs_mtk_init,
+ .exit = ufs_mtk_exit,
.get_ufs_hci_version = ufs_mtk_get_ufs_hci_version,
.setup_clocks = ufs_mtk_setup_clocks,
.hce_enable_notify = ufs_mtk_hce_enable_notify,
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails
2026-11-19 7:16 [PATCH v3 0/2] scsi: ufs-mediatek: fix va09 regulator lifecycle Xiangwu Lai
2026-11-19 7:16 ` [PATCH v3 1/2] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator Xiangwu Lai
@ 2026-11-19 7:16 ` Xiangwu Lai
2026-11-19 8:36 ` Peter Wang
1 sibling, 1 reply; 4+ messages in thread
From: Xiangwu Lai @ 2026-11-19 7:16 UTC (permalink / raw)
To: peter.wang, chaotian.jing
Cc: chu.stanley, alim.akhtar, bvanassche, stanley.chu, sashiko-bot,
linux-scsi, linux-mediatek, linux-kernel, Xiangwu Lai
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@mediatek.com>
Link: https://lore.kernel.org/r/sashiko-outbox-220026@kernel.org
Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator operations")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
drivers/ufs/host/ufs-mediatek.c | 10 ++++++++++
1 file changed, 10 insertions(+)
Changes in v3:
- restore the M-PHY power state when regulator_disable() fails
(phy_power_on() plus the va09 SMC call) instead of forcing
mphy_powered_on to false, as suggested by Peter Wang. This also
keeps the va09 enable count balanced and leaves the suspend error
recovery running with the M-PHY powered, resolving both findings of
the Sashiko AI review of v2
(https://lore.kernel.org/all/sashiko-outbox-220026@kernel.org/).
Link: https://lore.kernel.org/r/20261118032015.974-3-laixiangwu@cmss.chinamobile.com/
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index ebbc017d0..caf186966 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -541,6 +541,16 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
if (ufs_mtk_is_va09_supported(hba)) {
ufs_mtk_va09_pwr_ctrl(res, 0);
ret = regulator_disable(host->reg_va09);
+ if (ret) {
+ /*
+ * The va09 regulator stays enabled, so
+ * bring the M-PHY back up to keep the
+ * software state in sync with the
+ * hardware.
+ */
+ ufs_mtk_va09_pwr_ctrl(res, 1);
+ phy_power_on(mphy);
+ }
}
}
out:
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails
2026-11-19 7:16 ` [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails Xiangwu Lai
@ 2026-11-19 8:36 ` Peter Wang
0 siblings, 0 replies; 4+ messages in thread
From: Peter Wang @ 2026-11-19 8:36 UTC (permalink / raw)
To: Xiangwu Lai, chaotian.jing
Cc: chu.stanley, alim.akhtar, bvanassche, sashiko-bot, linux-scsi,
linux-mediatek, linux-kernel
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@mediatek.com>
> Link: https://lore.kernel.org/r/sashiko-outbox-220026@kernel.org
> Fixes: cf137b3ea49a ("scsi: ufs-mediatek: Support VA09 regulator
> operations")
> Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
> ---
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-19 8:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 7:16 [PATCH v3 0/2] scsi: ufs-mediatek: fix va09 regulator lifecycle Xiangwu Lai
2026-11-19 7:16 ` [PATCH v3 1/2] scsi: ufs-mediatek: use devm_regulator_get() for the va09 regulator Xiangwu Lai
2026-11-19 7:16 ` [PATCH v3 2/2] scsi: ufs-mediatek: restore the M-PHY power state when va09 disable fails Xiangwu Lai
2026-11-19 8:36 ` 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®