power: regulator: Fix power on/off delay issue
PATCH 1/1 power: regulator: Fix power on/off delay issue
SD initialization failure happens with some UHS-I SD cards on iMX8MM/iMX93/iMX91 EVK after
commit 4fcba5d556b4 ("regulator: implement basic reference counter"). When sending operation condition to SD card, the OCR does not return correct status. The root cause is regulator on/off delay is missed in MMC power cycle with above commit, so SD card is not completely power off.
When SD startup, the sequence of MMC power cycle is:mmc_power_init(get vmmc_supply dev) -> mmc_power_off -> udelay(2000) -> mmc_power_on
Before above commit, as a fixed regulator, the GPIO is set as:
GPIO inactive (in mmc_power_init) ->
GPIO inactive and delay off-on-delay-us (in mmc_power_off) -> udelay(2000) ->
GPIO active (in mmc_power_on)
After the commit:
GPIO inactive (in mmc_power_init) ->
enable_count is 0, regulator_set_enable returns -EALREADY immediately,
so GPIO is inactive but No off-on-delay-us (in mmc_power_off) ->
udelay(2000) ->
GPIO active (in mmc_power_on)
Add the on/off delay and startup delay after GPIO request in regulator_common_of_to_plat which is called in regulator device probing. So in mmc_power_init, after GPIO is set to default inactive, the off-on-delay-us is applied.
--- drivers/power/regulator/regulator_common.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/power/regulator/regulator_common.c +6 -0
@@ -46,6 +46,12 @@ int regulator_common_of_to_plat(struct udevice *dev,dev_read_u32_default (dev,"u-boot,off-on-delay-us" ,0 ); } +if ((flags &GPIOD_IS_OUT_ACTIVE ) && plat->startup_delay_us) +udelay (plat->startup_delay_us); + +if (!(flags &GPIOD_IS_OUT_ACTIVE ) && plat->off_on_delay_us) +udelay (plat->off_on_delay_us); +return 0 ; }
Signature · 1 line
2.37.1
Hi,
Quoted 40 lines · Ye Li
SD initialization failure happens with some UHS-I SD cards on iMX8MM/iMX93/iMX91 EVK after
commit4fcba5d556b4("regulator: implement basic reference counter"). When sending operation condition to SD card, the OCR does not return correct status. The root cause is regulator on/off delay is missed in MMC power cycle with above commit, so SD card is not completely power off.When SD startup, the sequence of MMC power cycle is:
mmc_power_init(get vmmc_supply dev)->mmc_power_off-> udelay(2000) ->mmc_power_onBefore above commit, as a fixed regulator, the GPIO is set as:
GPIO inactive (inmmc_power_init) ->
GPIO inactive and delay off-on-delay-us (inmmc_power_off) -> udelay(2000) ->
GPIO active (inmmc_power_on)After the commit:
GPIO inactive (inmmc_power_init) ->
enable_countis 0,regulator_set_enablereturns-EALREADYimmediately,so GPIO is inactive but No off-on-delay-us (in mmc_power_off) ->udelay(2000) ->
GPIO active (inmmc_power_on)Add the on/off delay and startup delay after GPIO request in
regulator_common_of_to_platwhich is called in regulator device probing. So inmmc_power_init, after GPIO is set to default inactive, the off-on-delay-us is applied.Signed-off-by Ye Li <[email protected]>--- drivers/power/regulator/regulator_common.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/power/regulator/regulator_common.c +0
-0
drivers/power/regulator/regulator_common.c int regulator_common_of_to_plat(struct udevice *dev, · line 53
Quoted 8 lines
drivers/power/regulator/regulator_common.c +5
-0@@ -46,6 +46,12 @@ int regulator_common_of_to_plat(struct udevice *dev,dev_read_u32_default (dev,"u-boot,off-on-delay-us" ,0 ); } +if ((flags &GPIOD_IS_OUT_ACTIVE ) && plat->startup_delay_us) +udelay (plat->startup_delay_us); + +if (!(flags &GPIOD_IS_OUT_ACTIVE ) && plat->off_on_delay_us) +udelay (plat->off_on_delay_us);
regulator_common_of_to_plat() is for parsing the values, no udelay() should be applied here.
regulator_common_set_enable() applies udelay() when the regulator is enabled.
Does your regulator .get_enable() ops not being called or does it not implement its own udelay() based on parsed values?
Regards,
Jonas
Quoted 4 lines
drivers/power/regulator/regulator_common.c +1
-0+return 0 ; }
Hi again,
Quoted 25 lines · Jonas Karlman
Hi,
Quoted 22 lines · Ye Li
SD initialization failure happens with some UHS-I SD cards on iMX8MM/iMX93/iMX91 EVK after
commit4fcba5d556b4("regulator: implement basic reference counter"). When sending operation condition to SD card, the OCR does not return correct status. The root cause is regulator on/off delay is missed in MMC power cycle with above commit, so SD card is not completely power off.When SD startup, the sequence of MMC power cycle is:
mmc_power_init(get vmmc_supply dev)->mmc_power_off-> udelay(2000) ->mmc_power_onBefore above commit, as a fixed regulator, the GPIO is set as:
GPIO inactive (inmmc_power_init) ->
GPIO inactive and delay off-on-delay-us (inmmc_power_off) -> udelay(2000) ->
GPIO active (inmmc_power_on)After the commit:
GPIO inactive (inmmc_power_init) ->
enable_countis 0,regulator_set_enablereturns-EALREADYimmediately,so GPIO is inactive but No off-on-delay-us (in mmc_power_off) ->
If the regulator is off at boot-on then this is working as intended.
However, if probing the regulator turns it off and that requires a off-on-delay-us delay, maybe you are missing a regulator-boot-on property to indicate that the regulator is on at boot/reset. That should also align the enable count with boot-on state of the regulator.
Looking at the kernel the off-on-delay-us is applied before a regulator is enabled, not after it is disabled like in U-Boot. Maybe U-Boot should do something similar, in simplest form always udelay off-on-delay-us before the regulator is enabled.
Quoted 30 lines
Quoted 18 lines
udelay(2000) ->
GPIO active (inmmc_power_on)Add the on/off delay and startup delay after GPIO request in
regulator_common_of_to_platwhich is called in regulator device probing. So inmmc_power_init, after GPIO is set to default inactive, the off-on-delay-us is applied.Signed-off-by Ye Li <[email protected]>--- drivers/power/regulator/regulator_common.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/power/regulator/regulator_common.c +0
-0drivers/power/regulator/regulator_common.c int regulator_common_of_to_plat(struct udevice *dev, · line 53
Quoted 8 lines
drivers/power/regulator/regulator_common.c +5
-0@@ -46,6 +46,12 @@ int regulator_common_of_to_plat(struct udevice *dev,dev_read_u32_default (dev,"u-boot,off-on-delay-us" ,0 ); } +if ((flags &GPIOD_IS_OUT_ACTIVE ) && plat->startup_delay_us) +udelay (plat->startup_delay_us); + +if (!(flags &GPIOD_IS_OUT_ACTIVE ) && plat->off_on_delay_us) +udelay (plat->off_on_delay_us);
regulator_common_of_to_plat()is for parsing the values, noudelay()should be applied here.
Quoted 2 lines
regulator_common_set_enable()appliesudelay()when the regulator is enabled.
Or disabled.
Quoted 3 lines
Does your regulator .get_enable() ops not being called or does it not implement its own
udelay()based on parsed values?
I meant set_enable() here :-)
Regards,
Jonas
Quoted 9 lines
Regards,
JonasQuoted 4 lines
drivers/power/regulator/regulator_common.c +1
-0+return 0 ; }
Quoted 36 lines · Jonas Karlman
Hi again,
Quoted 25 lines · Jonas Karlman
Hi,
Quoted 22 lines · Ye Li
SD initialization failure happens with some UHS-I SD cards on iMX8MM/iMX93/iMX91 EVK after
commit4fcba5d556b4("regulator: implement basic reference counter"). When sending operation condition to SD card, the OCR does not return correct status. The root cause is regulator on/off delay is missed in MMC power cycle with above commit, so SD card is not completely power off.When SD startup, the sequence of MMC power cycle is:
mmc_power_init(get vmmc_supply dev)->mmc_power_off-> udelay(2000) ->mmc_power_onBefore above commit, as a fixed regulator, the GPIO is set as:
GPIO inactive (inmmc_power_init) ->
GPIO inactive and delay off-on-delay-us (inmmc_power_off) -> udelay(2000) ->
GPIO active (inmmc_power_on)After the commit:
GPIO inactive (inmmc_power_init) ->
enable_countis 0,regulator_set_enablereturns-EALREADYimmediately,so GPIO is inactive but No off-on-delay-us (in mmc_power_off) ->If the regulator is off at boot-on then this is working as intended.
However, if probing the regulator turns it off and that requires a off-on-delay-us delay, maybe you are missing a regulator-boot-on property to indicate that the regulator is on at boot/reset. That should also align the enable count with boot-on state of the regulator.
Quoted 4 lines
Looking at the kernel the off-on-delay-us is applied before a regulator is enabled, not after it is disabled like in U-Boot. Maybe U-Boot should do something similar, in simplest form always udelay off-on-delay-us before the regulator is enabled.
Yeah. Something below should work(Not tested).
drivers/power/regulator/regulator_common.c +3 -3
@@ -68,6 +68,9 @@ int regulator_common_set_enable(const struct udevice *dev, dev->name, enable, plat->startup_delay_us, dm_gpio_is_valid(&plat->gpio)); +if (enable && plat->off_on_delay_us) +udelay (plat->off_on_delay_us); +/* Enable GPIO is optional */ if (CONFIG_IS_ENABLED (DM_GPIO ) &&dm_gpio_is_valid (&plat->gpio)) {/* If previously enabled, increase count */
@@ -97,9 +100,6 @@ int regulator_common_set_enable(const struct udevice *dev,if (enable && plat->startup_delay_us)udelay (plat->startup_delay_us); -if (!enable && plat->off_on_delay_us) -udelay (plat->off_on_delay_us); -if (enable) plat->enable_count++;else
Regards
Peng.
Quoted 56 lines
Quoted 31 lines
Quoted 19 lines
udelay(2000) ->
GPIO active (inmmc_power_on)Add the on/off delay and startup delay after GPIO request in
regulator_common_of_to_platwhich is called in regulator device probing. So inmmc_power_init, after GPIO is set to default inactive, the off-on-delay-us is applied.Signed-off-by Ye Li <[email protected]>--- drivers/power/regulator/regulator_common.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/power/regulator/regulator_common.c +0
-0drivers/power/regulator/regulator_common.c int regulator_common_of_to_plat(struct udevice *dev, · line 53
Quoted 8 lines
drivers/power/regulator/regulator_common.c +5
-0@@ -46,6 +46,12 @@ int regulator_common_of_to_plat(struct udevice *dev,dev_read_u32_default (dev,"u-boot,off-on-delay-us" ,0 ); } +if ((flags &GPIOD_IS_OUT_ACTIVE ) && plat->startup_delay_us) +udelay (plat->startup_delay_us); + +if (!(flags &GPIOD_IS_OUT_ACTIVE ) && plat->off_on_delay_us) +udelay (plat->off_on_delay_us);
regulator_common_of_to_plat()is for parsing the values, noudelay()should be applied here.Quoted 2 lines
regulator_common_set_enable()appliesudelay()when the regulator is enabled.Or disabled.
Quoted 3 lines
Does your regulator .get_enable() ops not being called or does it not implement its own
udelay()based on parsed values?I meant
set_enable()here :-)Regards,
JonasQuoted 9 lines
Regards,
JonasQuoted 4 lines
drivers/power/regulator/regulator_common.c +1
-0+return 0 ; }
Hi Jonas, Peng,
Quoted 30 lines · Peng Fan
Quoted 29 lines · Jonas Karlman
Hi again,
Quoted 25 lines · Jonas Karlman
Hi,
Quoted 22 lines · Ye Li
SD initialization failure happens with some UHS-I SD cards on iMX8MM/iMX93/iMX91 EVK after
commit4fcba5d556b4("regulator: implement basic reference counter"). When sending operation condition to SD card, the OCR does not return correct status. The root cause is regulator on/off delay is missed in MMC power cycle with above commit, so SD card is not completely power off.When SD startup, the sequence of MMC power cycle is:
mmc_power_init(get vmmc_supply dev)->mmc_power_off-> udelay(2000) ->mmc_power_onBefore above commit, as a fixed regulator, the GPIO is set as:
GPIO inactive (inmmc_power_init) ->
GPIO inactive and delay off-on-delay-us (inmmc_power_off) -> udelay(2000) ->
GPIO active (inmmc_power_on)After the commit:
GPIO inactive (inmmc_power_init) ->
enable_countis 0,regulator_set_enablereturns-EALREADYimmediately,so GPIO is inactive but No off-on-delay-us (in mmc_power_off) ->
Quoted 6 lines
Quoted 6 lines
If the regulator is off at boot-on then this is working as intended.
However, if probing the regulator turns it off and that requires a off-on-delay-us delay, maybe you are missing a regulator-boot-on property to indicate that the regulator is on at boot/reset. That should also align the enable count with boot-on state of the regulator.
This regulator is on at boot-on. But there is no regulator-boot-on used in kernel upstream dts. This will require to add it specifically for u-boot.
Quoted 5 lines
Quoted 5 lines
Looking at the kernel the off-on-delay-us is applied before a regulator is enabled, not after it is disabled like in U-Boot. Maybe U-Boot should do something similar, in simplest form always udelay off-on-delay-us before the regulator is enabled.
Agree, moving off-on-delay-us before regulator is enabled should work. I will use it in v2.
Quoted 8 lines
Yeah. Something below should work(Not tested).
drivers/power/regulator/regulator_common.c +0
-0
drivers/power/regulator/regulator_common.c int regulator_common_set_enable(const struct udevice *dev, · line 73
Quoted 6 lines
drivers/power/regulator/regulator_common.c +3
-0@@ -68,6 +68,9 @@ int regulator_common_set_enable(const struct udevice *dev, dev->name, enable, plat->startup_delay_us, dm_gpio_is_valid(&plat->gpio)); +if (enable && plat->off_on_delay_us) +udelay (plat->off_on_delay_us); +
Thanks for the patch. But I think off_on_delay_us should locate just before calling dm_gpio_set_value. Will send it in v2.
Best regards,
Ye Li
Quoted 73 lines
drivers/power/regulator/regulator_common.c +0
-3/* Enable GPIO is optional */ if (CONFIG_IS_ENABLED (DM_GPIO ) &&dm_gpio_is_valid (&plat->gpio)) {/* If previously enabled, increase count */ @@ -97,9 +100,6 @@ int regulator_common_set_enable(const struct udevice *dev,if (enable && plat->startup_delay_us)udelay (plat->startup_delay_us); -if (!enable && plat->off_on_delay_us) -udelay (plat->off_on_delay_us); -if (enable) plat->enable_count++;else Regards
Peng.Quoted 56 lines
Quoted 31 lines
Quoted 19 lines
udelay(2000) ->
GPIO active (inmmc_power_on)Add the on/off delay and startup delay after GPIO request in
regulator_common_of_to_platwhich is called in regulator device probing. So inmmc_power_init, after GPIO is set to default inactive, the off-on-delay-us is applied.Signed-off-by Ye Li <[email protected]>--- drivers/power/regulator/regulator_common.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/power/regulator/regulator_common.c +0
-0drivers/power/regulator/regulator_common.c int regulator_common_of_to_plat(struct udevice *dev, · line 53
Quoted 8 lines
drivers/power/regulator/regulator_common.c +5
-0@@ -46,6 +46,12 @@ int regulator_common_of_to_plat(struct udevice *dev,dev_read_u32_default (dev,"u-boot,off-on-delay-us" ,0 ); } +if ((flags &GPIOD_IS_OUT_ACTIVE ) && plat->startup_delay_us) +udelay (plat->startup_delay_us); + +if (!(flags &GPIOD_IS_OUT_ACTIVE ) && plat->off_on_delay_us) +udelay (plat->off_on_delay_us);
regulator_common_of_to_plat()is for parsing the values, noudelay()should be applied here.Quoted 2 lines
regulator_common_set_enable()appliesudelay()when the regulator is enabled.Or disabled.
Quoted 3 lines
Does your regulator .get_enable() ops not being called or does it not implement its own
udelay()based on parsed values?I meant
set_enable()here :-)Regards,
JonasQuoted 9 lines
Regards,
JonasQuoted 4 lines
drivers/power/regulator/regulator_common.c +1
-0+return 0 ; }