The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 0/3] mmc: Add power_off_delay_us support
@ 2026-07-22 20:56 Judith Mendez
  2026-07-22 20:56 ` [PATCH v2 1/3] dt-bindings: mmc: Add power-off-delay-us property Judith Mendez
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Judith Mendez @ 2026-07-22 20:56 UTC (permalink / raw)
  To: Judith Mendez, Ulf Hansson, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-mmc, devicetree, linux-kernel

This series adds power_off_delay_us support for MMC controllers,
enabling boards to specify custom delays after MMC power off to work around
hardware issues such as slow RC circuites on MMC VDD rails.

Rather than adding host driver-specific workarounds, we abstract the
implementation into the MMC core and pickup the delay value with a device
tree property (power-off-delay-us). This allows any board with slow
power off requirements to configure the necessary delay without code
changes.

The solution is minimal and follows existing patterns as with
power_delay_ms. The allowed minimum value = 1us and maximum value=
10000000us. The default value is 1000us to not deviate from the
original 1ms delay set in mmc_power_off().

Requesting comments for how big the delay should be maxed at, currently
it is set to 10000000us, but not sure if this is too high. Testing
10000000us on AM65 EVM seems to not break SD boot so going with this
value as the max allowed value for now.

Link to v1:
https://lore.kernel.org/all/20260716232641.2659710-1-jm@ti.com/

Changes since v1:
- Add mmc_delay_us()
- Switch from ms to us implementation due to switch from
  post_power_on_delay_ms to power_off_delay_us
- Update commit messages to include more coverletter descriptions

Judith Mendez (3):
  dt-bindings: mmc: Add power-off-delay-us property
  mmc: core: Add mmc_delay_us() for microsecond precision delays
  mmc: core: Add power-off-delay-us support

 .../bindings/mmc/mmc-controller-common.yaml         | 10 ++++++++++
 drivers/mmc/core/core.c                             |  2 +-
 drivers/mmc/core/core.h                             | 13 +++++++++++++
 drivers/mmc/core/host.c                             |  8 ++++++++
 include/linux/mmc/host.h                            |  1 +
 5 files changed, 33 insertions(+), 1 deletion(-)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] dt-bindings: mmc: Add power-off-delay-us property
  2026-07-22 20:56 [PATCH v2 0/3] mmc: Add power_off_delay_us support Judith Mendez
@ 2026-07-22 20:56 ` Judith Mendez
  2026-07-22 20:57 ` [PATCH v2 2/3] mmc: core: Add mmc_delay_us() for microsecond precision delays Judith Mendez
  2026-07-22 20:57 ` [PATCH v2 3/3] mmc: core: Add power-off-delay-us support Judith Mendez
  2 siblings, 0 replies; 5+ messages in thread
From: Judith Mendez @ 2026-07-22 20:56 UTC (permalink / raw)
  To: Judith Mendez, Ulf Hansson, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-mmc, devicetree, linux-kernel

Add power-off-delay-us property to MMC controller common.

This property shall be used to specify value of delay after
deasserting power during MMC power cycles. Default for delay
is 1000us but custom delay can be passed in to work around
hardware issues such as slow RC discharge on MMC VDD rails.

Signed-off-by: Judith Mendez <jm@ti.com>
---
Changes since v1:
- Change post-power-off-delay-ms to power-off-delay-us
- Fixup dt property description
- Fix check binding warnings and remove $ref
- Fix minimum from 0 to 1us
---
 .../devicetree/bindings/mmc/mmc-controller-common.yaml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml b/Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml
index 3d7195e9461c3..2015292618c80 100644
--- a/Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml
+++ b/Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml
@@ -275,6 +275,16 @@ properties:
       not available.
     default: 10
 
+  power-off-delay-us:
+    description:
+      Delay in microseconds after card power is deasserted during a power
+      cycle to allow time for proper power discharge. Larger values can be
+      configured to work around hardware issues such as slow RC discharge
+      on MMC VDD rails.
+    minimum: 1
+    maximum: 10000000
+    default: 1000
+
   supports-cqe:
     $ref: /schemas/types.yaml#/definitions/flag
     description:
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] mmc: core: Add mmc_delay_us() for microsecond precision delays
  2026-07-22 20:56 [PATCH v2 0/3] mmc: Add power_off_delay_us support Judith Mendez
  2026-07-22 20:56 ` [PATCH v2 1/3] dt-bindings: mmc: Add power-off-delay-us property Judith Mendez
@ 2026-07-22 20:57 ` Judith Mendez
  2026-07-24 22:17   ` Sebastian Reichel
  2026-07-22 20:57 ` [PATCH v2 3/3] mmc: core: Add power-off-delay-us support Judith Mendez
  2 siblings, 1 reply; 5+ messages in thread
From: Judith Mendez @ 2026-07-22 20:57 UTC (permalink / raw)
  To: Judith Mendez, Ulf Hansson, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-mmc, devicetree, linux-kernel

Add mmc_delay_us() to support microsecond-granularity delays needed
in MMC framework. It uses 25% margin consistent with  mmc_delay() for
timing flexibility.

Signed-off-by: Judith Mendez <jm@ti.com>
---
Changes since v1:
- add patch 2/3
---
 drivers/mmc/core/core.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index a028b48be1644..55e9fb3bab9f7 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -73,6 +73,19 @@ static inline void mmc_delay(unsigned int ms)
 		msleep(ms);
 }
 
+static inline void mmc_delay_us(unsigned int us)
+{
+	if (us < 1000) {
+		usleep_range(us, us + (us >> 2));
+	} else {
+		unsigned int rem_us = us % 1000;
+
+		msleep(us / 1000);
+		if (rem_us)
+			usleep_range(rem_us, rem_us + (rem_us >> 2));
+	}
+}
+
 void mmc_rescan(struct work_struct *work);
 void mmc_start_host(struct mmc_host *host);
 void __mmc_stop_host(struct mmc_host *host);
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] mmc: core: Add power-off-delay-us support
  2026-07-22 20:56 [PATCH v2 0/3] mmc: Add power_off_delay_us support Judith Mendez
  2026-07-22 20:56 ` [PATCH v2 1/3] dt-bindings: mmc: Add power-off-delay-us property Judith Mendez
  2026-07-22 20:57 ` [PATCH v2 2/3] mmc: core: Add mmc_delay_us() for microsecond precision delays Judith Mendez
@ 2026-07-22 20:57 ` Judith Mendez
  2 siblings, 0 replies; 5+ messages in thread
From: Judith Mendez @ 2026-07-22 20:57 UTC (permalink / raw)
  To: Judith Mendez, Ulf Hansson, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-mmc, devicetree, linux-kernel

Add support for power-off-delay-us which shall be used to specify
value of delay after deasserting power during MMC power cycles.
Default for delay is 1000us but custom delay can be passed in to work
around hardware issues such as slow RC discharge on MMC VDD rails.

Signed-off-by: Judith Mendez <jm@ti.com>
---
Changes since v1:
- Move delay to mmc_power_off
- Fix dt checks and remove print
- Move from mmc_host struct to mmc_ios struct
- Rename post-power-off-delay-ms to power_off_delay_us
---
 drivers/mmc/core/core.c  | 2 +-
 drivers/mmc/core/host.c  | 8 ++++++++
 include/linux/mmc/host.h | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 29e80e5f928e9..9472041fe1c20 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1388,7 +1388,7 @@ void mmc_power_off(struct mmc_host *host)
 	 * XO-1.5, require a short delay after poweroff before the card
 	 * can be successfully turned on again.
 	 */
-	mmc_delay(1);
+	mmc_delay_us(host->ios.power_off_delay_us);
 }
 
 void mmc_power_cycle(struct mmc_host *host, u32 ocr)
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index b7ce3137d4529..fac50a2860211 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -421,6 +421,13 @@ int mmc_of_parse(struct mmc_host *host)
 	device_property_read_u32(dev, "post-power-on-delay-ms",
 				 &host->ios.power_delay_ms);
 
+	device_property_read_u32(dev, "power-off-delay-us",
+				 &host->ios.power_off_delay_us);
+	if (host->ios.power_off_delay_us < 1)
+		host->ios.power_off_delay_us = 1000;
+	if (host->ios.power_off_delay_us > 10000000)
+		host->ios.power_off_delay_us = 10000000;
+
 	return mmc_pwrseq_alloc(host);
 }
 
@@ -574,6 +581,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 
 	host->fixed_drv_type = -EINVAL;
 	host->ios.power_delay_ms = 10;
+	host->ios.power_off_delay_us = 1000;
 	host->ios.power_mode = MMC_POWER_UNDEFINED;
 
 	return host;
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index ba84f02c2a101..714417466707c 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -23,6 +23,7 @@ struct mmc_ios {
 	unsigned int	clock;			/* clock rate */
 	unsigned short	vdd;
 	unsigned int	power_delay_ms;		/* waiting for stable power */
+	unsigned int	power_off_delay_us;	/* waiting for power discharge */
 
 /* vdd stores the bit number of the selected voltage range from below. */
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/3] mmc: core: Add mmc_delay_us() for microsecond precision delays
  2026-07-22 20:57 ` [PATCH v2 2/3] mmc: core: Add mmc_delay_us() for microsecond precision delays Judith Mendez
@ 2026-07-24 22:17   ` Sebastian Reichel
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2026-07-24 22:17 UTC (permalink / raw)
  To: Judith Mendez
  Cc: Ulf Hansson, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-mmc, devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

Hi,

On Wed, Jul 22, 2026 at 03:57:00PM -0500, Judith Mendez wrote:
> Add mmc_delay_us() to support microsecond-granularity delays needed
> in MMC framework. It uses 25% margin consistent with  mmc_delay() for
> timing flexibility.
> 
> Signed-off-by: Judith Mendez <jm@ti.com>
> ---
> Changes since v1:
> - add patch 2/3
> ---

Looks like you should just use fsleep() from <linux/delay.h>.

Greetings,

-- Sebastian

>  drivers/mmc/core/core.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
> index a028b48be1644..55e9fb3bab9f7 100644
> --- a/drivers/mmc/core/core.h
> +++ b/drivers/mmc/core/core.h
> @@ -73,6 +73,19 @@ static inline void mmc_delay(unsigned int ms)
>  		msleep(ms);
>  }
>  
> +static inline void mmc_delay_us(unsigned int us)
> +{
> +	if (us < 1000) {
> +		usleep_range(us, us + (us >> 2));
> +	} else {
> +		unsigned int rem_us = us % 1000;
> +
> +		msleep(us / 1000);
> +		if (rem_us)
> +			usleep_range(rem_us, rem_us + (rem_us >> 2));
> +	}
> +}
> +
>  void mmc_rescan(struct work_struct *work);
>  void mmc_start_host(struct mmc_host *host);
>  void __mmc_stop_host(struct mmc_host *host);
> -- 
> 2.54.0
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-24 22:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 20:56 [PATCH v2 0/3] mmc: Add power_off_delay_us support Judith Mendez
2026-07-22 20:56 ` [PATCH v2 1/3] dt-bindings: mmc: Add power-off-delay-us property Judith Mendez
2026-07-22 20:57 ` [PATCH v2 2/3] mmc: core: Add mmc_delay_us() for microsecond precision delays Judith Mendez
2026-07-24 22:17   ` Sebastian Reichel
2026-07-22 20:57 ` [PATCH v2 3/3] mmc: core: Add power-off-delay-us support Judith Mendez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox