From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796122559; b=UEhHImM/XOH/WuURNuByZ6Qf9mfUYuT3E+5SS74b0P9sd9xH/WfhFSt1ebhvZGmio92t pVYqlJTfhpxS2sOYevwMmOEp4+vXM6qctObKVlc1La7Qwt9dEMrH6BMT2rCvRyuNEVIoT 5cnJGlESz/FMZkVmp8pi30QMLLU4w6c0DIWVcX9HtIpxIkHJCUcgS/C4ribP/DQm/sFZ8 iRSv48+qE/hkHLKKOWLeAFlfWnSdCWusK1T/1Q2oTw2VmAGZfzp3Q5IE8dT3fJ6sTZhe5 zd2i2g6hu9/+lUYnKrvn+IDteMYUKV0lHehYVOqlte33+spXTjqZZTcYffZffg7CkNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796122559; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=IaO3wxijy5H6uk34LSBWCZz3rMSvoG+kTEjiW0ZI7T4=; b=IC6X3A+6DqUQRSb83TCQYZIYtO2LGko1sjRWRI6oI5DwgOpe30a3uONGDPai9FfUIlkv 3w7k/palpPXt+JxE2fpgsICJCJYIK1wax3DP5ko3dAv68Afo6tE711JJVX6euWR6nIieK yM5K3hqR7bGCqQhmb+L1m+t+M5nOyEdDWlNv/OF9/EcUz0JlrxCagABxhQ4Q5ZBwhI4I/ coH6qKO/eo8KL9db3R8aA2BbgHzIqLevqLsNP/nAbxvEamCSGTLKt20uiuSp2StFhrFSd KYeGoMhLk2slpvfPNu/S9WB1kLW1sGZ9gnGZ0VMt5Qg6lR56f/PpLnu6osenItlpCWA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CXZGabR6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78AD9606A320; Tue, 1 Dec 2026 10:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CXZGabR6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D7DB1F00925; Tue, 1 Dec 2026 10:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796122559; bh=IaO3wxijy5H6uk34LSBWCZz3rMSvoG+kTEjiW0ZI7T4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=CXZGabR6cEzwYFVSQSq4YdktYkBpndqY4rnsBvbIgO/M23mFv9ocyfXySDt9v+OFX GSFPD9bKxsyVb9FfqJnqMIeVlq7a0DJikjmSkWFY5z9fEGjgbSSjFHJRLTj0w9l09b qtJMni0CiUuOqPBD0vnS/jSnUhPoZCaOHTjWuKkvRB8+5Hm9DFI2FSJ7Sr8hHSJGHf VDgUz83olSH1Z0SVqwMdRJTvEMLNd6I7K9mWlpu54iSf4yxcFUVX4x8cgHG55zOxtN oItC+M7HLTzjs342/SQIt4bl18bhxu+4Yj6s5/ODR/U6hiBT/cz4Qmmpv57B5QhilX +LB4dgNwFygdg== From: Yixun Lan Date: Tue, 01 Dec 2026 10:54:47 +0000 Subject: [PATCH RESEND v2 8/8] mmc: sdhci-of-k1: Implement SD clock gating for voltage switch X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-07-k3-sdhci-fix-v2-8-6645f4fe6eb1@kernel.org> References: <20261201-07-k3-sdhci-fix-v2-0-6645f4fe6eb1@kernel.org> In-Reply-To: <20261201-07-k3-sdhci-fix-v2-0-6645f4fe6eb1@kernel.org> To: Adrian Hunter , Ulf Hansson Cc: Long Wan , Troy Mitchell , Hung-Chun Tseng , Iker Pedrosa , Anand Moon , Adrian Hunter , Trevor Gamblin , Vincent Legoll , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, Yixun Lan X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4567; i=dlan@kernel.org; h=from:subject:message-id; bh=UopBhX6Q1RXGnqvLn2YFeFl8w4uPe5G7UAouRTpLxt0=; b=owEB6QIW/ZANAwAKATGq6kdZTbvtAcsmYgBrDqeXQnU717jnMrUu4geKQdDYXzhlM+wbK2u0c cUonTKFm2eJAq8EAAEKAJkWIQS1urjJwxtxFWcCI9wxqupHWU277QUCaw6nlxsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDJfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5 maWZ0aGhvcnNlbWFuLm5ldEI1QkFCOEM5QzMxQjcxMTU2NzAyMjNEQzMxQUFFQTQ3NTk0REJCRU QACgkQMarqR1lNu+3rDg//b6dfMNJbakaj6+ikA5F7M5FyJjN+kKSdIfRPZ0vsZMg9hby4f/Ni0 1YGYeilJq/4LQWEXewxoabrbzUl82/OTDdc35pDbBnvhbge08rnhX3/p3AHmVXj8jgRp7j5t8G3 mFVKOHsUqHUlpIyEicFsgd3HP0PIghEG4U7uGQVPVvbS+eDC/hb6fbl6cunsl8a9QCZcjS5E9sE ZTXsQOkQtZk0QnIMmwgUmM1HT2mUvDZzRgvSqe9TDHWWWYSpCwYF6MJjJOR/ztBw1N7lbOgFUU0 azZfytX4IxQjWWun25I1uvsCeNyP9birq+beoW2FdywHPr8aCO8uoAK0dcgFA8BDTwAO6ynKVrO dmaecwwKNCTwwYQGmcL1KAuoBnIZhCd3hGrYEtpImGOWSsgXCbKSkryOcKcLNEZAgg9x4lFr7XV zq3VozOvhijUAjk446T7EkuW75xWEO7QW3RYL5FpeoidETVAlPMygQlq1SK61cy9KyZ2bqdDaov Gz/bAo+FgP1g3ZFJfbSFlRBgbrQFgySzodAKt5bXiEYBg+Y3GOlpVeDALnSgLexFGpYMYlGcmX4 Ws06uJHsodbuP6UCJ9Jv0nMyCH3ZNAbgtyh1i/Nf/O8VmY5Dqv828t4A4PQ5QpJ4gT53JDI/gLU 5/9QryG7AQGLfUVQnruy+f0PESYt94= X-Developer-Key: i=dlan@kernel.org; a=openpgp; fpr=50B03A1A5CBCD33576EF8CD7920C0DBCAABEFD55 From: Long Wan reset() permanently set OVRRD_CLK_OEN and FORCE_CLK_ON for SD/SDIO hosts and never cleared them, so the SD clock was forced on for the lifetime of the controller and hardware auto gating never took effect. These bits are only needed during the CMD11 1.8V voltage switch, where the clock has to keep running so DAT[3:0] can be sampled after the switch. Add a set_clk_gate() helper, force the clock on from set_clock() when CMD11 is in flight, and restore auto gating from card_busy() once the switch completes. card_busy() is registered for all card types since the CMD11 sequence is an SD/SDIO path and the DAT[0] level check is generic. Signed-off-by: Long Wan Signed-off-by: Yixun Lan --- drivers/mmc/host/sdhci-of-k1.c | 49 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-k1.c b/drivers/mmc/host/sdhci-of-k1.c index 9f15cc6a4a8c..e99e972f006b 100644 --- a/drivers/mmc/host/sdhci-of-k1.c +++ b/drivers/mmc/host/sdhci-of-k1.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -163,6 +164,16 @@ static void spacemit_sdhci_prepare_tuning(struct sdhci_host *host) spacemit_sdhci_setbits(host, SDHC_HS200_USE_RFIFO, SPACEMIT_SDHC_PHY_FUNC_REG); } +static void spacemit_sdhci_set_clk_gate(struct sdhci_host *host, unsigned int auto_gate) +{ + if (auto_gate) + spacemit_sdhci_clrbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON, + SPACEMIT_SDHC_OP_EXT_REG); + else + spacemit_sdhci_setbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON, + SPACEMIT_SDHC_OP_EXT_REG); +} + static void spacemit_sdhci_reset(struct sdhci_host *host, u8 mask) { sdhci_reset(host, mask); @@ -173,9 +184,6 @@ static void spacemit_sdhci_reset(struct sdhci_host *host, u8 mask) if (host->mmc->caps2 & MMC_CAP2_NO_MMC) { /* SD/SDIO: bypass PHY, use TX internal clock */ spacemit_sdhci_setbits(host, SDHC_TX_INT_CLK_SEL, SPACEMIT_SDHC_TX_CFG_REG); - - spacemit_sdhci_setbits(host, SDHC_OVRRD_CLK_OEN | SDHC_FORCE_CLK_ON, - SPACEMIT_SDHC_OP_EXT_REG); } else { /* eMMC: use PHY function mode */ spacemit_sdhci_setbits(host, SDHC_PHY_FUNC_EN | SDHC_PHY_PLL_LOCK, @@ -212,6 +220,20 @@ static void spacemit_sdhci_set_clock(struct sdhci_host *host, unsigned int clock spacemit_sdhci_clrbits(host, SDHC_TX_INT_CLK_SEL, SPACEMIT_SDHC_TX_CFG_REG); sdhci_set_clock(host, clock); + + if (host->mmc->caps2 & MMC_CAP2_NO_MMC) { + /* + * During CMD11 voltage switch to 1.8V, temporarily force the + * clock on to ensure DAT[3:0] can be sampled correctly after + * the switch. Auto gating is restored in card_busy() once the + * switch completes. + */ + if ((SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) == SD_SWITCH_VOLTAGE) && + host->mmc->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_180) { + if (clock) + spacemit_sdhci_set_clk_gate(host, 0); + } + } }; static void spacemit_sdhci_phy_dll_init(struct sdhci_host *host) @@ -497,6 +519,23 @@ static inline void spacemit_sdhci_get_pins(struct device *dev, sdhst->pinctrl_default, sdhst->pinctrl_uhs); } +static int spacemit_sdhci_card_busy(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + u32 present_state; + + present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); + + if (host->mmc->caps2 & MMC_CAP2_NO_MMC) { + if ((SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) == SD_SWITCH_VOLTAGE) && + host->mmc->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_180) + /* Recover auto clock after voltage switch */ + spacemit_sdhci_set_clk_gate(host, 1); + } + + return !(present_state & SDHCI_DATA_0_LVL_MASK); +} + static const struct sdhci_ops spacemit_sdhci_ops = { .get_max_clock = spacemit_sdhci_clk_get_max_clock, .reset = spacemit_sdhci_reset, @@ -561,8 +600,10 @@ static int spacemit_sdhci_probe(struct platform_device *pdev) sdhci_get_of_property(pdev); + mops = &host->mmc_host_ops; + mops->card_busy = spacemit_sdhci_card_busy; + if (!(host->mmc->caps2 & MMC_CAP2_NO_MMC)) { - mops = &host->mmc_host_ops; mops->hs400_prepare_ddr = spacemit_sdhci_pre_select_hs400; mops->hs400_complete = spacemit_sdhci_post_select_hs400; mops->hs400_downgrade = spacemit_sdhci_pre_hs400_to_hs200; -- 2.56.0