From patchwork Thu Mar 20 14:00:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024012 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 8DA2B222580 for ; Thu, 20 Mar 2025 14:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; cv=none; b=AfcJGCOwsxdTzpyCd2UVVXx0ob0KKExFVmcipXD16kggVYdsJpDPvg3SnX8CzYYEhewmvZN11fTO9ER5Gfbi8S37zanDODwkSYl9KXB8V3IIZR7WyTBvqY1dmxtf6S76w4ntVUKK4l2wsT01X7HGr8aWZvQfKZb1x2WJZ5ILQNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479254; c=relaxed/simple; bh=j4UBzDHgk4sG7kqb/Znxr+FvEZ/5sfuewiW9AIFkVSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KljY6c+27ywPmwSqp/q7cZILCorkHnGi/71JlQxk4EzayB7z12QlyqiNjRIiSx3j7WMZylz7V/N+hjFSLgIc0ui7U6kn45nrZoGyeaZ+BeSF7ZapOMo5i5gJ2DcsAy8T2AXglFqrq0HBhnEHervHS9peG1qI6JQnCB3dP3t4sQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=NKAeFCP+; arc=none smtp.client-ip=209.85.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="NKAeFCP+" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-30bfc79ad97so19698221fa.1 for ; Thu, 20 Mar 2025 07:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479250; x=1743084050; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c1plaKCpUseZn1Yu08x42hT09CM3UN2ZDD1b7XB7y9s=; b=NKAeFCP+tJ9jaqQlMdRR3APcTkkrZ99hA0tP5R5qtxhXeC4jt9eDkkl2pqQq0OGDMh aN/S9eJ+dzKpewWdQbaJEM2QB4jkSQBZIODAUhEp3pgrbdleSyLDkdTrAaersbQ0RTVj q57b5hdc9wfCRVjktN3OnYDVC1peOBL0RdD0TAxHK+fCJc/WhGkwu5mTsGiXKneA6DFI gyl16nK34SRjGjakXTzfnqWoudAhaLhfmPQs9FNkTgYSwNfFAf/dlFzUDjYCIMbPhkiC xQj1ZeFRuaYWbruVlDNmfgC/wiBfgo9yN4J0UP1q8zWizr9JZlUZ7ZJyi9sEh0KlVw7B Gktg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479250; x=1743084050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c1plaKCpUseZn1Yu08x42hT09CM3UN2ZDD1b7XB7y9s=; b=FOo3azgu20x4eWq2ye4vz42qS0Czsf6tjRk9bDEoUfSiMQsZykwcmqB3NQX47dy/z6 nYW8mb02fyVdidMbMPczcqB63mSAliXd/JVRE1S2OQXVfDm8aWXw6YMC77B+xmyp1WBy 27hNiNpBEJF5mVBfce+kWVJTLdfFcr9CMKkx6R+NV5hvEy2UK5Froq9Tns9WjgqhvYqd HcxkN1/HlxTpc9kmBXaOdd8Zumh1FeY6aLBEL0z1ujKhN+N3AAhfRvqeGe3WnigudPnE pCooimFCeuuTfXsf5gdo/SzJPVkTsM5tFFfcTCEH0uofGYpXRgDYeFNhwRKN5d6W9SSH 2v8g== X-Gm-Message-State: AOJu0Ywrm6N4XAftE3e81YBpHZVue7oYeEfI9SKmz9Se/lBxVsK7vki1 YhlMX4SNMFZ/+h2UvNpRHCbrpYW7fvgF2A/kW3V34uPtipzHiWIhAaSZi0qGGhblnazDobwrE1O c X-Gm-Gg: ASbGncs6klFGLhCx2LkUzHRUy7+gbbHYd8bc/N9xL7Ez3gJiYWpDc1Rru1Zjy3w2gOI LSRcYt8GSrJE+7S4WYxmKFZFvnFoGuSt0mSKz6by4x/7hGJDXGcdzIFtfnfrAfUgqI4qdMg5Ybm 5UpleK+yybhDoyOYrd1vcyI5d9JoeWpJ2Pb4T36XOnVNcXAUtBrEPPSWK40mLfRaXsgeEEpbE+D JAlwDdqEeJzrcIzNYFvLb67fhYYiFQsi/hwfdnolL5oRiSlUeFCBbNwzJL5mccvurjl66HchK+7 8Z5+anpFMMwtgyGsREalLOW3FXzQ3J61iRYmUakS+bCWXLszAO1m9uVhTqVpPxVk2KxqrcwisEk L6zg7DRCvsJNXIcbmR9Q= X-Google-Smtp-Source: AGHT+IGLDkayWqw+uQ+t5WY6cfFF97KDSfF4dlhtyKOD98B93BOTyBSUBT6MzlDFFxBRVZdolYijWg== X-Received: by 2002:a05:6512:304f:b0:549:6ae7:e679 with SMTP id 2adb3069b0e04-54acfa79c17mr1505467e87.3.1742479249732; Thu, 20 Mar 2025 07:00:49 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:49 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mmc: core: Convert mmc_can_poweroff_notify() into a bool Date: Thu, 20 Mar 2025 15:00:32 +0100 Message-ID: <20250320140040.162416-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-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. Signed-off-by: Ulf Hansson Reviewed-by: Avri Altman Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- drivers/mmc/core/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 1522fd2b517d..3424bc9e20c5 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2007,7 +2007,7 @@ static int mmc_sleep(struct mmc_host *host) return err; } -static int mmc_can_poweroff_notify(const struct mmc_card *card) +static bool mmc_can_poweroff_notify(const struct mmc_card *card) { return card && mmc_card_mmc(card) && From patchwork Thu Mar 20 14:00:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024014 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 19983223311 for ; Thu, 20 Mar 2025 14:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479255; cv=none; b=kcKvhq8qxMySUmvBQ+GHZF4TO74XfLBkMzToC8HeAwkMF3V6ZWNPMb9t584R/Avw7IFAOc5JWDXlIVe7a6Q5lknAJ0Rc7U9biBwjKkwuRl715HUtkc0QH8fZ+T77PGZ23YtmYlycbuCVkRDsgPQtl3IP+NpJP6BKy7kW8FR4FaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479255; c=relaxed/simple; bh=VhD8Av3HSuJHTUiv2cdROzFQDA9TdxYn3udhBrPmLPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UswrhxKRjtwBuRsr8pzZaatx0QxPw5w5x9bywbuklOYPQPhJTmhPGT7d9kdr3OpPm2NsnDP0FEqkTzZN3a0TDgk8WXpui/hz+lNNxTRhI98kAnMVfh4NQwO+hkdxF0MZF2ioOn1wcRIhQ3BSfTU8EkN8jRJDBBcvQoXsK9uqhas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=B1oLyqwG; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="B1oLyqwG" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-54991d85f99so2141473e87.1 for ; Thu, 20 Mar 2025 07:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479251; x=1743084051; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RYAI2eqixUcWJERcq8+IYiHipQCgnbOCM34Jd7N+9HY=; b=B1oLyqwGqyT03rP0GFXC82s/cDUh4gdQlsUNZve/uzwAbLZJk2y/RLv6ITzPYDRx2M etIcDIxYMpHP57RLIZhziRzmc0pmXnh6xJxrEQ4wCJlOJWnuAOXjfRL8p/1D+XJZa07p jbhbMWdRoS3f085uzNlQ+MhdThzt76ct++dW81eKzTEJkSmvKIZ2CopIVy2M5RwgQUIM h3RHxuYwFMtB96hFhSI8hVSul1FnxSVF1LJLJP/K108g2vidlIeegvkzlKNBbiEqtybk 1JDdZblJdqSeS8IDdOU7cI3JSSFlb6avt5L5dvO7wxgKc2a9xlqvZZI4dYuHDkiPVtOW nWNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479251; x=1743084051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYAI2eqixUcWJERcq8+IYiHipQCgnbOCM34Jd7N+9HY=; b=cvGyaykcSPrL/SQKny0DTkly2HyoQNm+O0JglULyixquGsPjcu7Dhl4fOtcZP3jbO3 nmMiSB0x3r6/r6oHLXz0p/FR1lLxLUD5icABsOT2w9rdYXOrBh9992EfMgvGcw2s3dSY EH9poUgrTyF/vXDDK1mE97ZfNxfzffszp8ivS6EG256s8Y7TZ5vTtU4MwI1rD1jw+q5j s4lho0PprZihdh52RRgeNd3eBHVm4XnyMSzJ2U6/LKds0prh9YLLcOZiZqvzwUhqtW0Z +INiW2ALH86OF9CuVarIRRvPIHAP0DRDq6VbqGWtdMHR3Z6R7GW2UjOi8ucL9aUQHzQx LUxg== X-Gm-Message-State: AOJu0YzzOXck9pJ50qe9aWb+mb01D7wm7hqHeuHNZEtkNaG+kd3Hqd0Z +Sqcwuj8woAOoySKHsPgoLqv0b2gpVvhbJ0yMtau9d56kH68Hf9JoMxIoPnBQTpdGm7oU+fZEZg L X-Gm-Gg: ASbGncskuBu7Q0zN06aBcAENxTIIMVmid3JfIJfa1oA9O1N6SkxELaPwxHgtOS2YPF2 swddDA+4h+UB+Gb8v8dGwHACoKLXcSFxl1DTV+LvXfMpHnRX76QVLNSNpeBgsLT0QdRo5u471mj Tt1DoZmjomk4vsZjNQM3QW+whX1OgHnPE2/x4fu00yEP2h+D729TXt2VPQuFJceJuObYIWOZLOR agbU6XLGyBVVNMWIJN2cRXmn9vYa4s0nHv6RmgM/bShFp2ronFOc7fnQXvUsEsfKONNU+Rdkfti F7bkqfQxYB2z2G5gVSYJAowp2UpaEcIwExXVC5GF+FrzE+4LMHNNDhI1tQyhySXvO7jgVyGasE7 FSPWm8mGQgQ+8utt0e8A= X-Google-Smtp-Source: AGHT+IE6l4M0DQlQYZg4ALvU5yllXDeu5+WFY7sQJFtppyPs0t//66RIGxg0FcrWHeDey/P2LeUHtw== X-Received: by 2002:a05:6512:39d6:b0:549:6309:2b9d with SMTP id 2adb3069b0e04-54acfaa1caamr1050147e87.13.1742479250703; Thu, 20 Mar 2025 07:00:50 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:50 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mmc: core: Further avoid re-storing power to the eMMC before a shutdown Date: Thu, 20 Mar 2025 15:00:33 +0100 Message-ID: <20250320140040.162416-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-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 preferred option is to use the poweroff-notification command. Due to an earlier suspend request the eMMC may already have been properly powered-off, hence we are sometimes leaving the eMMC in its current state. However, in one case when the host has MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND set we may unnecessarily restore the power to the eMMC, let's avoid this. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 3424bc9e20c5..400dd0449fec 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2014,6 +2014,18 @@ static bool mmc_can_poweroff_notify(const struct mmc_card *card) (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); } +static bool mmc_may_poweroff_notify(const struct mmc_host *host, + bool is_suspend) +{ + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) + return true; + + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && is_suspend) + return true; + + return !is_suspend; +} + static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) { unsigned int timeout = card->ext_csd.generic_cmd6_time; @@ -2124,8 +2136,7 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend) goto out; if (mmc_can_poweroff_notify(host->card) && - ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend || - (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND))) + mmc_may_poweroff_notify(host, is_suspend)) err = mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err = mmc_sleep(host); @@ -2191,7 +2202,7 @@ static int mmc_shutdown(struct mmc_host *host) * before we can shutdown it properly. */ if (mmc_can_poweroff_notify(host->card) && - !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE)) + !mmc_may_poweroff_notify(host, true)) err = _mmc_resume(host); if (!err) From patchwork Thu Mar 20 14:00:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024015 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D889222596 for ; Thu, 20 Mar 2025 14:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479257; cv=none; b=VT+yQpm4C2MaMdtjVyhUgBrKCcQ0wGepSzzRDUtEtqv9gQ1kei1ASH84toKB/CgtgMySq8O1sGKU+hcPqoT/+gEB+6iGEnyjS+QZrPe3ShETKMtgISLFM3NQ/NGQ5rib9nH0oRko1Fn6AYwAp38o4WYjJKpaPsyGx+EBSgQiQdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479257; c=relaxed/simple; bh=FLnJitILWx+gEhi0WoDSNfEnTW8g3N+Au1bp1k7MfuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XWlKnMn1Nj8I/PpbYd+wBKuK1Et/v00uSG6nPO5RQaetOtwz2w3qhNg9zuLhynTVYCJdU8mGV6FnhGOH+ioZsjBQ2KpT1OB0Bfr4LweDBqhdZPwFF4s3XSXIZWwc2hj2wGlxU/ReklSyBC8Gof50AStvOxNulNPIsUmzMk8o8FU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=HguNeC+5; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HguNeC+5" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-549b12ad16eso938312e87.0 for ; Thu, 20 Mar 2025 07:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479253; x=1743084053; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JRcl21cexCWaRdVFTtOPv6NXKn2Krk/8VDxch080WVM=; b=HguNeC+5Asj8t7W5EQxp1P0Mdk38xtl486pVZ9ifvZMHfudMi0mhDGqRB/t8NUmkAp sg5epSaSWeY5vAl8uahHBCtAQt61C6Xf702+FxlWQjT7jDlCGH+hZDj8RWtzKpG15nuT HNF/689VhAfbmErOb/5EwIYFs4u6mwisVo2kvbzgnISS/HbAwUa61jDfNOfq3attw0E+ MHcP1KDV+QLVMdRisNRftG8skh+DEXHKShUZJ6T6B95Dhmuqb0/utVc5MRrlvNiR9Q1F sGqhRIeiauB6tFC+IzAOCWB5dZUCSuDcV8K3Dovtrc2ishCUHYTqVMlvfphFPcn4s5Gy O/Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479253; x=1743084053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JRcl21cexCWaRdVFTtOPv6NXKn2Krk/8VDxch080WVM=; b=Bgu6WBSnF4TPgX3lMLjUG/XTYa/SQhQoQ/K88geiTiRQU1/poOzElCFVYhSUAUIFN9 h1jNK3vz3siipbPHQQ8W7x8jC6tXadD76L2FznCMyenmYPXAF7cgE3z5FYoiYcr2Yl0O WEi8pwbInVfdCCUYkOXEEVSagyREtnryNsiuoBGCGZYeo1NMw30w5rx9OtRmUrZ/maB3 E6+G5jnLy6U2Xo67TRXFEwbzD29XUMio1eH4ODYUk/kqgRNoZVNYKlxXsVSirI+VW2gT i0eEXb3yM0DwrjoqW2IPaDCQZAN4U4IJI0hl8g4YQW+ZxN3bul4WxEM9M508iMDcUlkw 2RWQ== X-Gm-Message-State: AOJu0YzNY808Q66J5U23nWVMjKoWH39Msu+pHiS1g3LBrEma3Rv0nanz oJQuWGQBUwzh2ZvYJqkm6UH9DSulxTQIEFjs9aYXGz5y+XSWHY3MNw7amDtssLK9VnFYu3q5Z+G Y X-Gm-Gg: ASbGncssmamamS+B6Xds2OcESa+7IEx4ZaRQehOs3jgfSdAuKNm576PpPXEVbuDo61G CNncBxrUmHDCxXEeLjPPxmuBDrTqV8Flemgtr1nfeo9VQdu/wEf18xaZrdLqNcRfcYrNmw3fzYN FzJE/k+0anU9/E/TyRnz9y3E4Ory5qJDdR+tZGUggpWHL4yB3rnjmYuDolcv1d9UCKZJV3YocKf 7pbkKzUHG5vLhmBYLvMd0RQ4eo26Z8DtwvCu3Hd2gavB964DLoB8YHvFnHwCL67lOa5gSRVNGkF 5kX//nHM8QbtgjGnkKe4MlTdINmeQPHh6h8ERLAcJz4dSjrIxytupUxms4duY51C7vIpGn37v1K bTs93ndDXL2JworfMfdA= X-Google-Smtp-Source: AGHT+IHc1LVnOgavvev5XnkpmYMq0e6WzcUCiI3zOA5mhol2kloudBiNfkN+fIfm+6kKRlyIRy6cnQ== X-Received: by 2002:a05:6512:2255:b0:549:4416:df02 with SMTP id 2adb3069b0e04-54ad0678646mr1146949e87.41.1742479252674; Thu, 20 Mar 2025 07:00:52 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:51 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] mmc: core: Convert into an enum for the poweroff-type for eMMC Date: Thu, 20 Mar 2025 15:00:34 +0100 Message-ID: <20250320140040.162416-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-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 Signed-off-by: Ulf Hansson Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- drivers/mmc/core/mmc.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 400dd0449fec..60af88ac0213 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -33,6 +33,11 @@ #define MIN_CACHE_EN_TIMEOUT_MS 1600 #define CACHE_FLUSH_TIMEOUT_MS 30000 /* 30s */ +enum mmc_poweroff_type { + MMC_POWEROFF_SUSPEND, + MMC_POWEROFF_SHUTDOWN, +}; + static const unsigned int tran_exp[] = { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 @@ -2015,15 +2020,16 @@ static bool mmc_can_poweroff_notify(const struct mmc_card *card) } static bool mmc_may_poweroff_notify(const struct mmc_host *host, - bool is_suspend) + enum mmc_poweroff_type pm_type) { if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) return true; - if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && is_suspend) + if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND && + pm_type == MMC_POWEROFF_SUSPEND) return true; - return !is_suspend; + return pm_type == MMC_POWEROFF_SHUTDOWN; } static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) @@ -2120,11 +2126,13 @@ static int _mmc_flush_cache(struct mmc_host *host) return err; } -static int _mmc_suspend(struct mmc_host *host, bool is_suspend) +static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type) { + unsigned int notify_type = EXT_CSD_POWER_OFF_SHORT; int err = 0; - unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT : - EXT_CSD_POWER_OFF_LONG; + + if (pm_type == MMC_POWEROFF_SHUTDOWN) + notify_type = EXT_CSD_POWER_OFF_LONG; mmc_claim_host(host); @@ -2136,7 +2144,7 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend) goto out; if (mmc_can_poweroff_notify(host->card) && - mmc_may_poweroff_notify(host, is_suspend)) + mmc_may_poweroff_notify(host, pm_type)) err = mmc_poweroff_notify(host->card, notify_type); else if (mmc_can_sleep(host->card)) err = mmc_sleep(host); @@ -2159,7 +2167,7 @@ static int mmc_suspend(struct mmc_host *host) { int err; - err = _mmc_suspend(host, true); + err = _mmc_suspend(host, MMC_POWEROFF_SUSPEND); if (!err) { pm_runtime_disable(&host->card->dev); pm_runtime_set_suspended(&host->card->dev); @@ -2202,11 +2210,11 @@ static int mmc_shutdown(struct mmc_host *host) * before we can shutdown it properly. */ if (mmc_can_poweroff_notify(host->card) && - !mmc_may_poweroff_notify(host, true)) + !mmc_may_poweroff_notify(host, MMC_POWEROFF_SUSPEND)) err = _mmc_resume(host); if (!err) - err = _mmc_suspend(host, false); + err = _mmc_suspend(host, MMC_POWEROFF_SHUTDOWN); return err; } @@ -2230,7 +2238,7 @@ static int mmc_runtime_suspend(struct mmc_host *host) if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) return 0; - err = _mmc_suspend(host, true); + err = _mmc_suspend(host, MMC_POWEROFF_SUSPEND); if (err) pr_err("%s: error %d doing aggressive suspend\n", mmc_hostname(host), err); From patchwork Thu Mar 20 14:00:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024016 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 772FD2253FB for ; Thu, 20 Mar 2025 14:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479260; cv=none; b=NHOK+kp62dJP2PDwzgI1szFTjjvZuy2S/eXPExsXpl2gn8VUYJH6415EeJ2sjSB/tJD1Ni0k8hWSsm6RfnjriDqu8FGbgqJvB+HNlITcFIdIB5medeBJVVTDDCFFWDH+LIzmkPCZ2UMGx9gW+GNm9uCc5iGcs18OX3nPGzpQDJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479260; c=relaxed/simple; bh=5q7KCE9db7ERhm5lr7U4Yg37JmaxdnTD/f+2sXkyzxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZmVfsbfQ0ewgFwEiS2RLwZtcp2VyCnL/foSN81pr6qPqKOCT9zRzBmrwM4byV+wj2sn3YE/vm+2yeA1LIpuhnt4WZ1P5uRIb6m2VgJdDBscO1x0IA6NrVuMtmltWvhPBeWZo5NS9JSSZTXgk8hQB7F5aDzgJWXjaO2poyHGOKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=xiTQvwwU; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xiTQvwwU" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5493b5bc6e8so877233e87.2 for ; Thu, 20 Mar 2025 07:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479256; x=1743084056; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rXE9dlseC0dhD7d4oX2r9ZUURR/ikgG5O0SCUhzKJLQ=; b=xiTQvwwUQMwy2rT+pjfqAWF6BwGiO35f3I4+17xJhhQRNv9pdDy/0/tTguJ2Cpd0c8 CJ+SBoG56JHPylJmxEX6nXspuwd98YAs2wzXaGSVeuJQ5BVSrymVnYYvVJpbPe0D+IKf 0lWWwnz0i8IlN5C9Z0umiA5mTxsmr8J0DBphm4fMb43o+DIxFlWp8gG5HbC2ulxzlUdq wmAjL5V2BWkJ66WfXdc4H2NSxvyVU+mZLYU68j8kREDg+uUKrGCizsy1JUupUnp+IyId qUh5OKBXbA/o0t8XoUKyggFwTtDi4sFzoTm7F+6NgQ+3TCy2Yv3gFT7x+X+djZ1JhIKH uA+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479256; x=1743084056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rXE9dlseC0dhD7d4oX2r9ZUURR/ikgG5O0SCUhzKJLQ=; b=Su4y8lvWdgMs6gC7bDN3QqVybYOkJfZmy2p1wRZLUQe72ieF5xKFwlDwUNOoe9C1O2 jVcIg1aJgiB9Ne6t0eCaa4tPW4hGVdwXq0F1kfjJzb/JyCKkuE+8MohJ1nERn50dWtgc fZTziilyKqinNZQSfDSGgk3g0idi3St0SsAxXBJQ/ZDq8CKFZbQAAK96Cc8tU+g0eW2l mRstx8Bls6sQBJAaHLi9rLSzOR+UTxoHTarBTHpIRK4HwPkDqskBeQa8VCHNMutH2iEg c8JB3Mffkv1pro3dxhKx1itnj3SA3dbMCZn15s6cxMCJYS9UGbRBu2lnDaRUJSi7Db1R xpmQ== X-Gm-Message-State: AOJu0YwSzni0VCVJlM2IRnZcutmoT0n0OeEeuamJsFgJZtG0RCjSsixe vkqyhpsHjCqlXfNr957IX57aYe6gxkU+ZQF1RhnyzyqsGqJVS78lJ6w1Gb4r0oxQcIC7lwV/cSI d X-Gm-Gg: ASbGnctv/dPuxljcqLo8pj96USCnUb6m9PiDLw9uKF/gHNobbGeRInCeHPTQ7hwJFxK eDmouvADHsGQhfn1VNdiqjJPEamLH6EGsFU6TgyMaIwCTws8B4bbdWEI+E9zvmHQ+QZzuSNXVRV IQgCzyhGd71JZIS4QW49e8kQXx+UUrjw8uobXqH5eeNN0GHSSzb+uy8q2GO4i3CTUvl8wrgSPQx ls2rxV4vUDuw6yFl+cFK1HW5HSI6WiB33fLqysHI7Vj7YmAQ9WR8wltw3vgC1RxvwmgHw9Wykgq Fzmbe8oSlq48x1S+T3nEgBsrbNOHxSvuV+U0nMB+JAi5Y0pTb7ngaPSoFW8183pzvY0HCy2u6wn ymh6Q+io5pQZGonU8Ga+JpkU4o90M4A== X-Google-Smtp-Source: AGHT+IHyRLgkNoCEkf9M1ICxzrsASm6on3//oo9APTxgLDD9aYJ0CrJh/ehpG879EGIFtCHQch+O4A== X-Received: by 2002:a05:6512:b99:b0:54a:cc04:ea24 with SMTP id 2adb3069b0e04-54ad068688cmr1116238e87.46.1742479254697; Thu, 20 Mar 2025 07:00:54 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:54 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mmc: core: Add support for graceful host removal for eMMC Date: Thu, 20 Mar 2025 15:00:35 +0100 Message-ID: <20250320140040.162416-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-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 Signed-off-by: Ulf Hansson Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- drivers/mmc/core/mmc.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 60af88ac0213..5a62a3d3df32 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -36,6 +36,7 @@ enum mmc_poweroff_type { MMC_POWEROFF_SUSPEND, MMC_POWEROFF_SHUTDOWN, + MMC_POWEROFF_UNBIND, }; static const unsigned int tran_exp[] = { @@ -2054,15 +2055,6 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) return err; } -/* - * Host is being removed. Free up the current card. - */ -static void mmc_remove(struct mmc_host *host) -{ - mmc_remove_card(host->card); - host->card = NULL; -} - /* * Card detection - card is alive. */ @@ -2088,7 +2080,8 @@ static void mmc_detect(struct mmc_host *host) mmc_put_card(host->card, NULL); if (err) { - mmc_remove(host); + mmc_remove_card(host->card); + host->card = NULL; mmc_claim_host(host); mmc_detach_bus(host); @@ -2160,6 +2153,20 @@ static int _mmc_suspend(struct mmc_host *host, enum mmc_poweroff_type pm_type) return err; } +/* + * Host is being removed. Free up the current card and do a graceful power-off. + */ +static void mmc_remove(struct mmc_host *host) +{ + get_device(&host->card->dev); + mmc_remove_card(host->card); + + _mmc_suspend(host, MMC_POWEROFF_UNBIND); + + put_device(&host->card->dev); + host->card = NULL; +} + /* * Suspend callback */ From patchwork Thu Mar 20 14:00:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14024017 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72322225410 for ; Thu, 20 Mar 2025 14:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479261; cv=none; b=UZyUlMtSr2vXfESlveZdBQYJ6hc6B0D4HfYtoRrc71St3jC887vn+LPgI/Az5ct4bCDtgxWhoG2XEPSNQGQuTXEISAhvUVoWVUThquyjOqyBBoKW9iHIdmrp5D7/0+UR3+61iWLRjDRNyZit4mVv9o/S7xo7nqQVS8ZJA9hc+fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742479261; c=relaxed/simple; bh=tJcpx7kVoOVh62Qzq7CsqXZyteSS2xTmfx3MklEEb5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qbcxnb7N4bJwSxpNZdEy+kLnkuom9g8F1cGzhwbw3B//NW0h1hMNcyO8AhUGkd5J0bq3bHU2OVRHUauCBBlRwQY7ryM1DTgs7Un5alr/PuA5KUzNIMsC8ylvOq4mrnPeGsz9wJCW818gDTXWvEOY5J7OdPG0wKwC3FegdLXcaAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ovGwlYVK; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ovGwlYVK" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-548430564d9so861775e87.2 for ; Thu, 20 Mar 2025 07:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742479257; x=1743084057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+cpurPguaZZPLjWUcw85lV4P2hxnhe8DmTCMrQ+sP8E=; b=ovGwlYVK5p5MCyM7n0n+8jzkYo3MDkQnvXTmQoBhq/Fjh5q1C8rjW8+ORWSc16MwdC bfG2H8MJeRj1WXehec8O2cCg/yKJGsAJG6c2aSvvVjDVuAuWKHkNW7bKFLr9cHUW0cXS OFIplJZpUJGcrZxpKZNOArUOjXFd8NcXyA4RNcOAfcjx8NcRArND8/CBRZlhB1k95wck vEdwWTfLJR+uvJDNLiE6CdoXE4l9g9eBPfyoAzQh3ixQMw+V/7yzpV/DFJYm0fpcpumN VvgkXx0rWCMtS6OCHQNWYM/7W048E8KX3lh+NXGxFqOEo6zAlH1+MZ/FuRNcD7rRE4IC x7Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742479257; x=1743084057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+cpurPguaZZPLjWUcw85lV4P2hxnhe8DmTCMrQ+sP8E=; b=S2L7un5g3o4wgr3uXEKCPDn6XTzBB3qujvtxoJQwXl4Ipk3dQ1U31GtNqO7hE0TciH bUQWhJZChyoHUi2bgME+7yKi9XLUnY2Xmb2FY3xR+GHZHgABwMpGVVJnUBs1omYnxqKE IOCBIlkVPf2vcupABBfI03UBCCkW9W8Y5VL4N6ogXJZn07cB4c2g1Jw3N5hCVDOT3NNg 8EHYSgW8JDHksxjHaZU3dQRMKmh0GJh26z9JbDg1z3p8dx/oExIEc8IAMyfgiWtTdx3o f2LOUFkAHegAFSC4tXck+CO2FI+P0oLB4h1Yq/oAbcxTZQQ7Yl/8Lg1EnyiBLMfHYkBY wY3A== X-Gm-Message-State: AOJu0YyMGkKtLIlt8MBIwk32qI/6nPffDsFRMDcKq7pMSKWu/Ib9hLI7 Zdh0bKTkCPKUoXlap0I3crvwKA4ZuubxHvvyhDQ2d5SjILWDlYR14mrQycN6Kq8JDBfrJ7LiBj5 V X-Gm-Gg: ASbGncuwlVDjia4Y7g1K1zwUCuJ9Ik2bkt5vYagZb5KDqZnUYD6+5WV3qzfZmg9M16V qwyFPCuLqQADMEasAuznSGTNilpotzgpVe+JTMC+Bf48xKqhahyNB4mfDSxhmZUseu3JuEUIIgW MP3h49RqywjnU3ZfAmr5t0/4H9JSf68fkgmU7h0N/PgXcPpEswHfamCrJocYdEyWGPb5xeqlgjZ fcpa4vzjaqZyB2MIkn09j+euTHHxLTcmnqUDpxN13u1sG2ySa0ivS7eqYj0/ntLigj+v/AdMPmk yj+cuit8b31d8MJTx0KqEi26Gvq9DXfjd2Uu6O073b3JmDP46iZJrXHgL7lvuviQNAAF6oM8KAu //Vd+3lF0bijcFUIdjgoa+PKuyXiFCA== X-Google-Smtp-Source: AGHT+IFI1fZrjfRWED8P3YwlNenPg/UaJprkHPw65/8Gv1KQD06yFcLy7lNo8+Ww7atrOreTQU9wBQ== X-Received: by 2002:a05:6512:400c:b0:549:9078:dd46 with SMTP id 2adb3069b0e04-54acb21a517mr2932004e87.43.1742479256977; Thu, 20 Mar 2025 07:00:56 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864dd9sm2295029e87.148.2025.03.20.07.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 07:00:56 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Yoshihiro Shimoda , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mmc: core: Add support for graceful host removal for SD Date: Thu, 20 Mar 2025 15:00:36 +0100 Message-ID: <20250320140040.162416-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org> References: <20250320140040.162416-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-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. Signed-off-by: Ulf Hansson Reviewed-by: Wolfram Sang --- drivers/mmc/core/sd.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 8eba697d3d86..cb4254a43f85 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1596,15 +1596,6 @@ static int mmc_sd_init_card(struct mmc_host *host, 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 */