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=1796113339; b=hOSFYVblfo5ETh+nbU0iwq4zFGH/5wfTEHR+9mw31dTiu3bUbEII+/htUnmMzTPhYAz1 f6whtJ9gyADgwKQR/O3D/awYTh87Vg/0WdWwOC4zboURAIwFoEf2YSHFfHaeH5KHCHxBn DoLRm2THw/fi8708DhdEqcdLFGTLUxhb3kLyRAoWXoWsPiiYYt65pxWCcG3OpPzlurVAC kHuKJ3A7sRwqw55P3DB/AHyO/oV8T6vwi/2cDdwBGnsWLBs0MmD7zKI7Xhmmce8sbrjRH w9DbAS971iWNNK+WfCKikspPpSyuxG6V/vVHaUt+zmiBucI4u0qfZZhxfjkjKDKq0GA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796113339; 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=JbacQUldg6mx/22ppWGA1qq2FbdCqZL4/Oh5EWl+sZM=; b=vkKgWUPKrtuqAx4YOJCTkTIq5L3bZhI+66Wf8DJC71AzSd4VNBz4id6Cbx8bkyeashIk r40C5VzrlRa9RFg6EWeVraPr/PwN3/c7OKP4CZpPrZs6WU/h+/qWc+4zObx55PF0npMEg 7arY8gkwmgqcrboDc2VH4XcQSDSB5nyX0fPFuQDT+V5mKbMZf+J44RZfskmXEx9PP9Bel bkRR2SRJ2KpC0IeV1yhgTG2n1++A0s+DrgXttc7Mvb31qzFHHMuxXKFnZFvAiJLB89HGv 3NcV7Wzh3GwiUgQmyoJTKOMSJ+nk9WQaiBHXU0Ble1w/kbbVn8cbJ12FNd8Ww74eagw== 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=CDBAi5GO; 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 2CC33606A31A; Tue, 1 Dec 2026 08:22:19 +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=CDBAi5GO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CFC51F00899; Tue, 1 Dec 2026 08:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796113338; bh=JbacQUldg6mx/22ppWGA1qq2FbdCqZL4/Oh5EWl+sZM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=CDBAi5GO8GGgBNwwWtRQePfTC97bGXNbRdtso394hvYm9C4ovgivpHkUANdxx/mhr RuHZCpirsjUzigs6OP5VitSPgwk6IGfTjYB/bpfDBpyHhJf5zg2XTUyLaW0ADMeHEo uLkMIEouaZ1Z7kZtJWlB5W/dSZd+nJZ6nRMgds22vonQhqMIM5Q6LjvAyBESGSb4a6 fSg7+seQ7NLTXx0HhtEbepTmiQzW5DQpGu9ARCbu0Ri262veqq19ETGiWqDJBwTYLS 5s744BkJHnM0G9rY8L7PCRmYa3Bt9//sBQGTcM1uUlCipqrne8FL/fBU6BkR8GWVuP wQoB8al3RJn7w== From: Yixun Lan Date: Tue, 01 Dec 2026 08:21:00 +0000 Subject: [PATCH 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-539d59063418@kernel.org> References: <20261201-07-k3-sdhci-fix-v2-0-539d59063418@kernel.org> In-Reply-To: <20261201-07-k3-sdhci-fix-v2-0-539d59063418@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=4596; i=dlan@kernel.org; h=from:subject:message-id; bh=p9WY+HNE2GNDRKJY0hUxBkG1PR2fRK6ghVSYs7Ets54=; b=owEB6QIW/ZANAwAKATGq6kdZTbvtAcsmYgBrDoOLOpKAuGYV421l7Q2ePnPhqocaQsf/aag0N FR5ctTGZ2aJAq8EAAEKAJkWIQS1urjJwxtxFWcCI9wxqupHWU277QUCaw6DixsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDJfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5 maWZ0aGhvcnNlbWFuLm5ldEI1QkFCOEM5QzMxQjcxMTU2NzAyMjNEQzMxQUFFQTQ3NTk0REJCRU QACgkQMarqR1lNu+0eSg/9Gs/cYrYlwO2q0WWm/1YKWlyV0Kw/rmebklOdRynzg8/B3t8NqvLK6 MQacTWLwsT/n0brix5SpKQTq3x5yS9047Y0bvOQhpGJsLq0PUwPTa8arYq42GC9YueGs0djLEwe qGS+8+qJuKaoGOlz5zVwlAd3HnBMM7IPiy+eE4sCeZuFgaoaud1yGFJ6Bxb1zuCdG52fyRPwobY 1AxChM5yTXT84WoXaSwzYS5edY4xkbVG6b/8K53LsfHlFz8Xgaj+Vr2dSTAjEgphrj9l/eFd9xA w3tRinIwDhSx8Gqj1OF7SNbErVDpfQHiUirS3DvrIXim0ccj/ytgsseB7FIsYAtK9n8FB4bF5zK GqsAaImYXLqYU3AASwzfD3zJuav0Exd8qKZNEBtyYwrRnfse9Am+Ub7lAKyAzKmbxPTD5E7+qSO hjBU6qyjZjFVhEJrdsvvuh5KJgs9zQy6Cuwugn8W/ocbG7D1+cCiXRQmYFunL0soNiXegGelLB+ BFZR7OuOUCWufzqSNa8Pt2UGgAcKAQG0KgTy9SE3efR4gzYAXPabHB/+/hqHiNQhJd8eGEiSPmn pvrCxTpcFu4HZ48hQg+yKnUJ1hzmead41Ox1aHP7WktNd4pr9Vbrm/nBu1ds+3oYz2imsxbbOqk KlnwUfZJYznwGXTdNbS7yoHaw6llRE= 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 e573d739f350..d8d70a0d4857 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 @@ -164,6 +165,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); @@ -174,9 +185,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, @@ -213,6 +221,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) @@ -512,6 +534,23 @@ static void spacemit_sdhci_get_tuning_params(struct device *dev, device_property_read_u8(dev, "spacemit,tx-delay", &sdhst->tx_delaycode); } +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, @@ -576,8 +615,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