mmc: tmio: set max_busy_timeout
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 25 Nov 2020 21:29:59 +0000 (22:29 +0100)
committerUlf Hansson <ulf.hansson@linaro.org>
Fri, 4 Dec 2020 12:28:25 +0000 (13:28 +0100)
Set max_busy_timeouts for variants known to support the TOPxx bits in
the SD_OPTION register. The timeout mechanism was running in the
background but not yet properly handled in the driver. So, let the MMC
core know when to not use R1B to avoid unhandled timeouts.

My datasheets for older variants (tmio_mmc.c) suggest that they support
it, too. However, actual bit descriptions are lacking, so I chose an
opt-in approach.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20201125213001.15003-2-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/renesas_sdhi_core.c
drivers/mmc/host/tmio_mmc.h
drivers/mmc/host/tmio_mmc_core.c
drivers/mmc/host/uniphier-sd.c
include/linux/mfd/tmio.h

index bb937411c2ec2b804ccd93ed88875eb3018e313d..153767054c0585617a623a5d8417f8f8ff64d68f 100644 (file)
@@ -1041,6 +1041,9 @@ int renesas_sdhi_probe(struct platform_device *pdev,
        /* All SDHI have SDIO status bits which must be 1 */
        mmc_data->flags |= TMIO_MMC_SDIO_STATUS_SETBITS;
 
+       /* All SDHI support HW busy detection */
+       mmc_data->flags |= TMIO_MMC_USE_BUSY_TIMEOUT;
+
        dev_pm_domain_start(&pdev->dev);
 
        ret = renesas_sdhi_clk_enable(host);
index 7ff41185896acf9d168b77aab7444b2db2828f4f..819198af17f4c7dad2f5324c4cb9e45c11e49ac2 100644 (file)
@@ -80,6 +80,8 @@
 #define        CLK_CTL_SCLKEN          BIT(8)
 
 /* Definitions for values the CTL_SD_MEM_CARD_OPT register can take */
+#define CARD_OPT_TOP_MASK      0xf0
+#define CARD_OPT_TOP_SHIFT     4
 #define CARD_OPT_WIDTH8                BIT(13)
 #define CARD_OPT_WIDTH         BIT(15)
 
index a89547f5d7332e0376c69132b456f8631a4ca944..7d2da5befe6b3edf530ea92d1d3908ad44dcbacd 100644 (file)
@@ -887,6 +887,18 @@ static void tmio_mmc_set_bus_width(struct tmio_mmc_host *host,
        sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, reg);
 }
 
+static void tmio_mmc_max_busy_timeout(struct tmio_mmc_host *host)
+{
+       u16 val = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT);
+       unsigned int clk_rate = host->mmc->actual_clock ?: host->mmc->f_max;
+       unsigned int cycles;
+
+       val = (val & CARD_OPT_TOP_MASK) >> CARD_OPT_TOP_SHIFT;
+       cycles = 1 << (13 + val);
+
+       host->mmc->max_busy_timeout = cycles / (clk_rate / MSEC_PER_SEC);
+}
+
 /* Set MMC clock / power.
  * Note: This controller uses a simple divider scheme therefore it cannot
  * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
@@ -945,6 +957,9 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                break;
        }
 
+       if (host->pdata->flags & TMIO_MMC_USE_BUSY_TIMEOUT)
+               tmio_mmc_max_busy_timeout(host);
+
        /* Let things settle. delay taken from winCE driver */
        usleep_range(140, 200);
        if (PTR_ERR(host->mrq) == -EINTR)
index 3092466a99abfaa649159de121683d007de7de05..a6cd16771d4e90f8aab057ec7ecc6b0afe482e74 100644 (file)
@@ -586,6 +586,7 @@ static int uniphier_sd_probe(struct platform_device *pdev)
 
        tmio_data = &priv->tmio_data;
        tmio_data->flags |= TMIO_MMC_32BIT_DATA_PORT;
+       tmio_data->flags |= TMIO_MMC_USE_BUSY_TIMEOUT;
 
        host = tmio_mmc_host_alloc(pdev, tmio_data);
        if (IS_ERR(host))
index 8ba042430d8e9314f1bd3f0934ddf51c263c2354..27264fe4b3b9a20f0debf41d3625ed86f1e1d87d 100644 (file)
  */
 #define TMIO_MMC_HAS_IDLE_WAIT         BIT(4)
 
-/* BIT(5) is unused */
+/*
+ * Use the busy timeout feature. Probably all TMIO versions support it. Yet,
+ * we don't have documentation for old variants, so we enable only known good
+ * variants with this flag. Can be removed once all variants are known good.
+ */
+#define TMIO_MMC_USE_BUSY_TIMEOUT      BIT(5)
 
 /*
  * Some controllers have CMD12 automatically