diff mbox series

[v2,02/14] regulator: core: Detach coupled regulator before coupling count is dropped

Message ID 20210523231335.8238-3-digetx@gmail.com
State Superseded
Headers show
Series NVIDIA Tegra memory and power management changes for 5.14 | expand

Commit Message

Dmitry Osipenko May 23, 2021, 11:13 p.m. UTC
Detach coupled regulator before dropping coupling count in order to allow
detaching callback to balance voltage of regulators. This is needed by
NVIDIA Tegra regulator couplers in order to bring back voltage to a value
that is safe for reboot once regulators are decoupled.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/regulator/core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Dmitry Osipenko May 24, 2021, 10:20 a.m. UTC | #1
24.05.2021 02:13, Dmitry Osipenko пишет:
> Detach coupled regulator before dropping coupling count in order to allow
> detaching callback to balance voltage of regulators. This is needed by
> NVIDIA Tegra regulator couplers in order to bring back voltage to a value
> that is safe for reboot once regulators are decoupled.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/regulator/core.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index aae978c0c148..83571f83af04 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -5084,6 +5084,13 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
>  
>  	n_coupled = c_desc->n_coupled;
>  
> +	if (coupler && coupler->detach_regulator) {
> +		err = coupler->detach_regulator(coupler, rdev);
> +		if (err)
> +			rdev_err(rdev, "failed to detach from coupler: %pe\n",
> +				 ERR_PTR(err));
> +	}
> +
>  	for (i = 1; i < n_coupled; i++) {
>  		c_rdev = c_desc->coupled_rdevs[i];
>  
> @@ -5111,13 +5118,6 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
>  		c_desc->n_resolved--;
>  	}
>  
> -	if (coupler && coupler->detach_regulator) {
> -		err = coupler->detach_regulator(coupler, rdev);
> -		if (err)
> -			rdev_err(rdev, "failed to detach from coupler: %pe\n",
> -				 ERR_PTR(err));
> -	}
> -
>  	kfree(rdev->coupling_desc.coupled_rdevs);
>  	rdev->coupling_desc.coupled_rdevs = NULL;
>  }
> 

I now realized that this is a bit too fragile approach. I'll drop this
patch in v3, there are better options of how to manage balancing on
detaching and this is not critical feature for now anyways.
diff mbox series

Patch

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index aae978c0c148..83571f83af04 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -5084,6 +5084,13 @@  static void regulator_remove_coupling(struct regulator_dev *rdev)
 
 	n_coupled = c_desc->n_coupled;
 
+	if (coupler && coupler->detach_regulator) {
+		err = coupler->detach_regulator(coupler, rdev);
+		if (err)
+			rdev_err(rdev, "failed to detach from coupler: %pe\n",
+				 ERR_PTR(err));
+	}
+
 	for (i = 1; i < n_coupled; i++) {
 		c_rdev = c_desc->coupled_rdevs[i];
 
@@ -5111,13 +5118,6 @@  static void regulator_remove_coupling(struct regulator_dev *rdev)
 		c_desc->n_resolved--;
 	}
 
-	if (coupler && coupler->detach_regulator) {
-		err = coupler->detach_regulator(coupler, rdev);
-		if (err)
-			rdev_err(rdev, "failed to detach from coupler: %pe\n",
-				 ERR_PTR(err));
-	}
-
 	kfree(rdev->coupling_desc.coupled_rdevs);
 	rdev->coupling_desc.coupled_rdevs = NULL;
 }