From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f227.google.com (mail-pl1-f227.google.com [209.85.214.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BAD5471D00 for ; Tue, 28 Jul 2026 19:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.227 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785265413; cv=none; b=bggebM3HbI97jXIqtemdznPWXtKb3V7o2tZDKZIrUqjTADpL5Zwx4NN2pegsIckaeVejQndQC94tWMTtnN9js1witrtGppdbwuse9dr7HsfYgJRz6omYqov0RVyUWauC1SH+I0JYusBXeFB+UKv8MzUK0MTLlsmTuv/9ogho1ZA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785265413; c=relaxed/simple; bh=eetq7XpE3Ybytc8Hsj07t5iui7R/XqM3b5H6eDBH200=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tJfiz83zhQRzGWzwe7WrH/Huid+Xi5+5Jt6b5OI0JP/EXpgIuNJ6l8KgY6BgYS5B0eP6sSqR7IeMLhMjfntXYqU+ZvgG2zZ6iHnrw5WHTEzg+tNW94YoZqGwttbbUVHhu3uXgnSKWcnZ03vYWe1tbg25D4EA3c2T2di43tn2q50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=SXqZIyzG; arc=none smtp.client-ip=209.85.214.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="SXqZIyzG" Received: by mail-pl1-f227.google.com with SMTP id d9443c01a7336-2cea3004256so3006465ad.0 for ; Tue, 28 Jul 2026 12:03:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785265409; x=1785870209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CCgHHDSjxqQac2HFS0bKfls/PU3Kxpy40sOV/zTVIrc=; b=aCvD0NTtjDkYXR8dqELF4Xn422ngsy6aTDULEwHPhvG3lNRpWUlELKdg3FeaMIARkN RsyHnurwcw1MS2cDX30LcqAghhA+3r25eLKRal9noBu1nNeqTcYEart3BQAVYfeDe9if lAZ5ChlKEZaPEJ87J4C5FGuQ9K28Exw3K8btCCw/yrVqtbeLBw4Jtg4eGjGVOuP33BDb YTtdiEPUURrpmIsaW+LNmnkBUV7liGqm1Od/wvLmINBEA6S8wzqDiiQtT6k2QkOTGBi8 hy9Z3CTr3GjJcCJYHjI8+3VBr7JSHINq+sX0+8X3j32JKyLMWitBqmrcpRc43dmBoQVF VV6A== X-Forwarded-Encrypted: i=1; AHgh+RpOK8by+pX6EmGb/hnyCaEGQvcrlhtseM8SWHSeyNSvn4yoYl1ubVFPPZoy2QAGSU7zkGsosYWaKe1GNmI=@vger.kernel.org X-Gm-Message-State: AOJu0YxgQ/ouF9acg5l3kgwUBS2ZseFpEagHTzo3NMM7dnixK1SsudJV rLBwPLeg30bGfCKujg+Th4jAnvF2oT6RNqRXs7IA8p267lNWzjd+PwzX+kfEBCYw+xkvkz1jRWR Z/6lZe2nGHrODuXJZPDhJ+oo/x2AOcbUqEGc5+3Zrwj1ZaMadgSJun/ZwiUqkIgT0+54yTiZUA/ 1GAgPvcndxJChI4XGcm7kLSlb128wc6EKbov+qJQ4alZ47IdJ+S61F5Ralb7pfhFJIhMn7VIN3e UqKsi+cwHAfVaVQ X-Gm-Gg: AR+sD10pFIWcqXRQtWVeYvfYMxBxXWzvGekpOIUpZCHpLQP4Zq0nJ84QGUTsghIq0S7 zrUf0F9Wdo6AEGDPeiO26pwoph8nIcXYG+7b2Qfee1x4uuFQC7mmtCRCz1j0fo7wz2WOeBMSRUY w55SVUKypRt/pE0xt/cHJ2QgF0vx7+5Smbkj+ztE5HKXR5Q99Zj/aeTYqA2EoCx/7SclbuUg3rP wIazulpCI0oTQvrxYPhATNEjLFmSPHevRrnNt7rVQ6BGQi3q24boA35+TCml0afdR0y1+Iveu3e GcYsF1teAf8Z0inMEXWTRaVFrvChPJPFkSUT78GlipQfY7mEjH4OiWu7Ww3cdQUm1pNURtsRAkw vWmvpYcIKSH4meAVbr3bJYDaWVBqFpdjAG3dWa4jCFfX2disBBendiHKst9eWsgqmGJo+Znvzhz 728xc2uudusw5AZE6tNyee1YabXe4+4yD/ X-Received: by 2002:a17:902:ffcf:b0:2cf:32bc:9722 with SMTP id d9443c01a7336-2d015c6db5cmr46070335ad.34.1785265408884; Tue, 28 Jul 2026 12:03:28 -0700 (PDT) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-26.dlp.protect.broadcom.com. [144.49.247.26]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2d022a30e9csm165905ad.2.2026.07.28.12.03.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2026 12:03:28 -0700 (PDT) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-8e97889ac8aso1976056d6.3 for ; Tue, 28 Jul 2026 12:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1785265408; x=1785870208; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CCgHHDSjxqQac2HFS0bKfls/PU3Kxpy40sOV/zTVIrc=; b=SXqZIyzG/5CPFxxGinxQzO+l5JwSMuAYr4LmjeEvKO42tusVbXGYTZ0jTXKly+3q+z Did1VGWlziX2AJ1XObhLSLZDmmUDHnpI/ib7XiYu0QWMtafFYCM821zqVDiA8FDgLXts /yPieoMbebUeuI13RxLLxz+Tynav3iJBdEI8U= X-Forwarded-Encrypted: i=1; AHgh+Rqyf1MNtngpFJx+Tc/IL1qotlqEVZaTiPOqLzit+ExypzOnQV/0skLMrtda2uwnK48xDPXWyirDD0sj2/o=@vger.kernel.org X-Received: by 2002:ac8:5a8f:0:b0:51c:83ee:e429 with SMTP id d75a77b69052e-529d7247571mr33198741cf.78.1785265407721; Tue, 28 Jul 2026 12:03:27 -0700 (PDT) X-Received: by 2002:ac8:5a8f:0:b0:51c:83ee:e429 with SMTP id d75a77b69052e-529d7247571mr33198201cf.78.1785265407041; Tue, 28 Jul 2026 12:03:27 -0700 (PDT) Received: from mail.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9081dd8b21esm5502856d6.46.2026.07.28.12.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 12:03:26 -0700 (PDT) From: Kamal Dasu To: Ulf Hansson Cc: Kamal Dasu , Florian Fainelli , Wolfram Sang , Oleksij Rempel , Avri Altman , Pedro Demarchi Gomes , Erick Shepherd , Adrian Hunter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] mmc: core: Honor keep-power-in-suspend for (e)MMC in suspend/resume Date: Tue, 28 Jul 2026 15:03:14 -0400 Message-Id: <20260728190314.2325906-3-kamal.dasu@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260728190314.2325906-1-kamal.dasu@broadcom.com> References: <20260728190314.2325906-1-kamal.dasu@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e On some platforms, firmware accesses the (e)MMC card directly during resume from Suspend-to-DRAM, before the kernel's own resume path has run, in order to load boot code. This requires the card to remain powered and responsive throughout suspend: putting it to sleep, sending it a power-off notification, or removing its supply is not safe, since firmware needs to talk to a live card. keep-power-in-suspend / MMC_PM_KEEP_POWER already exist for this purpose, but are only consumed in the SDIO suspend/resume path (mmc_sdio_suspend()/mmc_sdio_resume()), gated on a per-function runtime request via sdio_set_host_pm_flags(). (e)MMC has no equivalent function-driver layer to make that request, and the requirement here is a fixed platform characteristic rather than a per-cycle one, so _mmc_suspend() checks host->pm_caps directly instead of pm_flags. When pm_caps has MMC_PM_KEEP_POWER set and pm_type is MMC_POWEROFF_SUSPEND, skip the poweroff-notify/sleep/power-off sequence entirely: deselect the card, reset the host to its initial bus state the same way _mmc_hw_reset() does for a non-power-cycle reset, mark the card suspended, and set host->pm_flags |= MMC_PM_KEEP_POWER. Setting MMC_PM_KEEP_POWER in host->pm_flags during suspend ensures that host controller resume handlers are aware that card power was preserved across suspend, allowing them to perform a soft resume sequence instead of assuming power was lost. Clear this flag in _mmc_resume() upon completion. The pm_type check matters because _mmc_suspend() is also called for shutdown, driver unbind, and undervoltage, none of which are guaranteed a subsequent _mmc_resume() call, so those still need the normal power-off path. Reported-by: Florian Fainelli Closes: https://lore.kernel.org/r/20260413180551.3683969-1-florian.fainelli@broadcom.com/ Signed-off-by: Kamal Dasu --- Changes in v4: - Gated the fast path on pm_type == MMC_POWEROFF_SUSPEND; it was previously unconditional, so it wrongly skipped the required power-off/notify handling during shutdown, unbind and undervoltage as well. - Reset the host to its initial bus state (mmc_set_clock() + mmc_set_initial_state(), matching _mmc_hw_reset()'s non-power- cycle path) before marking the card suspended. - Set/clear host->pm_flags |= MMC_PM_KEEP_POWER around the suspend/ resume, mirroring the SDIO convention, so host controller resume handlers can tell power was preserved and perform a soft resume sequence instead of assuming power was lost. - Dropped MMC_CAP2_NO_POWEROFF_SUSPEND and the no-mmc-poweroff- suspend DT property entirely. Reuse keep-power-in-suspend / MMC_PM_KEEP_POWER instead, per Krzysztof's point that the new property described the same contract as the existing one. _mmc_suspend() now checks host->pm_caps directly rather than pm_flags, since (e)MMC has no per-function driver to make the dynamic sdio_set_host_pm_flags()-style request SDIO uses. Changes in v3: - Reworked _mmc_suspend() to skip poweroff-notify/sleep/power-off entirely, not just SLEEP, per Ulf. - Renamed to MMC_CAP2_NO_POWEROFF_SUSPEND/no-mmc-poweroff-suspend. Changes in v2: - Replaced the card-level MMC_QUIRK_BROKEN_SLEEP quirk with a host capability, per Ulf. - Added Reported-by/Closes crediting Florian. drivers/mmc/core/mmc.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 05444ecf3909..dff4e372ecc6 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2157,6 +2157,35 @@ static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type) goto out; } + /* + * Keep the card powered across an actual suspend; shutdown, unbind + * and undervoltage still need the normal power-off path below, + * since they aren't guaranteed a subsequent _mmc_resume(). + * + * Check pm_caps, not pm_flags: unlike SDIO, (e)MMC has no + * per-function driver to request this via + * sdio_set_host_pm_flags(), so it's a fixed platform trait here. + * + * Set MMC_PM_KEEP_POWER in pm_flags so host controller drivers + * know card power was preserved during suspend and perform a + * soft resume sequence. + * + * Reset the host to its initial bus state like _mmc_hw_reset() + * does. + */ + if (pm_type == MMC_POWEROFF_SUSPEND && + (host->pm_caps & MMC_PM_KEEP_POWER)) { + host->pm_flags |= MMC_PM_KEEP_POWER; + if (!mmc_host_is_spi(host)) + err = mmc_deselect_cards(host); + if (!err) { + mmc_set_clock(host, host->f_init); + mmc_set_initial_state(host); + mmc_card_set_suspended(host->card); + } + goto out; + } + if (mmc_card_can_poweroff_notify(host->card) && mmc_host_can_poweroff_notify(host, pm_type)) err = mmc_poweroff_notify(host->card, notify_type); @@ -2220,6 +2249,7 @@ static int _mmc_resume(struct mmc_host *host) mmc_power_up(host, host->card->ocr); err = mmc_init_card(host, host->card->ocr, host->card); mmc_card_clr_suspended(host->card); + host->pm_flags &= ~MMC_PM_KEEP_POWER; out: mmc_release_host(host); -- 2.34.1