All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller
@ 2021-03-15 14:59 Wolfram Sang
  2021-03-15 14:59 ` [PATCH v2 1/3] mmc: tmio: abort DMA before reset Wolfram Sang
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Wolfram Sang @ 2021-03-15 14:59 UTC (permalink / raw)
  To: linux-mmc; +Cc: linux-renesas-soc, Yoshihiro Shimoda, Wolfram Sang

This series enables SDHI to be reset via a reset controller.
Please let me know about your (and BSP team's) thoughts.
The series is based on mmc/next and tested on Salvator-XS with R-Car H3
ES2.0 with what I think I can do locally here.

Changes since v1:
* Niklas tag added to patch 1 (thanks!)
* new patch 2 to factor out SCC reset and make intentions clearer
  (thanks to Shimoda-san for the review!)
* patch 3 re-inits now the SD clock again after the hard reset

Wolfram Sang (3):
  mmc: tmio: abort DMA before reset
  mmc: renesas_sdhi: break SCC reset into own function
  mmc: renesas_sdhi: do hard reset if possible

 drivers/mmc/host/Kconfig             |  1 +
 drivers/mmc/host/renesas_sdhi.h      |  2 ++
 drivers/mmc/host/renesas_sdhi_core.c | 35 +++++++++++++++++++++-------
 drivers/mmc/host/tmio_mmc_core.c     |  4 ++--
 4 files changed, 32 insertions(+), 10 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/3] mmc: tmio: abort DMA before reset
  2021-03-15 14:59 [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Wolfram Sang
@ 2021-03-15 14:59 ` Wolfram Sang
  2021-03-15 14:59 ` [PATCH v2 2/3] mmc: renesas_sdhi: break SCC reset into own function Wolfram Sang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2021-03-15 14:59 UTC (permalink / raw)
  To: linux-mmc
  Cc: linux-renesas-soc, Yoshihiro Shimoda, Wolfram Sang,
	Niklas Söderlund

We will soon allow resetting the whole IP core via a reset controller.
For this case, DMA must be terminated before the actual reset. For the
other cases, it is probably better, too.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/mmc/host/tmio_mmc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
index 5aa57640d0e6..eca767dcabba 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -172,11 +172,11 @@ static void tmio_mmc_reset(struct tmio_mmc_host *host)
 	sd_ctrl_write16(host, CTL_RESET_SD, 0x0001);
 	usleep_range(10000, 11000);
 
+	tmio_mmc_abort_dma(host);
+
 	if (host->reset)
 		host->reset(host);
 
-	tmio_mmc_abort_dma(host);
-
 	if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) {
 		sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
 		sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/3] mmc: renesas_sdhi: break SCC reset into own function
  2021-03-15 14:59 [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Wolfram Sang
  2021-03-15 14:59 ` [PATCH v2 1/3] mmc: tmio: abort DMA before reset Wolfram Sang
@ 2021-03-15 14:59 ` Wolfram Sang
  2021-03-15 14:59 ` [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible Wolfram Sang
  2021-03-16  6:38 ` [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Yoshihiro Shimoda
  3 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2021-03-15 14:59 UTC (permalink / raw)
  To: linux-mmc; +Cc: linux-renesas-soc, Yoshihiro Shimoda, Wolfram Sang

renesas_sdhi_reset used to mainly reset the SCC but is now doing more
and even more will be added. So, factor out SCC reset to have a clear
distinction when we want to reset either SCC or SDHI+SCC.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/mmc/host/renesas_sdhi_core.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c
index 09a5e0dafbef..db753829eaf6 100644
--- a/drivers/mmc/host/renesas_sdhi_core.c
+++ b/drivers/mmc/host/renesas_sdhi_core.c
@@ -557,21 +557,25 @@ static int renesas_sdhi_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_io
 	return 0;
 }
 
+static void renesas_sdhi_scc_reset(struct tmio_mmc_host *host, struct renesas_sdhi *priv)
+{
+	renesas_sdhi_disable_scc(host->mmc);
+	renesas_sdhi_reset_hs400_mode(host, priv);
+	priv->needs_adjust_hs400 = false;
+
+	sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
+		       ~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
+		       sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
+}
+
 /* only populated for TMIO_MMC_MIN_RCAR2 */
 static void renesas_sdhi_reset(struct tmio_mmc_host *host)
 {
 	struct renesas_sdhi *priv = host_to_priv(host);
 	u16 val;
 
-	if (priv->scc_ctl) {
-		renesas_sdhi_disable_scc(host->mmc);
-		renesas_sdhi_reset_hs400_mode(host, priv);
-		priv->needs_adjust_hs400 = false;
-
-		sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
-			       ~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
-			       sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
-	}
+	if (priv->scc_ctl)
+		renesas_sdhi_scc_reset(host, priv);
 
 	sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, TMIO_MASK_ALL_RCAR2);
 
@@ -691,7 +695,7 @@ static int renesas_sdhi_execute_tuning(struct mmc_host *mmc, u32 opcode)
 
 	ret = renesas_sdhi_select_tuning(host);
 	if (ret < 0)
-		renesas_sdhi_reset(host);
+		renesas_sdhi_scc_reset(host, priv);
 	return ret;
 }
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible
  2021-03-15 14:59 [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Wolfram Sang
  2021-03-15 14:59 ` [PATCH v2 1/3] mmc: tmio: abort DMA before reset Wolfram Sang
  2021-03-15 14:59 ` [PATCH v2 2/3] mmc: renesas_sdhi: break SCC reset into own function Wolfram Sang
@ 2021-03-15 14:59 ` Wolfram Sang
  2021-03-16 12:53   ` Geert Uytterhoeven
  2021-03-16  6:38 ` [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Yoshihiro Shimoda
  3 siblings, 1 reply; 9+ messages in thread
From: Wolfram Sang @ 2021-03-15 14:59 UTC (permalink / raw)
  To: linux-mmc; +Cc: linux-renesas-soc, Yoshihiro Shimoda, Wolfram Sang

All recent SDHI instances can be reset via the reset controller. If one
is found, use it instead of the open coded reset. This is to get a
future-proof sane reset state.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/mmc/host/Kconfig             |  1 +
 drivers/mmc/host/renesas_sdhi.h      |  2 ++
 drivers/mmc/host/renesas_sdhi_core.c | 17 ++++++++++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index b236dfe2e879..1f1b691f10ce 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -707,6 +707,7 @@ config MMC_SDHI
 	tristate "Renesas SDHI SD/SDIO controller support"
 	depends on SUPERH || ARCH_RENESAS || COMPILE_TEST
 	select MMC_TMIO_CORE
+	select RESET_CONTROLLER
 	help
 	  This provides support for the SDHI SD/SDIO controller found in
 	  Renesas SuperH, ARM and ARM64 based SoCs
diff --git a/drivers/mmc/host/renesas_sdhi.h b/drivers/mmc/host/renesas_sdhi.h
index cb962c7883dc..53eded81a53e 100644
--- a/drivers/mmc/host/renesas_sdhi.h
+++ b/drivers/mmc/host/renesas_sdhi.h
@@ -70,6 +70,8 @@ struct renesas_sdhi {
 	DECLARE_BITMAP(smpcmp, BITS_PER_LONG);
 	unsigned int tap_num;
 	unsigned int tap_set;
+
+	struct reset_control *rstc;
 };
 
 #define host_to_priv(host) \
diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c
index db753829eaf6..d36181b6f687 100644
--- a/drivers/mmc/host/renesas_sdhi_core.c
+++ b/drivers/mmc/host/renesas_sdhi_core.c
@@ -20,6 +20,7 @@
 
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/mfd/tmio.h>
 #include <linux/mmc/host.h>
@@ -32,6 +33,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 #include <linux/sh_dma.h>
 #include <linux/slab.h>
 #include <linux/sys_soc.h>
@@ -572,10 +574,19 @@ static void renesas_sdhi_scc_reset(struct tmio_mmc_host *host, struct renesas_sd
 static void renesas_sdhi_reset(struct tmio_mmc_host *host)
 {
 	struct renesas_sdhi *priv = host_to_priv(host);
+	int ret;
 	u16 val;
 
-	if (priv->scc_ctl)
+	if (priv->rstc) {
+		reset_control_reset(priv->rstc);
+		/* Unknown why but without polling reset status, it will hang */
+		read_poll_timeout(reset_control_status, ret, ret == 0, 1, 100,
+				  false, priv->rstc);
+		priv->needs_adjust_hs400 = false;
+		renesas_sdhi_set_clock(host, host->clk_cache);
+	} else if (priv->scc_ctl) {
 		renesas_sdhi_scc_reset(host, priv);
+	}
 
 	sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, TMIO_MASK_ALL_RCAR2);
 
@@ -1081,6 +1092,10 @@ int renesas_sdhi_probe(struct platform_device *pdev,
 	if (ret)
 		goto efree;
 
+	priv->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(priv->rstc))
+		return PTR_ERR(priv->rstc);
+
 	ver = sd_ctrl_read16(host, CTL_VERSION);
 	/* GEN2_SDR104 is first known SDHI to use 32bit block count */
 	if (ver < SDHI_VER_GEN2_SDR104 && mmc_data->max_blk_count > U16_MAX)
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* RE: [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller
  2021-03-15 14:59 [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Wolfram Sang
                   ` (2 preceding siblings ...)
  2021-03-15 14:59 ` [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible Wolfram Sang
@ 2021-03-16  6:38 ` Yoshihiro Shimoda
  3 siblings, 0 replies; 9+ messages in thread
From: Yoshihiro Shimoda @ 2021-03-16  6:38 UTC (permalink / raw)
  To: Wolfram Sang, linux-mmc; +Cc: linux-renesas-soc

Hi Wolfram-san,

> From: Wolfram Sang, Sent: Tuesday, March 16, 2021 12:00 AM
> 
> This series enables SDHI to be reset via a reset controller.
> Please let me know about your (and BSP team's) thoughts.
> The series is based on mmc/next and tested on Salvator-XS with R-Car H3
> ES2.0 with what I think I can do locally here.

Thank you for the patches!

Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Also, I tested on R-Car H3 ES3.0 and I didn't observe any regression.
So,

Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Best regards,
Yoshihiro Shimoda


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible
  2021-03-15 14:59 ` [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible Wolfram Sang
@ 2021-03-16 12:53   ` Geert Uytterhoeven
  2021-03-16 12:57     ` Wolfram Sang
  0 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2021-03-16 12:53 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Linux MMC List, Linux-Renesas, Yoshihiro Shimoda

Hi Wolfram,

On Mon, Mar 15, 2021 at 4:00 PM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> All recent SDHI instances can be reset via the reset controller. If one
> is found, use it instead of the open coded reset. This is to get a
> future-proof sane reset state.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Thanks for your patch!

> --- a/drivers/mmc/host/Kconfig
> +++ b/drivers/mmc/host/Kconfig
> @@ -707,6 +707,7 @@ config MMC_SDHI
>         tristate "Renesas SDHI SD/SDIO controller support"
>         depends on SUPERH || ARCH_RENESAS || COMPILE_TEST
>         select MMC_TMIO_CORE
> +       select RESET_CONTROLLER

... if ARCH_RENESAS?

While RESET_CONTROLLER can be enabled on SuperH (and compiles),
there are no reset drivers for SuperH, so it won't be used anyway.

>         help
>           This provides support for the SDHI SD/SDIO controller found in
>           Renesas SuperH, ARM and ARM64 based SoCs

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible
  2021-03-16 12:53   ` Geert Uytterhoeven
@ 2021-03-16 12:57     ` Wolfram Sang
  2021-03-16 13:14       ` Geert Uytterhoeven
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfram Sang @ 2021-03-16 12:57 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Linux MMC List, Linux-Renesas, Yoshihiro Shimoda

[-- Attachment #1: Type: text/plain, Size: 418 bytes --]


> > +       select RESET_CONTROLLER
> 
> ... if ARCH_RENESAS?
> 
> While RESET_CONTROLLER can be enabled on SuperH (and compiles),
> there are no reset drivers for SuperH, so it won't be used anyway.

Yeah, I also thought about it and decided against it. Because a new arch
will then support resets out of the box while the overhead for old archs
is negligible, I'd think.

But no strong opinion here.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible
  2021-03-16 12:57     ` Wolfram Sang
@ 2021-03-16 13:14       ` Geert Uytterhoeven
  2021-03-16 16:59         ` Wolfram Sang
  0 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2021-03-16 13:14 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Linux MMC List, Linux-Renesas, Yoshihiro Shimoda

Hi Wolfram,

On Tue, Mar 16, 2021 at 1:57 PM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
> > > +       select RESET_CONTROLLER
> >
> > ... if ARCH_RENESAS?
> >
> > While RESET_CONTROLLER can be enabled on SuperH (and compiles),
> > there are no reset drivers for SuperH, so it won't be used anyway.
>
> Yeah, I also thought about it and decided against it. Because a new arch
> will then support resets out of the box while the overhead for old archs
> is negligible, I'd think.

Enabling RESET_CONTROLLER on SH increases kernel size by ca. 4 KiB.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible
  2021-03-16 13:14       ` Geert Uytterhoeven
@ 2021-03-16 16:59         ` Wolfram Sang
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2021-03-16 16:59 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Linux MMC List, Linux-Renesas, Yoshihiro Shimoda

[-- Attachment #1: Type: text/plain, Size: 155 bytes --]


> Enabling RESET_CONTROLLER on SH increases kernel size by ca. 4 KiB.

Well, I read this as "I insist on ARCH_RENESAS" ;) Will resend later or
tomorrow.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-16 16:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 14:59 [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Wolfram Sang
2021-03-15 14:59 ` [PATCH v2 1/3] mmc: tmio: abort DMA before reset Wolfram Sang
2021-03-15 14:59 ` [PATCH v2 2/3] mmc: renesas_sdhi: break SCC reset into own function Wolfram Sang
2021-03-15 14:59 ` [PATCH v2 3/3] mmc: renesas_sdhi: do hard reset if possible Wolfram Sang
2021-03-16 12:53   ` Geert Uytterhoeven
2021-03-16 12:57     ` Wolfram Sang
2021-03-16 13:14       ` Geert Uytterhoeven
2021-03-16 16:59         ` Wolfram Sang
2021-03-16  6:38 ` [PATCH v2 0/3] mmc: renesas_sdhi: reset via reset controller Yoshihiro Shimoda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.