Skip to contentSkip to conversation

mmc: tmio: Fix reset operation

PATCH Superseded Niklas Söderlund 3 participants 13 messages Jun 6, 2018 – Sep 20, 2018

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover mmc: tmio: Fix reset operation

Hi,

While looking at the Renesas BSP kernel I found patches which improves the state of the hardware at probe and after runtime resume. This is tested on R-Car H3 ES2.

Patch 1/3 ensures the IRQ mask have the default value according the datasheet (Rev 0.15) in case the bootloader have changed it. Patch 2/3 moves code around to prepare for 3/3 which improves the hardware reset by also resetting the SCC which was not previously reset.

Patches from Hayakawa-san have small changes done by me needed after they where rebased to mmc/next.

Masaharu Hayakawa (2):
mmc: tmio: Add initial setting of interrupt mask register
mmc: tmio: Fix reset operation

Niklas Söderlund (1):
mmc: tmio: move tmio_mmc_hw_reset()

 drivers/mmc/host/tmio_mmc.h      |  1 +
 drivers/mmc/host/tmio_mmc_core.c | 27 ++++++++++++++++-----------
 2 files changed, 17 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/3 mmc: tmio: Add initial setting of interrupt mask register

From: Masaharu Hayakawa <[email protected]>

The initial value of the interrupt mask register may be different from the H/W manual at the startup of the kernel by setting of initial program. Since the error interrupts may be unmasked, the driver sets initial value.

---
 drivers/mmc/host/tmio_mmc.h      | 1 +
 drivers/mmc/host/tmio_mmc_core.c | 1 +
 2 files changed, 2 insertions(+)
drivers/mmc/host/tmio_mmc.h +1 -0
index e7d651352dc90fb8..bfb76b2963f80894 100644
@@ -102,6 +102,7 @@
 
 /* Define some IRQ masks */
 /* This is the mask used at reset by the chip */
+#define TMIO_MASK_INIT          0x8b7f031d /* H/W initial value */
 #define TMIO_MASK_ALL           0x837f031d
 #define TMIO_MASK_READOP  (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
 #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
drivers/mmc/host/tmio_mmc_core.c +1 -0
index 3080299303045adc..2ede81476daf76ce 100644
@@ -1273,6 +1273,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host)
 	tmio_mmc_clk_stop(_host);
 	tmio_mmc_reset(_host);
 
+	sd_ctrl_write32_as_16_and_16(_host, CTL_IRQ_MASK, TMIO_MASK_INIT);
 	_host->sdcard_irq_mask = sd_ctrl_read16_and_16_as_32(_host, CTL_IRQ_MASK);
 	tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
 
Signature · 1 line
2.17.0
#2 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Hi Niklas,

Quoted 4 lines · Niklas Söderlund

From: Masaharu Hayakawa <[email protected]>

The initial value of the interrupt mask register may be different from the H/W manual at the startup of the kernel by setting of initial program.

s/initial program/bootloader/ ?

Quoted 14 lines

Since the error interrupts may be unmasked, the driver sets initial value.

---
 drivers/mmc/host/tmio_mmc.h      | 1 +
 drivers/mmc/host/tmio_mmc_core.c | 1 +
 2 files changed, 2 insertions(+)
drivers/mmc/host/tmio_mmc.h +0 -0
index e7d651352dc90fb8..bfb76b2963f80894 100644

drivers/mmc/host/tmio_mmc.h line 105

Quoted 4 lines
drivers/mmc/host/tmio_mmc.h +1 -0
@@ -102,6 +102,7 @@
 
 /* Define some IRQ masks */
 /* This is the mask used at reset by the chip */
+#define TMIO_MASK_INIT          0x8b7f031d /* H/W initial value */

known on R-Car 2+ only!

drivers/mmc/host/tmio_mmc_core.c int tmio_mmc_host_probe(struct tmio_mmc_host *_host) · line 1276

Quoted 12 lines
drivers/mmc/host/tmio_mmc.h +0 -0
 #define TMIO_MASK_ALL           0x837f031d
 #define TMIO_MASK_READOP  (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
 #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
drivers/mmc/host/tmio_mmc_core.c +1 -0
index 3080299303045adc..2ede81476daf76ce 100644
@@ -1273,6 +1273,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host)
 	tmio_mmc_clk_stop(_host);
 	tmio_mmc_reset(_host);
 
+	sd_ctrl_write32_as_16_and_16(_host, CTL_IRQ_MASK, TMIO_MASK_INIT);

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

Regards,

Wolfram

#3 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Hi Wolfram,

Thanks for your feedback.

Quoted 9 lines · Wolfram Sang

Hi Niklas,

Quoted 4 lines · Niklas S�derlund

From: Masaharu Hayakawa <[email protected]>

The initial value of the interrupt mask register may be different from the H/W manual at the startup of the kernel by setting of initial program.

s/initial program/bootloader/ ?

Sounds much better.

Quoted 16 lines
Quoted 16 lines

Since the error interrupts may be unmasked, the driver sets initial value.

---
 drivers/mmc/host/tmio_mmc.h      | 1 +
 drivers/mmc/host/tmio_mmc_core.c | 1 +
 2 files changed, 2 insertions(+)
drivers/mmc/host/tmio_mmc.h +0 -0
index e7d651352dc90fb8..bfb76b2963f80894 100644
@@ -102,6 +102,7 @@
 
Quoted 5 lines

drivers/mmc/host/tmio_mmc.h line 105

Quoted 3 lines
drivers/mmc/host/tmio_mmc.h +1 -0
 /* Define some IRQ masks */
 /* This is the mask used at reset by the chip */
+#define TMIO_MASK_INIT          0x8b7f031d /* H/W initial value */

known on R-Car 2+ only!

No it's also know on Gen3 :-)

If you check the documents for the registers SD_INFO1_MASK and SD_INFO2_MASK they describe there respective initial values. If one combines them you get the same constant as documented here.

The tricky part is that sd_ctrl_write32_as_16_and_16() is used to write them so you have to take 16 bits from each register description as that is how the are written. After the fun bus shift is applied this ends up writing the lower 16 bits of the constant to 0x80 and the higher 16 of it to 0x88.

Quoted 22 lines

drivers/mmc/host/tmio_mmc_core.c int tmio_mmc_host_probe(struct tmio_mmc_host *_host) · line 1276

Quoted 13 lines
drivers/mmc/host/tmio_mmc.h +0 -0
 #define TMIO_MASK_ALL           0x837f031d
 #define TMIO_MASK_READOP  (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
 #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
drivers/mmc/host/tmio_mmc_core.c +1 -0
index 3080299303045adc..2ede81476daf76ce 100644
@@ -1273,6 +1273,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host)
 	tmio_mmc_clk_stop(_host);
 	tmio_mmc_reset(_host);
 
+	sd_ctrl_write32_as_16_and_16(_host, CTL_IRQ_MASK, TMIO_MASK_INIT);

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

Regards,

Wolfram

Signature · 2 lines
Regards,
Niklas S�derlund
#4 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

+#define TMIO_MASK_INIT 0x8b7f031d /* H/W initial value */

known on R-Car 2+ only!

No it's also know on Gen3 :-)

Sure, 2+ means "R-Car 2 and later". Like with GPL2+. Sorry if this was not clear. And it is still my main argument to do...

Quoted 3 lines
Quoted 3 lines

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

... this.

#5 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Hi Wolfram,

Thanks for your feedback.

Quoted 9 lines · Wolfram Sang
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

+#define TMIO_MASK_INIT 0x8b7f031d /* H/W initial value */

known on R-Car 2+ only!

No it's also know on Gen3 :-)

Sure, 2+ means "R-Car 2 and later". Like with GPL2+. Sorry if this was not clear. And it is still my main argument to do...

When you point it out it's clear, sorry I missed that.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

... this.

I will look into this and send a new version :-)

Signature · 2 lines
Regards,
Niklas S�derlund
#6 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

... this.

I will look into this and send a new version :-)

Did you send V2 of this? I can't find it.

#7 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Hi Wolfram,

Quoted 5 lines · Wolfram Sang
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

... this.

I will look into this and send a new version :-)

Did you send V2 of this? I can't find it.

No I have not yet posted a v2 of this series. Perhaps I should break this patch out and send separate? I have handled the comments for this but patch 3/3 in this series still requires more work, what do you think?

Signature · 2 lines
Regards,
Niklas S�derlund
#8 lore raw

Re: [PATCH 1/3] mmc: tmio: Add initial setting of interrupt mask register

Quoted 13 lines · Niklas Söderlund

Hi Wolfram,

Quoted 10 lines · Wolfram Sang
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

So, we should at least protect this with TMIO_MMC_MIN_RCAR2, I'd think. Maybe we should even move it to renesas_sdhi_core.c, but I am not too sure about that.

... this.

I will look into this and send a new version :-)

Quoted 7 lines
Quoted 2 lines

Did you send V2 of this? I can't find it.

No I have not yet posted a v2 of this series. Perhaps I should break this patch out and send separate? I have handled the comments for this but patch 3/3 in this series still requires more work, what do you think?

Yes, please.

#9 lore raw

PATCH 2/3 mmc: tmio: move tmio_mmc_hw_reset()

In reply to Niklas Söderlund

Avoid having to use forward declaration when in a later patch fixing the reset operation by moving tmio_mmc_hw_reset() earlier in the source file. No functional change in this change.

---
 drivers/mmc/host/tmio_mmc_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/mmc/host/tmio_mmc_core.c +8 -8
index 2ede81476daf76ce..9f5793407552a23a 100644
@@ -243,6 +243,14 @@ static void tmio_mmc_reset(struct tmio_mmc_host *host)
 
 }
 
+static void tmio_mmc_hw_reset(struct mmc_host *mmc)
+{
+	struct tmio_mmc_host *host = mmc_priv(mmc);
+
+	if (host->hw_reset)
+		host->hw_reset(host);
+}
+
 static void tmio_mmc_reset_work(struct work_struct *work)
 {
 	struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host,
@@ -769,14 +777,6 @@ static int tmio_mmc_start_data(struct tmio_mmc_host *host,
 	return 0;
 }
 
-static void tmio_mmc_hw_reset(struct mmc_host *mmc)
-{
-	struct tmio_mmc_host *host = mmc_priv(mmc);
-
-	if (host->hw_reset)
-		host->hw_reset(host);
-}
-
 static int tmio_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
 {
 	struct tmio_mmc_host *host = mmc_priv(mmc);
Signature · 1 line
2.17.0
#10 lore raw

Re: [PATCH 2/3] mmc: tmio: move tmio_mmc_hw_reset()

Quoted 5 lines · Niklas Söderlund

Avoid having to use forward declaration when in a later patch fixing the reset operation by moving tmio_mmc_hw_reset() earlier in the source file. No functional change in this change.

I'd merge patches 2+3, but I'll leave that to Ulf...

#11 lore raw

PATCH 3/3 mmc: tmio: Fix reset operation

In reply to Niklas Söderlund

From: Masaharu Hayakawa <[email protected]>

SD / MMC did not operate properly when suspend transition failed. Because the SCC was not reset at resume, issue of the command failed. Changed tmio_mmc_reset() to tmio_mmc_hw_reset() in order to add reset of SCC to tmio_mmc_host_runtime_resume().

On runtime power management resume, the host clock needs to be enabled before calling tmio_mmc_reset. If the mmc device has a power domain entry, the host clock is enabled via genpd_runtime_resume, running before tmio_mmc_host_runtime_resume. If the mmc device has no power domain entry, however, genpd_runtime_resume is not called. This patch changes tmio_mmc_host_runtime_resume to enable the host clock before calling tmio_mmc_reset.

[Niklas: small fixes when rebase to mmc/next]
---
 drivers/mmc/host/tmio_mmc_core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/mmc/host/tmio_mmc_core.c +7 -3
index 9f5793407552a23a..da10b26d8f2d80e7 100644
@@ -247,6 +247,10 @@ static void tmio_mmc_hw_reset(struct mmc_host *mmc)
 {
 	struct tmio_mmc_host *host = mmc_priv(mmc);
 
+	tmio_mmc_reset(host);
+
+	tmio_mmc_abort_dma(host);
+
 	if (host->hw_reset)
 		host->hw_reset(host);
 }
@@ -289,7 +293,7 @@ static void tmio_mmc_reset_work(struct work_struct *work)
 
 	spin_unlock_irqrestore(&host->lock, flags);
 
-	tmio_mmc_reset(host);
+	tmio_mmc_hw_reset(host->mmc);
 
 	/* Ready for new calls */
 	host->mrq = NULL;
@@ -1271,7 +1275,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host)
 		_host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
 
 	tmio_mmc_clk_stop(_host);
-	tmio_mmc_reset(_host);
+	tmio_mmc_hw_reset(mmc);
 
 	sd_ctrl_write32_as_16_and_16(_host, CTL_IRQ_MASK, TMIO_MASK_INIT);
 	_host->sdcard_irq_mask = sd_ctrl_read16_and_16_as_32(_host, CTL_IRQ_MASK);
@@ -1372,8 +1376,8 @@ int tmio_mmc_host_runtime_resume(struct device *dev)
 {
 	struct tmio_mmc_host *host = dev_get_drvdata(dev);
 
-	tmio_mmc_reset(host);
 	tmio_mmc_clk_enable(host);
+	tmio_mmc_hw_reset(host->mmc);
 
 	if (host->clk_cache)
 		tmio_mmc_set_clock(host, host->clk_cache);
Signature · 1 line
2.17.0
#12 lore raw
Quoted 6 lines · Niklas Söderlund

From: Masaharu Hayakawa <[email protected]>

SD / MMC did not operate properly when suspend transition failed. Because the SCC was not reset at resume, issue of the command failed. Changed tmio_mmc_reset() to tmio_mmc_hw_reset() in order to add reset of SCC to tmio_mmc_host_runtime_resume().

So, my gut feeling is that this change, in general, seems OK. However, the naming (tmio_mmc_reset and tmio_mmc_hw_reset) becomes confusing and unneeded. tmio_mmc_reset now only gets called in tmio_mmc_hw_reset, so we can merge the two functions into one to reduce the confusion.

Because we add stuff to the function which gets pointed to by mmc_ops->hw_reset, it makes sense to me to double check when the MMC core calls this pointer and if our additions still make sense there. I'd think so, but better safe than sorry.

Quoted 7 lines

On runtime power management resume, the host clock needs to be enabled before calling tmio_mmc_reset. If the mmc device has a power domain entry, the host clock is enabled via genpd_runtime_resume, running before tmio_mmc_host_runtime_resume. If the mmc device has no power domain entry, however, genpd_runtime_resume is not called. This patch changes tmio_mmc_host_runtime_resume to enable the host clock before calling tmio_mmc_reset.

I think this makes sense but should be a seperate patch. Or maybe even something slightly different? Because we have a patch in the BSP [1] for which I ever wondered in what case it was needed. But seeing the above, it might make sense to add the clock enablement to the reset routine? Niklas, do you have time to check that?

Thanks,

Wolfram

[1] 940904fe4ea8 ("mmc: tmio: Add SDCLK enable after reset")