[PATCH RFC] mmc: pwrseq_simple: Handle !RESET_CONTROLLER properly

Stefan Wahren posted 1 patch 3 weeks, 1 day ago
There is a newer version of this series
drivers/mmc/core/pwrseq_simple.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
[PATCH RFC] mmc: pwrseq_simple: Handle !RESET_CONTROLLER properly
Posted by Stefan Wahren 3 weeks, 1 day ago
The recent introduction of reset control in pwrseq_simple introduced
a regression for platforms without RESET_CONTROLLER support, because
devm_reset_control_get_optional_shared() would return NULL and make all
resets no-ops. Instead of enforcing this dependency rely on this behavior
to determine reset support. As a benefit we can get the rid of the
use_reset flag.

Fixes: 73bf4b7381f7 ("mmc: pwrseq_simple: add support for one reset control")
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/mmc/core/pwrseq_simple.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Hi,
will trying to reproduce the Rpi 4 regression from here [1], I found
the issue above. I'm pretty sure the Rpi 4 regression is caused by the same
commit. Unfortunately I wasn't able to reproduce it.

[1] - https://lore.kernel.org/linux-next/6724d7d5.170a0220.1281e9.910a@mx.google.com/T/#u

diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
index 24e4e63a5dc8..b8782727750e 100644
--- a/drivers/mmc/core/pwrseq_simple.c
+++ b/drivers/mmc/core/pwrseq_simple.c
@@ -32,7 +32,6 @@ struct mmc_pwrseq_simple {
 	struct clk *ext_clk;
 	struct gpio_descs *reset_gpios;
 	struct reset_control *reset_ctrl;
-	bool use_reset;
 };

 #define to_pwrseq_simple(p) container_of(p, struct mmc_pwrseq_simple, pwrseq)
@@ -71,7 +70,7 @@ static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
 		pwrseq->clk_enabled = true;
 	}

-	if (pwrseq->use_reset) {
+	if (pwrseq->reset_ctrl) {
 		reset_control_deassert(pwrseq->reset_ctrl);
 		reset_control_assert(pwrseq->reset_ctrl);
 	} else
@@ -82,7 +81,7 @@ static void mmc_pwrseq_simple_post_power_on(struct mmc_host *host)
 {
 	struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);

-	if (pwrseq->use_reset)
+	if (pwrseq->reset_ctrl)
 		reset_control_deassert(pwrseq->reset_ctrl);
 	else
 		mmc_pwrseq_simple_set_gpios_value(pwrseq, 0);
@@ -95,7 +94,7 @@ static void mmc_pwrseq_simple_power_off(struct mmc_host *host)
 {
 	struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);

-	if (pwrseq->use_reset)
+	if (pwrseq->reset_ctrl)
 		reset_control_assert(pwrseq->reset_ctrl);
 	else
 		mmc_pwrseq_simple_set_gpios_value(pwrseq, 1);
@@ -137,15 +136,14 @@ static int mmc_pwrseq_simple_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(pwrseq->ext_clk), "external clock not ready\n");

 	ngpio = of_count_phandle_with_args(dev->of_node, "reset-gpios", "#gpio-cells");
-	if (ngpio == 1)
-		pwrseq->use_reset = true;
-
-	if (pwrseq->use_reset) {
+	if (ngpio == 1) {
 		pwrseq->reset_ctrl = devm_reset_control_get_optional_shared(dev, NULL);
 		if (IS_ERR(pwrseq->reset_ctrl))
 			return dev_err_probe(dev, PTR_ERR(pwrseq->reset_ctrl),
 					     "reset control not ready\n");
-	} else {
+	}
+
+	if (!pwrseq->reset_ctrl) {
 		pwrseq->reset_gpios = devm_gpiod_get_array(dev, "reset", GPIOD_OUT_HIGH);
 		if (IS_ERR(pwrseq->reset_gpios) &&
 		    PTR_ERR(pwrseq->reset_gpios) != -ENOENT &&
--
2.34.1
Re: [PATCH RFC] mmc: pwrseq_simple: Handle !RESET_CONTROLLER properly
Posted by Marco Felsch 2 weeks, 6 days ago
Hi Stefan,

On 24-11-02, Stefan Wahren wrote:
> The recent introduction of reset control in pwrseq_simple introduced
> a regression for platforms without RESET_CONTROLLER support, because

This is what I was afraid of :/

> devm_reset_control_get_optional_shared() would return NULL and make all
> resets no-ops. Instead of enforcing this dependency rely on this behavior
> to determine reset support. As a benefit we can get the rid of the
> use_reset flag.
> 
> Fixes: 73bf4b7381f7 ("mmc: pwrseq_simple: add support for one reset control")
> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
> ---
>  drivers/mmc/core/pwrseq_simple.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> Hi,
> will trying to reproduce the Rpi 4 regression from here [1], I found
> the issue above. I'm pretty sure the Rpi 4 regression is caused by the same
> commit. Unfortunately I wasn't able to reproduce it.
> 
> [1] - https://lore.kernel.org/linux-next/6724d7d5.170a0220.1281e9.910a@mx.google.com/T/#u
> 
> diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
> index 24e4e63a5dc8..b8782727750e 100644
> --- a/drivers/mmc/core/pwrseq_simple.c
> +++ b/drivers/mmc/core/pwrseq_simple.c
> @@ -32,7 +32,6 @@ struct mmc_pwrseq_simple {
>  	struct clk *ext_clk;
>  	struct gpio_descs *reset_gpios;
>  	struct reset_control *reset_ctrl;
> -	bool use_reset;
>  };
> 
>  #define to_pwrseq_simple(p) container_of(p, struct mmc_pwrseq_simple, pwrseq)
> @@ -71,7 +70,7 @@ static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
>  		pwrseq->clk_enabled = true;
>  	}
> 
> -	if (pwrseq->use_reset) {
> +	if (pwrseq->reset_ctrl) {
>  		reset_control_deassert(pwrseq->reset_ctrl);
>  		reset_control_assert(pwrseq->reset_ctrl);
>  	} else
> @@ -82,7 +81,7 @@ static void mmc_pwrseq_simple_post_power_on(struct mmc_host *host)
>  {
>  	struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
> 
> -	if (pwrseq->use_reset)
> +	if (pwrseq->reset_ctrl)
>  		reset_control_deassert(pwrseq->reset_ctrl);
>  	else
>  		mmc_pwrseq_simple_set_gpios_value(pwrseq, 0);
> @@ -95,7 +94,7 @@ static void mmc_pwrseq_simple_power_off(struct mmc_host *host)
>  {
>  	struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
> 
> -	if (pwrseq->use_reset)
> +	if (pwrseq->reset_ctrl)
>  		reset_control_assert(pwrseq->reset_ctrl);
>  	else
>  		mmc_pwrseq_simple_set_gpios_value(pwrseq, 1);
> @@ -137,15 +136,14 @@ static int mmc_pwrseq_simple_probe(struct platform_device *pdev)
>  		return dev_err_probe(dev, PTR_ERR(pwrseq->ext_clk), "external clock not ready\n");
> 
>  	ngpio = of_count_phandle_with_args(dev->of_node, "reset-gpios", "#gpio-cells");
> -	if (ngpio == 1)
> -		pwrseq->use_reset = true;
> -
> -	if (pwrseq->use_reset) {
> +	if (ngpio == 1) {
>  		pwrseq->reset_ctrl = devm_reset_control_get_optional_shared(dev, NULL);
>  		if (IS_ERR(pwrseq->reset_ctrl))
>  			return dev_err_probe(dev, PTR_ERR(pwrseq->reset_ctrl),
>  					     "reset control not ready\n");
> -	} else {
> +	}
> +

Can we add a comment like:

/*
 * Fallback to gpio based reset control in case of multiple reset lines
 * are specified or the platform doesn't have support for RESET at all.
 */

Regards,
  Marco

> +	if (!pwrseq->reset_ctrl) {
>  		pwrseq->reset_gpios = devm_gpiod_get_array(dev, "reset", GPIOD_OUT_HIGH);
>  		if (IS_ERR(pwrseq->reset_gpios) &&
>  		    PTR_ERR(pwrseq->reset_gpios) != -ENOENT &&
> --
> 2.34.1
> 
>
Re: [PATCH RFC] mmc: pwrseq_simple: Handle !RESET_CONTROLLER properly
Posted by Stefan Wahren 2 weeks, 5 days ago
Hi Mark,

Am 04.11.24 um 10:39 schrieb Marco Felsch:
> Hi Stefan,
>
> On 24-11-02, Stefan Wahren wrote:
>> The recent introduction of reset control in pwrseq_simple introduced
>> a regression for platforms without RESET_CONTROLLER support, because
> This is what I was afraid of :/
>
>> devm_reset_control_get_optional_shared() would return NULL and make all
>> resets no-ops. Instead of enforcing this dependency rely on this behavior
>> to determine reset support. As a benefit we can get the rid of the
>> use_reset flag.
>>
>> Fixes: 73bf4b7381f7 ("mmc: pwrseq_simple: add support for one reset control")
>> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
>> ---
>>   drivers/mmc/core/pwrseq_simple.c | 16 +++++++---------
>>   1 file changed, 7 insertions(+), 9 deletions(-)
>>
>> Hi,
>> will trying to reproduce the Rpi 4 regression from here [1], I found
>> the issue above. I'm pretty sure the Rpi 4 regression is caused by the same
>> commit. Unfortunately I wasn't able to reproduce it.
>>
>> [1] - https://lore.kernel.org/linux-next/6724d7d5.170a0220.1281e9.910a@mx.google.com/T/#u
I think i've a better unterstanding of the regression in your case. I
noticed on my Raspberry Pi 3 B+ that this change in combination with
arm64/defconfig causes a huge delay until wifi is probed (~ 32 seconds).
Maybe this is caused by the fact that RESET_GPIO is build as a module,
while PWRSEQ_SIMPLE is builtin. But this doesn't explain why the driver
seem to never probe in your case.

Regards