* [PATCH v3 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
2026-11-30 10:34 [PATCH v3 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
@ 2026-11-30 10:34 ` Ilia Snezhkov via B4 Relay
2026-11-30 10:34 ` [PATCH v3 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
2026-11-30 10:34 ` [PATCH v3 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov via B4 Relay
2 siblings, 0 replies; 5+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-30 10:34 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, phone-devel, linux-kernel
From: Ilia Snezhkov <iasnezhkov@gmail.com>
ufs_mtk_pre_pwr_change() calls ufshcd_dme_configure_adapt() on every
power mode change, which writes PA_TXHSADAPTTYPE (0x15d4) even when
passing PA_NO_ADAPT. PA_TXHSADAPTTYPE was introduced in UniPro 1.8, and
ufs_mtk_get_controller_version() sets host->hw_ver.major = 3 only when
PA_LOCALVERINFO >= UFS_UNIPRO_VER_1_8 (leaving older hosts at major = 2).
On pre-UniPro-1.8 MediaTek hosts such as MT6789 (UFS 2.2, HS-G3 rate B),
the DME write fails on every gear change with
"dme-set: attr-id 0x15d4 val 0x3 failed 0 retries". While mainline
ufshcd_change_power_mode() ignores the PRE_CHANGE return value after
commit d3eba21c7170 ("scsi: ufs: core: Introduce a new ufshcd vops
negotiate_pwr_mode()"), older stable kernels still discard the
negotiated parameters on PRE_CHANGE failure, and mainline still emits
spurious DME-SET errors on every power-mode transition.
Return early from ufs_mtk_pre_pwr_change() when host->hw_ver.major < 3
so pre-UniPro-1.8 hosts do not write PA_TXHSADAPTTYPE, and simplify the
remaining major >= 3 branch.
Fixes: 7212d624f863 ("scsi: ufs: host: mediatek: Fix PWM mode switch issue")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
---
Changes since v2:
- Collected Reviewed-by from Peter Wang.
- Rebased onto linux-next (no code changes).
Changes since v1:
- Corrected Fixes tag from e1e25d1b8996 to 7212d624f863.
- Updated commit description for mainline post-d3eba21c7170 behavior.
- Found on hardware and drafted with an AI coding assistant.
drivers/ufs/host/ufs-mediatek.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 338a1cc..4ba071e 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -1486,21 +1486,18 @@ static int ufs_mtk_pre_pwr_change(struct ufs_hba *hba,
return ret;
}
+ if (host->hw_ver.major < 3)
+ return ret;
+
if (dev_req_params->pwr_rx == FAST_MODE ||
dev_req_params->pwr_rx == FASTAUTO_MODE) {
- if (host->hw_ver.major >= 3) {
- ret = ufshcd_dme_configure_adapt(hba,
- dev_req_params->gear_tx,
- PA_INITIAL_ADAPT);
- } else {
- ret = ufshcd_dme_configure_adapt(hba,
- dev_req_params->gear_tx,
- PA_NO_ADAPT);
- }
+ ret = ufshcd_dme_configure_adapt(hba,
+ dev_req_params->gear_tx,
+ PA_INITIAL_ADAPT);
} else {
ret = ufshcd_dme_configure_adapt(hba,
- dev_req_params->gear_tx,
- PA_NO_ADAPT);
+ dev_req_params->gear_tx,
+ PA_NO_ADAPT);
}
return ret;
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
2026-11-30 10:34 [PATCH v3 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
2026-11-30 10:34 ` [PATCH v3 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
@ 2026-11-30 10:34 ` Ilia Snezhkov via B4 Relay
2026-11-30 11:54 ` Peter Wang
2026-11-30 10:34 ` [PATCH v3 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov via B4 Relay
2 siblings, 1 reply; 5+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-30 10:34 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, phone-devel, linux-kernel
From: Ilia Snezhkov <iasnezhkov@gmail.com>
ufs_mtk_is_clk_scale_ready() only requires ufs_sel, ufs_sel_max_src, and
ufs_sel_min_src, and _ufs_mtk_clk_scale() already gates FDE clock
scaling behind clk_fde_scale (mclk->ufs_fde_max_clki &&
mclk->ufs_fde_min_clki). However, _ufs_mtk_clk_scale() still returns
early on !fde_clki.
Because of that check, platforms without FDE clock scaling currently
have to provide dummy ufs_fde entries in DT (pointing ufs_fde_min_src
and ufs_fde_max_src to the same clock); otherwise _ufs_mtk_clk_scale()
silently becomes a no-op and neither switches ufs_sel nor updates
dvfsrc-vcore when called from devfreq scaling, suspend/resume, or
ufs_mtk_fix_clock_scaling().
Only require clki (ufs_sel) in _ufs_mtk_clk_scale(), and gate
clk_fde_scale on fde_clki being non-NULL alongside its min/max parents
so platforms that do not use FDE scaling can omit the ufs_fde clock
settings.
Fixes: 5e5976f5242d ("scsi: ufs: host: mediatek: Support FDE (AES) clock scaling")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
Changes since v2:
- Rewrote the commit message per Peter Wang's review: dropped the MT6789
DT example (mainline ufs_mtk_fix_clock_scaling() disables clock scaling
below UFS 4.0) and explained that omitting ufs_fde removes the need for
dummy identical ufs_fde_min_src/ufs_fde_max_src DT entries.
- Rebased onto linux-next (no code changes).
Changes since v1:
- Moved AI coding assistant note below ---.
- Found on hardware and drafted with an AI coding assistant.
drivers/ufs/host/ufs-mediatek.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 4ba071e..a7981a3 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -2077,7 +2077,7 @@ static void _ufs_mtk_clk_scale(struct ufs_hba *hba, bool scale_up)
if (!hba->clk_scaling.is_initialized)
return;
- if (!clki || !fde_clki)
+ if (!clki)
return;
reg = host->mclk.reg_vcore;
@@ -2085,7 +2085,7 @@ static void _ufs_mtk_clk_scale(struct ufs_hba *hba, bool scale_up)
if (reg && volt != 0)
clk_bind_vcore = true;
- if (mclk->ufs_fde_max_clki && mclk->ufs_fde_min_clki)
+ if (fde_clki && mclk->ufs_fde_max_clki && mclk->ufs_fde_min_clki)
clk_fde_scale = true;
ret = clk_prepare_enable(clki->clk);
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
2026-11-30 10:34 ` [PATCH v3 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
@ 2026-11-30 11:54 ` Peter Wang
0 siblings, 0 replies; 5+ messages in thread
From: Peter Wang @ 2026-11-30 11:54 UTC (permalink / raw)
To: iasnezhkov, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, phone-devel, linux-kernel
On Mon, 2026-11-30 at 10:34 +0000, Ilia Snezhkov via B4 Relay wrote:
> From: Ilia Snezhkov <iasnezhkov@gmail.com>
>
> ufs_mtk_is_clk_scale_ready() only requires ufs_sel, ufs_sel_max_src,
> and
> ufs_sel_min_src, and _ufs_mtk_clk_scale() already gates FDE clock
> scaling behind clk_fde_scale (mclk->ufs_fde_max_clki &&
> mclk->ufs_fde_min_clki). However, _ufs_mtk_clk_scale() still returns
> early on !fde_clki.
>
> Because of that check, platforms without FDE clock scaling currently
> have to provide dummy ufs_fde entries in DT (pointing ufs_fde_min_src
> and ufs_fde_max_src to the same clock); otherwise
> _ufs_mtk_clk_scale()
> silently becomes a no-op and neither switches ufs_sel nor updates
> dvfsrc-vcore when called from devfreq scaling, suspend/resume, or
> ufs_mtk_fix_clock_scaling().
>
> Only require clki (ufs_sel) in _ufs_mtk_clk_scale(), and gate
> clk_fde_scale on fde_clki being non-NULL alongside its min/max
> parents
> so platforms that do not use FDE scaling can omit the ufs_fde clock
> settings.
>
> Fixes: 5e5976f5242d ("scsi: ufs: host: mediatek: Support FDE (AES)
> clock scaling")
> Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
> ---
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
2026-11-30 10:34 [PATCH v3 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
2026-11-30 10:34 ` [PATCH v3 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
2026-11-30 10:34 ` [PATCH v3 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
@ 2026-11-30 10:34 ` Ilia Snezhkov via B4 Relay
2 siblings, 0 replies; 5+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-30 10:34 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, phone-devel, linux-kernel
From: Ilia Snezhkov <iasnezhkov@gmail.com>
ufshcd_devfreq_target() determines scale_up via an exact equality check
against clki->max_freq after rounding the target frequency. When a DT
freq-table-hz lists a nominal value that a PLL-derived clock cannot hit
exactly (for example, msdcpll_d2 on MT6789 delivers 191999939 Hz for a
192000000 Hz DT maximum), clk_round_rate() produces a rate that never
equals clki->max_freq, so devfreq scales down once and can never scale
back up.
Round clki->max_freq and clki->min_freq with clk_round_rate() in
ufs_mtk_init_clocks() for ufs_sel (and ufs_fde when present) before
ufshcd_devfreq_init() builds the OPP table from those bounds, keeping
clki->curr_freq synchronized with the rounded bound and skipping the
adjustment if rounding fails, overflows u32, or collapses min >= max.
Fixes: b7dbc686f60b ("scsi: ufs: ufs-mediatek: Support clk-scaling to optimize power consumption")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
---
Changes since v2:
- Collected Reviewed-by from Peter Wang.
- Rebased onto linux-next (no code changes).
Changes since v1:
- Use IS_ERR_OR_NULL(clki->clk) and cast max_rounded to u64 before
comparing against U32_MAX for 32-bit cleanliness.
- Found on hardware and drafted with an AI coding assistant.
drivers/ufs/host/ufs-mediatek.c | 35 +++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index a7981a3..ff00db7 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -978,6 +978,37 @@ static u32 ufs_mtk_get_ufs_hci_version(struct ufs_hba *hba)
return hba->ufs_version;
}
+static void ufs_mtk_round_clk_freq(struct ufs_hba *hba,
+ struct ufs_clk_info *clki)
+{
+ long max_rounded, min_rounded;
+
+ if (IS_ERR_OR_NULL(clki->clk) || !clki->max_freq || !clki->min_freq)
+ return;
+
+ max_rounded = clk_round_rate(clki->clk, clki->max_freq);
+ min_rounded = clk_round_rate(clki->clk, clki->min_freq);
+ if (max_rounded <= 0 || min_rounded <= 0 ||
+ min_rounded >= max_rounded || (u64)max_rounded > U32_MAX)
+ return;
+
+ if (max_rounded != clki->max_freq) {
+ dev_dbg(hba->dev, "%s: max_freq %u rounds to %ld\n",
+ clki->name, clki->max_freq, max_rounded);
+ if (clki->curr_freq == clki->max_freq)
+ clki->curr_freq = max_rounded;
+ clki->max_freq = max_rounded;
+ }
+
+ if (min_rounded != clki->min_freq) {
+ dev_dbg(hba->dev, "%s: min_freq %u rounds to %ld\n",
+ clki->name, clki->min_freq, min_rounded);
+ if (clki->curr_freq == clki->min_freq)
+ clki->curr_freq = min_rounded;
+ clki->min_freq = min_rounded;
+ }
+}
+
/**
* ufs_mtk_init_clocks - Init mtk driver private clocks
*
@@ -1033,6 +1064,10 @@ static void ufs_mtk_init_clocks(struct ufs_hba *hba)
return;
}
+ ufs_mtk_round_clk_freq(hba, host->mclk.ufs_sel_clki);
+ if (host->mclk.ufs_fde_clki)
+ ufs_mtk_round_clk_freq(hba, host->mclk.ufs_fde_clki);
+
/*
* Default get vcore if dts have these settings.
* No matter clock scaling support or not. (may disable by customer)
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 5+ messages in thread