From nobody Wed Dec 17 08:53:01 2025 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 0F089222595 for ; Thu, 20 Mar 2025 14:00:54 +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=1742479256; cv=none; b=oJrlbIWvfQtsml6GEqOJLOP+QmiEFiNIL8LqCoCF8MzWsjyKi1bg5b0BjRGncKqUM7hdo9aBwFu98TFjHX5IEPQEocGUAthOHEDy8UC5hY+/+/5qHkTWhTYuUfdQbVdIC3Vq+Q+6LKSOVW7e8nQUqVsNtfuBN1TJRVaXfUZKo/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479256; c=relaxed/simple; bh=j4UBzDHgk4sG7kqb/Znxr+FvEZ/5sfuewiW9AIFkVSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kpLvbUZkO5MxhkYuwFGV1c4etDqS4jeISMTe54cIRZAjDQePpASrgHIQio219SvjW8K6mQWMCpQTL/x2BAmStpdg91r/RRo2R9DL7J4agnAo8WhA/bi8ujhb2EmIJmiM+708cyY0lEYAj7J503T4EtftqEmU1EOHfsJag+qqZJc= 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=cQKm0sLe; 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="cQKm0sLe" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5439a6179a7so904047e87.1 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=c1plaKCpUseZn1Yu08x42hT09CM3UN2ZDD1b7XB7y9s=; b=cQKm0sLeTjuwdlVVvYLjN9asI7wj2qtKjMsKwagbLBhQsuKFjOROR4CefAp/TMN9KL BU9SMUv3CmjzGVxwiwG1ikgSm1FlU2axBS0yT7smPmWGRTjH2EL2G8hJHcvIW5L2iWtB ue7WqJ2vAnZYF/VI7N3A339gVTUkTB5GgGJAk5TISCuAz9NoK2hz4cPJHy+A4UrLGgtJ KHZ63nhfwmUoTVTIqiktk08sZZ8UPbSS3vaLaYlbPx67YtARPqe/f1eu+qEm3RZE3N3+ XpJGI4IIqBGAZuJlhJm2FAjqNeoQqogsaGXckcI8eiB30ztKRhPhGVz/UoAfG6ljdXQx 9p0A== 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=c1plaKCpUseZn1Yu08x42hT09CM3UN2ZDD1b7XB7y9s=; b=b2iVTRlSSYr3h1lc6Rb1N3B7Z6IwO9byAPFJvcJiu+R6SbyhChxfwAldlvDuuNhm6C +F7rmG7J51JboXPpxcmyb1kDWc82lPJRBzBQ5Upz5hq/tjwGM2j9y6ugTZul1apF/EQ3 xsLG7i6koTrOROgI6iAYZjJFewxv35u9DDqWW+Q1WJp3aQkWXQdivF+v75mIZ49M+TMa eXGWLHVTq2xG81IWVzAJokbrLQPnyntAGJCpfbP2iwkokq7ENS7aTcTLZ/aLBweMMbSD D4flRmEIRwhgD8UieZkWTKuR/oMvqPTWugZPe5Kd7Ml8+Q8uuLVdT7Y2DVjBWne0A9io qohA== X-Forwarded-Encrypted: i=1; AJvYcCXKbCLQn0G/8rsTJAdy63oKHg9Y77hL7P9WGN/QYJijqfJnqGcIrrF2QcygCnhribNx0u+rKFa7RfotbiE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2xJtOXnoTWrXVgUNmY2RWBuN5S1s1HcV67atAuEsHZHMIkqyL japQCVkuxzaT9SoW7lHNzY++PAdul6uV3zpWnDX3gm9RA0GoW4lugIz0HSrSRRw= X-Gm-Gg: ASbGncvRtCkejwQKaIfknUdUBdxMzk0b+7S+5joqE69RQONrTTVs2cx7AJDa9IhJ8g9 8MBJeXwRxhJ7RBdIclQrqEUlBNvgNa/U9DuxacTkRew5KYYNNobJPTTsgABLZm3zoyQqclcTo0c OMcEaHHeC2x+GMUKqumOxpGG51LC8aqJo6GBjHtAFFUre8MmeVrs1MaTqkWRRLnyArf6mraDwax qJJ37OIdEuoB+poKFIaQKfE81d3HFS/t4O3VQ/StvTmqsvy25i/VgmeekzcmZPRDqNXN4xS6UU1 xeS36MqeEg+LFYYU3a5PWc7JJ5hHBTxACUg7rohOwRPDS5xEaz8vyXAf/nh6lAo9I8JWbMbXgq6 zN7ymuViPCQ0V+m9TgjA= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Wolfram Sang Tested-by: Wolfram Sang --- 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; } =20 -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) && --=20 2.43.0 From nobody Wed Dec 17 08:53:01 2025 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 DC55A1A287E for ; Thu, 20 Mar 2025 14:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; cv=none; b=j0i6HsuC6K6Rzrb6vsZmM3GE2r5udrLXws4gNZBlH65vPgQYjhe+Lz++pnHq9mbTJw9Hh56A18UgkhVEZAhzx8HcbhvVP09o5ZMCwkfy2Llo10IiUuWm4InAkpR3INVh8XPRrnDB9NWstO6iSVJjDYBXxXEM1+6NX0lpS719GAU= 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.178 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-f178.google.com with SMTP id 38308e7fff4ca-30bee278c2aso21614001fa.0 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=gTXeVaqd7eJdobkl1+ggwfkHBC54fbsYdCd6DJtE6fhbRLztlRSFhAjPJx/UWVu+MV latP3ArjPFe9JxqxjNB3p7ZUw8tHhQNPrkTfXWmVZBDZ+KbI5ZqIJZa/TY+ceNyQjwkX joOeKoYoBPiOlX++E63RLMkBfR9v4XSTzW8YjA6CJ26jTpycDqcHIlM3avFW+wlPM6fb vaxrGySHgc42iUcCx5j4/d36LShjN34CsDAffBswCizbt4VwWOXnJYran/qbzjffC46S D0bCk1xDoQn5NEnwR5duLTpVMI7Vwlg9pLVOTkj9iUeF+yIyTwtSnVst5riCu+qXQ6JX 9z4g== X-Forwarded-Encrypted: i=1; AJvYcCWXJJMDzwX/6tKk86BpvlcJusw0RBayn3wXHmT0Oo43//jfoxNx/g+HzY2pOWVOe6x5KxI+9MvQ8+OWv6U=@vger.kernel.org X-Gm-Message-State: AOJu0YwpF3qlV05xqjQ+C46cZKGK5zmvRBqDz9XMLoiBXkpwJyhWr3+o IA8HtrmslNhAONYWXPE0Nq5nOc4V6za/tm3bCSLcuE5bDkXgOxBM1oFcGDtLJiI= X-Gm-Gg: ASbGncunc3E7XgcKbB9mocyQQFwPTZJVxLpyPzu4K9ZeVJTaxnLmL0tJdtOHeuxXAzJ gvhD3ERGZRCOHSjJlo3KHJOSEDqJA6TXEhfWmH40TN6t2EKQOd5mjhAwEbWWHavKZL6aqXpMemY tTSMvyzMemIrzJQOi27S9EJVwt6YcS+s4E2Epk7k3KSEIgGYpb4BrjPTZGvWYo3NuFnXP4XhYA9 rCNE8tnyZI5djRyzKflQjgaM2Ac94s0L5D0N9LCTXt3ALdrbDp4Qj5bVtlIjAqJ++vfrdEyf2A+ SOu13bwLCjH6H0b4tmuk95UM12MeGlqUNXs9EyEuJGDpcnHx9XVF4se46LIJ2K/e4OtGbIjmez9 erAvmXiJ3lia0L8G3vQM= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D=3D EXT_CSD_POWER_ON); } =20 +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 =3D card->ext_csd.generic_cmd6_time; @@ -2124,8 +2136,7 @@ static int _mmc_suspend(struct mmc_host *host, bool i= s_suspend) goto out; =20 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 =3D mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err =3D 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 =3D _mmc_resume(host); =20 if (!err) --=20 2.43.0 From nobody Wed Dec 17 08:53:01 2025 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 DB9B6224234 for ; Thu, 20 Mar 2025 14:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479257; cv=none; b=VT+yQpm4C2MaMdtjVyhUgBrKCcQ0wGepSzzRDUtEtqv9gQ1kei1ASH84toKB/CgtgMySq8O1sGKU+hcPqoT/+gEB+6iGEnyjS+QZrPe3ShETKMtgISLFM3NQ/NGQ5rib9nH0oRko1Fn6AYwAp38o4WYjJKpaPsyGx+EBSgQiQdw= 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.42 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-f42.google.com with SMTP id 2adb3069b0e04-54298ec925bso1374163e87.3 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=b7kGAYsqUqv3eqwMF4+fcSAj5rITAm/UJB0sbFOgs3IyXIuRdlbAo3fLWEYvw5jSnI KiSaS2TYuyDqdEznjugBF0kMg4VoE9KbLSx1OjqaCXoGc8A/0hsQvvzzWvXDDGF83oVR FV2KgNKQoYekkV9cc1I3+BHdTjWy+SjgUHakZo8gTivT6QHdRuDbWCITUJDh+7XQqCko XFrc9Nkroy/BkEnJtAM8o7VXiQ0HuzylSdMCYk9J8qpQ1Y80jkZtpD2cDUtnUjeqJHXV 16gqdAnnWbOj3WPNs9miYG6fruT0p+1PFxf5eo6xUd+nZrhhptL2VEQ1XehBiDw6KlSs kKIg== X-Forwarded-Encrypted: i=1; AJvYcCWFatDJB/tp7drh4vRyQwp8xByr1RFv5VmCAb6c/mSzVhRVxVHoXs0WLbpakGj26WNUASVnVoJ/BTFhjFY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy60ABBTVHcVvRBo4zezYXpA0woX4zambpPpZMxerRZ3SZtewc+ kKZGKYGW3ox8BhZnI3yQjC9tJSlhErcVD2olE+omHdJ1LLZ3rkele9DLH3exQ9w= X-Gm-Gg: ASbGncun2eINiyF06Q3zTa9xzK/4x/Fm5SDkeb+3uiFFCplMkuw749ILjYByHcpw7oB 9LZ5sa+HOcTBVk7v9t8dlslbFCgJK8xxdE102IQvO9rc3MoYnuQME1dNvhO7Ur96csiZK+wyFg/ mgETb55vt8kUX1nxsdMZthPsmRXEp2ZBse+SDyXJ/aGucJ9GY3axEzDJ0iUZUQJ3rI9kSV5Ec7E 0oEW1B3jHctnN13ZdJJzsVbqeOQ/gzEH44VoeGH0TAbkgMg3BAIAd8s68jd4H4Hj59R9fAEot88 /Ro2xnn2XkFitbd4Yd3EkApWrhFvgWCerit/A2QWXdKK+J8zC6ASlPNYNIVaz8Jhlx8+qOnb4+N tf+VXdArEspkCrloHHSY= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- 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 */ =20 +enum mmc_poweroff_type { + MMC_POWEROFF_SUSPEND, + MMC_POWEROFF_SHUTDOWN, +}; + static const unsigned int tran_exp[] =3D { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 @@ -2015,15 +2020,16 @@ static bool mmc_can_poweroff_notify(const struct mm= c_card *card) } =20 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; =20 - if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && is_suspend) + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && + pm_type =3D=3D MMC_POWEROFF_SUSPEND) return true; =20 - return !is_suspend; + return pm_type =3D=3D MMC_POWEROFF_SHUTDOWN; } =20 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; } =20 -static int _mmc_suspend(struct mmc_host *host, bool is_suspend) +static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_t= ype) { + unsigned int notify_type =3D EXT_CSD_POWER_OFF_SHORT; int err =3D 0; - unsigned int notify_type =3D is_suspend ? EXT_CSD_POWER_OFF_SHORT : - EXT_CSD_POWER_OFF_LONG; + + if (pm_type =3D=3D MMC_POWEROFF_SHUTDOWN) + notify_type =3D EXT_CSD_POWER_OFF_LONG; =20 mmc_claim_host(host); =20 @@ -2136,7 +2144,7 @@ static int _mmc_suspend(struct mmc_host *host, bool i= s_suspend) goto out; =20 if (mmc_can_poweroff_notify(host->card) && - mmc_may_poweroff_notify(host, is_suspend)) + mmc_may_poweroff_notify(host, pm_type)) err =3D mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err =3D mmc_sleep(host); @@ -2159,7 +2167,7 @@ static int mmc_suspend(struct mmc_host *host) { int err; =20 - err =3D _mmc_suspend(host, true); + err =3D _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 =3D _mmc_resume(host); =20 if (!err) - err =3D _mmc_suspend(host, false); + err =3D _mmc_suspend(host, MMC_POWEROFF_SHUTDOWN); =20 return err; } @@ -2230,7 +2238,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, MMC_POWEROFF_SUSPEND); if (err) pr_err("%s: error %d doing aggressive suspend\n", mmc_hostname(host), err); --=20 2.43.0 From nobody Wed Dec 17 08:53:01 2025 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 4BA522253F6 for ; Thu, 20 Mar 2025 14:00:58 +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=1742479260; cv=none; b=frQ13eufH8p7iHb2s4WAHYZ3i2SChTUE9PCR2NQ+vPnkjX0bpV8bBGCJXYfvBKe1qNUB4zfzvcJCXze+0Cf2D4L/31o0ryT6RxW6g80BWx5gjhO9xImUwLL9ai8E+wLxouKq1y/sfTv3FPL0TOu9EBI4FvxKrQZHHDwqsOkwJ6A= 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.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="xiTQvwwU" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-543e4bbcd86so976377e87.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=F4/CBMpO71iX0EisbNMfKxHC6B6eIwk/lMXIiYQwAzNDdTG+4zF+jXKBVYIPkMQQOW AY/yTM/q68fXCcxG/dBuuKfh5OphjpCmWoaD11DagWEyGs2FiizkkCInuH395BsHbSM4 j1JM/K+xp6RrI/SpQBR/M6SVogFMCZ7ggjzvWp9e3v2Ysl1d15tGJO3NMpLPliNjOWTj HDaZ/FIUsOmDid4FAocs6PaQCHgeuF1VRHxiKr1M4eEjF45J4D6VHUdPdoWTsWHSgV+D WKFK2htY/AydUMCGJqBPX/jRcQenGWp2Q4fbrHlzEDpA2MCFpUG8HyqjiXLLGEGmSXRt tcPQ== X-Forwarded-Encrypted: i=1; AJvYcCV+AOMh6vyy15u0zfel3GrLcN5HChcyN578IHMi8baWmiXjk6yWHllC0hcoF8Xvd8XlpmgCLmLxF3vvyIQ=@vger.kernel.org X-Gm-Message-State: AOJu0YygIEwpfkD/HIK94stTGYXcsE6ifk7kbdyNJxENAtF2Bxptuqoq zv4E4LqfusDZeDR+J5CZvb+h0/Fl+WHjfRXJtagXlw4mRfO46XVNbgpj9pObXLM= X-Gm-Gg: ASbGncuUqiHlDUoMRD5Pn0ehb9svBV+sP9r2MWrX1hA8KCTvRxeAVCwVYsGBcCH9LCC 2WFOgsH7DBgA3lTMkB03PgxOFhIxD41yJlhtUqqyqSZKm8h0xdKyYsRPEeIZP+pJZorkDpaZncT CLrmmnOTOWQUdG9LxTb033/fFsi7Zw81sWMtH+hTTT+uFu0ZpR6AeKebfMU7ji7hdot4Qt+Tmo1 xMR/5Ct/aTSWeUjGxPBQ1tCAYbsveynYNbdtQ+L/TDlyY7JJ+Ej+Q6QcTxQPKNvbLJ00pJEkech nywy+JLRe6zU5HvO7mPqju35ueiH/Lk2JmQSgb/c9zIteaQKLjh2u66yP3tazDMwwNrSJpBBNDC cQp8TeO+7CWPNTkwXkA1h7lGaXri9uA== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- 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, }; =20 static const unsigned int tran_exp[] =3D { @@ -2054,15 +2055,6 @@ static int mmc_poweroff_notify(struct mmc_card *card= , unsigned int notify_type) return err; } =20 -/* - * Host is being removed. Free up the current card. - */ -static void mmc_remove(struct mmc_host *host) -{ - mmc_remove_card(host->card); - host->card =3D NULL; -} - /* * Card detection - card is alive. */ @@ -2088,7 +2080,8 @@ static void mmc_detect(struct mmc_host *host) mmc_put_card(host->card, NULL); =20 if (err) { - mmc_remove(host); + mmc_remove_card(host->card); + host->card =3D NULL; =20 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; } =20 +/* + * 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 =3D NULL; +} + /* * Suspend callback */ --=20 2.43.0 From nobody Wed Dec 17 08:53:01 2025 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 EE538225405 for ; Thu, 20 Mar 2025 14:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479260; cv=none; b=Dk9os9rMQcijITwckXzJ/PqnCPUuqwdfKx8mHqRUSJOscgu2eY5xIuqLM3nBgWUKugz45Vn9Sb/E4bKR6EUF3eCfyz3IdT7R0R9btScfRgHLnFE0xLqM5MKZKDauqo0Y8VPgB5vdE9Xi9s3lkRTcAzWI9FwMTxDOj0XZBlIPweE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479260; c=relaxed/simple; bh=tJcpx7kVoOVh62Qzq7CsqXZyteSS2xTmfx3MklEEb5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZG0HdZaQwUFRpuA1sG5klM8MskeBLhQIOHgefJT80q3ErZC5iXvERD4+g5P82he7nx9OZSaGZvqHWjLkw65wiipUCIRx+xfFljyyi+idgw9T4LrKLgyjap0Q6tJ7hmsxbsClRwC/YHj/kUPXoL3Zpv5AlJuygEl9CVvWIajHVXQ= 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.47 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-f47.google.com with SMTP id 2adb3069b0e04-5499d2134e8so1120556e87.0 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=ULPp1DdX4Ax+lQs75R9ZToHk2pNjSFrgt8+n2THamwHnIzIw/C+WkTs6YLoK7CuHsi gCOw9P3zscAka3SKoL3xQiVc0RWsQgpDPJ+CtjTimSFLaH5JnugWhsecim/DpRAceCHh 2rSVovDxaUQCRX6tYmz/RxC2sPLlX0hbNWzFFnPM34tyFaIZn9u9sCmIvsO7CiraAdf1 qQEsgRWgDMGTXhJYeLW732f1ne7iVeIoS+HJ8DJmcfaLlihEOk6HQlvYf6nMnZTV+evE L+ataXGju9i7rDPJjStgqKf5vjCBqJs3VP4WVQtYz/vepMu/+M82ryP142xHVHLnJykU 7ErA== X-Forwarded-Encrypted: i=1; AJvYcCXCrcVor1sZMx5zSUg1dHFEmw6lDPs03bG+zYA/a82bYD0zPH0TEg06xRRG1NCPp/4oEDBV4svRKO8B2ko=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3VA+TGSbZujOznt1cW1uessp0bn0lyYjGWe22ETnm0jtuRrvM o5fbNOB+5dBQiC2ub/1V7Mx0HQqJXJso9+jTLbkNpeqM86ZQUwNU5Nt6LAzOr78= X-Gm-Gg: ASbGncvlFAZsaHyN6g72QzAEfnPa8aoI9LC0krqtjvFj3/r+VVO26zl1MgAWXc+luPl 0tE8rEHVmJf3271oQlgsgcu2MNbqhVIeHD1GkaUfCuPpmvCfQjCt8atqYAZWmL48sMQ3hfRxa7n VvmLNP7qbU8DZkoE2ApHUfVnXoA6Dva/T/TkagLZg3r4ZTfY+Mh2nwDynr8lOu4VE7hTXgq9YVm xb90u5cVPnRYlTwbIQWAFbuUABlfDhSopKF7xljTqXk1+eze7iWnpaFzMGoYeHg2K0QX/y2ucNq hIhCX7TU/zDuK/RpVA6Efhd81EQyAz2ML+zWamsWweYMs0r8wf2FIO1lDtpEx4ZwkCoIvE16ejw Z8RZsLePsVap9jT0fyETyQY29y2iFeg== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- 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, u= 32 ocr, return err; } =20 -/* - * 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 =3D 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); =20 if (err) { - mmc_sd_remove(host); + mmc_remove_card(host->card); + host->card =3D NULL; =20 mmc_claim_host(host); mmc_detach_bus(host); @@ -1730,6 +1722,19 @@ static int _mmc_sd_suspend(struct mmc_host *host) return err; } =20 +/* + * 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 =3D NULL; +} /* * Callback for suspend */ --=20 2.43.0