mmc: Add post-power-off-delay-ms support
Subsystems (2)
PATCH 1/2 dt-bindings: mmc: Add post-power-off-delay-ms property
In reply to Judith MendezAdd post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +8 -0
@@ -275,6 +275,14 @@ properties: not available. default: 10 + post-power-off-delay-ms: + description: + The presence of this property indicates that the card requires a + delay (in milliseconds) after power off before the next power on. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 10000 + supports-cqe: $ref: /schemas/types.yaml#/definitions/flag description:
Signature · 1 line
2.54.0
PATCH 2/2 mmc: core: Add post-power-off-delay-ms support
In reply to Judith MendezAdd support for post-power-off-delay-ms which shall be used to insert a configurable delay post MMC power off.
--- drivers/mmc/core/core.c | 8 ++++++-- drivers/mmc/core/host.c | 8 ++++++++ include/linux/mmc/host.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-)
drivers/mmc/core/core.c +6 -2
@@ -1394,8 +1394,12 @@ void mmc_power_off(struct mmc_host *host)void mmc_power_cycle (struct mmc_host *host,u32 ocr) {mmc_power_off (host); -/* Wait at least 1 ms according to SD spec */ -mmc_delay (1 ); +if (host->post_power_off_delay_ms) { +mmc_delay (host->post_power_off_delay_ms); + }else { +/* Wait at least 1 ms according to SD spec */ +mmc_delay (1 ); + }mmc_power_up (host, ocr); }
drivers/mmc/core/host.c +8 -0
@@ -421,6 +421,14 @@ 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,"post-power-off-delay-ms" , + &host->post_power_off_delay_ms); +if (host->post_power_off_delay_ms >10000 ) { +dev_err (dev,"post-power-off-delay-ms %u exceeds max 10000, setting 10000\n" , + host->post_power_off_delay_ms); + host->post_power_off_delay_ms =10000 ; + } +return mmc_pwrseq_alloc (host); }
include/linux/mmc/host.h +1 -0
@@ -578,6 +578,7 @@ struct mmc_host {u32 err_stats[MMC_ERR_MAX ];u32 max_sd_hs_hz; +u32 post_power_off_delay_ms;unsigned long private[]____cacheline_aligned ; };
Signature · 1 line
2.54.0
cover mmc: Add post-power-off-delay-ms support
This series adds post-power-off-delay-ms 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 (post-power-off-delay-ms). This allows any board with slow power off requirements to configure the necessary delay without code changes.
Requesting comments for how big the delay should be maxed at, currently it is set to 10000ms, but not sure if this is too high.
The solution is minimal and follows existing patterns as with (post-power-on-delay-ms).
Judith Mendez (2):
dt-bindings: mmc: Add post-power-off-delay-ms property
mmc: core: Add post-power-off-delay-ms support
.../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ drivers/mmc/core/core.c | 8 ++++++-- drivers/mmc/core/host.c | 8 ++++++++ include/linux/mmc/host.h | 1 + 4 files changed, 23 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 2/2] mmc: core: Add post-power-off-delay-ms support
In reply to Judith MendezThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The `post-power-off-delay-ms` hardware constraint is only enforced in `mmc_power_cycle()`…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The post-power-off-delay-ms hardware constraint is only enforced in mmc_power_cycle(), leaving decoupled power-off/power-on sequences vulnerable to hardware timing violations.
- [Low] Explicitly configuring a 0 ms post-power-off delay in the device tree is ignored, falling back to the 1 ms default.
--
--- Patch [2]: [PATCH 2/2] mmc: core: Add post-power-off-delay-ms support --- commit 36ce7de56b9b7e7608c56353aede4cb3de73df5b
Author: Judith Mendez <[email protected]>
mmc: core: Add post-power-off-delay-ms support
This commit adds support for post-power-off-delay-ms, allowing a configurable delay after an MMC power off.
Quoted 6 lines
drivers/mmc/core/core.c +0
-0@@ -1394,8 +1394,12 @@ void mmc_power_off(struct mmc_host *host)void mmc_power_cycle (struct mmc_host *host,u32 ocr)
drivers/mmc/core/core.c void mmc_power_off(struct mmc_host *host) · line 1402
Quoted 10 lines
drivers/mmc/core/core.c +6
-2{mmc_power_off (host); -/* Wait at least 1 ms according to SD spec */ -mmc_delay (1 ); +if (host->post_power_off_delay_ms) { +mmc_delay (host->post_power_off_delay_ms); + }else { +/* Wait at least 1 ms according to SD spec */ +mmc_delay (1 ); + }
[Severity: Medium]
Will this delay be missed for decoupled power-off and power-on sequences?
If a device relies on post-power-off-delay-ms (e.g., 100ms) but goes through a runtime PM suspend or system suspend, mmc_power_off() will be called, followed later by mmc_power_up(). Because the delay is only enforced here in mmc_power_cycle(), will the decoupled off/on path violate the power-off time constraint?
Could mmc_power_off() record a timestamp, and mmc_power_up() calculate the elapsed time to only delay the remaining required duration?
[Severity: Low]
Does this ignore an explicitly configured 0 ms delay?
If a developer explicitly specifies post-power-off-delay-ms = <0> in the device tree, this condition will evaluate to false and unexpectedly fall back to the 1 ms default.
Could this be resolved by initializing the default value in mmc_alloc_host() and removing the if/else condition here?
Quoted 2 lines
drivers/mmc/core/core.c +0
-0mmc_power_up (host, ocr); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Rob Herring (Arm)
maintainerRe: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
In reply to Judith MendezQuoted 10 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Signed-off-by Judith Mendez <[email protected]>--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml: properties:post-power-off-delay-ms: '$ref' should not be valid under {'const': '$ref'}
hint: Standard unit suffix properties don't need a type $ref
from schema $id: http://devicetree.org/meta-schemas/core.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.kernel.org/project/devicetree/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
In reply to Judith MendezQuoted 5 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Please clarify with some additional information from the cover-letter, like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 11 lines
Signed-off-by Judith Mendez <[email protected]>--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +0
-0
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 278
Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-0@@ -275,6 +275,14 @@ properties: not available. default: 10 + post-power-off-delay-ms:
For mmc-pwrseq-simple we already have "power-off-delay-us", perhaps better to re-use that name instead.
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 281
Quoted 3 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +3
-0+ description: + The presence of this property indicates that the card requires a + delay (in milliseconds) after power off before the next power on.
Again, maybe something to indicate this is specific like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 284
Quoted 3 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +3
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 10000
Are the above limits needed at all?
I suggest we add a "default: 1", as that would correspond to the hardcoded value that the mmc core currently uses for this delay.
Quoted 7 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-1+ supports-cqe: $ref: /schemas/types.yaml#/definitions/flag description: --2.54.0
Kind regards
Uffe
Re: [PATCH 2/2] mmc: core: Add post-power-off-delay-ms support
In reply to Judith MendezQuoted 16 lines · Judith Mendez
Add support for post-power-off-delay-ms which shall be used to insert a configurable delay post MMC power off.
Signed-off-by Judith Mendez <[email protected]>--- drivers/mmc/core/core.c | 8 ++++++-- drivers/mmc/core/host.c | 8 ++++++++ include/linux/mmc/host.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-)drivers/mmc/core/core.c +0
-0
drivers/mmc/core/core.c void mmc_power_off(struct mmc_host *host) · line 1398
Quoted 5 lines
drivers/mmc/core/core.c +0
-2@@ -1394,8 +1394,12 @@ void mmc_power_off(struct mmc_host *host)void mmc_power_cycle (struct mmc_host *host,u32 ocr) {mmc_power_off (host); -/* Wait at least 1 ms according to SD spec */ -mmc_delay (1 );
The above delay is kind of questionable in the first place, as we already have a mmc_delay(1) at the end of mmc_power_off().
Maybe the delay is needed for legacy reasons and because of that, I would suggest that we leave mmc_power_cycle() as is, for now. In the end, I would rather see that the above delay gets removed altogether.
Instead, how about making the mmc_delay(1) in mmc_power_off() configurable?
Moreover, rather than the code below, I think it would be better to set a default value for "host->post_power_off_delay_ms" to 1 in mmc_alloc_host(). In fact, there is already similar code for "host->ios.power_delay_ms", please try to follow that for this case too.
Quoted 41 lines
drivers/mmc/core/core.c +6
-0+if (host->post_power_off_delay_ms) { +mmc_delay (host->post_power_off_delay_ms); + }else { +/* Wait at least 1 ms according to SD spec */ +mmc_delay (1 ); + }mmc_power_up (host, ocr); }drivers/mmc/core/host.c +8
-0@@ -421,6 +421,14 @@ 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,"post-power-off-delay-ms" , + &host->post_power_off_delay_ms); +if (host->post_power_off_delay_ms >10000 ) { +dev_err (dev,"post-power-off-delay-ms %u exceeds max 10000, setting 10000\n" , + host->post_power_off_delay_ms); + host->post_power_off_delay_ms =10000 ; + } +return mmc_pwrseq_alloc (host); }include/linux/mmc/host.h +1
-1@@ -578,6 +578,7 @@ struct mmc_host {u32 err_stats[MMC_ERR_MAX ];u32 max_sd_hs_hz; +u32 post_power_off_delay_ms;unsigned long private[]____cacheline_aligned ; }; --
Quoted 2 lines
2.54.0
Kind regards
Uffe
Re: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
In reply to Ulf HanssonHi Ulf,
Quoted 25 lines · Ulf Hansson
Quoted 5 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Please clarify with some additional information from the cover-letter, like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 14 lines
Signed-off-by Judith Mendez <[email protected]>--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +0
-0@@ -275,6 +275,14 @@ properties: not available. default: 10
Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 278
Quoted 1 line
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-0+ post-power-off-delay-ms:For mmc-pwrseq-simple we already have "power-off-delay-us", perhaps better to re-use that name instead.
Besides having the same dt property name as mmc-pwrseq-simple what is the benefit of switching to power-off-delay-us?
All values will have to be in us instead of ms and thus will look a bit less clean in code. If it is just a naming preference, I do prefer the current name in this version, please let me know if we can keep:
post-power-off-delay-ms.
All other comments I agree with and will fix in v2.
Thanks for reviewing (:
~ Judith
Quoted 28 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 281
Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +3
-0+ description: + The presence of this property indicates that the card requires a + delay (in milliseconds) after power off before the next power on.Again, maybe something to indicate this is specific like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 284
Quoted 3 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +3
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 10000Are the above limits needed at all?
I suggest we add a "default: 1", as that would correspond to the hardcoded value that the mmc core currently uses for this delay.
Quoted 7 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-1+ supports-cqe: $ref: /schemas/types.yaml#/definitions/flag description: --2.54.0
Kind regards
Uffe
Re: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
Hi Ulf,
Quoted 33 lines · Judith Mendez
Hi Ulf,
Quoted 25 lines · Ulf Hansson
Quoted 5 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Please clarify with some additional information from the cover-letter, like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 14 lines
Signed-off-by Judith Mendez <[email protected]>---
.../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++1 file changed, 8 insertions(+)Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +0
-0@@ -275,6 +275,14 @@ properties:not available.
default: 10Quoted 4 lines
Quoted 1 line
+ post-power-off-delay-ms:
For mmc-pwrseq-simple we already have "power-off-delay-us", perhaps better to re-use that name instead.
Quoted 8 lines
Besides having the same dt property name as mmc-pwrseq-simple what is the benefit of switching to power-off-delay-us?
All values will have to be in us instead of ms and thus will look a bit less clean in code. If it is just a naming preference, I do prefer the current name in this version, please let me know if we can keep:
post-power-off-delay-ms.
Forgot to mention, we are using mmc_delay which takes ms, if we switch to microsecond dt property, we would have to make conversions or not use mmc_delay.
~ Judith
Re: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
In reply to Ulf HanssonHi Ulf,
Quoted 38 lines · Ulf Hansson
Quoted 5 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Please clarify with some additional information from the cover-letter, like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 11 lines
Signed-off-by Judith Mendez <[email protected]>--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +0
-0Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 278
Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-0@@ -275,6 +275,14 @@ properties: not available. default: 10 + post-power-off-delay-ms:For mmc-pwrseq-simple we already have "power-off-delay-us", perhaps better to re-use that name instead.
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 281
Quoted 3 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +3
-0+ description: + The presence of this property indicates that the card requires a + delay (in milliseconds) after power off before the next power on.Again, maybe something to indicate this is specific like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 5 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 284
Quoted 3 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +3
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 10000Are the above limits needed at all?
I would like to keep the limits from minimum 1ms to 10000ms just because likely someone will go ahead and add a huge delay and wonder why their board just crashed. I think 10000ms or 10s is large enough, what do you think?
...
Re: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
In reply to Judith MendezQuoted 29 lines · Judith Mendez
Hi Ulf,
Quoted 25 lines · Ulf Hansson
Quoted 5 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Please clarify with some additional information from the cover-letter, like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 14 lines
Signed-off-by Judith Mendez <[email protected]>--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +0
-0@@ -275,6 +275,14 @@ properties: not available. default: 10
Quoted 7 lines
Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 278
Quoted 1 line
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-0+ post-power-off-delay-ms:For mmc-pwrseq-simple we already have "power-off-delay-us", perhaps better to re-use that name instead.
Besides having the same dt property name as mmc-pwrseq-simple what is the benefit of switching to power-off-delay-us?
Using ms as the unit is limiting and completely unnecessary. What is some HW is fine with 300 us, for example.
Quoted 5 lines
All values will have to be in us instead of ms and thus will look a bit less clean in code. If it is just a naming preference, I do prefer the current name in this version, please let me know if we can keep:
post-power-off-delay-ms.
The code is a separate thing, this is the DT property for supporting different HWs.
[...]
Kind regards
Uffe
Re: [PATCH 1/2] dt-bindings: mmc: Add post-power-off-delay-ms property
Hi Ulf,
Quoted 35 lines · Ulf Hansson
Quoted 34 lines · Judith Mendez
Hi Ulf,
Quoted 29 lines · Ulf Hansson
Quoted 5 lines · Judith Mendez
Add post-power-off-delay-ms property to MMC controller common.
This property shall be used to specify delay if needed after deasserting power during MMC power cycles.
Please clarify with some additional information from the cover-letter, like "specify custom delays after MMC power off to work around hardware issues such as slow RC circuites on MMC VDD rails."
Quoted 11 lines
Signed-off-by Judith Mendez <[email protected]>--- .../devicetree/bindings/mmc/mmc-controller-common.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +0
-0Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml properties: · line 278
Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-controller-common.yaml +1
-0@@ -275,6 +275,14 @@ properties: not available. default: 10 + post-power-off-delay-ms:For mmc-pwrseq-simple we already have "power-off-delay-us", perhaps better to re-use that name instead.
Quoted 5 lines
Quoted 2 lines
Besides having the same dt property name as mmc-pwrseq-simple what is the benefit of switching to power-off-delay-us?
Using ms as the unit is limiting and completely unnecessary. What is some HW is fine with 300 us, for example.
Ok then, will use power-off-delay-us. thanks.
Quoted 9 lines
Quoted 6 lines
All values will have to be in us instead of ms and thus will look a bit less clean in code. If it is just a naming preference, I do prefer the current name in this version, please let me know if we can keep:
post-power-off-delay-ms.The code is a separate thing, this is the DT property for supporting different HWs.
got it, will fix and respin. thanks.
~ Judith