From patchwork Mon Apr 7 15:27:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14041137 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 4066E1FFC4D for ; Mon, 7 Apr 2025 15:28:08 +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=1744039690; cv=none; b=JNhow6F8Wmi8FAkCW2yZgtEEv5iJh/XAzZVWUf2nRRP4a8aCT2iUeiK0IwqKleGXZ3Ug90DTYH9otvsqUIRlATQIBTvc1T08jwtTBucgQIdk42+4dDDFoRNBEV2DuURQNDP5uFtBb+PmFeGT0Rj7iM/YOzRBJGdI2XlFuIH1p98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039690; c=relaxed/simple; bh=AeCDJp54wAGtMg9CHmvKgr9djrzK4GgL9KpmTxPCRpU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pswHz/BKiDvS4prCZQKoDnF0dEE8oO1XaNWRIIDCQOHWwv02tEgOXIy4n1fNIiaZl8i0tSebspJrMe0v9Ku+H5zUyluqQm4po/95spfXobKBXZ+mtTrsqKGDzJ62MU4PT6C+n1h4BUwvLL49JP/3bP2jgtMTMRFSghljYvI9yZY= 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=ip7+SdGj; 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="ip7+SdGj" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-54b166fa41bso353942e87.0 for ; Mon, 07 Apr 2025 08:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744039686; x=1744644486; 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=Q0o6na0F8TAk6lCusT5NLJ6CNUgxmH5Vy2ajrZSzJE8=; b=ip7+SdGjNUtgxOKuleuXElFbE+taTNOp21mE4yMEU060uNwuijy+AaNAIgkpy5Xe1b BMWxoMO7/2KNMJoH92cbcDgPL+ydUOPzVhpS/06/At+OS13M4SJF5d7nhKoEcDyC5hUi 5NanepfdNLqTl4Q61rQwBk3tnjreCcerW+it/02yO8n4jjZGcdrXpwzTxyYZum723/JJ FcoYbC51fXiVoSPfEJANbdIGK5a8t5q+l2R7ximUipadjB+CL+RCz/R4OqYMC1ErfNrx kSU+eCd/j3VK8Z0DRfneu+J10UO7CXHJlJF3iOCObzF3e/LtcgZuQ9TVct9L2uWuB39S kdHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744039686; x=1744644486; 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=Q0o6na0F8TAk6lCusT5NLJ6CNUgxmH5Vy2ajrZSzJE8=; b=wWgFEkBmmgv/nv7dgtyDCu/wXtY+2KhWWPYDPiNTJTGak7tRlg24kCL8L1ikJ5WiPC 4EFjAu3CcAbQejYCVlN014+kgNuik5h3CbhTI925Q97GaKUYajW4L/G0skxU72XPS27z R8SKF0hGak/HOpDXrfcErogW2sOTxtxS9SGZtLYwzhqt7y6WJU+TBPydBrDCPKlzJyPi WvLqGRrktLtg6BY4+NLAjNimgLRqEi0u0aAFHsEpnueqCNfGqlgLFNmMUZ2UFje795Vc dzQAFaQvsB392BiGlS3b9Xvv+s8llJ4IGUUCBo/VLnPMsl/R8DAgnV+nbFuYA9wbFFQK F14g== X-Forwarded-Encrypted: i=1; AJvYcCXLQ1biTa1hjcTnW6uE9j4TAhO2H72R6p0MHcwIhhwXDBFgXph5G/hq7g3JdP/ZPh/PZbVRtUvksYu+XoUQN+3RdA==@vger.kernel.org X-Gm-Message-State: AOJu0Yy2Te01rm6jEll8nnQM8ul6fIWKPSTYEKdYnNLGXZ5gPEuYC0sy wBJHdeBDFpEP2KbJZkOou+CjzkIXu5XWeSUQqfyafoeywxDqZ9BYNkAARzehRzQ= X-Gm-Gg: ASbGncvd6+Jllt6+xbZIU39ZS8vytMby4CykprtIzL5oS8hxtyNo50ku8rFm6Ya1Lml al34CUnb5mvDKgEvK35ISCRkjCB9Pz1Cio/AbVvhQDURtGgGOGPyTxNagClpYZD/aW1BThCR2Kn JxhBBILsKqy5sL1qZUPNu9tvPYYZQujTsDmVUqWozbLo3s+io6H7NJqRxHJQeGJR5cMbZ82nOu1 tcUAedY1Wlq6xCeUc6oxrAMrpvu04N9JptaZrs9W38obcwY2cEUjHrjPiNctXXRcTmr7s0ayv05 fDvWEcIOxFFsOPbwskIQvIYewCxc5nXdv8ywVeNNO9FfCLmr54NPkGmc1vKpoF6YpmsnrXWVE6S Fi/B1UBn2YvFdwjTff6c= X-Google-Smtp-Source: AGHT+IGP9ssOV6pn79yVfRWiq3KAcys7QHTQQoul8wvyG5t+BivqElpyAW6czWaQuzr79w8RI0P1Cg== X-Received: by 2002:a05:651c:211c:b0:308:f860:7c1 with SMTP id 38308e7fff4ca-30f0c03c545mr42993461fa.30.1744039686432; Mon, 07 Apr 2025 08:28:06 -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 38308e7fff4ca-30f0314c62bsm16158691fa.61.2025.04.07.08.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 08:28:05 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , Avri Altman , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Avri Altman Subject: [PATCH v2 1/5] mmc: core: Convert mmc_can_poweroff_notify() into a bool Date: Mon, 7 Apr 2025 17:27:51 +0200 Message-ID: <20250407152759.25160-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250407152759.25160-1-ulf.hansson@linaro.org> References: <20250407152759.25160-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. Reviewed-by: Avri Altman Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- 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 Mon Apr 7 15:27:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14041138 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 4D7301FFC69 for ; Mon, 7 Apr 2025 15:28:09 +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=1744039691; cv=none; b=laKe1PD8c4At/Tq475b+uF0IP1Jh47Z4NREG/GjcuDrdlvgyq/y+TaFgZdw/dONF3cvHV3lpgIV8JkyGQCgqaOZ2luw1SvGucPxgFcOg2s4tgbVmXm0r0ku9sZWxFKdpLKY2dp9ClyBwyAFe7zH7lDVACbJAEwbLJrAFlqFBMQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039691; c=relaxed/simple; bh=YFGgFVZPO4gvL4I94QxKzw7LMTFbifBp14DoIXK02zs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aOCPSmuP7IrACFNJ4jIgybwpT2qrRj+8K3fgxuDIqYNEoNrkioay4xIozpMe/8m2hzAC8sZXgFfWD9u8Lx/Ar/SdqrL/BMX5s/qTT8Remm635b8s00fgj+x04Snjv72d630eItMtb/Vsr/Niw1nX24hkTqG/Dh/ix8ZqRZu6s8U= 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=ZIbtqNSr; 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="ZIbtqNSr" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-30eef9ce7feso46197481fa.0 for ; Mon, 07 Apr 2025 08:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744039687; x=1744644487; 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=u+pgF1XCcw3LX396XqHvp0lR6UpYQKe9OvVkFZWMDPQ=; b=ZIbtqNSrkldocotfcHSutbxSeNpXPBMPZBKk7I+DW8fPBdOIqtIaijNeWtcBj1sykQ 7HVBpHtKOJOGwHsL5U6+Pov0eDUCHhMpx4t9iQ/FB2/S3EGR5YUEfCytRTIo2Rh/0NXN RaJ3Ai6mQ8RTIT7sKtwOfEX1VJrOdDd4YNuukGsD/60xCQyhk/p9uDeeoiXnY0XguXrm Dk0AKjKj7ZUFSW6k43g1yL/daePfXAxM9rgiEbjwny6tIxT3zH3E2uB9n0hMrEqWziZu U4mJTSClFK/G832b2/j3MunhJzGwxvyVvZ52PNj8/CxAJlhXwys7bpBhunloFq4nLEg0 V8Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744039687; x=1744644487; 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=u+pgF1XCcw3LX396XqHvp0lR6UpYQKe9OvVkFZWMDPQ=; b=hTFaeMHgeUhqKg//g+vPqvve3ToS7rfdE5HUW0WAtnNRLt+5/QyYV5Ep9Hb3uFVlM2 GGjwhks+PM7psJI1r8xJs3DVAUnWnWqqUj1zyzVNZ8E36xmtY3vqnKlvym0/OnZhTArF xXjHWk74nf7FtrlaQ8rWs9XEhLuuJmzQX5uEr2oa2WoXxOsErwzHDMcVypZeijEdJCqB JLbAGRMF7x8NfF6Df3jV/8jRmOWRbSCALZRPS3JueSnz5plYwq9/dOqpV9z1f1cYu0k9 tCtc7u94+mGH9cHdubI0IOEHWZ1LzBjuCgbgGTElOm4AuuA8MLUFXNUUQB46KZvO5tJY kDNg== X-Forwarded-Encrypted: i=1; AJvYcCUjjUWiyEM6XZzXzcrh+EkJuPiTLDlG/zX6VftOFXhf/F/YaPNK4NrUYkmVxcTRTkDSxkjIkrrZ9yKgg3a5YPZk9Q==@vger.kernel.org X-Gm-Message-State: AOJu0Yxk9O5VBm38KokarJL6YsI8TgLMflmvUdtKbS1YyK0269mdGnJ1 s7VU8xFe+CYiRcmaNL/voLmBNRSscz5LgRXV3U38KLXRV+CDY37IeKYFl/ZhhQU= X-Gm-Gg: ASbGncv/ZRDYewhxe0c9XwddoK9wN/iyg8PE3m/Ak1CYN+WvhCHMUI+q/f6Dpru21kF RmyBM6H+1f7rxIcgg2BzpOom2OMdtEzCnx1H3Q7eladvsWi7D7tXNSeO3IBdRV+0jbFl4AaqiEu O0gKADg9eA72KucuFx0mWHmUrnrohJXEsn/0GhknMVNiKdGcHSXdfX2JcugBc05Ic53cMQZ4K6p kXLAOiumV09U4tdmyjJIo3c7xyNBTzNJOvSsOpOtyvVTZrWULFBncZWk+Q/vlkorWb3aoFMInfx LaeuC85nMhT0wsTOPTn4tY2nbKS86NlxMpg95eW/Iz1jBNwRwLKtf9VYL9m3DVqN5Kv4JvyuPmP iHs4M2yRNdCr7RXOM8vs= X-Google-Smtp-Source: AGHT+IGKFFXXs/zoQFbwjMJSn5/Y2OgqzEvHiVsqN6vOlmAJ+S4/vcsfkBfaBXLhJVMXv7YgnpaLyw== X-Received: by 2002:a05:651c:982:b0:308:e8d3:7578 with SMTP id 38308e7fff4ca-30f0a1c31edmr43821991fa.35.1744039687449; Mon, 07 Apr 2025 08:28:07 -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 38308e7fff4ca-30f0314c62bsm16158691fa.61.2025.04.07.08.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 08:28:07 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , Avri Altman , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] mmc: core: Further avoid re-storing power to the eMMC before a shutdown Date: Mon, 7 Apr 2025 17:27:52 +0200 Message-ID: <20250407152759.25160-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250407152759.25160-1-ulf.hansson@linaro.org> References: <20250407152759.25160-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 prioritized option is to use the poweroff-notification command, if the eMMC card supports it. During a suspend request we may decide to fall back to use the sleep command, instead of the poweroff-notification, unless the mmc host supports a complete power-cycle of the eMMC. For this reason, we may need to restore power and re-initialize the card, if it remains suspended when a shutdown request is received. However, the current condition to restore power and re-initialize the card doesn't take into account MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND properly. This may lead to doing a re-initialization when it really isn't needed, as the eMMC may already have been powered-off using the poweroff-notification command. Let's fix the condition to avoid this. Tested-by: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v2: - Updated commit message, clarified comment in the code and renamed a function, according to Wolfram/Avri's comments. --- drivers/mmc/core/mmc.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 3424bc9e20c5..ee65c5b85f95 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_host_can_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_host_can_poweroff_notify(host, is_suspend)) err = mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err = mmc_sleep(host); @@ -2187,11 +2198,12 @@ static int mmc_shutdown(struct mmc_host *host) int err = 0; /* - * In a specific case for poweroff notify, we need to resume the card - * before we can shutdown it properly. + * If the card remains suspended at this point and it was done by using + * the sleep-cmd (CMD5), we may need to re-initialize it first, to allow + * us to send the preferred poweroff-notification cmd at shutdown. */ if (mmc_can_poweroff_notify(host->card) && - !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE)) + !mmc_host_can_poweroff_notify(host, true)) err = _mmc_resume(host); if (!err) From patchwork Mon Apr 7 15:27:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14041139 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 765B22040BF for ; Mon, 7 Apr 2025 15:28:10 +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=1744039693; cv=none; b=RjFGhbfaYKTuWE6UPiU2UegW6SlqwlV6EnMnyYwJe8ctVO26VzhaOusu+KyMJ/BBOBk0VmPKuq49tmSCpvKP5Jqtw08TTjnxwtB6hrqVkvv6wV64OS80QUSSK0UqRqvk0VTbplVxkJuzogqMCjekUVN1m9qlJTDmTysr0S0or+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039693; c=relaxed/simple; bh=6z5WCu9BKEtjznjzzsmgKzbsHck7/xCTm4ZcI9BylgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mgfWBe+pvQcERt2Zd/muKb+a71KSErrThIlapUJVZ+BeZYuZxj29jAuF0/EDf6jpMoDHuh6OqIvSlxQ26+AMgb8x7Azglx6Jo5t0U6TanUAN27zx/WggxKK1gvtSI4iy9GddcQll5d+C+YiDA7VFy/FGUKaJ5Ks56Nyzt6zWGVc= 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=s/X6XMk/; 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="s/X6XMk/" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-30ddad694c1so48118541fa.2 for ; Mon, 07 Apr 2025 08:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744039688; x=1744644488; 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=kFgvCtbiUg2Axc8JMkDx3HvUYjKIsrcxL/JNSE1oUNI=; b=s/X6XMk/75K9Gj3zRaB/0v0dyUzD88BJWMAWmkAwaPRsV+atJbPDRWp9NHg4tyvsjs lfeDwP3wQTd4fp+rr/0qhAIjqBNq9DR0VGUp2ng9HULTpHM6XaARToYW+EZx6qXVQ68t ytcRa+skw/uI1gABLngvZnKXVYRTrfwS2FWx8LqkJhhoOmcbpuWNWXT3v1KmkGXJZsWc g2IJoz/PZcaCGDXptQRrIxP6xwMIvmic5pitZ167NFi6LLDb+iIgpEjgJjpFVSPTDNXI 2/e8Q1rXsfBNw2vmd5k7P6uRWF84wEZ5TJPMEt7M3UTXzyTSNGV+tC8QPxm7gqIr5qh4 mJxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744039688; x=1744644488; 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=kFgvCtbiUg2Axc8JMkDx3HvUYjKIsrcxL/JNSE1oUNI=; b=uoRPAaQddxaO4p2wfc4YOK02xB0r0Wr/HfTikV9mbP6ndkOgq6lixBv3DH2UlXsgvx Aa91QJYrjjm67MuqCMTHgmILVhBKtUXzlY0fi/dmPUnldoEPtxjJ372qSA2uRrq5Kltj 5nGEDhUlCqEEhb37PGJbHzdgwqalHxwBB+7VHPtzdzb4pWB7ijY41z4el2ga6dvs9feP ztE2qzEwkqx5cp0TKRY9HJ/Dy5nmUxhPaKMqIeWg1vRfWr5S/r934bRq7Tr2FVYLO3bv TOBUBIeRQmQoh0WkxhjB86SkyctB+a57PogkRDBfZtQ80s/fhhzff2Pc4sxmh+Ti7HE4 IXbQ== X-Forwarded-Encrypted: i=1; AJvYcCVJZEwZJ5s8KvAfLXLLV80XWfvmNbAcrAmfihkB98voKbcV9Sa40NadINVY2Jg1rAHN/rUZl44m75PTO4Qx1DE/UQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyzrPMElJlNAMCUR9FWeYqWz1kQ1/6eBa4o/UQuN4Q4UW9EqPts ttofeG54patz/htSDU+homoFDoNdL/DVMF4agcgNcq37r0vcj+01Tafc/wLmBSU= X-Gm-Gg: ASbGncuo++tGb+YF6EpnDrVIgH5wheOf1ddbizfBKvB20wka80oMq05roupZSYVADh6 nke96oKfMgH6d/uPR3adzwoLSvGzdnJYJgphJteU96khHlYDd1xXggQvnj8dxB/0izyp8beA1Dd DKd3/9apqRqrdqSPSxiMlfePs+2PAdh5UqBhjkUZkZKRXlLlCa7oRowAG5zQ2C51ttiqiPv69Rg bvCgg+mFVQ5PMkk8iKYJ5d0LInhNjH+XQ4YvFebw/SuNDy7fztgVRUkXA6CcbDQM0m2FuplOuTB FucKgZ9EzKSlQ+ZZ7a+qSaHd4iNFdxRJ7/9Hi/MuIRfKLnBEN/w4HFXs9YEi8MSOne2lfxeaRlo EnsndbEQRVzc91YtdYN8= X-Google-Smtp-Source: AGHT+IFdkzDl7qG+++GgExUEpecThyhFzUirOW/vapvpkFtPwvl1pIIZxAmc9QEAxBzudyVIXtO/Ig== X-Received: by 2002:a05:651c:158c:b0:30c:2e22:c893 with SMTP id 38308e7fff4ca-30f0bf50edemr39634651fa.23.1744039688540; Mon, 07 Apr 2025 08:28:08 -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 38308e7fff4ca-30f0314c62bsm16158691fa.61.2025.04.07.08.28.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 08:28:08 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , Avri Altman , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] mmc: core: Convert into an enum for the poweroff-type for eMMC Date: Mon, 7 Apr 2025 17:27:53 +0200 Message-ID: <20250407152759.25160-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250407152759.25160-1-ulf.hansson@linaro.org> References: <20250407152759.25160-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 Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- 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 ee65c5b85f95..c41cee7ef267 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_host_can_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_host_can_poweroff_notify(host, is_suspend)) + mmc_host_can_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); @@ -2203,11 +2211,11 @@ static int mmc_shutdown(struct mmc_host *host) * us to send the preferred poweroff-notification cmd at shutdown. */ if (mmc_can_poweroff_notify(host->card) && - !mmc_host_can_poweroff_notify(host, true)) + !mmc_host_can_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; } @@ -2231,7 +2239,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 Mon Apr 7 15:27:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14041141 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 9BB9C204598 for ; Mon, 7 Apr 2025 15:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039695; cv=none; b=GNLKwdrqVGEw6XCfBTKvldjZKGz1HdKpIHFXxfiJX4MIeYn1qgIcy3lg1xE5A/HSNPysSXPz1qePxhXZlqkGctJQwT9zZa76zujQxl8ERJcO7cseEHvGuu1H014JLS0lZlTD6UGXDomeoAgHVQ7slmIwyLVtX/XOufUcnboEXCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039695; c=relaxed/simple; bh=KZB+pX8+Z+t02Vyu3JiH1fIAeOGA3SvV4prne66BLo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oLVZENIxtweNpOYjNsbdJA/k+5QsCg4JVNz+FNnR0spIhLyMqZblm7SVQPJHJKyUtkivui/g6G4N3G3bBR/16nBx0DpQpAJjl9lxFPrSFaT8WwJ40qLVqOQJHdGaGpaBUqhUJzWAYHkueaSmM1h6rVqutmWvi4KQc5ZRXahT+LE= 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=HdAI2e7m; arc=none smtp.client-ip=209.85.208.174 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="HdAI2e7m" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-30dd5a93b49so41053901fa.0 for ; Mon, 07 Apr 2025 08:28:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744039690; x=1744644490; 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=qa0NqKrTJ654Zn0Q1P84Jb3f7w9bMHpFgeDh4gI/15Y=; b=HdAI2e7mDs1MEGlnG9DCsAZAN6uv0tgrwh0PSd6SBdIzNZ+h/bI9WrQsuMfu3fQL18 U7OfNz7jdvi2bdtbxaVOGmT9QldDz8Rt6Fjd8tM87Nymhv+D6pcLrEym3BD8GcFzZaRD MPTrWww2ybXBfNJwwU98KOIF52xHJVylIbymjn2QH2fy1QOM+qoVb+O/k9WKpu+yHcZG GMdg6tZcfwB0xAdmVWnq6WRhgqZncDirSyizjfrNlAmVN9GWvR8NsrnTdSL7FyXef4u6 hUW9tAOjwyaXzfLsy4JHkD2UWzenYg+tXhGiYPgu+Mx8gwf3qaabaiJ0EmlTcvg4XGR+ 9nDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744039690; x=1744644490; 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=qa0NqKrTJ654Zn0Q1P84Jb3f7w9bMHpFgeDh4gI/15Y=; b=UdQ+3dT1wLeQ7EtEe90MG4UF4AMXtquhB4LOgveffM/8wugAzzksOYdkin9I3pWFuv 6BZyFFTgoRHrBQRMAx0N2pOZbhxe2BI/64SbI3+9/NSU8zP9JapJ83i6j9QwdDyeHNGI DedXiub43JSKe3JpMLMLfjO1nCWT8zF3+Q9q9CLtjMoB8UYaIa8crJTXm2JlFS1aJY/V 672YetNPtNpxwbNul5Puqgfc99qS7Sw719zcIZseli0kf//mUshFU7iCyOYs8+VbAnTH gh+9N759BV4MUhpdjNYMKeqNT72gXKl6f2yMXIVS3d19QqkhvYSzE5wWXC+eM3S6nsqZ hdaw== X-Forwarded-Encrypted: i=1; AJvYcCVTftvWsfuXltwipOFBAOcgRain5Wf5QURB4TEqLuZTUlMEDYSFe0vXBfXfB7zmApKyZfqBPpMDDd3kA1PI+WxRkw==@vger.kernel.org X-Gm-Message-State: AOJu0YzEexv0dH+5opmQ7I638BZD4l0MTQu/1iU/ee2hJcGrQJTKfn2v Mq/ZeqQWKFcXGjc7cTF0tLw9sRdF488K7gYBoUq4RArxkQFvcEloFCDbkLHFU4A= X-Gm-Gg: ASbGncv7HeyRxmfvSQ7XXQv6PJ7Yc3dsYgM7OX6GaYNxGqKcRUS+YZx+gqpMvsgaF/l ubxo7ZJJDKwWpfOVCjCQ+u7z9FbGxydB3YmFyWxudwjtvHiw0vZ9j++KkHWF4HbNJBpR/m0sbHg 31dS/MSkkrQBCvqEdC+h1PiITZCajq7Pt/29mOEafrpnhOb3zzocJ63vbORrRWcDmwn2ItJ8PrI 6VY5eAkYJ2vH1C9TjY+KYrzKCIIykg8NmgPwFcO09IphwtW/kFCYmk4mCWqijYlW460ekjmj8ge rb5JH093QHSZA3KHfDqPCBHolmZ3ETgjfZKAo+LC0kN8qAQVcSWKWfKMb5y1dHu8s2Jirz8lNYz iU+NwoZTAg9qBRWM3cPdbCJxQAzqVqw== X-Google-Smtp-Source: AGHT+IFeOmjZZCVinZE9PYC+J15PmJZZVU9CLynwj9bgWoY1cdAzycB5GWB7cxZRv+fyPdkRgXGDbg== X-Received: by 2002:a05:651c:3130:b0:30b:cef8:de87 with SMTP id 38308e7fff4ca-30f0a0ec55dmr40033581fa.4.1744039689698; Mon, 07 Apr 2025 08:28:09 -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 38308e7fff4ca-30f0314c62bsm16158691fa.61.2025.04.07.08.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 08:28:09 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , Avri Altman , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] mmc: core: Add support for graceful host removal for eMMC Date: Mon, 7 Apr 2025 17:27:54 +0200 Message-ID: <20250407152759.25160-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250407152759.25160-1-ulf.hansson@linaro.org> References: <20250407152759.25160-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 Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- 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 c41cee7ef267..48656dadf93b 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 Mon Apr 7 15:27:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14041140 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 A68881FFC74 for ; Mon, 7 Apr 2025 15:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039694; cv=none; b=s1oSfgwas8HUPlAR00g9f8Bc34IUtvseGxgYjnFZLjtVQu+4L21C5QRfnxfK3xBqetcXbSHHwtSOaNV5BHbaW0Yp8f63cdNMZoeHTp9tzWDmWVb3X7wfstPKeauLkALJPBMl6WdoFCemA7pDELE9H8CyWQTWP8aV6ikZXISbFdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039694; c=relaxed/simple; bh=Ijknpk5Uk4hIjq83+lZpg+DXsxI0t9quWol4n7s82Jg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uk1+3nCFP4ueUdxcTSmpsyRj1JR0BF+LDf8vMtge+/SGx7hdflxkxMOQsNtUpwP49cXW6SqMlHMkVuVni97Mi1YdHFsL3fFDAfyqTPT1gF7XWfrahAYcGICaf7YVLNC0LGTWkajEKuWhrrJclr7sLaPTvL7tPTpEVWJkCk+8ITo= 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=TXgppfrF; arc=none smtp.client-ip=209.85.208.172 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="TXgppfrF" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-30beedb99c9so42394401fa.3 for ; Mon, 07 Apr 2025 08:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744039691; x=1744644491; 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=7gicrhysR2QFFxxlVaKRKpkwXL5D7hQu+/seU1sSHjg=; b=TXgppfrFtNPf8da4F7uAvFWqVrsHkeQNDYtI2xo4entXqZpt2yjyH+KnOTJ2Pxm8qf UzsRa9oLlXwwevmkU8+s0U7XXZlnKc5Fi7aN1wEzPZSWeD0bQIXCr7ORdfBNCojAiPlt Hgt/CsA8zyC1kI7XWa6w9b7aLYkCg9r8q36Mea5IVL4UQUyhBq1SNZc43ZT3GeQftdA9 H8ejQO5c4fHVPAy2fE32jQJ3R4g1xPtyceDMyvuhorbeC5nTHEOMN8UazEhY78EZ4YG/ YVI8DVRZdNKP3t4Itk0opmuvlnP3nTUH1FxdAD8eKQ6U3m23t64C93F7MNINzhceBaJe 2RbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744039691; x=1744644491; 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=7gicrhysR2QFFxxlVaKRKpkwXL5D7hQu+/seU1sSHjg=; b=NqNrYqWC6KRpj8GainS6PO1UzJb3q1PdpDEXX41UUKD92K1nFlTGQASIA/fojZ9A0e uHmlx89anT4tdS0Pc0+vCtG8M7J9NLzcR52MUNPy+kNgm2YQO8FH2VmuQTDYRK8RnGtI WNan2CMb15+DPG4Ubwoy3SpeyPOVDkiaoMBX2dEWk2eH34nHlwon6WiqOpDlUrZ0gJ70 2AhUZ5qErDR828LAttu1pOjd0PDzWCAQgYCvo1TmCWxSLkiIKyusIRW9sITLBZC3zLar MC2i2W5FhX4st1J48kmXbOiPwzPd40Kr+vl85mFDFjG4qa3CSWTsIiQajFSCkIsK3kt3 L2cA== X-Forwarded-Encrypted: i=1; AJvYcCWTecQUTbApg7KPCAw/xhZjXHtY5BKAVPbM6HM1cltvBWL4LyLA2RhO4bCEiyd6kCdPH+BPl5usaqYUVNHR5y5xpg==@vger.kernel.org X-Gm-Message-State: AOJu0YxqLFodkKqbThJ9o2pQmT0qB/LgS3bk30LLYH+PW3MYtgmSYaif FoSD00JCijzKOG43C221W/2KEJtM7zaRI7doIChgl2jR4LmR8gjeOTgMfNStVrg= X-Gm-Gg: ASbGncuR4XepyGT4Z50ulT/JN8Oh0M0RtCmiWi2/Amy9htZKd6z8oPZP/SWi6wp2qCB c/+WHVNtwEhYFOh/ky0utET/cpugc06FiG7loPFKnzz/7k6vlyck8wz627HZbOT280xlXiXNNLQ ar1oFQVoC2Becc1xssUR4HOLT5FW9A6OsRbsKNjw9msO8GijxniVpWGoWz6/myZOgYzbgz4r7ik JJPY44xveGeuCiBIHixe/NbOYZ4UeQuPL5PBrL6ydvt5LQYbXhwvnkVHEyzQJIscQbLQfoBkE2Y EvcthzX2ca/yUNV6ie85d7P96+KiG1g+DLmVvKWmlWggh+AKHyQAL4m8+37IqwfHcas3ejS7zwN DAoBfAcbiFpHSC6NVhzk= X-Google-Smtp-Source: AGHT+IHhIxQb3ouOtoDhkU3Fmd8/KhI6GFSskoCR2n+C2BKMnFkWdfA/ZJhkp0ALJ+c5RIpyY/oQvA== X-Received: by 2002:a2e:bc1b:0:b0:302:22e6:5f8 with SMTP id 38308e7fff4ca-30f16539e48mr25655121fa.22.1744039690725; Mon, 07 Apr 2025 08:28:10 -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 38308e7fff4ca-30f0314c62bsm16158691fa.61.2025.04.07.08.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 08:28:10 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , Avri Altman , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] mmc: core: Add support for graceful host removal for SD Date: Mon, 7 Apr 2025 17:27:55 +0200 Message-ID: <20250407152759.25160-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250407152759.25160-1-ulf.hansson@linaro.org> References: <20250407152759.25160-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. Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- 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 */