mmc: tmio: fix access width of Block Count Register [Linux 5.0]

mmc: tmio: fix access width of Block Count Register [Linux 5.0]

This Linux kernel change "mmc: tmio: fix access width of Block Count Register" is included in the Linux 5.0 release. This change is authored by Takeshi Saito <takeshi.saito.xv [at]> on Thu Feb 21 20:38:05 2019 +0100. The commit for this change in Linux stable tree is 5603731 (patch).

mmc: tmio: fix access width of Block Count Register

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 <[email protected]>
[wsa: use max_blk_count in if(), add Gen2, update commit message]
Signed-off-by: Wolfram Sang <[email protected]>
Cc: [email protected]
Reviewed-by: Simon Horman <[email protected]>
[Ulf: Fixed build error]
Signed-off-by: Ulf Hansson <[email protected]>

There are 12 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

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

diff --git a/drivers/mmc/host/renesas_sdhi_sys_dmac.c b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
index 8471160..02cd878 100644
--- a/drivers/mmc/host/renesas_sdhi_sys_dmac.c
+++ b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
@@ -65,6 +65,7 @@
    .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 c03529e..2adb0d2 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 41d7972..f7a6f00 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -43,6 +43,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/mmc/sdio.h>
 #include <linux/scatterlist.h>
+#include <linux/sizes.h>
 #include <linux/spinlock.h>
 #include <linux/swiotlb.h>
 #include <linux/workqueue.h>
@@ -703,7 +704,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);

Leave a Reply

Your email address will not be published. Required fields are marked *