Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Sarthak Garg <quic_sartgarg@quicinc.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Al Cooper <alcooperx@gmail.com>, Haibo Chen <haibo.chen@nxp.com>,
	Andrew Jeffery <andrew@aj.id.au>,
	Eugen Hristev <eugen.hristev@microchip.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Prabu Thangamuthu <prabu.t@synopsys.com>,
	Manjunath M B <manjumb@synopsys.com>,
	Ben Dooks <ben-linux@fluff.org>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Viresh Kumar <vireshk@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Hu Ziji <huziji@marvell.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Brian Norris <briannorris@chromium.org>,
	Wenchao Chen <wenchao.chen@unisoc.com>,
	Chevron Li <chevron.li@bayhubtech.com>,
	linux-mmc@vger.kernel.org
Subject: [PATCH V2 3/4] mmc: sdhci: Avoid unnecessary ->set_clock()
Date: Mon, 28 Nov 2022 15:32:58 +0200	[thread overview]
Message-ID: <20221128133259.38305-4-adrian.hunter@intel.com> (raw)
In-Reply-To: <20221128133259.38305-1-adrian.hunter@intel.com>

To avoid glitches on the clock line, the card clock is disabled when making
timing changes. Do not do that separately for HISPD and UHS settings.

Tested-by: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/mmc/host/sdhci.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 17e5ccf9a855..beb1fe643634 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -2400,8 +2400,21 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 	if (host->version >= SDHCI_SPEC_300) {
 		u16 clk, ctrl_2;
 
+		/*
+		 * According to SDHCI Spec v3.00, if the Preset Value
+		 * Enable in the Host Control 2 register is set, we
+		 * need to reset SD Clock Enable before changing High
+		 * Speed Enable to avoid generating clock glitches.
+		 */
+		clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
+		if (clk & SDHCI_CLOCK_CARD_EN) {
+			clk &= ~SDHCI_CLOCK_CARD_EN;
+			sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+		}
+
+		sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+
 		if (!host->preset_enabled) {
-			sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
 			/*
 			 * We only need to set Driver Strength if the
 			 * preset value enable is not set.
@@ -2424,30 +2437,8 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 
 			sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
 			host->drv_type = ios->drv_type;
-		} else {
-			/*
-			 * According to SDHC Spec v3.00, if the Preset Value
-			 * Enable in the Host Control 2 register is set, we
-			 * need to reset SD Clock Enable before changing High
-			 * Speed Enable to avoid generating clock gliches.
-			 */
-
-			/* Reset SD Clock Enable */
-			clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
-			clk &= ~SDHCI_CLOCK_CARD_EN;
-			sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
-
-			sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
-
-			/* Re-enable SD Clock */
-			host->ops->set_clock(host, host->clock);
 		}
 
-		/* Reset SD Clock Enable */
-		clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
-		clk &= ~SDHCI_CLOCK_CARD_EN;
-		sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
-
 		host->ops->set_uhs_signaling(host, ios->timing);
 		host->timing = ios->timing;
 
-- 
2.34.1


  parent reply	other threads:[~2022-11-28 13:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28 13:32 [PATCH V2 0/4] mmc: sdhci: Fix voltage switch delay Adrian Hunter
2022-11-28 13:32 ` [PATCH V2 1/4] " Adrian Hunter
2022-11-28 13:32 ` [PATCH V2 2/4] mmc: sdhci: Avoid unnecessary re-configuration Adrian Hunter
2022-11-30 11:54   ` Robert Marko
2022-11-30 12:45     ` Adrian Hunter
2022-11-30 13:00       ` Robert Marko
2022-11-30 14:15         ` Adrian Hunter
2022-11-30 17:24           ` Robert Marko
2022-11-30 18:39             ` Florian Fainelli
2022-11-30 19:56               ` Robert Marko
2022-12-01  8:40                 ` Adrian Hunter
2022-12-01 10:48                   ` Robert Marko
2022-12-01 10:58                   ` Ulf Hansson
2022-11-28 13:32 ` Adrian Hunter [this message]
2022-11-28 13:32 ` [PATCH V2 4/4] mmc: sdhci: Enable card clock instead of ->set_clock() Adrian Hunter
2022-12-06 23:03   ` Michael Walle
2022-12-07  8:13     ` Adrian Hunter
2022-12-07 12:37       ` Ulf Hansson
2022-11-29 15:36 ` [PATCH V2 0/4] mmc: sdhci: Fix voltage switch delay 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=20221128133259.38305-4-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=alcooperx@gmail.com \
    --cc=andrew@aj.id.au \
    --cc=ben-linux@fluff.org \
    --cc=briannorris@chromium.org \
    --cc=chevron.li@bayhubtech.com \
    --cc=eugen.hristev@microchip.com \
    --cc=f.fainelli@gmail.com \
    --cc=haibo.chen@nxp.com \
    --cc=huziji@marvell.com \
    --cc=jh80.chung@samsung.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=manjumb@synopsys.com \
    --cc=prabu.t@synopsys.com \
    --cc=quic_sartgarg@quicinc.com \
    --cc=s.hauer@pengutronix.de \
    --cc=thierry.reding@gmail.com \
    --cc=ulf.hansson@linaro.org \
    --cc=vigneshr@ti.com \
    --cc=vireshk@kernel.org \
    --cc=wenchao.chen@unisoc.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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