Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: h.grohne@intenta.de (Helmut Grohne)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] mmc: sdhci-of-arasan: Add quirk for unstable clocks
Date: Fri, 15 Jun 2018 10:18:32 +0200	[thread overview]
Message-ID: <20180615081830.zrgx6arwn6ga27gu@laureti-dev> (raw)
In-Reply-To: <da0ebcb3-b19a-86a6-8462-87a1c0e81fff@intel.com>

Some controllers immediately report SDHCI_CLOCK_INT_STABLE after
enabling the clock even when the clock is not stable. When used in
conjunction with older/slower cards, this can result in:

    mmc0: error -84 whilst initialising SD card

When the stable reporting is broken, we simply wait for the maximum
stabilization period.

Signed-off-by: Helmut Grohne <h.grohne@intenta.de>
---
 Documentation/devicetree/bindings/mmc/arasan,sdhci.txt |  2 ++
 drivers/mmc/host/sdhci-of-arasan.c                     | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

Changes since v1 (RFC):
 * Use an arasan-specific quirk in the ->set_clock() callback as requested by
   Adrian Hunter.

diff --git a/Documentation/devicetree/bindings/mmc/arasan,sdhci.txt b/Documentation/devicetree/bindings/mmc/arasan,sdhci.txt
index 60481bfc3d31..c0e0f04a8504 100644
--- a/Documentation/devicetree/bindings/mmc/arasan,sdhci.txt
+++ b/Documentation/devicetree/bindings/mmc/arasan,sdhci.txt
@@ -39,6 +39,8 @@ Optional Properties:
   - xlnx,fails-without-test-cd: when present, the controller doesn't work when
     the CD line is not connected properly, and the line is not connected
     properly. Test mode can be used to force the controller to function.
+  - xlnx,int-clock-stable-broken: when present, the controller always reports
+    that the internal clock is stable even when it is not.
 
 Example:
 	sdhci at e0100000 {
diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c
index c33a5f7393bd..f7fe26c75150 100644
--- a/drivers/mmc/host/sdhci-of-arasan.c
+++ b/drivers/mmc/host/sdhci-of-arasan.c
@@ -102,6 +102,9 @@ struct sdhci_arasan_data {
 
 /* Controller does not have CD wired and will not function normally without */
 #define SDHCI_ARASAN_QUIRK_FORCE_CDTEST	BIT(0)
+/* Controller immediately reports SDHCI_CLOCK_INT_STABLE after enabling the
+ * internal clock even when the clock isn't stable */
+#define SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE BIT(1)
 };
 
 static const struct sdhci_arasan_soc_ctl_map rk3399_soc_ctl_map = {
@@ -207,6 +210,16 @@ static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock)
 
 	sdhci_set_clock(host, clock);
 
+	if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE)
+		/*
+		 * Some controllers immediately report SDHCI_CLOCK_INT_STABLE
+		 * after enabling the clock even though the clock is not
+		 * stable. Trying to use a clock without waiting here results
+		 * in EILSEQ while detecting some older/slower cards. The
+		 * chosen delay is the maximum delay from sdhci_set_clock.
+		 */
+		msleep(20);
+
 	if (ctrl_phy) {
 		phy_power_on(sdhci_arasan->phy);
 		sdhci_arasan->is_phy_on = true;
@@ -759,6 +772,9 @@ static int sdhci_arasan_probe(struct platform_device *pdev)
 	if (of_property_read_bool(np, "xlnx,fails-without-test-cd"))
 		sdhci_arasan->quirks |= SDHCI_ARASAN_QUIRK_FORCE_CDTEST;
 
+	if (of_property_read_bool(np, "xlnx,int-clock-stable-broken"))
+		sdhci_arasan->quirks |= SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE;
+
 	pltfm_host->clk = clk_xin;
 
 	if (of_device_is_compatible(pdev->dev.of_node,
-- 
2.11.0

  reply	other threads:[~2018-06-15  8:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04  6:42 [RFC PATCH] sdhci-of-arasan: card initialization failure -84 Helmut Grohne
2018-06-14  7:14 ` Adrian Hunter
2018-06-14  7:19 ` Adrian Hunter
2018-06-15  8:18   ` Helmut Grohne [this message]
2018-06-18  8:59     ` [PATCH v2] mmc: sdhci-of-arasan: Add quirk for unstable clocks Ulf Hansson
2018-06-19  9:09     ` Adrian Hunter
2018-06-20 11:32     ` [PATCH v3 0/2] mmc: sdhci-of-arasan: workaround for broken clocks Helmut Grohne
2018-06-20 11:32       ` [PATCH v3 1/2] dt-bindings: mmc: broken clock stable indicator on arasan controllers Helmut Grohne
2018-06-20 19:08         ` Rob Herring
2018-06-20 11:33       ` [PATCH v3 2/2] mmc: sdhci-of-arasan: Add quirk for unstable clocks Helmut Grohne
2018-07-02 13:17       ` [PATCH v3 0/2] mmc: sdhci-of-arasan: workaround for broken clocks Ulf Hansson

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=20180615081830.zrgx6arwn6ga27gu@laureti-dev \
    --to=h.grohne@intenta.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox