Skip to contentSkip to conversation

mmc: tegra: Write xfer_mode, CMD regs in together

PATCH Superseded Rhyland Klein 3 participants 6 messages Jan 27, 2015 – Feb 10, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: tegra: Write xfer_mode, CMD regs in together

From: Pavan Kunapuli <[email protected]>

If there is a gap between xfer mode and command register writes, tegra SDMMC controller can sometimes issue a spurious command before the CMD register is written. To avoid this, these two registers need to be written together in a single write operation.

---
 drivers/mmc/host/sdhci-tegra.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +30 -1
index 59797106af93..3d34de47e57e 100644
@@ -41,6 +41,7 @@
 #define NVQUIRK_DISABLE_SDR50		BIT(3)
 #define NVQUIRK_DISABLE_SDR104		BIT(4)
 #define NVQUIRK_DISABLE_DDR50		BIT(5)
+#define NVQUIRK_SHADOW_XFER_MODE_REG	BIT(6)
 
 struct sdhci_tegra_soc_data {
 	const struct sdhci_pltfm_data *pdata;
@@ -67,6 +68,32 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
 	return readw(host->ioaddr + reg);
 }
 
+static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
+{
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct sdhci_tegra *tegra_host = pltfm_host->priv;
+	const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
+
+	if (soc_data->nvquirks * NVQUIRK_SHADOW_XFER_MODE_REG) {
+		switch (reg) {
+		case SDHCI_TRANSFER_MODE:
+			/*
+			 * Postpone this write, we must do it together with a
+			 * command write that is down below.
+			 */
+			pltfm_host->xfer_mode_shadow = val;
+			return;
+		case SDHCI_COMMAND:
+			writel((val << 16) | pltfm_host->xfer_mode_shadow,
+				host->ioaddr + SDHCI_TRANSFER_MODE);
+			pltfm_host->xfer_mode_shadow = 0;
+			return;
+		}
+	}
+
+	writew(val, host->ioaddr + reg);
+}
+
 static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 {
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -147,6 +174,7 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
 static const struct sdhci_ops tegra_sdhci_ops = {
 	.get_ro     = tegra_sdhci_get_ro,
 	.read_w     = tegra_sdhci_readw,
+	.write_w    = tegra_sdhci_writew,
 	.write_l    = tegra_sdhci_writel,
 	.set_clock  = sdhci_set_clock,
 	.set_bus_width = tegra_sdhci_set_bus_width,
@@ -201,7 +229,8 @@ static struct sdhci_tegra_soc_data soc_data_tegra114 = {
 	.pdata = &sdhci_tegra114_pdata,
 	.nvquirks = NVQUIRK_DISABLE_SDR50 |
 		    NVQUIRK_DISABLE_DDR50 |
-		    NVQUIRK_DISABLE_SDR104,
+		    NVQUIRK_DISABLE_SDR104 |
+		    NVQUIRK_SHADOW_XFER_MODE_REG,
 };
 
 static const struct of_device_id sdhci_tegra_dt_match[] = {
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 26 lines · Rhyland Klein

From: Pavan Kunapuli <[email protected]>

If there is a gap between xfer mode and command register writes, tegra SDMMC controller can sometimes issue a spurious command before the CMD register is written. To avoid this, these two registers need to be written together in a single write operation.

---
 drivers/mmc/host/sdhci-tegra.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +1 -0
index 59797106af93..3d34de47e57e 100644
@@ -41,6 +41,7 @@
 #define NVQUIRK_DISABLE_SDR50          BIT(3)
 #define NVQUIRK_DISABLE_SDR104         BIT(4)
 #define NVQUIRK_DISABLE_DDR50          BIT(5)
+#define NVQUIRK_SHADOW_XFER_MODE_REG   BIT(6)
 
 struct sdhci_tegra_soc_data {
        const struct sdhci_pltfm_data *pdata;

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 77

Quoted 10 lines
drivers/mmc/host/sdhci-tegra.c +7 -0
@@ -67,6 +68,32 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
        return readw(host->ioaddr + reg);
 }
 
+static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct sdhci_tegra *tegra_host = pltfm_host->priv;
+       const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
+
+       if (soc_data->nvquirks * NVQUIRK_SHADOW_XFER_MODE_REG) {

Isn't the '*' supposed to be a '&' here?

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 89

Quoted 12 lines
drivers/mmc/host/sdhci-tegra.c +12 -0
+               switch (reg) {
+               case SDHCI_TRANSFER_MODE:
+                       /*
+                        * Postpone this write, we must do it together with a
+                        * command write that is down below.
+                        */
+                       pltfm_host->xfer_mode_shadow = val;
+                       return;
+               case SDHCI_COMMAND:
+                       writel((val << 16) | pltfm_host->xfer_mode_shadow,
+                               host->ioaddr + SDHCI_TRANSFER_MODE);
+                       pltfm_host->xfer_mode_shadow = 0;

That last line is probably not needed and could actually be harmful - if we try to write SDHCI_COMMAND twice in a raw without a write to SDHCI_TRANSFER_MODE in between, the zero will overwrite the previous value of SDHCI_TRANSFER_MODE.

Quoted 19 lines
drivers/mmc/host/sdhci-tegra.c +8 -0
+                       return;
+               }
+       }
+
+       writew(val, host->ioaddr + reg);
+}
+
 static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -147,6 +174,7 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
 static const struct sdhci_ops tegra_sdhci_ops = {
        .get_ro     = tegra_sdhci_get_ro,
        .read_w     = tegra_sdhci_readw,
+       .write_w    = tegra_sdhci_writew,
        .write_l    = tegra_sdhci_writel,
        .set_clock  = sdhci_set_clock,
        .set_bus_width = tegra_sdhci_set_bus_width,

drivers/mmc/host/sdhci-tegra.c static struct sdhci_tegra_soc_data soc_data_tegra114 = { · line 234

Quoted 7 lines
drivers/mmc/host/sdhci-tegra.c +2 -1
@@ -201,7 +229,8 @@ static struct sdhci_tegra_soc_data soc_data_tegra114 = {
        .pdata = &sdhci_tegra114_pdata,
        .nvquirks = NVQUIRK_DISABLE_SDR50 |
                    NVQUIRK_DISABLE_DDR50 |
-                   NVQUIRK_DISABLE_SDR104,
+                   NVQUIRK_DISABLE_SDR104 |
+                   NVQUIRK_SHADOW_XFER_MODE_REG,
 };

Since this only applies to Tegra114 (?), I wonder whether it would not be better to have a dedicated tegra114_sdhci_ops that implements tegra_sdhci_writew, and use it only in tegra_sdhci_writew. That way you could get rid of the NVQUIRK_SHADOW_XFER_MODE_REG and the test for it in tegra_sdhci_writew(), and chips prior to Tegra114 will not have to needlessly check for it every time they write a register.

#2 lore raw
Quoted 30 lines · Alexandre Courbot
Quoted 29 lines · Rhyland Klein

From: Pavan Kunapuli <[email protected]>

If there is a gap between xfer mode and command register writes, tegra SDMMC controller can sometimes issue a spurious command before the CMD register is written. To avoid this, these two registers need to be written together in a single write operation.

---
 drivers/mmc/host/sdhci-tegra.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +1 -0
index 59797106af93..3d34de47e57e 100644
@@ -41,6 +41,7 @@
 #define NVQUIRK_DISABLE_SDR50          BIT(3)
 #define NVQUIRK_DISABLE_SDR104         BIT(4)
 #define NVQUIRK_DISABLE_DDR50          BIT(5)
+#define NVQUIRK_SHADOW_XFER_MODE_REG   BIT(6)
 
 struct sdhci_tegra_soc_data {
        const struct sdhci_pltfm_data *pdata;
@@ -67,6 +68,32 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
        return readw(host->ioaddr + reg);
 }
 
Quoted 9 lines

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 77

Quoted 7 lines
drivers/mmc/host/sdhci-tegra.c +7 -0
+static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct sdhci_tegra *tegra_host = pltfm_host->priv;
+       const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
+
+       if (soc_data->nvquirks * NVQUIRK_SHADOW_XFER_MODE_REG) {

Isn't the '*' supposed to be a '&' here?

Yah .. not sure how that happened, but it should be '&' good catch.

Quoted 14 lines

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 89

Quoted 13 lines
drivers/mmc/host/sdhci-tegra.c +12 -0
+               switch (reg) {
+               case SDHCI_TRANSFER_MODE:
+                       /*
+                        * Postpone this write, we must do it together with a
+                        * command write that is down below.
+                        */
+                       pltfm_host->xfer_mode_shadow = val;
+                       return;
+               case SDHCI_COMMAND:
+                       writel((val << 16) | pltfm_host->xfer_mode_shadow,
+                               host->ioaddr + SDHCI_TRANSFER_MODE);
+                       pltfm_host->xfer_mode_shadow = 0;
Quoted 4 lines

That last line is probably not needed and could actually be harmful - if we try to write SDHCI_COMMAND twice in a raw without a write to SDHCI_TRANSFER_MODE in between, the zero will overwrite the previous value of SDHCI_TRANSFER_MODE.

True, will remove it.

Quoted 26 lines
Quoted 26 lines
drivers/mmc/host/sdhci-tegra.c +10 -1
+                       return;
+               }
+       }
+
+       writew(val, host->ioaddr + reg);
+}
+
 static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -147,6 +174,7 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
 static const struct sdhci_ops tegra_sdhci_ops = {
        .get_ro     = tegra_sdhci_get_ro,
        .read_w     = tegra_sdhci_readw,
+       .write_w    = tegra_sdhci_writew,
        .write_l    = tegra_sdhci_writel,
        .set_clock  = sdhci_set_clock,
        .set_bus_width = tegra_sdhci_set_bus_width,
@@ -201,7 +229,8 @@ static struct sdhci_tegra_soc_data soc_data_tegra114 = {
        .pdata = &sdhci_tegra114_pdata,
        .nvquirks = NVQUIRK_DISABLE_SDR50 |
                    NVQUIRK_DISABLE_DDR50 |
-                   NVQUIRK_DISABLE_SDR104,
+                   NVQUIRK_DISABLE_SDR104 |
+                   NVQUIRK_SHADOW_XFER_MODE_REG,
Quoted 8 lines

drivers/mmc/host/sdhci-tegra.c static struct sdhci_tegra_soc_data soc_data_tegra114 = { · line 234

Quoted 1 line
drivers/mmc/host/sdhci-tegra.c +0 -0
 };

Since this only applies to Tegra114 (?), I wonder whether it would not be better to have a dedicated tegra114_sdhci_ops that implements tegra_sdhci_writew, and use it only in tegra_sdhci_writew. That way you could get rid of the NVQUIRK_SHADOW_XFER_MODE_REG and the test for it in tegra_sdhci_writew(), and chips prior to Tegra114 will not have to needlessly check for it every time they write a register.

The reason I did it this way, is that this doesn't explicitly just apply to T114. It actually applies to T114, T124 and T132. In that case, I think it makes sense to keep the QUIRK and I can update the commit description to reflect that.

Thanks!
-rhyland

Quoted 1 line
Signature · 1 line
nvpublic
#3 lore raw
Quoted 99 lines · Rhyland Klein
Quoted 30 lines · Alexandre Courbot
Quoted 29 lines · Rhyland Klein

From: Pavan Kunapuli <[email protected]>

If there is a gap between xfer mode and command register writes, tegra SDMMC controller can sometimes issue a spurious command before the CMD register is written. To avoid this, these two registers need to be written together in a single write operation.

---
 drivers/mmc/host/sdhci-tegra.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +1 -0
index 59797106af93..3d34de47e57e 100644
@@ -41,6 +41,7 @@
 #define NVQUIRK_DISABLE_SDR50          BIT(3)
 #define NVQUIRK_DISABLE_SDR104         BIT(4)
 #define NVQUIRK_DISABLE_DDR50          BIT(5)
+#define NVQUIRK_SHADOW_XFER_MODE_REG   BIT(6)
 
 struct sdhci_tegra_soc_data {
        const struct sdhci_pltfm_data *pdata;
@@ -67,6 +68,32 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
        return readw(host->ioaddr + reg);
 }
 
Quoted 9 lines

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 77

Quoted 7 lines
drivers/mmc/host/sdhci-tegra.c +7 -0
+static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct sdhci_tegra *tegra_host = pltfm_host->priv;
+       const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
+
+       if (soc_data->nvquirks * NVQUIRK_SHADOW_XFER_MODE_REG) {

Isn't the '*' supposed to be a '&' here?

Yah .. not sure how that happened, but it should be '&' good catch.

Quoted 14 lines

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 89

Quoted 13 lines
drivers/mmc/host/sdhci-tegra.c +12 -0
+               switch (reg) {
+               case SDHCI_TRANSFER_MODE:
+                       /*
+                        * Postpone this write, we must do it together with a
+                        * command write that is down below.
+                        */
+                       pltfm_host->xfer_mode_shadow = val;
+                       return;
+               case SDHCI_COMMAND:
+                       writel((val << 16) | pltfm_host->xfer_mode_shadow,
+                               host->ioaddr + SDHCI_TRANSFER_MODE);
+                       pltfm_host->xfer_mode_shadow = 0;
Quoted 4 lines

That last line is probably not needed and could actually be harmful - if we try to write SDHCI_COMMAND twice in a raw without a write to SDHCI_TRANSFER_MODE in between, the zero will overwrite the previous value of SDHCI_TRANSFER_MODE.

True, will remove it.

Quoted 26 lines
Quoted 26 lines
drivers/mmc/host/sdhci-tegra.c +10 -1
+                       return;
+               }
+       }
+
+       writew(val, host->ioaddr + reg);
+}
+
 static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -147,6 +174,7 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
 static const struct sdhci_ops tegra_sdhci_ops = {
        .get_ro     = tegra_sdhci_get_ro,
        .read_w     = tegra_sdhci_readw,
+       .write_w    = tegra_sdhci_writew,
        .write_l    = tegra_sdhci_writel,
        .set_clock  = sdhci_set_clock,
        .set_bus_width = tegra_sdhci_set_bus_width,
@@ -201,7 +229,8 @@ static struct sdhci_tegra_soc_data soc_data_tegra114 = {
        .pdata = &sdhci_tegra114_pdata,
        .nvquirks = NVQUIRK_DISABLE_SDR50 |
                    NVQUIRK_DISABLE_DDR50 |
-                   NVQUIRK_DISABLE_SDR104,
+                   NVQUIRK_DISABLE_SDR104 |
+                   NVQUIRK_SHADOW_XFER_MODE_REG,
Quoted 8 lines

drivers/mmc/host/sdhci-tegra.c static struct sdhci_tegra_soc_data soc_data_tegra114 = { · line 234

Quoted 1 line
drivers/mmc/host/sdhci-tegra.c +0 -0
 };

Since this only applies to Tegra114 (?), I wonder whether it would not be better to have a dedicated tegra114_sdhci_ops that implements tegra_sdhci_writew, and use it only in tegra_sdhci_writew. That way you could get rid of the NVQUIRK_SHADOW_XFER_MODE_REG and the test for it in tegra_sdhci_writew(), and chips prior to Tegra114 will not have to needlessly check for it every time they write a register.

Quoted 4 lines

The reason I did it this way, is that this doesn't explicitly just apply to T114. It actually applies to T114, T124 and T132. In that case, I think it makes sense to keep the QUIRK and I can update the commit description to reflect that.

All the same, I don't see what advantage we have checking for that condition for every single write while we could simply set the right function to use at probe time?

#4 lore raw
Quoted 100 lines · Alexandre Courbot
Quoted 99 lines · Rhyland Klein
Quoted 30 lines · Alexandre Courbot
Quoted 29 lines · Rhyland Klein

From: Pavan Kunapuli <[email protected]>

If there is a gap between xfer mode and command register writes, tegra SDMMC controller can sometimes issue a spurious command before the CMD register is written. To avoid this, these two registers need to be written together in a single write operation.

---
 drivers/mmc/host/sdhci-tegra.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +1 -0
index 59797106af93..3d34de47e57e 100644
@@ -41,6 +41,7 @@
 #define NVQUIRK_DISABLE_SDR50          BIT(3)
 #define NVQUIRK_DISABLE_SDR104         BIT(4)
 #define NVQUIRK_DISABLE_DDR50          BIT(5)
+#define NVQUIRK_SHADOW_XFER_MODE_REG   BIT(6)
 
 struct sdhci_tegra_soc_data {
        const struct sdhci_pltfm_data *pdata;
@@ -67,6 +68,32 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
        return readw(host->ioaddr + reg);
 }
 
Quoted 9 lines

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 77

Quoted 7 lines
drivers/mmc/host/sdhci-tegra.c +7 -0
+static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct sdhci_tegra *tegra_host = pltfm_host->priv;
+       const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
+
+       if (soc_data->nvquirks * NVQUIRK_SHADOW_XFER_MODE_REG) {

Isn't the '*' supposed to be a '&' here?

Yah .. not sure how that happened, but it should be '&' good catch.

Quoted 14 lines

drivers/mmc/host/sdhci-tegra.c static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg) · line 89

Quoted 13 lines
drivers/mmc/host/sdhci-tegra.c +12 -0
+               switch (reg) {
+               case SDHCI_TRANSFER_MODE:
+                       /*
+                        * Postpone this write, we must do it together with a
+                        * command write that is down below.
+                        */
+                       pltfm_host->xfer_mode_shadow = val;
+                       return;
+               case SDHCI_COMMAND:
+                       writel((val << 16) | pltfm_host->xfer_mode_shadow,
+                               host->ioaddr + SDHCI_TRANSFER_MODE);
+                       pltfm_host->xfer_mode_shadow = 0;
Quoted 4 lines

That last line is probably not needed and could actually be harmful - if we try to write SDHCI_COMMAND twice in a raw without a write to SDHCI_TRANSFER_MODE in between, the zero will overwrite the previous value of SDHCI_TRANSFER_MODE.

True, will remove it.

Quoted 34 lines
Quoted 20 lines
drivers/mmc/host/sdhci-tegra.c +8 -0
+                       return;
+               }
+       }
+
+       writew(val, host->ioaddr + reg);
+}
+
 static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -147,6 +174,7 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
 static const struct sdhci_ops tegra_sdhci_ops = {
        .get_ro     = tegra_sdhci_get_ro,
        .read_w     = tegra_sdhci_readw,
+       .write_w    = tegra_sdhci_writew,
        .write_l    = tegra_sdhci_writel,
        .set_clock  = sdhci_set_clock,
        .set_bus_width = tegra_sdhci_set_bus_width,

drivers/mmc/host/sdhci-tegra.c static struct sdhci_tegra_soc_data soc_data_tegra114 = { · line 234

Quoted 7 lines
drivers/mmc/host/sdhci-tegra.c +2 -1
@@ -201,7 +229,8 @@ static struct sdhci_tegra_soc_data soc_data_tegra114 = {
        .pdata = &sdhci_tegra114_pdata,
        .nvquirks = NVQUIRK_DISABLE_SDR50 |
                    NVQUIRK_DISABLE_DDR50 |
-                   NVQUIRK_DISABLE_SDR104,
+                   NVQUIRK_DISABLE_SDR104 |
+                   NVQUIRK_SHADOW_XFER_MODE_REG,
 };

Since this only applies to Tegra114 (?), I wonder whether it would not be better to have a dedicated tegra114_sdhci_ops that implements tegra_sdhci_writew, and use it only in tegra_sdhci_writew. That way you could get rid of the NVQUIRK_SHADOW_XFER_MODE_REG and the test for it in tegra_sdhci_writew(), and chips prior to Tegra114 will not have to needlessly check for it every time they write a register.

Quoted 8 lines
Quoted 4 lines

The reason I did it this way, is that this doesn't explicitly just apply to T114. It actually applies to T114, T124 and T132. In that case, I think it makes sense to keep the QUIRK and I can update the commit description to reflect that.

All the same, I don't see what advantage we have checking for that condition for every single write while we could simply set the right function to use at probe time?

The above seems like a reasonable optimization to do!

Now, since $subject patch has been applied, I suggest you send a new patch addressing this issue.

Kind regards
Uffe

#5 lore raw
In reply to Rhyland Klein
Quoted 6 lines · Rhyland Klein

From: Pavan Kunapuli <[email protected]>

If there is a gap between xfer mode and command register writes, tegra SDMMC controller can sometimes issue a spurious command before the CMD register is written. To avoid this, these two registers need to be written together in a single write operation.'

Please repost to linux-mmc.

Kind regards
Uffe

Quoted 73 lines
---
 drivers/mmc/host/sdhci-tegra.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-tegra.c +30 -2
index 59797106af93..3d34de47e57e 100644
@@ -41,6 +41,7 @@
 #define NVQUIRK_DISABLE_SDR50          BIT(3)
 #define NVQUIRK_DISABLE_SDR104         BIT(4)
 #define NVQUIRK_DISABLE_DDR50          BIT(5)
+#define NVQUIRK_SHADOW_XFER_MODE_REG   BIT(6)
 
 struct sdhci_tegra_soc_data {
        const struct sdhci_pltfm_data *pdata;
@@ -67,6 +68,32 @@ static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
        return readw(host->ioaddr + reg);
 }
 
+static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct sdhci_tegra *tegra_host = pltfm_host->priv;
+       const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
+
+       if (soc_data->nvquirks * NVQUIRK_SHADOW_XFER_MODE_REG) {
+               switch (reg) {
+               case SDHCI_TRANSFER_MODE:
+                       /*
+                        * Postpone this write, we must do it together with a
+                        * command write that is down below.
+                        */
+                       pltfm_host->xfer_mode_shadow = val;
+                       return;
+               case SDHCI_COMMAND:
+                       writel((val << 16) | pltfm_host->xfer_mode_shadow,
+                               host->ioaddr + SDHCI_TRANSFER_MODE);
+                       pltfm_host->xfer_mode_shadow = 0;
+                       return;
+               }
+       }
+
+       writew(val, host->ioaddr + reg);
+}
+
 static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -147,6 +174,7 @@ static void tegra_sdhci_set_bus_width(struct sdhci_host *host, int bus_width)
 static const struct sdhci_ops tegra_sdhci_ops = {
        .get_ro     = tegra_sdhci_get_ro,
        .read_w     = tegra_sdhci_readw,
+       .write_w    = tegra_sdhci_writew,
        .write_l    = tegra_sdhci_writel,
        .set_clock  = sdhci_set_clock,
        .set_bus_width = tegra_sdhci_set_bus_width,
@@ -201,7 +229,8 @@ static struct sdhci_tegra_soc_data soc_data_tegra114 = {
        .pdata = &sdhci_tegra114_pdata,
        .nvquirks = NVQUIRK_DISABLE_SDR50 |
                    NVQUIRK_DISABLE_DDR50 |
-                   NVQUIRK_DISABLE_SDR104,
+                   NVQUIRK_DISABLE_SDR104 |
+                   NVQUIRK_SHADOW_XFER_MODE_REG,
 };
 
 static const struct of_device_id sdhci_tegra_dt_match[] = {
--

1.7.9.5