linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: tmio: fix access width of Block Count Register
@ 2019-02-21 19:38 Wolfram Sang
  2019-02-25  9:20 ` Simon Horman
  2019-02-26  8:18 ` Ulf Hansson
  0 siblings, 2 replies; 3+ messages in thread
From: Wolfram Sang @ 2019-02-21 19:38 UTC (permalink / raw)
  To: linux-mmc
  Cc: linux-renesas-soc, Niklas Söderlund, Yoshihiro Shimoda,
	Masahiro Yamada, Wolfram Sang, Takeshi Saito

From: Takeshi Saito <takeshi.saito.xv@renesas.com>

In R-Car Gen2 or later, the maximum number of transfer blocks are
changed from 0xFFFF to 0xFFFFFFFF. Therefore, Block Count Register
should use iowrite32().

If another system (U-boot, Hypervisor OS, etc) uses bit[31:16], this
value will not be cleared. So, SD/MMC card initialization fails.

So, check for the bigger register and use apropriate write. Also, mark
the register as extended on Gen2.

Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: use max_blk_count in if(), add Gen2, update commit message]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: stable@kernel.org
---

No Fixes tag because it is hard to point to a specific commit. So, just a
stable tag. I think as long as it applies, we are good to go.

Yamada-san, please check if your driver needs to set max_blk_count, too.

Tested on a Renesas Lager board (R-Car H2) and Salvator-XS (R-Car M3N).
Verified with debug prints that the correct code path was executed, no
regressions encountered when checksumming large files.

 drivers/mmc/host/renesas_sdhi_sys_dmac.c | 1 +
 drivers/mmc/host/tmio_mmc.h              | 5 +++++
 drivers/mmc/host/tmio_mmc_core.c         | 5 ++++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/renesas_sdhi_sys_dmac.c b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
index 8471160316e0..02cd878e209f 100644
--- a/drivers/mmc/host/renesas_sdhi_sys_dmac.c
+++ b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
@@ -65,6 +65,7 @@ static const struct renesas_sdhi_of_data of_rcar_gen2_compatible = {
 	.scc_offset	= 0x0300,
 	.taps		= rcar_gen2_scc_taps,
 	.taps_num	= ARRAY_SIZE(rcar_gen2_scc_taps),
+	.max_blk_count  = 0xffffffff,
 };
 
 /* Definitions for sampling clocks */
diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index c03529e3f01a..2adb0d24360f 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -277,6 +277,11 @@ static inline void sd_ctrl_write32_as_16_and_16(struct tmio_mmc_host *host,
 	iowrite16(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
 }
 
+static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
+{
+	iowrite32(val, host->ctl + (addr << host->bus_shift));
+}
+
 static inline void sd_ctrl_write32_rep(struct tmio_mmc_host *host, int addr,
 				       const u32 *buf, int count)
 {
diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
index 085a0fab769c..198c811b478c 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -700,7 +700,10 @@ static int tmio_mmc_start_data(struct tmio_mmc_host *host,
 
 	/* Set transfer length / blocksize */
 	sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz);
-	sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
+	if (host->mmc->max_blk_count >= SZ_64K)
+		sd_ctrl_write32(host, CTL_XFER_BLK_COUNT, data->blocks);
+	else
+		sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
 
 	tmio_mmc_start_dma(host, data);
 
-- 
2.11.0


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

* Re: [PATCH] mmc: tmio: fix access width of Block Count Register
  2019-02-21 19:38 [PATCH] mmc: tmio: fix access width of Block Count Register Wolfram Sang
@ 2019-02-25  9:20 ` Simon Horman
  2019-02-26  8:18 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2019-02-25  9:20 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-mmc, linux-renesas-soc, Niklas Söderlund,
	Yoshihiro Shimoda, Masahiro Yamada, Takeshi Saito

On Thu, Feb 21, 2019 at 08:38:05PM +0100, Wolfram Sang wrote:
> From: Takeshi Saito <takeshi.saito.xv@renesas.com>
> 
> In R-Car Gen2 or later, the maximum number of transfer blocks are
> changed from 0xFFFF to 0xFFFFFFFF. Therefore, Block Count Register
> should use iowrite32().
> 
> If another system (U-boot, Hypervisor OS, etc) uses bit[31:16], this
> value will not be cleared. So, SD/MMC card initialization fails.
> 
> So, check for the bigger register and use apropriate write. Also, mark
> the register as extended on Gen2.
> 
> Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
> [wsa: use max_blk_count in if(), add Gen2, update commit message]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Cc: stable@kernel.org

Reviewed-by: Simon Horman <horms+renesas@verge.net.au>

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

* Re: [PATCH] mmc: tmio: fix access width of Block Count Register
  2019-02-21 19:38 [PATCH] mmc: tmio: fix access width of Block Count Register Wolfram Sang
  2019-02-25  9:20 ` Simon Horman
@ 2019-02-26  8:18 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2019-02-26  8:18 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-mmc, Linux-Renesas, Niklas Söderlund,
	Yoshihiro Shimoda, Masahiro Yamada, Takeshi Saito

On Thu, 21 Feb 2019 at 20:38, Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> From: Takeshi Saito <takeshi.saito.xv@renesas.com>
>
> In R-Car Gen2 or later, the maximum number of transfer blocks are
> changed from 0xFFFF to 0xFFFFFFFF. Therefore, Block Count Register
> should use iowrite32().
>
> If another system (U-boot, Hypervisor OS, etc) uses bit[31:16], this
> value will not be cleared. So, SD/MMC card initialization fails.
>
> So, check for the bigger register and use apropriate write. Also, mark
> the register as extended on Gen2.
>
> Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
> [wsa: use max_blk_count in if(), add Gen2, update commit message]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Cc: stable@kernel.org

Applied for fixes, thanks!

Kind regards
Uffe


> ---
>
> No Fixes tag because it is hard to point to a specific commit. So, just a
> stable tag. I think as long as it applies, we are good to go.
>
> Yamada-san, please check if your driver needs to set max_blk_count, too.
>
> Tested on a Renesas Lager board (R-Car H2) and Salvator-XS (R-Car M3N).
> Verified with debug prints that the correct code path was executed, no
> regressions encountered when checksumming large files.
>
>  drivers/mmc/host/renesas_sdhi_sys_dmac.c | 1 +
>  drivers/mmc/host/tmio_mmc.h              | 5 +++++
>  drivers/mmc/host/tmio_mmc_core.c         | 5 ++++-
>  3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/renesas_sdhi_sys_dmac.c b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
> index 8471160316e0..02cd878e209f 100644
> --- a/drivers/mmc/host/renesas_sdhi_sys_dmac.c
> +++ b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
> @@ -65,6 +65,7 @@ static const struct renesas_sdhi_of_data of_rcar_gen2_compatible = {
>         .scc_offset     = 0x0300,
>         .taps           = rcar_gen2_scc_taps,
>         .taps_num       = ARRAY_SIZE(rcar_gen2_scc_taps),
> +       .max_blk_count  = 0xffffffff,
>  };
>
>  /* Definitions for sampling clocks */
> diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
> index c03529e3f01a..2adb0d24360f 100644
> --- a/drivers/mmc/host/tmio_mmc.h
> +++ b/drivers/mmc/host/tmio_mmc.h
> @@ -277,6 +277,11 @@ static inline void sd_ctrl_write32_as_16_and_16(struct tmio_mmc_host *host,
>         iowrite16(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
>  }
>
> +static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
> +{
> +       iowrite32(val, host->ctl + (addr << host->bus_shift));
> +}
> +
>  static inline void sd_ctrl_write32_rep(struct tmio_mmc_host *host, int addr,
>                                        const u32 *buf, int count)
>  {
> diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
> index 085a0fab769c..198c811b478c 100644
> --- a/drivers/mmc/host/tmio_mmc_core.c
> +++ b/drivers/mmc/host/tmio_mmc_core.c
> @@ -700,7 +700,10 @@ static int tmio_mmc_start_data(struct tmio_mmc_host *host,
>
>         /* Set transfer length / blocksize */
>         sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz);
> -       sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
> +       if (host->mmc->max_blk_count >= SZ_64K)
> +               sd_ctrl_write32(host, CTL_XFER_BLK_COUNT, data->blocks);
> +       else
> +               sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
>
>         tmio_mmc_start_dma(host, data);
>
> --
> 2.11.0
>

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

end of thread, other threads:[~2019-02-26  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 19:38 [PATCH] mmc: tmio: fix access width of Block Count Register Wolfram Sang
2019-02-25  9:20 ` Simon Horman
2019-02-26  8:18 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).