Skip to contentSkip to conversation

mmc: sdhci: Fix HISPD bit handling

PATCH In review Jagan Teki 2 participants 3 messages Jun 10, 2020 – Jun 12, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH v3 1/1 mmc: sdhci: Fix HISPD bit handling

SDHCI HISPD bits need to be configured based on desired mmc timings mode and some HISPD quirks.

So, handle the HISPD bit based on the mmc computed selected mode(timing parameter) rather than fixed mmc card clock frequency.

Linux handle the HISPD similar like this in below commit,

commit <501639bf2173> ("mmc: sdhci: fix SDHCI_QUIRK_NO_HISPD_BIT handling")

This eventually fixed the mmc write issue observed in rk3399 sdhci controller.

Bug log for refernece,
=> gpt write mmc 0 $partitions
Writing GPT: mmc write failed
** Can't write to device 0 **
** Can't write to device 0 **
error!

---
Changes for v3:
- use && for quirk check.

 drivers/mmc/sdhci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/sdhci.c +15 -8
index 92cc8434af..a7db278a0e 100644
@@ -594,14 +594,21 @@ static int sdhci_set_ios(struct mmc *mmc)
 			ctrl &= ~SDHCI_CTRL_4BITBUS;
 	}
 
-	if (mmc->clock > 26000000)
-		ctrl |= SDHCI_CTRL_HISPD;
-	else
-		ctrl &= ~SDHCI_CTRL_HISPD;
-
-	if ((host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) ||
-	    (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE))
-		ctrl &= ~SDHCI_CTRL_HISPD;
+	if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) &&
+	    !(host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE)) {
+		if (mmc->selected_mode == MMC_HS ||
+		    mmc->selected_mode == SD_HS ||
+		    mmc->selected_mode == MMC_DDR_52 ||
+		    mmc->selected_mode == MMC_HS_200 ||
+		    mmc->selected_mode == MMC_HS_400 ||
+		    mmc->selected_mode == UHS_SDR25 ||
+		    mmc->selected_mode == UHS_SDR50 ||
+		    mmc->selected_mode == UHS_SDR104 ||
+		    mmc->selected_mode == UHS_DDR50)
+			ctrl |= SDHCI_CTRL_HISPD;
+		else
+			ctrl &= ~SDHCI_CTRL_HISPD;
+	}
 
 	sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 
Signature · 1 line
2.25.1
#1 lore raw

Hi Jagan,

Quoted 43 lines · Jagan Teki

SDHCI HISPD bits need to be configured based on desired mmc timings mode and some HISPD quirks.

So, handle the HISPD bit based on the mmc computed selected mode(timing parameter) rather than fixed mmc card clock frequency.

Linux handle the HISPD similar like this in below commit,

commit <501639bf2173> ("mmc: sdhci: fix SDHCI_QUIRK_NO_HISPD_BIT handling")

This eventually fixed the mmc write issue observed in rk3399 sdhci controller.

Bug log for refernece,
=> gpt write mmc 0 $partitions
Writing GPT: mmc write failed
** Can't write to device 0 **
** Can't write to device 0 **
error!

---
Changes for v3:
- use && for quirk check.

 drivers/mmc/sdhci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/sdhci.c +0 -0
index 92cc8434af..a7db278a0e 100644
@@ -594,14 +594,21 @@ static int sdhci_set_ios(struct mmc *mmc)
 			ctrl &= ~SDHCI_CTRL_4BITBUS;
 	}
 

drivers/mmc/sdhci.c static int sdhci_set_ios(struct mmc *mmc) · line 598

Quoted 10 lines
drivers/mmc/sdhci.c +2 -8
-	if (mmc->clock > 26000000)
-		ctrl |= SDHCI_CTRL_HISPD;
-	else
-		ctrl &= ~SDHCI_CTRL_HISPD;
-
-	if ((host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) ||
-	    (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE))
-		ctrl &= ~SDHCI_CTRL_HISPD;
+	if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) &&
+	    !(host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE)) {

Sorry, it needs to check more. Because it's different with kernel code. Kernel code is only checking condition about SDHCI_QUIRK_NO_HISPD_BIT. but in u-boot, one more checking about SDHCI_QUIRK_BROKEN_HISPD_MODE.

So if it doesn't set to both, it's possible to set SDHCI_CTRL_HISPD as ctrl's flags.

Quoted 4 lines
drivers/mmc/sdhci.c +4 -0
+		if (mmc->selected_mode == MMC_HS ||
+		    mmc->selected_mode == SD_HS ||
+		    mmc->selected_mode == MMC_DDR_52 ||
+		    mmc->selected_mode == MMC_HS_200 ||

drivers/mmc/sdhci.c static int sdhci_set_ios(struct mmc *mmc) · line 612

Quoted 10 lines
drivers/mmc/sdhci.c +9 -0
+		    mmc->selected_mode == MMC_HS_400 ||
+		    mmc->selected_mode == UHS_SDR25 ||
+		    mmc->selected_mode == UHS_SDR50 ||
+		    mmc->selected_mode == UHS_SDR104 ||
+		    mmc->selected_mode == UHS_DDR50)
+			ctrl |= SDHCI_CTRL_HISPD;
+		else
+			ctrl &= ~SDHCI_CTRL_HISPD;
+	}
 

I think that needs to add at here

	 else 
		ctrl &= ~SDHCI_CTRL_HISPD; 
Quoted 3 lines
drivers/mmc/sdhci.c +0 -0
 	sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 

A message that is not in the archive (sent off-list or not yet received): 8c7edc3c-2876-f407-86a5-708a0164db1d-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org

author
#3 lore raw
Quoted 78 lines · Jaehoon Chung

Hi Jagan,

Quoted 43 lines · Jagan Teki

SDHCI HISPD bits need to be configured based on desired mmc timings mode and some HISPD quirks.

So, handle the HISPD bit based on the mmc computed selected mode(timing parameter) rather than fixed mmc card clock frequency.

Linux handle the HISPD similar like this in below commit,

commit <501639bf2173> ("mmc: sdhci: fix SDHCI_QUIRK_NO_HISPD_BIT handling")

This eventually fixed the mmc write issue observed in rk3399 sdhci controller.

Bug log for refernece,
=> gpt write mmc 0 $partitions
Writing GPT: mmc write failed
** Can't write to device 0 **
** Can't write to device 0 **
error!

---
Changes for v3:
- use && for quirk check.

 drivers/mmc/sdhci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/sdhci.c +0 -0
index 92cc8434af..a7db278a0e 100644
@@ -594,14 +594,21 @@ static int sdhci_set_ios(struct mmc *mmc)
                      ctrl &= ~SDHCI_CTRL_4BITBUS;
      }
 

drivers/mmc/sdhci.c static int sdhci_set_ios(struct mmc *mmc) · line 598

Quoted 10 lines
drivers/mmc/sdhci.c +2 -8
-     if (mmc->clock > 26000000)
-             ctrl |= SDHCI_CTRL_HISPD;
-     else
-             ctrl &= ~SDHCI_CTRL_HISPD;
-
-     if ((host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) ||
-         (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE))
-             ctrl &= ~SDHCI_CTRL_HISPD;
+     if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) &&
+         !(host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE)) {

Sorry, it needs to check more. Because it's different with kernel code. Kernel code is only checking condition about SDHCI_QUIRK_NO_HISPD_BIT. but in u-boot, one more checking about SDHCI_QUIRK_BROKEN_HISPD_MODE.

So if it doesn't set to both, it's possible to set SDHCI_CTRL_HISPD as ctrl's flags.

Quoted 4 lines
drivers/mmc/sdhci.c +4 -0
+             if (mmc->selected_mode == MMC_HS ||
+                 mmc->selected_mode == SD_HS ||
+                 mmc->selected_mode == MMC_DDR_52 ||
+                 mmc->selected_mode == MMC_HS_200 ||

drivers/mmc/sdhci.c static int sdhci_set_ios(struct mmc *mmc) · line 612

Quoted 10 lines
drivers/mmc/sdhci.c +9 -0
+                 mmc->selected_mode == MMC_HS_400 ||
+                 mmc->selected_mode == UHS_SDR25 ||
+                 mmc->selected_mode == UHS_SDR50 ||
+                 mmc->selected_mode == UHS_SDR104 ||
+                 mmc->selected_mode == UHS_DDR50)
+                     ctrl |= SDHCI_CTRL_HISPD;
+             else
+                     ctrl &= ~SDHCI_CTRL_HISPD;
+     }
 
Quoted 3 lines

I think that needs to add at here

         else
                ctrl &= ~SDHCI_CTRL_HISPD;

Okay, Can you look at this logic?

drivers/mmc/sdhci.c +9 -5
@@ -567,6 +567,7 @@ static int sdhci_set_ios(struct mmc *mmc)
 #endif
        u32 ctrl;
        struct sdhci_host *host = mmc->priv;
+       bool no_hispd_bit = false;
 
        if (host->ops && host->ops->set_control_reg)
                host->ops->set_control_reg(host);
@@ -594,13 +595,16 @@ static int sdhci_set_ios(struct mmc *mmc)
                        ctrl &= ~SDHCI_CTRL_4BITBUS;
        }
 
-       if (mmc->clock > 26000000)
-               ctrl |= SDHCI_CTRL_HISPD;
-       else
-               ctrl &= ~SDHCI_CTRL_HISPD;
-
        if ((host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) ||
            (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE))
+               no_hispd_bit = true;
+
+       if (((mmc->selected_mode != MMC_LEGACY) ||
+             (mmc->selected_mode != MMC_HS_52) ||
+             (mmc->selected_mode != UHS_SDR12) ||
+             (mmc->selected_mode != MMC_HS_400_ES)) && !no_hispd_bit)
+               ctrl |= SDHCI_CTRL_HISPD;
+       else
                ctrl &= ~SDHCI_CTRL_HISPD;
 
        sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);