* [PATCH v2 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes
@ 2026-11-26 3:10 Ilia Snezhkov via B4 Relay
2026-11-26 3:10 ` [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26 3:10 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, linux-kernel
This series fixes three bugs in the MediaTek UFS host driver observed on
MT6789 (UFS 2.2, pre-UniPro-1.8, HS-G3 rate B, no ufs_fde clock):
1. Skip ufshcd_dme_configure_adapt() when host->hw_ver.major < 3 so
pre-UniPro-1.8 hosts do not fail DME-SET on PA_TXHSADAPTTYPE (0x15d4)
on every power-mode change.
2. Allow _ufs_mtk_clk_scale() to switch ufs_sel when the optional
ufs_fde clock is absent, matching ufs_mtk_is_clk_scale_ready().
3. Round clki->max_freq and clki->min_freq with clk_round_rate() during
ufs_mtk_init_clocks() so PLL-derived clocks whose rounded rate
differs from the nominal DT frequency can scale back up in
ufshcd_devfreq_target().
Changes since v1:
- Patch 1: corrected Fixes tag to 7212d624f863 ("scsi: ufs: host:
mediatek: Fix PWM mode switch issue") and clarified mainline behavior
after d3eba21c7170 vs older stable kernels.
- Patch 3: use IS_ERR_OR_NULL(clki->clk) and cast max_rounded to u64
before comparing with U32_MAX to avoid 32-bit -Wtype-limits warnings.
- Moved AI assistant disclosure out of commit logs (below --- and in
this cover letter).
Found on hardware and drafted with an AI coding assistant.
Ilia Snezhkov (3):
scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
drivers/ufs/host/ufs-mediatek.c | 58 +++++++++++++++++++++++++--------
1 file changed, 45 insertions(+), 13 deletions(-)
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
2026-11-26 3:10 [PATCH v2 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
@ 2026-11-26 3:10 ` Ilia Snezhkov via B4 Relay
2026-11-26 13:01 ` Peter Wang
2026-11-26 3:10 ` [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
2026-11-26 3:10 ` [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov via B4 Relay
2 siblings, 1 reply; 11+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26 3:10 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, 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>
---
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 7691349..38d05ac 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -1468,21 +1468,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] 11+ messages in thread
* [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
2026-11-26 3:10 [PATCH v2 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
2026-11-26 3:10 ` [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
@ 2026-11-26 3:10 ` Ilia Snezhkov via B4 Relay
2026-11-26 13:03 ` Peter Wang
2026-11-26 3:10 ` [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov via B4 Relay
2 siblings, 1 reply; 11+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26 3:10 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, linux-kernel
From: Ilia Snezhkov <iasnezhkov@gmail.com>
ufs_mtk_is_clk_scale_ready() enables UFSHCD_CAP_CLK_SCALING whenever
ufs_sel, ufs_sel_max_src, and ufs_sel_min_src are present, treating the
FDE (AES) clock as optional. However, _ufs_mtk_clk_scale() bails out
early on !fde_clki, so on SoCs without a ufs_fde clock (such as MT6789)
ufshcd believes scaling succeeded and updates clki->curr_freq while the
ufs_sel mux never switches parents.
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.
Fixes: 5e5976f5242d ("scsi: ufs: host: mediatek: Support FDE (AES) clock scaling")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
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 38d05ac..09b7993 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -2059,7 +2059,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;
@@ -2067,7 +2067,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] 11+ messages in thread
* [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
2026-11-26 3:10 [PATCH v2 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
2026-11-26 3:10 ` [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
2026-11-26 3:10 ` [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
@ 2026-11-26 3:10 ` Ilia Snezhkov via B4 Relay
2026-11-26 13:04 ` Peter Wang
2 siblings, 1 reply; 11+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26 3:10 UTC (permalink / raw)
To: peter.wang, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, 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>
---
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 09b7993..4de72ae 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -967,6 +967,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
*
@@ -1022,6 +1053,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] 11+ messages in thread
* Re: [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
2026-11-26 3:10 ` [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
@ 2026-11-26 13:01 ` Peter Wang
0 siblings, 0 replies; 11+ messages in thread
From: Peter Wang @ 2026-11-26 13:01 UTC (permalink / raw)
To: iasnezhkov, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, linux-kernel
On Thu, 2026-11-26 at 03:10 +0000, Ilia Snezhkov via B4 Relay wrote:
> 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>
> ---
Hi Ilia,
Thank you for fixing this bug.
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
2026-11-26 3:10 ` [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
@ 2026-11-26 13:03 ` Peter Wang
2026-11-27 1:10 ` Ilia Snezhkov
0 siblings, 1 reply; 11+ messages in thread
From: Peter Wang @ 2026-11-26 13:03 UTC (permalink / raw)
To: iasnezhkov, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, linux-kernel
On Thu, 2026-11-26 at 03:10 +0000, Ilia Snezhkov via B4 Relay wrote:
> From: Ilia Snezhkov <iasnezhkov@gmail.com>
>
> ufs_mtk_is_clk_scale_ready() enables UFSHCD_CAP_CLK_SCALING whenever
> ufs_sel, ufs_sel_max_src, and ufs_sel_min_src are present, treating
> the
> FDE (AES) clock as optional. However, _ufs_mtk_clk_scale() bails out
> early on !fde_clki, so on SoCs without a ufs_fde clock (such as
> MT6789)
> ufshcd believes scaling succeeded and updates clki->curr_freq while
> the
> ufs_sel mux never switches parents.
>
> 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.
Hi Ilia,
The logic is basically fine, but I'm a bit curious:
would this change cause MT6789 to enable UFSHCD_CAP_CLK_SCALING?
Thanks
Peter
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
2026-11-26 3:10 ` [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov via B4 Relay
@ 2026-11-26 13:04 ` Peter Wang
2026-11-27 1:14 ` Ilia Snezhkov
0 siblings, 1 reply; 11+ messages in thread
From: Peter Wang @ 2026-11-26 13:04 UTC (permalink / raw)
To: iasnezhkov, stanley.chu, martin.petersen, James.Bottomley
Cc: matthias.bgg, angelogioacchino.delregno, louisalexis.eyraud,
linux-scsi, linux-mediatek, linux-kernel
On Thu, 2026-11-26 at 03:10 +0000, Ilia Snezhkov via B4 Relay wrote:
> 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
Hi Ilia,
I am curious why the HW generates this value of 191999939 Hz.
Should the HW need a calibration to generate exactly 192000000 Hz?
Thanks.
Peter
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
2026-11-26 13:03 ` Peter Wang
@ 2026-11-27 1:10 ` Ilia Snezhkov
2026-11-27 6:44 ` Peter Wang
0 siblings, 1 reply; 11+ messages in thread
From: Ilia Snezhkov @ 2026-11-27 1:10 UTC (permalink / raw)
To: Peter Wang
Cc: stanley.chu, martin.petersen, James.Bottomley, matthias.bgg,
angelogioacchino.delregno, louisalexis.eyraud, linux-scsi,
linux-mediatek, linux-kernel
Hi Peter,
No — this patch does not change whether UFSHCD_CAP_CLK_SCALING is
enabled.
ufs_mtk_is_clk_scale_ready() only checks ufs_sel, ufs_sel_max_src, and
ufs_sel_min_src, so on any platform (including MT6789) whose DT
provides those three clocks, UFSHCD_CAP_CLK_SCALING is already enabled
today and devfreq already runs. Platforms that omit ufs_sel_{min,max}_src
still have UFSHCD_CAP_CLK_SCALING cleared as before.
What was broken without this patch is that when a DT provides ufs_sel
and its min/max sources without ufs_fde, _ufs_mtk_clk_scale() returned
early on `!fde_clki`, so ufs_sel never actually switched parents while
ufshcd still treated the scaling transition as successful and updated
clki->curr_freq.
With this change, MT6789's already-enabled clock scaling actually
switches ufs_sel between 26 MHz (tck_26m_mx9) and 192 MHz (msdcpll_d2)
as intended.
Best regards,
Ilia
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
2026-11-26 13:04 ` Peter Wang
@ 2026-11-27 1:14 ` Ilia Snezhkov
2026-11-27 7:11 ` Peter Wang
0 siblings, 1 reply; 11+ messages in thread
From: Ilia Snezhkov @ 2026-11-27 1:14 UTC (permalink / raw)
To: Peter Wang
Cc: stanley.chu, martin.petersen, James.Bottomley, matthias.bgg,
angelogioacchino.delregno, louisalexis.eyraud, linux-scsi,
linux-mediatek, linux-kernel
Hi Peter,
It is not a missing hardware calibration — it comes directly from the
fractional-N PLL PCW quantization against the 26 MHz reference crystal
(clk26m).
On MT6789, msdcpll has pcwbits = 22 and pcwibits = 8 (14 fractional
bits, 2^14 = 16384), with VCO range 1500..3800 MHz, and ufs_sel_max_src
is msdcpll_d2 (msdcpll / 2). To target msdcpll = 384 MHz (msdcpll_d2 =
192 MHz) at postdiv = 4, VCO = 1536 MHz, so the required multiplier is:
1536 / 26 = 768 / 13 = 59 + 1/13
Because 1/13 is a non-terminating binary fraction, no integer PCW value
can represent 384 MHz exactly in 14 fractional bits:
pcw = 0xec4ec (967916) -> vco = 1535999512 Hz -> msdcpll = 383999878 Hz -> msdcpll_d2 = 191999939 Hz (-61 Hz)
pcw = 0xec4ed (967917) -> vco = 1536001099 Hz -> msdcpll = 384000275 Hz -> msdcpll_d2 = 192000137 Hz (+137 Hz)
(With postdiv = 8, VCO = 3072 MHz = 26 MHz * (118 + 2/13), the closest
PCW values give 191999939 Hz and 192000038 Hz — still never exactly
192000000 Hz.)
So the CCF __mtk_pll_recalc_rate() / clk_round_rate() result for
msdcpll_d2 is deterministically 191999939 Hz, which never matches a
nominal 192000000 Hz entry in freq-table-hz under ufshcd_devfreq_target()'s
exact `freq == clki->max_freq` check.
Best regards,
Ilia
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
2026-11-27 1:10 ` Ilia Snezhkov
@ 2026-11-27 6:44 ` Peter Wang
0 siblings, 0 replies; 11+ messages in thread
From: Peter Wang @ 2026-11-27 6:44 UTC (permalink / raw)
To: Ilia Snezhkov
Cc: martin.petersen, James.Bottomley, matthias.bgg,
angelogioacchino.delregno, louisalexis.eyraud, linux-scsi,
linux-mediatek, linux-kernel
On Fri, 2026-11-27 at 09:10 +0800, Ilia Snezhkov wrote:
> Hi Peter,
>
> No — this patch does not change whether UFSHCD_CAP_CLK_SCALING is
> enabled.
>
> ufs_mtk_is_clk_scale_ready() only checks ufs_sel, ufs_sel_max_src,
> and
> ufs_sel_min_src, so on any platform (including MT6789) whose DT
> provides those three clocks, UFSHCD_CAP_CLK_SCALING is already
> enabled
> today and devfreq already runs. Platforms that omit
> ufs_sel_{min,max}_src
> still have UFSHCD_CAP_CLK_SCALING cleared as before.
>
> What was broken without this patch is that when a DT provides ufs_sel
> and its min/max sources without ufs_fde, _ufs_mtk_clk_scale()
> returned
> early on `!fde_clki`, so ufs_sel never actually switched parents
> while
> ufshcd still treated the scaling transition as successful and updated
> clki->curr_freq.
>
> With this change, MT6789's already-enabled clock scaling actually
> switches ufs_sel between 26 MHz (tck_26m_mx9) and 192 MHz
> (msdcpll_d2)
> as intended.
>
> Best regards,
> Ilia
Hi Ilia,
Sorry, my question was not clear.
Because MediaTek sets the minimum gear to G4:
hba->clk_scaling.min_gear = UFS_HS_G4;
So if the host does not support UFS 4.0 or above, there
should be no reason to enable clock scaling.
And MT6789 is UFSHCI 2.1, as I remember, so clock scaling
should be disabled and ufs_sel_max_src/ufs_sel_min_src
should not be set. So I am curious why they have been set,
and what behavior would clock scaling change in the power mode?
Thanks
Peter
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
2026-11-27 1:14 ` Ilia Snezhkov
@ 2026-11-27 7:11 ` Peter Wang
0 siblings, 0 replies; 11+ messages in thread
From: Peter Wang @ 2026-11-27 7:11 UTC (permalink / raw)
To: Ilia Snezhkov
Cc: stanley.chu, martin.petersen, James.Bottomley, matthias.bgg,
angelogioacchino.delregno, louisalexis.eyraud, linux-scsi,
linux-mediatek, linux-kernel
On Fri, 2026-11-27 at 09:14 +0800, Ilia Snezhkov wrote:
> Hi Peter,
>
> It is not a missing hardware calibration — it comes directly from the
> fractional-N PLL PCW quantization against the 26 MHz reference
> crystal
> (clk26m).
>
> On MT6789, msdcpll has pcwbits = 22 and pcwibits = 8 (14 fractional
> bits, 2^14 = 16384), with VCO range 1500..3800 MHz, and
> ufs_sel_max_src
> is msdcpll_d2 (msdcpll / 2). To target msdcpll = 384 MHz (msdcpll_d2
> =
> 192 MHz) at postdiv = 4, VCO = 1536 MHz, so the required multiplier
> is:
>
> 1536 / 26 = 768 / 13 = 59 + 1/13
>
> Because 1/13 is a non-terminating binary fraction, no integer PCW
> value
> can represent 384 MHz exactly in 14 fractional bits:
>
> pcw = 0xec4ec (967916) -> vco = 1535999512 Hz -> msdcpll =
> 383999878 Hz -> msdcpll_d2 = 191999939 Hz (-61 Hz)
> pcw = 0xec4ed (967917) -> vco = 1536001099 Hz -> msdcpll =
> 384000275 Hz -> msdcpll_d2 = 192000137 Hz (+137 Hz)
>
> (With postdiv = 8, VCO = 3072 MHz = 26 MHz * (118 + 2/13), the
> closest
> PCW values give 191999939 Hz and 192000038 Hz — still never exactly
> 192000000 Hz.)
>
> So the CCF __mtk_pll_recalc_rate() / clk_round_rate() result for
> msdcpll_d2 is deterministically 191999939 Hz, which never matches a
> nominal 192000000 Hz entry in freq-table-hz under
> ufshcd_devfreq_target()'s
> exact `freq == clki->max_freq` check.
>
> Best regards,
> Ilia
Thank you for your detailed explanation.
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-27 7:11 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 3:10 [PATCH v2 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov via B4 Relay
2026-11-26 3:10 ` [PATCH v2 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov via B4 Relay
2026-11-26 13:01 ` Peter Wang
2026-11-26 3:10 ` [PATCH v2 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov via B4 Relay
2026-11-26 13:03 ` Peter Wang
2026-11-27 1:10 ` Ilia Snezhkov
2026-11-27 6:44 ` Peter Wang
2026-11-26 3:10 ` [PATCH v2 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov via B4 Relay
2026-11-26 13:04 ` Peter Wang
2026-11-27 1:14 ` Ilia Snezhkov
2026-11-27 7:11 ` 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®