All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes
@ 2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay
  0 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov @ 2026-11-26  0:53 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)
   and discard negotiated power-mode parameters on every gear 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() (keeping clki->curr_freq synchronized and
   preserving min < max <= U32_MAX) so PLL-derived clocks whose rounded
   rate differs from the nominal DT frequency can scale back up in
   ufshcd_devfreq_target().

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] 9+ messages in thread

* [PATCH 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes
@ 2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay
  0 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:53 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)
   and discard negotiated power-mode parameters on every gear 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() (keeping clki->curr_freq synchronized and
   preserving min < max <= U32_MAX) so PLL-derived clocks whose rounded
   rate differs from the nominal DT frequency can scale back up in
   ufshcd_devfreq_target().

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] 9+ messages in thread

* [PATCH 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
  2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay
@ 2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  -1 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov @ 2026-11-26  0:53 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

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". Because the failing
status is returned from PRE_CHANGE, ufshcd_config_pwr_mode() discards
the negotiated parameters and applies the caller's desired parameters
instead.

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.

Found on hardware and drafted with an AI coding assistant.

Fixes: e1e25d1b8996 ("scsi: ufs: ufs-mediatek: Use common ADAPT configuration function")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 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 related	[flat|nested] 9+ messages in thread

* [PATCH 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
@ 2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  0 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:53 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". Because the failing
status is returned from PRE_CHANGE, ufshcd_config_pwr_mode() discards
the negotiated parameters and applies the caller's desired parameters
instead.

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.

Found on hardware and drafted with an AI coding assistant.

Fixes: e1e25d1b8996 ("scsi: ufs: ufs-mediatek: Use common ADAPT configuration function")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 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 related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
  2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay
@ 2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  -1 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov @ 2026-11-26  0:53 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

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.

Found on hardware and drafted with an AI coding assistant.

Fixes: 5e5976f5242d ("scsi: ufs: host: mediatek: Support FDE (AES) clock scaling")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 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 related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent
@ 2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  0 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:53 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.

Found on hardware and drafted with an AI coding assistant.

Fixes: 5e5976f5242d ("scsi: ufs: host: mediatek: Support FDE (AES) clock scaling")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 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 related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
  2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay
@ 2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  -1 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov @ 2026-11-26  0:53 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

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.

Found on hardware and drafted with an AI coding assistant.

Fixes: b7dbc686f60b ("scsi: ufs: ufs-mediatek: Support clk-scaling to optimize power consumption")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 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..b4fa2b9 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 (!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 || 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 related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate()
@ 2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  0 siblings, 0 replies; 9+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:53 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.

Found on hardware and drafted with an AI coding assistant.

Fixes: b7dbc686f60b ("scsi: ufs: ufs-mediatek: Support clk-scaling to optimize power consumption")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
 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..b4fa2b9 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 (!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 || 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 related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
  2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
  (?)
@ 2026-11-26  0:59   ` sashiko-bot
  -1 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26  0:59 UTC (permalink / raw)
  To: Ilia Snezhkov; +Cc: linux-scsi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: ufs: mediatek: inaccurate Fixes tag for
  ufs_mtk_pre_pwr_change()
--

commit 7768df4fa0e6861ba7a4e62b4a777b086e4e8d42
Author: Ilia Snezhkov <iasnezhkov@gmail.com>

> scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts
>
> 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". Because the failing
> status is returned from PRE_CHANGE, ufshcd_config_pwr_mode() discards
> the negotiated parameters and applies the caller's desired parameters
> instead.
>
> 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.
>
> Found on hardware and drafted with an AI coding assistant.
>
> Fixes: e1e25d1b8996 ("scsi: ufs: ufs-mediatek: Use common ADAPT configuration function")
> Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>

[Severity: Low]
Should the Fixes tag reference 7212d624f863 ("scsi: ufs: host: mediatek:
Fix PWM mode switch issue") instead?

In e1e25d1b8996 ("scsi: ufs: ufs-mediatek: Use common ADAPT configuration
function"), the call to ufshcd_dme_configure_adapt() was still guarded by
if (host->hw_ver.major >= 3).  The else branch calling
ufshcd_dme_configure_adapt(..., PA_NO_ADAPT) when host->hw_ver.major < 3
was added by 7212d624f863 ("scsi: ufs: host: mediatek: Fix PWM mode switch
issue").

Also, the description of ufshcd_config_pwr_mode() discarding negotiated
parameters on PRE_CHANGE failure no longer matches the current tree, as
d3eba21c7170 ("scsi: ufs: core: Introduce a new ufshcd vops
negotiate_pwr_mode()") moved negotiation to
ufshcd_vops_negotiate_pwr_mode() and ufshcd_change_power_mode() ignores
the return value of PRE_CHANGE.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126005329.72010-1-iasnezhkov@gmail.com?part=1

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-26  0:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  0:53 [PATCH 0/3] scsi: ufs: mediatek: pre-UniPro-1.8 adapt and clock scaling fixes Ilia Snezhkov
2026-11-26  0:53 ` Ilia Snezhkov via B4 Relay
2026-11-26  0:53 ` [PATCH 1/3] scsi: ufs: mediatek: skip PA_TXHSADAPTTYPE on pre-UniPro-1.8 hosts Ilia Snezhkov
2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
2026-11-26  0:59   ` sashiko-bot
2026-11-26  0:53 ` [PATCH 2/3] scsi: ufs: mediatek: allow clock scaling when ufs_fde is absent Ilia Snezhkov
2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay
2026-11-26  0:53 ` [PATCH 3/3] scsi: ufs: mediatek: round scalable clock bounds to clk_round_rate() Ilia Snezhkov
2026-11-26  0:53   ` Ilia Snezhkov via B4 Relay

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.