Skip to contentSkip to conversation

Possible bug in sdhci.c

U-Boot New Matt Reimer 2 participants 6 messages Feb 19, 2015 – Mar 18, 2015 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

In sdhci_init() a writel() is used on a byte-sized register, which would clobber the adjacent registers. Below is my suggested fix. If it looks correct, I can submit a proper patch.

Matt

drivers/mmc/sdhci.c +1 -1
index 82d7984..1f8917b 100644
@@ -412,7 +412,7 @@ static int sdhci_init(struct mmc *mmc)
        if (host->quirks & SDHCI_QUIRK_NO_CD) {
                unsigned int status;
 
-               sdhci_writel(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
+               sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
                        SDHCI_HOST_CONTROL);
 
                status = sdhci_readl(host, SDHCI_PRESENT_STATE);
#1 lore raw

Hi Matt,

Quoted 13 lines · Matt Reimer

In sdhci_init() a writel() is used on a byte-sized register, which would clobber the adjacent registers. Below is my suggested fix. If it looks correct, I can submit a proper patch.

Matt

drivers/mmc/sdhci.c +0 -0
index 82d7984..1f8917b 100644

drivers/mmc/sdhci.c static int sdhci_init(struct mmc *mmc) · line 418

Quoted 8 lines
drivers/mmc/sdhci.c +1 -1
@@ -412,7 +412,7 @@ static int sdhci_init(struct mmc *mmc)
       if (host->quirks & SDHCI_QUIRK_NO_CD) {
               unsigned int status;
 
-               sdhci_writel(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
+               sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
                       SDHCI_HOST_CONTROL);
 
               status = sdhci_readl(host, SDHCI_PRESENT_STATE);

Correct again. Please send a proper patch.

Regards

? Pantelis

#2 lore raw

PATCH 1/1 mmc: sdhci: don't clobber adjacent registers

SDHCI_HOST_CONTROL is a byte-sized register, so don't write to it as if it were a long, as that would result in clobbering the three registers following.

---
 drivers/mmc/sdhci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/sdhci.c +1 -1
index 82d7984..1f8917b 100644
@@ -412,7 +412,7 @@ static int sdhci_init(struct mmc *mmc)
 	if (host->quirks & SDHCI_QUIRK_NO_CD) {
 		unsigned int status;
 
-		sdhci_writel(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
+		sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
 			SDHCI_HOST_CONTROL);
 
 		status = sdhci_readl(host, SDHCI_PRESENT_STATE);
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 1/1 mmc: sdhci: don't clobber adjacent registers

Quoted 23 lines · Matt Reimer

SDHCI_HOST_CONTROL is a byte-sized register, so don't write to it as if it were a long, as that would result in clobbering the three registers following.

---
 drivers/mmc/sdhci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/sdhci.c +1 -1
index 82d7984..1f8917b 100644
@@ -412,7 +412,7 @@ static int sdhci_init(struct mmc *mmc)
        if (host->quirks & SDHCI_QUIRK_NO_CD) {
                unsigned int status;
 
-               sdhci_writel(host, SDHCI_CTRL_CD_TEST_INS |
 SDHCI_CTRL_CD_TEST,
+               sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS |
 SDHCI_CTRL_CD_TEST,
                        SDHCI_HOST_CONTROL);
Quoted 5 lines
                status = sdhci_readl(host, SDHCI_PRESENT_STATE);

--
1.7.9.5

ping

#4 lore raw

PATCH 1/1 mmc: sdhci: don't clobber adjacent registers

In reply to Matt Reimer

Hi Matt,

Quoted 27 lines · Matt Reimer

SDHCI_HOST_CONTROL is a byte-sized register, so don't write to it as if it were a long, as that would result in clobbering the three registers following.

---
drivers/mmc/sdhci.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/sdhci.c +1 -1
index 82d7984..1f8917b 100644
@@ -412,7 +412,7 @@ static int sdhci_init(struct mmc *mmc)
 	if (host->quirks & SDHCI_QUIRK_NO_CD) {
 		unsigned int status;
 
-		sdhci_writel(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
+		sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
 			SDHCI_HOST_CONTROL);
 
 		status = sdhci_readl(host, SDHCI_PRESENT_STATE);
Signature · 1 line
1.7.9.5

The patch is obviously correct and I?ll pick it up for my next pull-req.

Relax :)

Regards

? Pantelis

#5 lore raw

PATCH 1/1 mmc: sdhci: don't clobber adjacent registers

In reply to Matt Reimer

Hi Matt,

Quoted 27 lines · Matt Reimer

SDHCI_HOST_CONTROL is a byte-sized register, so don't write to it as if it were a long, as that would result in clobbering the three registers following.

---
drivers/mmc/sdhci.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/sdhci.c +1 -1
index 82d7984..1f8917b 100644
@@ -412,7 +412,7 @@ static int sdhci_init(struct mmc *mmc)
 	if (host->quirks & SDHCI_QUIRK_NO_CD) {
 		unsigned int status;
 
-		sdhci_writel(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
+		sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
 			SDHCI_HOST_CONTROL);
 
 		status = sdhci_readl(host, SDHCI_PRESENT_STATE);
Signature · 1 line
1.7.9.5

Thanks, applied.

? Pantelis