From nobody Wed Dec 17 03:04:19 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 740B9205E15 for ; Fri, 21 Feb 2025 09:39:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740130771; cv=none; b=VbUDzfSw5wuzTJD+BLKZEVsQ8TmaJ3qcfUYyYyU9AoKVEMqU+mPWFE3mS394H55gWZZ3WtKO5ca4S1bN/nEqAs8yh0q6EOYrQdCA6K2nAKVqyJjyErTkG1DxaNwEgW5sn2JI6Cix8HOW4exoFB5chvTwIUY3B0hd8WctQJrFEOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740130771; c=relaxed/simple; bh=xXysUgnWUb03Ymxd112UPtaKGIb6V9So/mjGhcDZ7TQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jx7lh6cLYNEs2VELZpHaJvyZIIjLgW2KYCiWM1xxn55G40YIkFTkBj9SHzxdI9x3FYvgDajRXBWmxPrtybjkTAk1sVf/56cPBt9KlB3a/m0I756gBWRQcfy6Spi32D8/BoUGfbb0Ea8obw0S3UuU4pqa4CTekoBnQn6DiIiBkdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tlPV9-0001zV-QE; Fri, 21 Feb 2025 10:39:19 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tlPV9-0024uv-1K; Fri, 21 Feb 2025 10:39:19 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tlPV9-00GXbk-17; Fri, 21 Feb 2025 10:39:19 +0100 From: Oleksij Rempel To: Ulf Hansson Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, Greg Kroah-Hartman , Mark Brown , "Rafael J. Wysocki" , =?UTF-8?q?S=C3=B8ren=20Andersen?= , Christian Loehle Subject: [PATCH v3 3/6] mmc: core: refactor _mmc_suspend() for undervoltage handling Date: Fri, 21 Feb 2025 10:39:15 +0100 Message-Id: <20250221093918.3942378-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250221093918.3942378-1-o.rempel@pengutronix.de> References: <20250221093918.3942378-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce an is_undervoltage parameter to _mmc_suspend() to apply a short power-off sequence and optionally flush the cache. This refactoring prepares for undervoltage support in a follow-up patch. Signed-off-by: Oleksij Rempel --- changes v3: - add comments - make sure _mmc_flush_cache is not executed in the undervoltage case --- drivers/mmc/core/mmc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 6a23be214543..9270bde445ad 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2104,20 +2104,32 @@ static int _mmc_flush_cache(struct mmc_host *host) return err; } =20 -static int _mmc_suspend(struct mmc_host *host, bool is_suspend) +static int _mmc_suspend(struct mmc_host *host, bool is_suspend, + bool is_undervoltage) { + unsigned int notify_type; int err =3D 0; - unsigned int notify_type =3D is_suspend ? EXT_CSD_POWER_OFF_SHORT : - EXT_CSD_POWER_OFF_LONG; + + /* In case of undervoltage, we don't have much time, so use short. */ + if (is_undervoltage || is_suspend) + notify_type =3D EXT_CSD_POWER_OFF_SHORT; + else + notify_type =3D EXT_CSD_POWER_OFF_LONG; =20 mmc_claim_host(host); =20 if (mmc_card_suspended(host->card)) goto out; =20 - err =3D _mmc_flush_cache(host); - if (err) - goto out; + /* + * For the undervoltage case, we care more about device integrity. + * Avoid cache flush and notify the device to power off quickly. + */ + if (!is_undervoltage) { + err =3D _mmc_flush_cache(host); + if (err) + goto out; + } =20 if (mmc_can_poweroff_notify(host->card) && ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend || @@ -2144,7 +2156,7 @@ static int mmc_suspend(struct mmc_host *host) { int err; =20 - err =3D _mmc_suspend(host, true); + err =3D _mmc_suspend(host, true, false); if (!err) { pm_runtime_disable(&host->card->dev); pm_runtime_set_suspended(&host->card->dev); @@ -2191,7 +2203,7 @@ static int mmc_shutdown(struct mmc_host *host) err =3D _mmc_resume(host); =20 if (!err) - err =3D _mmc_suspend(host, false); + err =3D _mmc_suspend(host, false, false); =20 return err; } @@ -2215,7 +2227,7 @@ static int mmc_runtime_suspend(struct mmc_host *host) if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) return 0; =20 - err =3D _mmc_suspend(host, true); + err =3D _mmc_suspend(host, true, false); if (err) pr_err("%s: error %d doing aggressive suspend\n", mmc_hostname(host), err); --=20 2.39.5