diff mbox series

[v3,2/2] iio: adc: rzg2l: Cleanup suspend/resume path

Message ID 20250224120608.1769039-3-claudiu.beznea.uj@bp.renesas.com (mailing list archive)
State New
Headers show
Series iio: rzg2l_adc: Cleanups for rzg2l_adc driver | expand

Commit Message

Claudiu Beznea Feb. 24, 2025, 12:06 p.m. UTC
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

There is no need to manually track the runtime PM status in the driver.
The pm_runtime_force_suspend() and pm_runtime_force_resume() functions
already call pm_runtime_status_suspended() to check the runtime PM state.

Additionally, avoid calling pm_runtime_put_autosuspend() during the
suspend/resume path, as this would decrease the usage counter of a
potential user that had the ADC open before the suspend/resume cycle.

Fixes: cb164d7c1526 ("iio: adc: rzg2l_adc: Add suspend/resume support")
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v3:
- collected tags

Changes in v2:
- none

 drivers/iio/adc/rzg2l_adc.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

Comments

Lad, Prabhakar Feb. 25, 2025, 8:36 p.m. UTC | #1
On Mon, Feb 24, 2025 at 12:13 PM Claudiu <claudiu.beznea@tuxon.dev> wrote:
>
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>
> There is no need to manually track the runtime PM status in the driver.
> The pm_runtime_force_suspend() and pm_runtime_force_resume() functions
> already call pm_runtime_status_suspended() to check the runtime PM state.
>
> Additionally, avoid calling pm_runtime_put_autosuspend() during the
> suspend/resume path, as this would decrease the usage counter of a
> potential user that had the ADC open before the suspend/resume cycle.
>
> Fixes: cb164d7c1526 ("iio: adc: rzg2l_adc: Add suspend/resume support")
> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---
>
> Changes in v3:
> - collected tags
>
> Changes in v2:
> - none
>
>  drivers/iio/adc/rzg2l_adc.c | 29 ++++++++---------------------
>  1 file changed, 8 insertions(+), 21 deletions(-)
>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Cheers,
Prabhakar

> diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
> index 7db04416e1cf..5236ca0da167 100644
> --- a/drivers/iio/adc/rzg2l_adc.c
> +++ b/drivers/iio/adc/rzg2l_adc.c
> @@ -89,7 +89,6 @@ struct rzg2l_adc {
>         struct completion completion;
>         struct mutex lock;
>         u16 last_val[RZG2L_ADC_MAX_CHANNELS];
> -       bool was_rpm_active;
>  };
>
>  /**
> @@ -594,14 +593,9 @@ static int rzg2l_adc_suspend(struct device *dev)
>         };
>         int ret;
>
> -       if (pm_runtime_suspended(dev)) {
> -               adc->was_rpm_active = false;
> -       } else {
> -               ret = pm_runtime_force_suspend(dev);
> -               if (ret)
> -                       return ret;
> -               adc->was_rpm_active = true;
> -       }
> +       ret = pm_runtime_force_suspend(dev);
> +       if (ret)
> +               return ret;
>
>         ret = reset_control_bulk_assert(ARRAY_SIZE(resets), resets);
>         if (ret)
> @@ -610,9 +604,7 @@ static int rzg2l_adc_suspend(struct device *dev)
>         return 0;
>
>  rpm_restore:
> -       if (adc->was_rpm_active)
> -               pm_runtime_force_resume(dev);
> -
> +       pm_runtime_force_resume(dev);
>         return ret;
>  }
>
> @@ -630,11 +622,9 @@ static int rzg2l_adc_resume(struct device *dev)
>         if (ret)
>                 return ret;
>
> -       if (adc->was_rpm_active) {
> -               ret = pm_runtime_force_resume(dev);
> -               if (ret)
> -                       goto resets_restore;
> -       }
> +       ret = pm_runtime_force_resume(dev);
> +       if (ret)
> +               goto resets_restore;
>
>         ret = rzg2l_adc_hw_init(dev, adc);
>         if (ret)
> @@ -643,10 +633,7 @@ static int rzg2l_adc_resume(struct device *dev)
>         return 0;
>
>  rpm_restore:
> -       if (adc->was_rpm_active) {
> -               pm_runtime_mark_last_busy(dev);
> -               pm_runtime_put_autosuspend(dev);
> -       }
> +       pm_runtime_force_suspend(dev);
>  resets_restore:
>         reset_control_bulk_assert(ARRAY_SIZE(resets), resets);
>         return ret;
> --
> 2.43.0
>
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
index 7db04416e1cf..5236ca0da167 100644
--- a/drivers/iio/adc/rzg2l_adc.c
+++ b/drivers/iio/adc/rzg2l_adc.c
@@ -89,7 +89,6 @@  struct rzg2l_adc {
 	struct completion completion;
 	struct mutex lock;
 	u16 last_val[RZG2L_ADC_MAX_CHANNELS];
-	bool was_rpm_active;
 };
 
 /**
@@ -594,14 +593,9 @@  static int rzg2l_adc_suspend(struct device *dev)
 	};
 	int ret;
 
-	if (pm_runtime_suspended(dev)) {
-		adc->was_rpm_active = false;
-	} else {
-		ret = pm_runtime_force_suspend(dev);
-		if (ret)
-			return ret;
-		adc->was_rpm_active = true;
-	}
+	ret = pm_runtime_force_suspend(dev);
+	if (ret)
+		return ret;
 
 	ret = reset_control_bulk_assert(ARRAY_SIZE(resets), resets);
 	if (ret)
@@ -610,9 +604,7 @@  static int rzg2l_adc_suspend(struct device *dev)
 	return 0;
 
 rpm_restore:
-	if (adc->was_rpm_active)
-		pm_runtime_force_resume(dev);
-
+	pm_runtime_force_resume(dev);
 	return ret;
 }
 
@@ -630,11 +622,9 @@  static int rzg2l_adc_resume(struct device *dev)
 	if (ret)
 		return ret;
 
-	if (adc->was_rpm_active) {
-		ret = pm_runtime_force_resume(dev);
-		if (ret)
-			goto resets_restore;
-	}
+	ret = pm_runtime_force_resume(dev);
+	if (ret)
+		goto resets_restore;
 
 	ret = rzg2l_adc_hw_init(dev, adc);
 	if (ret)
@@ -643,10 +633,7 @@  static int rzg2l_adc_resume(struct device *dev)
 	return 0;
 
 rpm_restore:
-	if (adc->was_rpm_active) {
-		pm_runtime_mark_last_busy(dev);
-		pm_runtime_put_autosuspend(dev);
-	}
+	pm_runtime_force_suspend(dev);
 resets_restore:
 	reset_control_bulk_assert(ARRAY_SIZE(resets), resets);
 	return ret;