1 From 5603731a15ef9ca317c122cc8c959f1dee1798b4 Mon Sep 17 00:00:00 2001
2 From: Takeshi Saito <takeshi.saito.xv@renesas.com>
3 Date: Thu, 21 Feb 2019 20:38:05 +0100
4 Subject: mmc: tmio: fix access width of Block Count Register
6 From: Takeshi Saito <takeshi.saito.xv@renesas.com>
8 commit 5603731a15ef9ca317c122cc8c959f1dee1798b4 upstream.
10 In R-Car Gen2 or later, the maximum number of transfer blocks are
11 changed from 0xFFFF to 0xFFFFFFFF. Therefore, Block Count Register
12 should use iowrite32().
14 If another system (U-boot, Hypervisor OS, etc) uses bit[31:16], this
15 value will not be cleared. So, SD/MMC card initialization fails.
17 So, check for the bigger register and use apropriate write. Also, mark
18 the register as extended on Gen2.
20 Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
21 [wsa: use max_blk_count in if(), add Gen2, update commit message]
22 Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
24 Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
25 [Ulf: Fixed build error]
26 Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 drivers/mmc/host/renesas_sdhi_sys_dmac.c | 1 +
31 drivers/mmc/host/tmio_mmc.h | 5 +++++
32 drivers/mmc/host/tmio_mmc_core.c | 6 +++++-
33 3 files changed, 11 insertions(+), 1 deletion(-)
35 --- a/drivers/mmc/host/renesas_sdhi_sys_dmac.c
36 +++ b/drivers/mmc/host/renesas_sdhi_sys_dmac.c
37 @@ -68,6 +68,7 @@ static const struct renesas_sdhi_of_data
39 .taps = rcar_gen2_scc_taps,
40 .taps_num = ARRAY_SIZE(rcar_gen2_scc_taps),
41 + .max_blk_count = 0xffffffff,
44 /* Definitions for sampling clocks */
45 --- a/drivers/mmc/host/tmio_mmc.h
46 +++ b/drivers/mmc/host/tmio_mmc.h
47 @@ -279,6 +279,11 @@ static inline void sd_ctrl_write32_as_16
48 iowrite16(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
51 +static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
53 + iowrite32(val, host->ctl + (addr << host->bus_shift));
56 static inline void sd_ctrl_write32_rep(struct tmio_mmc_host *host, int addr,
57 const u32 *buf, int count)
59 --- a/drivers/mmc/host/tmio_mmc_core.c
60 +++ b/drivers/mmc/host/tmio_mmc_core.c
62 #include <linux/regulator/consumer.h>
63 #include <linux/mmc/sdio.h>
64 #include <linux/scatterlist.h>
65 +#include <linux/sizes.h>
66 #include <linux/spinlock.h>
67 #include <linux/swiotlb.h>
68 #include <linux/workqueue.h>
69 @@ -777,7 +778,10 @@ static int tmio_mmc_start_data(struct tm
71 /* Set transfer length / blocksize */
72 sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz);
73 - sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
74 + if (host->mmc->max_blk_count >= SZ_64K)
75 + sd_ctrl_write32(host, CTL_XFER_BLK_COUNT, data->blocks);
77 + sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
79 tmio_mmc_start_dma(host, data);