Skip to contentSkip to conversation

mmc: sdhci-sprd: Fix the limitation of div

PATCH In review Wenchao Chen 2 participants 2 messages Sep 14, 2022 – Sep 21, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: sdhci-sprd: Fix the limitation of div

From: Wenchao Chen <[email protected]>

Because the bit field size of the divider coefficient register is 1023, it is limited before returning the value.

---
 drivers/mmc/host/sdhci-sprd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-sprd.c +3 -3
index f33e9349e4e6..46c55ab4884c 100644
@@ -205,14 +205,14 @@ static inline u32 sdhci_sprd_calc_div(u32 base_clk, u32 clk)
 	if ((base_clk / div) > (clk * 2))
 		div++;
 
-	if (div > SDHCI_SPRD_CLK_MAX_DIV)
-		div = SDHCI_SPRD_CLK_MAX_DIV;
-
 	if (div % 2)
 		div = (div + 1) / 2;
 	else
 		div = div / 2;
 
+	if (div > SDHCI_SPRD_CLK_MAX_DIV)
+		div = SDHCI_SPRD_CLK_MAX_DIV;
+
 	return div;
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 7 lines · Wenchao Chen

From: Wenchao Chen <[email protected]>

Because the bit field size of the divider coefficient register is 1023, it is limited before returning the value.

Applied for next, thanks!

Kind regards
Uffe

Quoted 29 lines
---
 drivers/mmc/host/sdhci-sprd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/host/sdhci-sprd.c +3 -4
index f33e9349e4e6..46c55ab4884c 100644
@@ -205,14 +205,14 @@ static inline u32 sdhci_sprd_calc_div(u32 base_clk, u32 clk)
        if ((base_clk / div) > (clk * 2))
                div++;
 
-       if (div > SDHCI_SPRD_CLK_MAX_DIV)
-               div = SDHCI_SPRD_CLK_MAX_DIV;
-
        if (div % 2)
                div = (div + 1) / 2;
        else
                div = div / 2;
 
+       if (div > SDHCI_SPRD_CLK_MAX_DIV)
+               div = SDHCI_SPRD_CLK_MAX_DIV;
+
        return div;
 }
 
--

2.17.1