From nobody Wed Dec 17 08:56:01 2025 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 3F4E01FC107 for ; Mon, 7 Apr 2025 15:28:08 +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=1744039690; cv=none; b=thHGfdXGZp2ESFpruW0JTiEG+xwdAJM3zdWplGSZ4fgl8cW7M0ZpOelr2NSCDLwK2eWfGe8fuXxGoiR8/9rPY7rEbxphx1HhOk6Pli4/iKu6GvBsA3uvTjYgpCKG9hmnFOVcfHNg0KDAZxX7mIWsMrhIngVQvZJagD+TM9pgyaY= 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.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="ip7+SdGj" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-30bf5d7d107so35430171fa.2 for ; Mon, 07 Apr 2025 08:28:07 -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=i7p2HKWAqr+Ovm0Wys1RxhnQKUJqHD43ZQUcNLx8ARjjekx1UPN1533rJ9vZS5Qk+a P9Ot9H/rRNu/6eWvGyXkR9YazL3hi/yJPvHtzaL8aQsrk3/U6iMoRyMjBKP4vJl9geV4 OHkNZa87mPUS867LQNYHyIMrbDcE6cVnce5u1adV8nCJJkvIalThDWk+caXlweJrg+PZ /Xz3nP0LAwkgrkRKqeXPzUyO3v97KjEseKd60bCUB3b17ITTfa8icgw+nF/YmxKYFAqW kssZ39OPAy8ew99RcVncuEJhcfM1Ii1gEurz0+pGOlxVjj5QG2WmZvVXvgIjvFDJTyHR VhiQ== X-Forwarded-Encrypted: i=1; AJvYcCV/arkpwIvW9UwXbuzsu/YwfRL2qX6PRRnsW8ws0UImjDMoC1hkIc2AEPAXmyFKJSgjkU1RBIMecgbesgI=@vger.kernel.org X-Gm-Message-State: AOJu0YxQfdvMRHo3KpPrn7hZsdABRI2groXVgzXmcQue3MpNUPhyYgRw gL8y+QAjqeotH9YinaoJ6StsjNFvtvJjaRAmgs0U6MKv2+tm2dnA07nShOp7cSQ= X-Gm-Gg: ASbGncvP1lJsfIKHeoIvVtSqUq3PM2nJYOW9R8rCLI+7iZBzpoGR8SY2xDCQrMoEEp1 CST98kuddkgA/hNv7ypZAyb+Zjrzzz1tAzUX61ylgaWloFKT8rsfrdGTl3Tch+IPzjyZOgYIdPB hBGOUbgkHcVuweuMto13T77wtVjRx47fIOkRaLU3Ci9J9jDYAdRcvhdMtCgeGPrB7EIM8qGLSfJ 1Q9xagDLm7YG0DpjzjMeYEFFTbxPLNueG0XhHOTnpfoYbH+4fvZKUoyP7BkK0vAlKDu0fNA1T08 /mFhOzjnkES7SIjb+4sfXyZs7CQjpLH7oCK7ypz3WZMEt4e+CTRbMS6cix84Ys8JIfqGFxepzVP 48HVgS2a4t9V8zdRc6qc= 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-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. 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; } =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:56:01 2025 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 4C5DF1FFC68 for ; Mon, 7 Apr 2025 15:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039691; cv=none; b=ijh0wrD7ifP+2SsZjpEgmulBILR/5GVgri6qI3Wx71RAFqMrobkN0bqIcxX4KG2dWCfK5Kz8OKk5eR5FKGjPzd/sfBoClBkbjSZaJigIJVM1idNMpbsWIsrSrWsXkFgeGE7C34zL8TCvyRpv2eoK9Q2xZn28sq2qaBb+xcKVGEo= 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.182 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-f182.google.com with SMTP id 38308e7fff4ca-30eef9ce7feso46197471fa.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=QvF6Wx0nxD+C1J0vGzZ/pDxZPjqmYeBahypNcXLd1kOUaZQ1MIbH9bMjZFUdtSvVnX FWMnSMSNhCQN19W/vnQQgKUl8sEZux0LfFkMvM+X9b67nU3Sp/5aTLBC+S68L5Ri4CNR oSzcdEu/cruZAxTmohzX46FpzQiRPFNH4kSSe8Sh48QyqFea1AptaGt5h9JK5ECM3vFk jO9iKpnIZ/OjOKrUgia7o2qFu3Dg3VvoyMXP7sF49XOGkjd23BL1fcKG9TQvnplIvVjq oYcqp39/yAzViPbalyEqUMRSzj0d9S5UFz0PDLYog0JDGWERPe9zFXSgbsMTw4eXy7gu +SzQ== X-Forwarded-Encrypted: i=1; AJvYcCWq8oGCyo6eKEEmtH/At4f3zu0kb5IKwIXcmZJQOSjyemepTW7cb92/pKEnn4GM5cH5yd7c3z1E7ZmPAOw=@vger.kernel.org X-Gm-Message-State: AOJu0YykUJ0vLNf48vdKx8rTz8vMK3QIO13s6D000iJ43CgqfVpG1X7d +F29tqSldG+Bz++eLnPZB9dZI2ciiLjopBezT3sHED16tn0O6Q7MBQ+jimuHMaE= X-Gm-Gg: ASbGncvL/LvECVqLC1d+FaCXC1Zeu8dcp17BQxuVUaZsHwH/o8lrY9R2btD9heXNKET 8sHjDiZZdFGW2zae5IhWSexZXZvkrZNCDdzYH6SutqM5IE/P3eDfbZPH2Ms32cEZIm1mexOVdWt sGSX7NOCbn76EnpA8ldevze0E2A9kicbo9Av3DIHXlbgirWIlYbJUvzEPYO8DT1YGwPzzbznnlI etZiYI9ZM1MPGX+gW9lEiCZdzObj4hGDR2r3Ah4dBdnUaVDOcqRCh05AiGx/XWqn2+YIe7K9vVi RNKoSt1bJi2XkysE+eqAaDDoHS0WAAyYiI75doxkg7Yxa07yGwDJrUpX1SjhfI3a0M+SSrgD7jR e1aV4GxKEArKcOMV3nJs= 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-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 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 =3D=3D EXT_CSD_POWER_ON); } =20 +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 =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_host_can_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); @@ -2187,11 +2198,12 @@ static int mmc_shutdown(struct mmc_host *host) int err =3D 0; =20 /* - * 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 =3D _mmc_resume(host); =20 if (!err) --=20 2.43.0 From nobody Wed Dec 17 08:56:01 2025 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 71C4F202C38 for ; Mon, 7 Apr 2025 15:28:10 +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=1744039692; cv=none; b=qt9v83TCEvrS34krNeP2Mi0qCcngOLivzXY1BEAIq1MrywVFHS2RVWX8cc5u3/42WROErwd1P/pvSlgCrqn7KjA87zi/K9pbRT6951bX38duFaEmtlIDsRZtE4JjWChpDbSjTthERfKHkd06ZOGwZlQvCFwUaEBoH0Zirt/yQ+I= 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.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="s/X6XMk/" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-30613802a59so47792821fa.0 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=hEYXps1+18RcZ/mBszPg+1CW/yhDoWqo2dMIDFWCnkt5vjVspJHwcnK9BFQawrphkA 8MOHmD6Qd2L4GTNpwmOKWTGpTsYIU2jnm9ATE3N8dSmw6SdOuCeSyWSczIYSPzRgee25 TUCmGDTZ1yjm/jPJD14mYfH6ELBmCXH7Bw5TpYYiW4m/wUdkVNNTGgdzahC0BjxDtgnU 6TroIjAAwyv2SAj5VsbW7iOz/Nu8Ek+hyXY4MRfuBAKoyzjQ3McAkEZqzvwuO470VEr9 rLz3Oij5osqZkB29uJV54dFKUgGBawio4zPkQX2K/cTFhlNPP9D6z5yfMYPbq5iBQJFJ 7uMA== X-Forwarded-Encrypted: i=1; AJvYcCUyGq8OtzguiGqdfgyZLzUbqU14u4wzxVpcv+DXCC8B4c9ZgaupdbVQe25pk1vsmCyu++/fpA0bqjR/LDY=@vger.kernel.org X-Gm-Message-State: AOJu0YxxyLDEsudlZVzVhh0lltjUlqSVQUQmMykOGJB2LQXimVXWD4U+ i9U5vYhmDv2+WHhfeGJC7275WZOY4uuecXQV/0KaCNdL3WIc4L/bFlE/c2f1zwY= X-Gm-Gg: ASbGncuP2iljmbaOQ4Z0T4f1nsAg82ownJimuKi2eQXqMdb0zfXlWnkTsSVL2vZauie 4UzcCf/IRIAhmjSVhH8rku1RiaG9DYkW4DlnVdeUM95nGEpAwfJ7ksNc71xuW1kwZlIuXVIqsBU QNHybjITyzCZBD/hb4iXU1Y/eTpNmrnem/rkF2fpUySL4fI+JIQ69Y6o3BZM/lGP4IiIhNYnI9J 920DQnJIXHNlF7ii5QBVFm4VzOHT/uBSIvLs6xb62fa9/VXG01TWPBLyoR0g6C/yR7wK/pQeUm/ sfWHWlQEYwdSXcQ3Lbr8lSiabPweJEbXHA1khLMEw5iieb+M5af+W71kqp2zTK/s7rCnHWPZYkx lx5MRkR/PmS9lH7kLFaA= 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-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 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 */ =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_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; =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_host_can_poweroff_notify(host, is_suspend)) + mmc_host_can_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); @@ -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 =3D _mmc_resume(host); =20 if (!err) - err =3D _mmc_suspend(host, false); + err =3D _mmc_suspend(host, MMC_POWEROFF_SHUTDOWN); =20 return err; } @@ -2231,7 +2239,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:56: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 85E72204592 for ; Mon, 7 Apr 2025 15:28:11 +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=1744039693; cv=none; b=cR5gqyoP4Ny2jw6EuqwmPkgp/4qUAwQxAwu6o83BsFkxhUUKROT6endz3/+FXzEEc5+wFj8/F5GJ2RCfW82j6XOlEoQIrv0Iu0vTHKv4KiGys/34zrz21YWzeA/M5WUs5KcCZ9wbXkd3jYYvvRgJ8TslxVPEmidg9LGY2hvP04o= 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.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="HdAI2e7m" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-30bfed67e08so45199471fa.2 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=K2Ot7MCI/Cyf9nC2mYpGSc7TqO+0J56ccCGUoY8V2edHKRljGK4CNRQyRN7fvQPPhx osaESCtuYyuhkjYwzx89X5g3Rh9xTxa3UiiLZIyhBBeGX1UUQjft8tVqjlXc5lO+BSFs c+5caZ/SkBCgQPC66F6sY30eHOiN4NZqoWWT4K0x21n1mhpWx6h9YImzOkXPYkSZtUGo DkeX1yr2QXVaHjK5HPbPYRjmT9nStsjrvPHKrG2XDWIRc4dQeZIFx2tUf2BxtHG4NH+f a4fnRH7CmwvcNUfvWLsOsQLV77BOk5+VHT85V9Vw78A0lc6YYXCQT55nw249LlSyLnwE QjBw== X-Forwarded-Encrypted: i=1; AJvYcCX/c3b+jCK/e6WWOOmHdESF6k+TmM6xo9jn3+NeRklkL+V4b+q07qCV9zxikBEjpNNum4Dx5sxqLjqGnDY=@vger.kernel.org X-Gm-Message-State: AOJu0YxTeH8ozm7VAoGO1WxvcJwsp5YjQ7f4AG6jDK/MrrFwbLhntE0Q gTWOXsw6aNtE3Py1qKWfkcPRwM1UDjm0txBW7kFkK9xIFQhff2Aqs60T7hiY+C844cCfHqAYp2j y X-Gm-Gg: ASbGncsOg0Vc72UiBEHEKm2AivlC7bhBS+x6waX0eZ5IpCjEkZZsSuSV8ZcxeQc3Pdn j0D/Z79DOT5szCMkdgIgGq/WC6PhusU6p+CECJAKu5eVnappt8Ndlh4HYAMQ3FrSfDQPV8W8vah y0Yd1iS5cdSh9Si1O+whleABsU1oN6384h3M8Bs9aUToQRG1TnRziH7ExKh0dIp9jHLQW+ZONkN tIZagpNdlV1C/duDM+QCTUm/7TQ39prxVwANk0wQokQ0NhBZjMpb7LFeqRpGfcyifyOydpFZW4x 8JUhSeTKSJf1eYDf7usck9l436+8q9ZJr9/VBwvRy2CYe5fO+MLF+iKIknsjG8MobrlMJUvNhJ/ 5yOkpk41uFrerhMxTfC0Xy1pR3MFmbw== 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-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 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, }; =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:56:01 2025 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 7C5312046A0 for ; Mon, 7 Apr 2025 15:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744039694; cv=none; b=K4HtXQDihDCMhSYaf0ElUMKztGuDV2zvfU1brnOcpk30xGEn9XvwoK0BibKI/Utqs7XqBW4gZEBwkEqaZaJAeSJhp0H7E7FOxvU2vI33uNaJ0H7354Y2Y4UC1jPjEee2mQ+aPrBZ4LzVFwdYIuoa/nSY5EEl5iXxiqd49uKwq1c= 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.181 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-f181.google.com with SMTP id 38308e7fff4ca-30db1bc464dso40799461fa.0 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=gxgTZGaSqmNu5YVLDmjpZSfHal80I1pEZr4IDUEjSD9MTprwmIkhQx6jy4nrKNbX3Q Q3Pbiqf2GTQguMjNFq5SCigk0MRf8IejjBGsFg9lgtbelUs6iridzVCM9ohsCNocP9Zc txq5suxq40Y/3JfOey77d9MPrE+3FV4fNTpaXE6mqc9lBYsdMG7BOpOGydksAk+acdCd bWi2X3vWKEglPeRGSAesO1bYC+GxaoX+Nzi+pLgShYwRhkd98lNntb1AtVRuHrOmx8Qh EMSXD9a7deOZkFaErhrb6TAgVUqUraiazNKlk5Z4ioFTFv09783yzfNJNvJArez1/9dR sagA== X-Forwarded-Encrypted: i=1; AJvYcCX1BDrhWlqDD+YsvmPTdxgYcbw67wsvRM7pLvGe7smW48ehOxtofpRcFxnkpLEcY3lAvRsN7v54QHe51ks=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7J5gFG8bSzKecbuXb3BJQxgzbck0wH78N/i+s9FzTUuqKxkqZ ZjU7VqBQoqgFSL4TNPlSI3MC9pstYarK0HOS0TvkBCfHXGTb8IONC+kxBCNK5nA= X-Gm-Gg: ASbGncs1bcFsA+20xRH7+oLqQ4t7PzX+0bfKI4jYA++yolEEYEZ2PUeCVaGC9lwt8s8 3g0ruF92+n4zOAQyU6qPRUJV6RqPxxvugBnjKHxQ/w6i7Ja7ewiZE6Tc+kXQy0cO67RQrQhw3CL efP7J4wU36L706XV8TyBCr/y0cnSZ4/o1qXrFcfxPVeAYZtaJ5QS/zqt03S1qHyYerI/hOzSOIG zCmlrsRwuGlk5kYsJXG+yf5QeBfp55Z+hBbQsVwEAtbJh+tOsQ5kWeHYqG0Zc1w5NeddFt5gOZE 1FTx+sgKRuoK85/iXy7k5xm8lFBPUVuc1JPxeHE6oC3OFByUBPkFaGvOBsOL8EdjK1NrAEzxWiF etO1CXfRTVzI22d+HYqA= 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-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. 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, 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