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: 878944 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 821E31FDE00 for ; Mon, 7 Apr 2025 15:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039690; cv=none; b=BqoOCbcnzuWm9dGrb2xkxNThu1y58TNhsrLNXPk5yA3OUQKnjndeMTeHRv+qgUjIjFhIJal0ZrK7B+8XwFDs6167G1aDQ+0WBb3RoGr8gQKlXY7kyqtiFMkidIoQgr1+cTGMSLTuEGTqQ8DBN99qmm6+q6MZEVjN9QevM6Mkfso= 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.208.177 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-lj1-f177.google.com with SMTP id 38308e7fff4ca-307325f2436so47140691fa.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=m4xbOLMGQaTCWuSguQp7YJBEP49x9OcZb5ckwrJKWspE0uWz7S8n+iEB2eFANu/RoT Bqs6+EsRbOEjKPIjIvWi+/NopLGP7CBwEbYfQd3jVkZVjgbp9XRhDVtNDX9B2WLTsXbg GuoqVSqWe0JzIoxLXgIbpiq5yMAjrQns6Tmx9jPBp+Irm26/zftXABl1Wv7YRq+UV9Ql d/63JmYJV3XDEeoVRMJVacFbi2caKh02zLaYXIN+bv+7ZPtAJB4AqMYlu+9xzGd31Azq j5/PvdykME9A6LDTOauAT+j7JOLJA+u1qJAHiveRmHniQVhLX16NKBSc7EcK9ydAV/18 SWEQ== X-Gm-Message-State: AOJu0YxswfjUOiP6/b/oBNVnt2Hv0yfD7IGrix2P1jGY3cPyrVWvChA+ WO18Pk7dA1PMPYm6LSTE1eDcvVb8GVHaulU9+uswvUC3ZKxSqOoY//uWCfuUQDid2P7No1zoW9T c X-Gm-Gg: ASbGncvp/2QzQykfFDXL6YsEHFoQKS6eun/eYJMcG3aP/RGW51Aup6GtufIORd8Liye Yphz3ykmekiUvmuJieVDshNn3mAtVGxf1mdp3c1h5Q0Pks/+uXm6nOhmA8chzCy/QTOBFdDZw1X 7ea87WWZlPXlkqtXWIFK4wFL3kN60KL0I4ngAUhlSNNcLQF03PhnCx9ItZQ8rtJYfgh5RIJ8/yo jlTC7U//cNl5CZFXm5XeuIA/KGzsgmC5QYvzlySPyiffjL/4qtyC+oU1j/ofMtUqFCPFEugYuTT t7zkRf7Aw0+e0t1r64YjDf+Ey5Ws6amCknoz1UD4vbXKJhSyD6bkAjVlNw6gCn1lNBWKgAyic1P 3Xrs718QDbz0BkWqiWRI= 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-mmc@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: 879976 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 A174F1FFC6E for ; Mon, 7 Apr 2025 15:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039691; cv=none; b=A6Esi/e/qZIGGKnruuSOaC2pdnmslwXjuVJL5VaYDpfJ4pU8lEYraCRvxtbfdr0R9NKOsItH6fO3PPsVOH74HvZuSxh7sbC+lnWTOBbW+N4BJOKD3wUpUei3K3H31DcDghO6bUdJkzL7WvxfgrGzz9/G2ejdaKWAzVFq69HzwsE= 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.173 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-f173.google.com with SMTP id 38308e7fff4ca-30db3f3c907so41289731fa.1 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=VDoF+28HpuUykuVC2Dszc/iBkALOc5nSZhiXaj8wlfWgxlmte08S9PpYHT+Zlmi/M6 toILx8yBl8oO5iHro58jelA7CDho9zp3r0N+/aho0MIR7sRkpwPEz6Q6lgyTjoG6CyhB w02Q1HWHKGsd5hTJMqswctCdFqCDkk8gFT8nDP+MX8c6/zNTfhu1GFKE9KCO0G8RWTcC HgXsqwIrcIUllUzSfzToov0KJAXiW3jfGl5jLsL0jN2zBubDDBgLL8bUgGBmMtVBwuAU BDae8jIWICnYP5h3Jv71uDw5BCM9x1/NH/l6MFCfWTQD1TVBz9AGrmo39L1t4dgUAUY4 qK2w== X-Gm-Message-State: AOJu0YwK0hYQ9c3ajKk0EQH0QOBFss6V8TcKPJ7Mu0Pi0oytmWXk9RPF YyRrkl5m0DmOozK1OyD0x5QuG6oMZkJuimBcraQot8WJ1a5GVFl2DPrDBdom6bnrjotMGruL0dw Y X-Gm-Gg: ASbGnctTrAbGGPqt4ixpZs4QyiHzn1AofIXc3Evqt1CRKNtVNNkkq/a2TNJmF/ogh4E D+4RBFlnoKLXlfPOhnC+/ikq+I3T37DvULkO56CYY2itMvsKogNS0rOoFJnn6ygzDX+Lt+AqosB Z18nU3KzQYCy2w9Qm8GfFhkCe/bxeEQr5bPWj1z9vMt1wNy69CKF/CJkETrdUZOmBZ/ZUSN6LpE NeG6lmOurCSqIjjv1y6NYAGBzAl6CexDlApxxN2K06rFbhfqFn2XuW0xP69Z1MXzaNenR2r5g88 JJjQ5vlm9ZYZ01/MrfQz5X8LmTlKS2tIrggB3xkZiZSdqvyJCFqD2h3no2FC9MtDBXkvzhztdFC Icp1qxB0hxarHYwg6k1E= 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-mmc@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: 878943 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 9B84B204097 for ; Mon, 7 Apr 2025 15:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039692; cv=none; b=lcCJ8+QRz/1Wp9dMc5xOBSbvdC3h+rkZMEmG+qYFyq13ivu92vkbB+Aoa9ReVBCZyflBfagbZ7bPAe/wQKlR8Mx/FW+U/A3KWeaJdvxwDAve5IXnKjJZQ7e5clucKe6oUewwu/NKNQTNnZG5n2EO+nBH90pqq6I8xXCJyxMmLuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039692; c=relaxed/simple; bh=6z5WCu9BKEtjznjzzsmgKzbsHck7/xCTm4ZcI9BylgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p5GfMPqKFNzm9mrNu6rPnfFIt62Ham6cSo2xPdW1vYYUBnB2Dh1NA4lTtCKkjFIjMiC7NEVJeY7HItZW7DBolKYGxo2Q59E3PMkSWcAK79bB6AAbicyUf8I2zVSi8Hz/EXTph1Ua6gchUkIJGhZWStN73Ak5eajw89OSFKz5A7Q= 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.176 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-f176.google.com with SMTP id 38308e7fff4ca-30f30200b51so5528861fa.3 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=uGF2T4ClQfOfFd/b+pUl3wkvP3lC7Fntjm9vXzJSRw0P6xSF9cV3H9Xvizx9OZX16e 4PNUWIWsv+iU/hntM41A6TQVoWFbwwaH2D4zM4+DH10yUwrlQ0YilFLBOM+rLKiuFuov XShkE0sxbrvjN/tPOfe/SQ5AJdc2ErESRERMivYF3/Ios/pDUYtsIoBlhKi/UigYY5xq 9mqwnEk6qIHgbK/BBkP21YVZELS48PSWmrOX/xxXe3yhwLWeoDuCxGVGN73Iv9KvlUBf hKOLYPsVcptZfTPCUtZzF3PQLfjH7zOinOW5xSasXHbH2mIk5UpXtMOotGSbRtySMhJu iBNg== X-Gm-Message-State: AOJu0YzJRodfWQZ2xD+Ruzuw4ZYdT506IeuApnKnB6q9uGWI2QnM/0WT 8XERuwO38hNQA0Ng0K1FIPBbVXT5THvP9nUqrM243WbwjeY5HM0P7yX2lP7tz8HeCym/+sdqmIq Y X-Gm-Gg: ASbGncsDrLY3MFLm0RDG8HEHdxvUhReyOHcoO23kjDxdcrrCBbowPQtgOu39gmCEis0 3/tw3B39Cqq8HCroFrXMM1Ap0wDkBwae5sI7KJk08FD6Qp47ugfJsjVb2z1XIKufhoqpFQO/aZj VPPtHKyB3G7NeYHiZwfj70Ly/4hyWmARLkwaVVCrWFf/ItO5WDdg9LXrRki1EaxaGAwbjCgRNWm QZC2RMbTjsmhdPKtU9Z5G++7OjYgWTd5pni0nlmeKwMPKARPHRevXJaOPpXIMO9gXGlcxOVlq1d TKJKI5seBIiPvxj3aV7r0KRsWQW7//yNDMmPNl8VK1t1ay+nqqEB2B0ABFEKkFDqm7QRcwx08Uy 92zaX7JesoJkbdAzfr+8= 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-mmc@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: 879975 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 C493A1FA177 for ; Mon, 7 Apr 2025 15:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039693; cv=none; b=K9q4AAh8XpS/cJci5yE7KfiBp80qsKrTYIElx9Pdx7TKCHYg8MNTrk/4mp1xMWHBUxggFN9gnTApZuA9sQ+Nlq45k0uL7sF5gTFH+prFcXqSC8/RYlwKpZetJ6LbEmEj4RRms59Sbwk2R49zNrOAR5GLAnDnh5qRITTQnK2bM2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039693; c=relaxed/simple; bh=KZB+pX8+Z+t02Vyu3JiH1fIAeOGA3SvV4prne66BLo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i4N1brFTRFPBIfUys9j1xEIeAvF0bB/tlor/DdJN4P7Gi3rEHs3tV/GEVLsMKTw6GQ+5qFCVAoI9l/eohbmojQ8licqLcYhri3qjSY3+s0XFR8D+ydQYHjzoO6ahzsy/Sq5inLEgBI0HW9S9pQ+7yxoDxgTL1mQosfvj2KCGEic= 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.175 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-f175.google.com with SMTP id 38308e7fff4ca-30dd5a93b49so41053921fa.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=ZyDwUx1FNLOhwmgJSMFK6Xcm4emMs7NhOtOCryXiUUAHSF8nh7ZHp2aE4xPpF2IefF znpOBdZNYmbGzgV8zgixTyMWRqYrT8dZkNkbdh8R3OHTU7gON9D/BSa0dLanNTSDeo3x l2mEh88bI7m9J73zE45bOULFV6/gtXDyuOj3QU+AdsO7qmpPUaYblZ2gMFJ3BUoweTWE iOmnV8WTZHGfJtp5NEp9j7BUvhh1DaQou1C6smbXV8y+dXrcm8EAi2Z7/zX0EWQK6jAu 8tZtu4xuFKhB7dcMNdJHhwHQMOZJgAqbm+msoyy4dJcH70EO2yB0Q50ztYzZaN3yNfhO I0Dw== X-Gm-Message-State: AOJu0YzakNE6qRGkmDuag1lVotdcWPYYU8GY/jwlAMEYuKw6xy8L7s35 USTVx+pgpoygsPlFzrBKdk6FP/KvWlbgIy+o88dPN87owRIY5FJx3sorWEho7ui6N9t2JyHELdx T X-Gm-Gg: ASbGncu/igQvjxGvcYQJMGH00rBYnS+HIM/5GBxCvMX+5ZGMPzb8qp/Q05m5otejcJb FiNmMFI+WuH2ADg+VGdeEotpuLL6KLTL051XueRzoHepeiXl3HkQdyDmFm4I5nuoe8yFDwLYO1u jHA4SKRXMbllBgMyMJMxFImg2g44O59F0L4DEybXwNTdpE+c4IJjS3n/PwjQIGGMJ0/oZnppl+i /jpdJNx2NfHK9vxydZ20taA+wqG8Op8PDmt6Vll5UDyRZrVk8uI7asTw3qEaC/fD0vG1s2zgAs9 RtKHqfdbtbfJzPlOjqrUjG0mX9DprpJfD1d9e3pBtStbEOnPQGHGPfPtlrHCcS1csl8iU4pFmum rU6JS7T8eWMZgJxNDRL1W31mdvhu0Gg== 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-mmc@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: 878942 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 EECD31FF60B for ; Mon, 7 Apr 2025 15:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039694; cv=none; b=LoX90frkfGR1cP1veIQkh+JgJr758mK8f34GJC71TxeBzc0MFiCWSO5/1j7kQybBQBp0kyDO2Pq0QrSNhcPHcNAMV69anL0EhRnFf3XKnNr+Vzz56sPDzR330N6d86nVVvvM/zvJ9pghCQ4G8C1QNMJ4Oz2l1P5nOn/yll1SnJg= 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.173 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-f173.google.com with SMTP id 38308e7fff4ca-30613802a04so49099621fa.2 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=H+2SD715n81zDHW9pmGaOXQfQiiXTwM9jlFV2vKWHfqSTRE8S6Lm64hZOKmRy1NZC3 hPELrZR4nlw1EoIRp+LUPwRinZMdTpDivexs7ZOt6kU1ahVW5Q75b3em/ozwAOQkb7ur VCgYIHq1wtg/NrRXFruJGQfgssSMnk+SJF/abYx9I96HAlk5KQcVLnFVHY8gkQopYolX F9Vyj92Ju5wS6BFsQHzieohAvmfWT8c/tKXx9qTj5pLJoB4vw2NyDoQC5C/zRO05vWEZ V4EbUXihGaEsC9mfT/icCfQi0wlhu5BinEcGVse4sI0nIFKRt/C9Bvdf6I7biYcB8JCA zzXg== X-Gm-Message-State: AOJu0Yy9vPQFya08gwow1jEujfhB1vNQkM/PZm0QJ3zl49brZV+dD+8X Vo/ZV5cJFeNMvDnljMW4uvnLCxeVfebCh+uYBMQRFIwjD3SxefroUJTvL0WC6N+qtjQzGVKOb1E u X-Gm-Gg: ASbGncugDwCuhmRrZ3AzM4MzOSHhdC6rpMQ3sNrYg1CaofBP+UaUIipgGxQi3Z9Lf+K xxFiaT5tjBeQYzx7LUIiGxQwvOwd/O8I5WHSljuBmiplbGaDBX660h22FLhUJtepvbrCVS6jOz4 rKd918R2wJHy9ZYlj0zK/J/OwItAgDHz40KlxmAlK9uUtni/MW+lzVtT8Yqcc1HjLnR9BEafyUQ 305rvPWIm/6ER8i6E64AhEM1k1R42vQbASNrO9rlO2PQvJRDo1aT51U0FlUKn3Ct3ja7N/fWWRQ HfrPNKgfIayxNIp39MHx7P94tD10YWxfQaB7bwzu/klatCMRK6dyaX+H3xs8FIdhjqxI3WNDOas SGuv9Jw5kBem3VlaNncg= 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-mmc@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 */