All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
To: cip-dev@lists.cip-project.org,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>,
	Pavel Machek <pavel@denx.de>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Subject: [RESEND PATCH 5.10.y-cip 11/40] mmc: tmio: set max_busy_timeout
Date: Fri,  1 Apr 2022 20:42:05 +0100	[thread overview]
Message-ID: <20220401194234.14057-12-prabhakar.mahadev-lad.rj@bp.renesas.com> (raw)
In-Reply-To: <20220401194234.14057-1-prabhakar.mahadev-lad.rj@bp.renesas.com>

From: Wolfram Sang <wsa+renesas@sang-engineering.com>

commit 30ae3e13caeaa47884c222ebf5711ce27ed25f19 upstream.

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>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/mmc/host/renesas_sdhi_core.c |  3 +++
 drivers/mmc/host/tmio_mmc.h          |  2 ++
 drivers/mmc/host/tmio_mmc_core.c     | 15 +++++++++++++++
 drivers/mmc/host/uniphier-sd.c       |  1 +
 include/linux/mfd/tmio.h             |  7 ++++++-
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c
index 751e21243ebf..980c50b9226e 100644
--- a/drivers/mmc/host/renesas_sdhi_core.c
+++ b/drivers/mmc/host/renesas_sdhi_core.c
@@ -1046,6 +1046,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);
diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index 7ff41185896a..819198af17f4 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -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)
 
diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
index ac4e7874a3f1..a896595cf575 100644
--- a/drivers/mmc/host/tmio_mmc_core.c
+++ b/drivers/mmc/host/tmio_mmc_core.c
@@ -885,6 +885,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
@@ -943,6 +955,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)
diff --git a/drivers/mmc/host/uniphier-sd.c b/drivers/mmc/host/uniphier-sd.c
index 196e94bf37f0..73d5bebd0f33 100644
--- a/drivers/mmc/host/uniphier-sd.c
+++ b/drivers/mmc/host/uniphier-sd.c
@@ -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))
diff --git a/include/linux/mfd/tmio.h b/include/linux/mfd/tmio.h
index 8ba042430d8e..27264fe4b3b9 100644
--- a/include/linux/mfd/tmio.h
+++ b/include/linux/mfd/tmio.h
@@ -55,7 +55,12 @@
  */
 #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
-- 
2.17.1



  parent reply	other threads:[~2022-04-04 18:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01 19:41 [RESEND PATCH 5.10.y-cip 00/40] Add SD/eMMC support for Renesas RZ/G2L SoC Lad Prabhakar
2022-04-01 19:41 ` [RESEND PATCH 5.10.y-cip 01/40] mmc: renesas_sdhi: only reset SCC when its pointer is populated Lad Prabhakar
2022-04-01 19:41 ` [RESEND PATCH 5.10.y-cip 02/40] mmc: renesas_sdhi: probe into TMIO after SCC parameters have been setup Lad Prabhakar
2022-04-01 19:41 ` [RESEND PATCH 5.10.y-cip 03/40] mmc: renesas_sdhi: populate SCC pointer at the proper place Lad Prabhakar
2022-04-01 19:41 ` [RESEND PATCH 5.10.y-cip 04/40] mmc: renesas_sdhi: simplify reset routine a little Lad Prabhakar
2022-04-01 19:41 ` [RESEND PATCH 5.10.y-cip 05/40] mmc: renesas_sdhi: clear TAPEN when resetting, too Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 06/40] mmc: renesas_sdhi: merge the SCC reset functions Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 07/40] mmc: renesas_sdhi: remove superfluous SCLKEN Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 08/40] mmc: renesas_sdhi: improve HOST_MODE usage Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 09/40] mmc: renesas_sdhi: don't hardcode SDIF values Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 10/40] mmc: renesas_sdhi: sort includes Lad Prabhakar
2022-04-01 19:42 ` Lad Prabhakar [this message]
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 12/40] mmc: tmio: add hook for custom busy_wait calculation Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 13/40] mmc: renesas_sdhi: populate hook for longer busy_wait Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 14/40] mmc: renesas_internal_dmac: add pre_req and post_req support Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 15/40] mmc: tmio: Add data timeout error detection Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 16/40] mmc: renesas_sdhi: Add a condition of cmd/data timeout for retune Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 17/40] mmc: tmio: support custom irq masks Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 18/40] mmc: renesas_sdhi: use custom mask for TMIO_MASK_ALL Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 19/40] mmc: tmio: abort DMA before reset Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 20/40] mmc: tmio: restore bus width when resetting Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 21/40] mmc: renesas_sdhi: break SCC reset into own function Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 22/40] mmc: renesas_sdhi: do hard reset if possible Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 23/40] mmc: tmio: always flag retune when resetting and a card is present Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 24/40] mmc: tmio: always restore irq register Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 25/40] mmc: tmio: reenable card irqs after the reset callback Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 26/40] mmc: tmio: reinit card irqs in reset routine Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 27/40] clk: renesas: rzg2l: Add SDHI clk mux support Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 28/40] clk: renesas: rzg2l: Add missing kerneldoc for resets Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 29/40] clk: renesas: rzg2l: Check return value of pm_genpd_init() Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 30/40] clk: renesas: rzg2l: propagate return value of_genpd_add_provider_simple() Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 31/40] clk: renesas: r9a07g044: Add SDHI clock and reset entries Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 32/40] dt-bindings: Fix errors in 'if' schemas Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 33/40] dt-bindings: Drop redundant minItems/maxItems Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 34/40] dt-bindings: mmc: renesas,sdhi: Fix dtbs-check warning Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 35/40] dt-bindings: mmc: renesas,sdhi: Document RZ/G2L bindings Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 36/40] dt-bindings: mmc: renesas,sdhi: Add optional SDnH clock Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 37/40] dt-bindings: mmc: renesas,sdhi: Rename RZ/G2L clocks Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 38/40] arm64: dts: renesas: r9a07g044: Add SDHI nodes Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 39/40] arm64: dts: renesas: rzg2l-smarc-som: Enable eMMC on SMARC platform Lad Prabhakar
2022-04-01 19:42 ` [RESEND PATCH 5.10.y-cip 40/40] arm64: dts: renesas: rzg2l-smarc: Enable microSD " Lad Prabhakar
2022-04-01 21:33 ` [RESEND PATCH 5.10.y-cip 00/40] Add SD/eMMC support for Renesas RZ/G2L SoC Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220401194234.14057-12-prabhakar.mahadev-lad.rj@bp.renesas.com \
    --to=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=pavel@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.