From patchwork Thu Mar 20 14:00:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024006 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 414C21D6DBF for ; Thu, 20 Mar 2025 14:00:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; cv=none; b=TordnJBKjVrghkwnEx1l1xiPhi96Ug6YKAF1/7iobsbyQlVJvrDK3LmmteSVXd+Q/dl+97LVtdMNhHCb0rYe6Z2u/0WciBzBhskttmAB85tfiOsd4BUrJfiFgtYmXHLPImfYHA7bL1Esgrxqf8DTzZooolys+HGviiF3Vh7NvNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; c=relaxed/simple; bh=j4UBzDHgk4sG7kqb/Znxr+FvEZ/5sfuewiW9AIFkVSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KljY6c+27ywPmwSqp/q7cZILCorkHnGi/71JlQxk4EzayB7z12QlyqiNjRIiSx3j7WMZylz7V/N+hjFSLgIc0ui7U6kn45nrZoGyeaZ+BeSF7ZapOMo5i5gJ2DcsAy8T2AXglFqrq0HBhnEHervHS9peG1qI6JQnCB3dP3t4sQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=NKAeFCP+; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="NKAeFCP+" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5439a6179a7so903976e87.1 for ; Thu, 20 Mar 2025 07:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479250; x=1743084050; 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; bh=c1plaKCpUseZn1Yu08x42hT09CM3UN2ZDD1b7XB7y9s=; b=NKAeFCP+tJ9jaqQlMdRR3APcTkkrZ99hA0tP5R5qtxhXeC4jt9eDkkl2pqQq0OGDMh aN/S9eJ+dzKpewWdQbaJEM2QB4jkSQBZIODAUhEp3pgrbdleSyLDkdTrAaersbQ0RTVj q57b5hdc9wfCRVjktN3OnYDVC1peOBL0RdD0TAxHK+fCJc/WhGkwu5mTsGiXKneA6DFI gyl16nK34SRjGjakXTzfnqWoudAhaLhfmPQs9FNkTgYSwNfFAf/dlFzUDjYCIMbPhkiC xQj1ZeFRuaYWbruVlDNmfgC/wiBfgo9yN4J0UP1q8zWizr9JZlUZ7ZJyi9sEh0KlVw7B Gktg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479250; x=1743084050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c1plaKCpUseZn1Yu08x42hT09CM3UN2ZDD1b7XB7y9s=; b=Y5eAnsiCLd5E4g6Plt4z3KXoqqiBTuv2x+vv9f5aeUzgkPkDfZSFIHh+dc0ovYucFX JKnzTokIYj3MZNEG9pxjLuUlZKbEz7YoTUZm3wtSDLOZxKUx182J4t4Xl+s5cdc4j1JP J7D/nR/2bZXKE16nf5zq16O5oafpHHNzK8ti6CMK0NGzPkDfsWwu/GivSP7pI3YL5UMl 0XodgwKMZpjNYcvAfeFTTwe6U3tPICMrPsi6Jkg732zY++wjb5ZM1FDXdKpUW1xhAZWG 9gWn4WEMdhc1lVeCNQoTynrIQh9lQd844RMfmnlXctmLpiOR22s0z1oDI0DGDT/kUSg4 LC6A== X-Forwarded-Encrypted: i=1; AJvYcCUiGoxRoSUz5OlEoXFMRGNEKsobSUgXk9OVb+PMGehHc9n0XMeCRoxoQGNxQkNfn36exTvVoQVFVvBjkvbHsF/xpw==@vger.kernel.org X-Gm-Message-State: AOJu0YyGAveIkmkfWwrbj4mBVRRI+baKm/YBlWkGceR3adMY5k+LkPqi MyzVp3IoRVcQ75bJf09Sfs4eBP57V9rH2VBIZLeUA+hyFOQb5FOSUm9kUbJLbzM= X-Gm-Gg: ASbGncvU4Mwif5T+NsJWbMjl7VBGic3g60zdgXI67U07tBD/lck9WRPnTiJX3B5HYpY 2JWB24wYN1fRMtNvjnQwSIHRpfb/Wk2T2Wr/NTuEKGoDNJLCkQH/KaYs2P/Qdxka0JCKXJc9ASe p5isJ6ZJBqYB6qr4ymxOfHdy7dCaMx4dbr3jLv0ysJbmB1L+cau/kK2q/6rjnaxccLpcT+PWuUM 3aKUQG4tGKBffiUthZWpnQqdsDH16fR4WBTTpM/6XUD73xUqmxEL8hTDv0UxP3QZAahUYJFw0Pj mYbqH9l6YhA7Dg1SRWbQtFcRFAZbGgbsSINdVIELG/ZRCJkUZLb8wQZ/mogs1+jHlwg8DfCC7tl ioONG3rhbstjHjUlbKv0= X-Google-Smtp-Source: AGHT+IGLDkayWqw+uQ+t5WY6cfFF97KDSfF4dlhtyKOD98B93BOTyBSUBT6MzlDFFxBRVZdolYijWg== X-Received: by 2002:a05:6512:304f:b0:549:6ae7:e679 with SMTP id 2adb3069b0e04-54acfa79c17mr1505467e87.3.1742479249732; Thu, 20 Mar 2025 07:00:49 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:49 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mmc: core: Convert mmc_can_poweroff_notify() into a bool Date: Thu, 20 Mar 2025 15:00:32 +0100 Message-ID: <20250320140040.162416-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's really a true/false value that matters, let's make it clear by returning a bool instead. Signed-off-by: Ulf Hansson Reviewed-by: Avri Altman --- drivers/mmc/core/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 1522fd2b517d..3424bc9e20c5 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2007,7 +2007,7 @@ static int mmc_sleep(struct mmc_host *host) return err; } -static int mmc_can_poweroff_notify(const struct mmc_card *card) +static bool mmc_can_poweroff_notify(const struct mmc_card *card) { return card && mmc_card_mmc(card) && From patchwork Thu Mar 20 14:00:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024008 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 EAA8C222596 for ; Thu, 20 Mar 2025 14:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; cv=none; b=a1hY5Poi6YbklSRpkjgwLBvLIkRkNmWKJeTIJ1abgMFzGUSeiFTclf04+1Bin8UCC2L2Mo8CfrXttm2bldxunWddLMnWT4d0DMUvEXvLxKOCAG7tEIFJy0ZKaORmvc+SA0qjQlWNjpButqQMsDcP5mJiklasbHS3dQBPys/9zJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; c=relaxed/simple; bh=VhD8Av3HSuJHTUiv2cdROzFQDA9TdxYn3udhBrPmLPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AUdb8fJ7TGgVIrSJzyifBYYQP8YO3W9kakOKSiXoqOXhpjByfNyUWCyHRbwPv7YBpc/FYUsXScgkPdf2ccZI55tMkG/z4KysYN9mxKfyAi5gIq052IRFfV8LUyosQR3mjx/3QsMetcJgaPIFlcjHX/ZUYMx4ONEiX7JLuarItsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=B1oLyqwG; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="B1oLyqwG" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-30bfc79ad97so19698301fa.1 for ; Thu, 20 Mar 2025 07:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479251; x=1743084051; 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; bh=RYAI2eqixUcWJERcq8+IYiHipQCgnbOCM34Jd7N+9HY=; b=B1oLyqwGqyT03rP0GFXC82s/cDUh4gdQlsUNZve/uzwAbLZJk2y/RLv6ITzPYDRx2M etIcDIxYMpHP57RLIZhziRzmc0pmXnh6xJxrEQ4wCJlOJWnuAOXjfRL8p/1D+XJZa07p jbhbMWdRoS3f085uzNlQ+MhdThzt76ct++dW81eKzTEJkSmvKIZ2CopIVy2M5RwgQUIM h3RHxuYwFMtB96hFhSI8hVSul1FnxSVF1LJLJP/K108g2vidlIeegvkzlKNBbiEqtybk 1JDdZblJdqSeS8IDdOU7cI3JSSFlb6avt5L5dvO7wxgKc2a9xlqvZZI4dYuHDkiPVtOW nWNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479251; x=1743084051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYAI2eqixUcWJERcq8+IYiHipQCgnbOCM34Jd7N+9HY=; b=tzzIApXSD9kG0qevISBKfogOPCfLnRCrVUOTuMXhdPlhxJSzwamabGibiaJQKwP77m j2dnz9czy+4/neZcHPlAZYPqkYF6b1fIjj9PlIuH+GYvwtUbO832Vz3pUaGo8tWu58yQ UhgozGNUUi9lYIqfBWhbSPJgYw/LtVw5D1GDMlyKjHBB//XdJ/KI0W947kO7Kx3baD5u Ix2L6MelodhFMD6GNS16tnrXarVsKAjcxVA35QWTiLwGRYX047J4hRoek9o1SKGrBbcO 93XyE6eepsVM2EkMnYEk2V742dayzePIc9ZjYV+7Nak06K+t+ut0pmtz0FlsQ0TrXPKo dDPA== X-Forwarded-Encrypted: i=1; AJvYcCVuTLm8BVFeSA+WWUY6BE+3VgPZY6eECj5jjD8SmdFsch7ejQlhL923TKe32V/gGJkdkTHaI2+l2mX/jPexyMjiNw==@vger.kernel.org X-Gm-Message-State: AOJu0YwK+/p3uBBc8V25NxXbgQ41ccsCSjlKZniCfzLqBOcGoQ3TYs5X UVTZOk0Vd4d5xYo71EDPeKe5hm9zHjYb6+D7yqR5lzpBksbAwAcWjec1nlBPhwk= X-Gm-Gg: ASbGncsedA5ivraqlvMSL/ZDbyfA/dj50jCNDeIvvskD3/qlI7rBTnSHqVf/LPUxYHm 5zxbztoN/2av+uH996hv/OGQ6vXBDI+5jHNKE3ugbxrwI40IqkzURspk/FlKD5mBbEwP6LRM529 cKcbznZ+xLiKOIwjedsyT7pwOa0nhlfnDL1/EYHV0uVdhkGnWmpiHOgCA2onnWKPFTm/S0LsASt TWsbicfktaErM8owhKuzEMV+bnxU0i1qyzgmJDMPtEIKhAPV9haXEySiUfgJZ/yb5Ix1XcWD1uY SeDmOgZPOYK4RzaqP3apOEvnjpJl6zktmJL4KHFq/H1cqLqchVx4kGryhjPjJPKRieCwugHIetv YGtWy8Cy2vMXajAqdj5M= X-Google-Smtp-Source: AGHT+IE6l4M0DQlQYZg4ALvU5yllXDeu5+WFY7sQJFtppyPs0t//66RIGxg0FcrWHeDey/P2LeUHtw== X-Received: by 2002:a05:6512:39d6:b0:549:6309:2b9d with SMTP id 2adb3069b0e04-54acfaa1caamr1050147e87.13.1742479250703; Thu, 20 Mar 2025 07:00:50 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:50 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mmc: core: Further avoid re-storing power to the eMMC before a shutdown Date: Thu, 20 Mar 2025 15:00:33 +0100 Message-ID: <20250320140040.162416-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To manage a graceful power-off of the eMMC card during platform shutdown, the preferred option is to use the poweroff-notification command. Due to an earlier suspend request the eMMC may already have been properly powered-off, hence we are sometimes leaving the eMMC in its current state. However, in one case when the host has MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND set we may unnecessarily restore the power to the eMMC, let's avoid this. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 3424bc9e20c5..400dd0449fec 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2014,6 +2014,18 @@ static bool mmc_can_poweroff_notify(const struct mmc_card *card) (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); } +static bool mmc_may_poweroff_notify(const struct mmc_host *host, + bool is_suspend) +{ + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) + return true; + + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && is_suspend) + return true; + + return !is_suspend; +} + static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) { unsigned int timeout = card->ext_csd.generic_cmd6_time; @@ -2124,8 +2136,7 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend) goto out; if (mmc_can_poweroff_notify(host->card) && - ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend || - (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND))) + mmc_may_poweroff_notify(host, is_suspend)) err = mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err = mmc_sleep(host); @@ -2191,7 +2202,7 @@ static int mmc_shutdown(struct mmc_host *host) * before we can shutdown it properly. */ if (mmc_can_poweroff_notify(host->card) && - !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE)) + !mmc_may_poweroff_notify(host, true)) err = _mmc_resume(host); if (!err) From patchwork Thu Mar 20 14:00:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024009 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 DA3C1224233 for ; Thu, 20 Mar 2025 14:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479257; cv=none; b=GenZ3nlrKOaAUISa/naFMBi5nU4EX8mbJ3H9K5qU/P5zs3y6i6rChUPNSgf0PxxROMu0qXZ7CNXF9bNuDi2Q12mV564duGZaN9rWFlhlIUEx3AyRVROc5aJ4bNpnCOXR0qOqZDtVo47UnNWK/KDqWw+fwwz8KGPSyRYM40x4g2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479257; c=relaxed/simple; bh=FLnJitILWx+gEhi0WoDSNfEnTW8g3N+Au1bp1k7MfuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XWlKnMn1Nj8I/PpbYd+wBKuK1Et/v00uSG6nPO5RQaetOtwz2w3qhNg9zuLhynTVYCJdU8mGV6FnhGOH+ioZsjBQ2KpT1OB0Bfr4LweDBqhdZPwFF4s3XSXIZWwc2hj2wGlxU/ReklSyBC8Gof50AStvOxNulNPIsUmzMk8o8FU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=HguNeC+5; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HguNeC+5" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-549b12ad16eso938307e87.0 for ; Thu, 20 Mar 2025 07:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479253; x=1743084053; 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; bh=JRcl21cexCWaRdVFTtOPv6NXKn2Krk/8VDxch080WVM=; b=HguNeC+5Asj8t7W5EQxp1P0Mdk38xtl486pVZ9ifvZMHfudMi0mhDGqRB/t8NUmkAp sg5epSaSWeY5vAl8uahHBCtAQt61C6Xf702+FxlWQjT7jDlCGH+hZDj8RWtzKpG15nuT HNF/689VhAfbmErOb/5EwIYFs4u6mwisVo2kvbzgnISS/HbAwUa61jDfNOfq3attw0E+ MHcP1KDV+QLVMdRisNRftG8skh+DEXHKShUZJ6T6B95Dhmuqb0/utVc5MRrlvNiR9Q1F sGqhRIeiauB6tFC+IzAOCWB5dZUCSuDcV8K3Dovtrc2ishCUHYTqVMlvfphFPcn4s5Gy O/Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479253; x=1743084053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JRcl21cexCWaRdVFTtOPv6NXKn2Krk/8VDxch080WVM=; b=bFZ9BZ53eG2RcQsrMOWCpsesFbmIeO2GDoBpeBSKOFDNiQFsGm6jfm0t/3wHra3wV/ lZCAX+h3xFpuB5F9Ha5aTQVR2zmcU2tBJyZIeXPg2uEipBpsdZ5QclWnl2nP18X87Dst FvH9O0HdJRzPmTlNTUVNkSBufQDM9nT5tfB/L+hCtPqU4xRwDzy4I+HW5wDZDpXS/cR+ Mxs0EHjUq9PLtW6EFsRqqy+0UyUphCN1TjIJHYWnlaO865YhWyxuH7Yh9p8s8S9L3l0A NwlHo1ZOrT4wQsBUp4CaruuBtoQlisWE8Ga9/wQ24K/cOR9Me1GGFXaOTfpu5WjdF/lV CzTQ== X-Forwarded-Encrypted: i=1; AJvYcCVUyPYDadiO8M43aTOftyRrfmPgA7fzJjstCYaVErX6FqYeIWXcPSiR8x1i4MZoMdJQe0sed8mzB5uFcp0rzh57GA==@vger.kernel.org X-Gm-Message-State: AOJu0Ywlp2YZrHzFNVe2N1433FddakO1iIEP9totTHYIhGa1VuNDr04Q ZoS6TX8XzVuCrRxKbHXw88MuMZ5UE3ii3zo382aBuvphiE6/j0XlrqXicVwOWkc= X-Gm-Gg: ASbGncumz1J9qQtjz1DA5pnQ17xGYvBoG6zRvhnwV1/dTqmURlTRzR9RU4eUJjmskIx 0ZbRn9nWre+WWKpD1hVADTWiYKFkeH/GFS8tHwHlI7bZJ0iXhVXyuMVytoju5MTrlP7aNhB8GWc MEJAnZDC/g5E0P6xLiRO7qzab5wrOOL7V5iyOpEsOglnl3QbN1ouy/5zW4VtUYq0a+3SN7OGWrL V41di+WQ4tiqXxrAQsybOqc2GsftwFIBr9N1NPmn31kIOapQGQgllIp9K/LJMAiFLs8KKqgRzYD 69k6iexRSFg/nq3qi1LcYP4/PIk5mSSMk/y56uR6zKl5tL48I+sm8+Z8G7FlZiK0Y2s2oDxMIfY cSVh5TeKHanjmlogBygY= X-Google-Smtp-Source: AGHT+IHc1LVnOgavvev5XnkpmYMq0e6WzcUCiI3zOA5mhol2kloudBiNfkN+fIfm+6kKRlyIRy6cnQ== X-Received: by 2002:a05:6512:2255:b0:549:4416:df02 with SMTP id 2adb3069b0e04-54ad0678646mr1146949e87.41.1742479252674; Thu, 20 Mar 2025 07:00:52 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:51 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] mmc: core: Convert into an enum for the poweroff-type for eMMC Date: Thu, 20 Mar 2025 15:00:34 +0100 Message-ID: <20250320140040.162416-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently we are only distinguishing between the suspend and the shutdown scenarios, which make a bool sufficient as in-parameter to the various PM functions for eMMC. However, to prepare for adding support for another scenario in a subsequent change, let's convert into using an enum. Suggested-by: Wolfram Sang Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 400dd0449fec..60af88ac0213 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -33,6 +33,11 @@ #define MIN_CACHE_EN_TIMEOUT_MS 1600 #define CACHE_FLUSH_TIMEOUT_MS 30000 /* 30s */ +enum mmc_poweroff_type { + MMC_POWEROFF_SUSPEND, + MMC_POWEROFF_SHUTDOWN, +}; + static const unsigned int tran_exp[] = { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 @@ -2015,15 +2020,16 @@ static bool mmc_can_poweroff_notify(const struct mmc_card *card) } static bool mmc_may_poweroff_notify(const struct mmc_host *host, - bool is_suspend) + enum mmc_poweroff_type pm_type) { if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) return true; - if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && is_suspend) + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && + pm_type == MMC_POWEROFF_SUSPEND) return true; - return !is_suspend; + return pm_type == MMC_POWEROFF_SHUTDOWN; } static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) @@ -2120,11 +2126,13 @@ static int _mmc_flush_cache(struct mmc_host *host) return err; } -static int _mmc_suspend(struct mmc_host *host, bool is_suspend) +static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type) { + unsigned int notify_type = EXT_CSD_POWER_OFF_SHORT; int err = 0; - unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT : - EXT_CSD_POWER_OFF_LONG; + + if (pm_type == MMC_POWEROFF_SHUTDOWN) + notify_type = EXT_CSD_POWER_OFF_LONG; mmc_claim_host(host); @@ -2136,7 +2144,7 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend) goto out; if (mmc_can_poweroff_notify(host->card) && - mmc_may_poweroff_notify(host, is_suspend)) + mmc_may_poweroff_notify(host, pm_type)) err = mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err = mmc_sleep(host); @@ -2159,7 +2167,7 @@ static int mmc_suspend(struct mmc_host *host) { int err; - err = _mmc_suspend(host, true); + err = _mmc_suspend(host, MMC_POWEROFF_SUSPEND); if (!err) { pm_runtime_disable(&host->card->dev); pm_runtime_set_suspended(&host->card->dev); @@ -2202,11 +2210,11 @@ static int mmc_shutdown(struct mmc_host *host) * before we can shutdown it properly. */ if (mmc_can_poweroff_notify(host->card) && - !mmc_may_poweroff_notify(host, true)) + !mmc_may_poweroff_notify(host, MMC_POWEROFF_SUSPEND)) err = _mmc_resume(host); if (!err) - err = _mmc_suspend(host, false); + err = _mmc_suspend(host, MMC_POWEROFF_SHUTDOWN); return err; } @@ -2230,7 +2238,7 @@ static int mmc_runtime_suspend(struct mmc_host *host) if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) return 0; - err = _mmc_suspend(host, true); + err = _mmc_suspend(host, MMC_POWEROFF_SUSPEND); if (err) pr_err("%s: error %d doing aggressive suspend\n", mmc_hostname(host), err); From patchwork Thu Mar 20 14:00:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024010 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 4DA752253F8 for ; Thu, 20 Mar 2025 14:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479260; cv=none; b=NjtBJ2NnAohtBvR+HMhp3jEasVHT1NPsU8rLJhjUgGESV/MMNxwsYEAiK5N1wIbqMnOwht6MuoNqPL6mRYCWfUuu7Ojj0Mrl150WB1w4EQ5IFbM1HMdLuN6uxo2vFaMc6B7/oK6V6jcnXdq9PNsVUvWVNsbzRrCQSO7vVtYT8HY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479260; c=relaxed/simple; bh=5q7KCE9db7ERhm5lr7U4Yg37JmaxdnTD/f+2sXkyzxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZmVfsbfQ0ewgFwEiS2RLwZtcp2VyCnL/foSN81pr6qPqKOCT9zRzBmrwM4byV+wj2sn3YE/vm+2yeA1LIpuhnt4WZ1P5uRIb6m2VgJdDBscO1x0IA6NrVuMtmltWvhPBeWZo5NS9JSSZTXgk8hQB7F5aDzgJWXjaO2poyHGOKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=xiTQvwwU; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xiTQvwwU" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-543e4bbcd86so976376e87.1 for ; Thu, 20 Mar 2025 07:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479256; x=1743084056; 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; bh=rXE9dlseC0dhD7d4oX2r9ZUURR/ikgG5O0SCUhzKJLQ=; b=xiTQvwwUQMwy2rT+pjfqAWF6BwGiO35f3I4+17xJhhQRNv9pdDy/0/tTguJ2Cpd0c8 CJ+SBoG56JHPylJmxEX6nXspuwd98YAs2wzXaGSVeuJQ5BVSrymVnYYvVJpbPe0D+IKf 0lWWwnz0i8IlN5C9Z0umiA5mTxsmr8J0DBphm4fMb43o+DIxFlWp8gG5HbC2ulxzlUdq wmAjL5V2BWkJ66WfXdc4H2NSxvyVU+mZLYU68j8kREDg+uUKrGCizsy1JUupUnp+IyId qUh5OKBXbA/o0t8XoUKyggFwTtDi4sFzoTm7F+6NgQ+3TCy2Yv3gFT7x+X+djZ1JhIKH uA+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479256; x=1743084056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rXE9dlseC0dhD7d4oX2r9ZUURR/ikgG5O0SCUhzKJLQ=; b=G2FNGy3fhVrhTKQq7Mt2P+CenEiWJqbIUfgsPYlHnpLNMEdpu13onQgEDiWXgcG9Fo WBHTmEVz4WXpqh51cDibxSeoOADSTrzVLZ7oQLUqkt1QbHqEqL8cQpVmQE+u1lMqiZnJ FCuIMxJCZYAhbp4zr0iv+6gOMu0qE20HO7bk8qNyNwHH/zB/CQ6WIDglaihGDU8WeuNb tI0j7V7zmNfwrMJ3wVycyyEo6SA4f3TCmhQClpcoO96h2/p+RcRuUOqhlhQMMMe2KL8N dir+EJrTbic8+Lc5rBYzr5XubiAr6mzdQ+yj1b4hbGkrGwf+EycLbiZCxiAjNPcf2dt+ 1V+g== X-Forwarded-Encrypted: i=1; AJvYcCVKEQEEqjUo3FHbH9pD/V9J2VLcV0frM0Droe6mh3MdfhcT/bgX+/lNEKabQU/LO6hfzfNV0L8KgW+zpV7EDhaG2Q==@vger.kernel.org X-Gm-Message-State: AOJu0Yw8w6rqxDQh2KbAtl5up4mjG8+FoYbb/5ZVIPmmQ+K/kT2utgHi CJOtJC+zcij3DEXcHONW/KAr999Lbt6B6CiMsbuLd3KSeZx+HUA6bqfXi51WQ5k= X-Gm-Gg: ASbGncv/+tgWfUcIqnYm2098Or3zlQwMdNUN7srsggMzTSAxQYPFG6zcppxw2vrDi2z ObrUxti+SKRnrpfvhKgZVnFBrftKPYAb35vHQ57J3tRYm+32gVLYeug/1oxm70t9/imlBbGwm0L V/JjoJ1Q1waPFmfmiVIO6ZJnt1jFG+lo/3EbmBTe7gitAXHsHg/NnZcTcV25vp/zr8SDl9SvXRm RwW8Vq9XjIDruSuUWlUYRuOqw/o9zJjqIWZmJnRa2UFSThG17fHFv9pDs2j1jn6w7wapPGFu8qp 4UewGHjPyggBBwkLR7qSY4LfV0TipT75+IFXawj0QNg9LwEwbTNzyjlyzdGlLn/rM4GMOvPUDly A+CV8lXML9thlGSnJGUOVTOLpN1vLSw== X-Google-Smtp-Source: AGHT+IHyRLgkNoCEkf9M1ICxzrsASm6on3//oo9APTxgLDD9aYJ0CrJh/ehpG879EGIFtCHQch+O4A== X-Received: by 2002:a05:6512:b99:b0:54a:cc04:ea24 with SMTP id 2adb3069b0e04-54ad068688cmr1116238e87.46.1742479254697; Thu, 20 Mar 2025 07:00:54 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:54 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mmc: core: Add support for graceful host removal for eMMC Date: Thu, 20 Mar 2025 15:00:35 +0100 Message-ID: <20250320140040.162416-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 An mmc host driver may allow to unbind from its corresponding host device. If an eMMC card is attached to the host, the mmc core will just try to cut the power for it, without obeying to the eMMC spec. Potentially this may damage the card and it may also prevent us from successfully doing a re-initialization of it, which would typically happen if/when we try to re-bind the mmc host driver. To fix these problems, let's implement a graceful power-down of the card at host removal. Reported-by: Wolfram Sang Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 60af88ac0213..5a62a3d3df32 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -36,6 +36,7 @@ enum mmc_poweroff_type { MMC_POWEROFF_SUSPEND, MMC_POWEROFF_SHUTDOWN, + MMC_POWEROFF_UNBIND, }; static const unsigned int tran_exp[] = { @@ -2054,15 +2055,6 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) return err; } -/* - * Host is being removed. Free up the current card. - */ -static void mmc_remove(struct mmc_host *host) -{ - mmc_remove_card(host->card); - host->card = NULL; -} - /* * Card detection - card is alive. */ @@ -2088,7 +2080,8 @@ static void mmc_detect(struct mmc_host *host) mmc_put_card(host->card, NULL); if (err) { - mmc_remove(host); + mmc_remove_card(host->card); + host->card = NULL; mmc_claim_host(host); mmc_detach_bus(host); @@ -2160,6 +2153,20 @@ static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type) return err; } +/* + * Host is being removed. Free up the current card and do a graceful power-off. + */ +static void mmc_remove(struct mmc_host *host) +{ + get_device(&host->card->dev); + mmc_remove_card(host->card); + + _mmc_suspend(host, MMC_POWEROFF_UNBIND); + + put_device(&host->card->dev); + host->card = NULL; +} + /* * Suspend callback */ From patchwork Thu Mar 20 14:00:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024011 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 0E53E2222A5 for ; Thu, 20 Mar 2025 14:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479261; cv=none; b=YuF/7f0aPA4hwSLj8rwzjihHibeTAMeG38aliJ6b6wsreG+bUCMHvTGk312uP9LAqHGTiXmXbijq0Ht7OAbmOpDTeojCZyK+GXVj73mJZd8xwRPh1axrdJEQuYIht2PGsVyI73p+ptNaqe3rcy81KuNXLmlvqPkLTP6rzSD5tvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479261; c=relaxed/simple; bh=tJcpx7kVoOVh62Qzq7CsqXZyteSS2xTmfx3MklEEb5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qbcxnb7N4bJwSxpNZdEy+kLnkuom9g8F1cGzhwbw3B//NW0h1hMNcyO8AhUGkd5J0bq3bHU2OVRHUauCBBlRwQY7ryM1DTgs7Un5alr/PuA5KUzNIMsC8ylvOq4mrnPeGsz9wJCW818gDTXWvEOY5J7OdPG0wKwC3FegdLXcaAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ovGwlYVK; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ovGwlYVK" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-54acc04516cso1026439e87.1 for ; Thu, 20 Mar 2025 07:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479257; x=1743084057; 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; bh=+cpurPguaZZPLjWUcw85lV4P2hxnhe8DmTCMrQ+sP8E=; b=ovGwlYVK5p5MCyM7n0n+8jzkYo3MDkQnvXTmQoBhq/Fjh5q1C8rjW8+ORWSc16MwdC bfG2H8MJeRj1WXehec8O2cCg/yKJGsAJG6c2aSvvVjDVuAuWKHkNW7bKFLr9cHUW0cXS OFIplJZpUJGcrZxpKZNOArUOjXFd8NcXyA4RNcOAfcjx8NcRArND8/CBRZlhB1k95wck vEdwWTfLJR+uvJDNLiE6CdoXE4l9g9eBPfyoAzQh3ixQMw+V/7yzpV/DFJYm0fpcpumN VvgkXx0rWCMtS6OCHQNWYM/7W048E8KX3lh+NXGxFqOEo6zAlH1+MZ/FuRNcD7rRE4IC x7Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479257; x=1743084057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+cpurPguaZZPLjWUcw85lV4P2hxnhe8DmTCMrQ+sP8E=; b=QYKZZPwFUhuS2DoKR8yNtMqUSsHyPUk+vwrdYSBbIdPl/iGTHuqhyBVOxxeYKjoyPr o5JgKaKBw/7Twh9XDGbx2T6oGSgvsJadY7K6SdOvPgzTrOVz+b1vQbGdoxJQk0uE0BXe EDyeVm4juYoIQxOefufuwzg9a2lCImwVUUMS70mEDQA2Pkjm9h0yNQCLVHYTvE9BCmWu G+TLTFgUwyfF2O54PAtz8GOH9gfa1TRZRK4LQ2KF8Dl22lPQ+gAaA9URmb8bUazJ0fyi Ny7+HHgyj9M9SVTcPc99rjVcfl5gR5ApI242yWg4F7M8lMimLurxUB0fcX4Iv1W3/ges GwvA== X-Forwarded-Encrypted: i=1; AJvYcCWEYTxGkrN7Mfwy7LyzfSpI4QCnJx+qpNK0MeeoTYT54A9pf0D9GzR2fqQZ1KjquG7PmFusS7Dp/2WBbEE0RKYfQg==@vger.kernel.org X-Gm-Message-State: AOJu0YyKmZYHJmtAeerZ1++iTVN0DXzeGK73Oh1YIEX+wKuUqMUJkAFn qiNt9v35SChZ9c0wnkZQzf4NzCoBXJFx9XfwoiUsYYKkukX6iPr/YTIZJmSk3UY= X-Gm-Gg: ASbGnctD5OHkr03cuJShZzHjQtMT2J8jdxgllz1UGtO0NP1ZGvMQgDGe6EtfQbn340M iwDjlH83TVLxvVX2LUSLTiN7yOaGK1HLiEymOzTlbzb+XsgfR2vOTWonZ/6zJc+db+r4E8ImI0M wT2AELbC7ox13ej8YzDdgNsmSEV9yLigG62vOXVx9mkOS8divER3PGCqbXTSHGmqdLT/mR6pEPv hm6KM8w3Ds5JcRRVkeFztbbbYF3dmVERX3VH/TL4+h7Q8wI3ifgKtq7A8ixaYg23UJ6e8s7/12O 0oq2dcpd3pXbgyRTubIuGoQM/+L1ClPAgIMr4IwgWqBZxrNhM/tccMWgK6cVkkARFl+O5xy9TqN +tFubh1PX3K4MWqD1U06akcZA6/gPfA== X-Google-Smtp-Source: AGHT+IFI1fZrjfRWED8P3YwlNenPg/UaJprkHPw65/8Gv1KQD06yFcLy7lNo8+Ww7atrOreTQU9wBQ== X-Received: by 2002:a05:6512:400c:b0:549:9078:dd46 with SMTP id 2adb3069b0e04-54acb21a517mr2932004e87.43.1742479256977; Thu, 20 Mar 2025 07:00:56 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:56 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mmc: core: Add support for graceful host removal for SD Date: Thu, 20 Mar 2025 15:00:36 +0100 Message-ID: <20250320140040.162416-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 An mmc host driver may allow to unbind from its corresponding host device. If an SD card is attached to the host, the mmc core will just try to cut the power for it, without obeying to the SD spec that potentially may damage the card. Let's fix this problem by implementing a graceful power-down of the card at host removal. Signed-off-by: Ulf Hansson --- drivers/mmc/core/sd.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 8eba697d3d86..cb4254a43f85 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1596,15 +1596,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, return err; } -/* - * Host is being removed. Free up the current card. - */ -static void mmc_sd_remove(struct mmc_host *host) -{ - mmc_remove_card(host->card); - host->card = NULL; -} - /* * Card detection - card is alive. */ @@ -1630,7 +1621,8 @@ static void mmc_sd_detect(struct mmc_host *host) mmc_put_card(host->card, NULL); if (err) { - mmc_sd_remove(host); + mmc_remove_card(host->card); + host->card = NULL; mmc_claim_host(host); mmc_detach_bus(host); @@ -1730,6 +1722,19 @@ static int _mmc_sd_suspend(struct mmc_host *host) return err; } +/* + * Host is being removed. Free up the current card and do a graceful power-off. + */ +static void mmc_sd_remove(struct mmc_host *host) +{ + get_device(&host->card->dev); + mmc_remove_card(host->card); + + _mmc_sd_suspend(host); + + put_device(&host->card->dev); + host->card = NULL; +} /* * Callback for suspend */