linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/2] iio: rzg2l_adc: Cleanups for rzg2l_adc driver
@ 2025-08-10 12:33 Claudiu
  2025-08-10 12:33 ` [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path Claudiu
  2025-08-10 12:33 ` [PATCH v5 2/2] iio: adc: rzg2l_adc: Set driver data before enabling runtime PM Claudiu
  0 siblings, 2 replies; 5+ messages in thread
From: Claudiu @ 2025-08-10 12:33 UTC (permalink / raw)
  To: prabhakar.mahadev-lad.rj, jic23, dlechner, nuno.sa, andy
  Cc: claudiu.beznea, linux-iio, linux-renesas-soc, linux-kernel,
	Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Hi,

Series adds some cleanups for the RZ/G2L ADC driver after the support
for the RZ/G3S SoC.

Thank you,
Claudiu Beznea

Changes in v4:
- dropped patch "iio: adc: rzg2l_adc: Open a devres group" as it is
  now fixed by [1]
- added patch "iio: adc: rzg2l_adc: Set driver data before enabling runtime PM"

[1] https://lore.kernel.org/all/20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com/

Changes in v4:
- open the devres group in its own function and rename the
  rzg2l_adc_probe() to rzg2l_adc_probe_helper() to have simpler code
- collected tags

Changes in v3:
- in patch 2/2 use a devres group for all the devm resources
  acquired in the driver's probe

Changes in v2:
- updated cover letter
- collected tags
- updated patch 1/2 to drop devres APIs from the point the
  runtime PM is enabled

Claudiu Beznea (2):
  iio: adc: rzg2l: Cleanup suspend/resume path
  iio: adc: rzg2l_adc: Set driver data before enabling runtime PM

 drivers/iio/adc/rzg2l_adc.c | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path
  2025-08-10 12:33 [PATCH v5 0/2] iio: rzg2l_adc: Cleanups for rzg2l_adc driver Claudiu
@ 2025-08-10 12:33 ` Claudiu
  2025-08-16 13:53   ` Jonathan Cameron
  2025-08-10 12:33 ` [PATCH v5 2/2] iio: adc: rzg2l_adc: Set driver data before enabling runtime PM Claudiu
  1 sibling, 1 reply; 5+ messages in thread
From: Claudiu @ 2025-08-10 12:33 UTC (permalink / raw)
  To: prabhakar.mahadev-lad.rj, jic23, dlechner, nuno.sa, andy
  Cc: claudiu.beznea, linux-iio, linux-renesas-soc, linux-kernel,
	Claudiu Beznea, Ulf Hansson

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>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v5:
- none

Changes in v4:
- collected tags

Changes in v3:
- collected tags

Changes in v2:
- none

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

diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
index 9674d48074c9..0cb5a67fd497 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;
 };
 
 /**
@@ -541,14 +540,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)
@@ -557,9 +551,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;
 }
 
@@ -577,11 +569,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)
@@ -590,10 +580,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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v5 2/2] iio: adc: rzg2l_adc: Set driver data before enabling runtime PM
  2025-08-10 12:33 [PATCH v5 0/2] iio: rzg2l_adc: Cleanups for rzg2l_adc driver Claudiu
  2025-08-10 12:33 ` [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path Claudiu
@ 2025-08-10 12:33 ` Claudiu
  1 sibling, 0 replies; 5+ messages in thread
From: Claudiu @ 2025-08-10 12:33 UTC (permalink / raw)
  To: prabhakar.mahadev-lad.rj, jic23, dlechner, nuno.sa, andy
  Cc: claudiu.beznea, linux-iio, linux-renesas-soc, linux-kernel,
	Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

When stress-testing the system by repeatedly unbinding and binding the ADC
device in a loop, and the ADC is a supplier for another device (e.g., a
thermal hardware block that reads temperature through the ADC), it may
happen that the ADC device is runtime-resumed immediately after runtime PM
is enabled, triggered by its consumer. At this point, since drvdata is not
yet set and the driver's runtime PM callbacks rely on it, a crash can
occur. To avoid this, set drvdata just after it was allocated.

Fixes: 89ee8174e8c8 ("iio: adc: rzg2l_adc: Simplify the runtime PM code")
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v5:
- none; this patch is new

 drivers/iio/adc/rzg2l_adc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
index 0cb5a67fd497..cadb0446bc29 100644
--- a/drivers/iio/adc/rzg2l_adc.c
+++ b/drivers/iio/adc/rzg2l_adc.c
@@ -427,6 +427,8 @@ static int rzg2l_adc_probe(struct platform_device *pdev)
 	if (!indio_dev)
 		return -ENOMEM;
 
+	platform_set_drvdata(pdev, indio_dev);
+
 	adc = iio_priv(indio_dev);
 
 	adc->hw_params = device_get_match_data(dev);
@@ -459,8 +461,6 @@ static int rzg2l_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	platform_set_drvdata(pdev, indio_dev);
-
 	ret = rzg2l_adc_hw_init(dev, adc);
 	if (ret)
 		return dev_err_probe(&pdev->dev, ret,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path
  2025-08-10 12:33 ` [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path Claudiu
@ 2025-08-16 13:53   ` Jonathan Cameron
  2025-08-18  5:54     ` Claudiu Beznea
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2025-08-16 13:53 UTC (permalink / raw)
  To: Claudiu
  Cc: prabhakar.mahadev-lad.rj, dlechner, nuno.sa, andy, linux-iio,
	linux-renesas-soc, linux-kernel, Claudiu Beznea, Ulf Hansson

On Sun, 10 Aug 2025 15:33:27 +0300
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")
That SHA isn't upstream. I think it should be.
563cf94f9329

With that fixes up, applied these to the fixes-togreg branch of iio.git and
marked them for stable.

> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---
> 
> Changes in v5:
> - none
> 
> Changes in v4:
> - collected tags
> 
> Changes in v3:
> - collected tags
> 
> Changes in v2:
> - none
> 
>  drivers/iio/adc/rzg2l_adc.c | 29 ++++++++---------------------
>  1 file changed, 8 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c
> index 9674d48074c9..0cb5a67fd497 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;
>  };
>  
>  /**
> @@ -541,14 +540,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)
> @@ -557,9 +551,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;
>  }
>  
> @@ -577,11 +569,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)
> @@ -590,10 +580,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;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path
  2025-08-16 13:53   ` Jonathan Cameron
@ 2025-08-18  5:54     ` Claudiu Beznea
  0 siblings, 0 replies; 5+ messages in thread
From: Claudiu Beznea @ 2025-08-18  5:54 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: prabhakar.mahadev-lad.rj, dlechner, nuno.sa, andy, linux-iio,
	linux-renesas-soc, linux-kernel, Claudiu Beznea, Ulf Hansson



On 16.08.2025 16:53, Jonathan Cameron 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")
> That SHA isn't upstream. I think it should be.
> 563cf94f9329

You're right! Thank you for handling it.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-18  5:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 12:33 [PATCH v5 0/2] iio: rzg2l_adc: Cleanups for rzg2l_adc driver Claudiu
2025-08-10 12:33 ` [PATCH v5 1/2] iio: adc: rzg2l: Cleanup suspend/resume path Claudiu
2025-08-16 13:53   ` Jonathan Cameron
2025-08-18  5:54     ` Claudiu Beznea
2025-08-10 12:33 ` [PATCH v5 2/2] iio: adc: rzg2l_adc: Set driver data before enabling runtime PM Claudiu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).