diff mbox series

[2/2] watchdog: rti_wdt: Drop RPM watchdog when unused

Message ID 20231110100726.2930218-3-vigneshr@ti.com
State New
Headers show
Series watchdog: rti_wdt: Disable module when unused | expand

Commit Message

Vignesh Raghavendra Nov. 10, 2023, 10:07 a.m. UTC
Do a RPM put if watchdog is not already started during probe and re
enable it in watchdog start.

On K3 SoCs, watchdogs and their corresponding CPUs are under same PD, so
if the reference count of unused watchdogs aren't dropped, it will lead
to CPU hotplug failures as Device Management firmware won't allow to
turn off the PD due to dangling reference count.

Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support")
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---
 drivers/watchdog/rti_wdt.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Guenter Roeck Nov. 10, 2023, 3:05 p.m. UTC | #1
On 11/10/23 02:07, Vignesh Raghavendra wrote:
> Do a RPM put if watchdog is not already started during probe and re
> enable it in watchdog start.
> 
> On K3 SoCs, watchdogs and their corresponding CPUs are under same PD, so
> if the reference count of unused watchdogs aren't dropped, it will lead
> to CPU hotplug failures as Device Management firmware won't allow to
> turn off the PD due to dangling reference count.
> 
> Fixes: 2d63908bdbfb ("watchdog: Add K3 RTI watchdog support")
> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
> ---
>   drivers/watchdog/rti_wdt.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
> index 163bdeb6929a..87f2c333a41d 100644
> --- a/drivers/watchdog/rti_wdt.c
> +++ b/drivers/watchdog/rti_wdt.c
> @@ -78,6 +78,9 @@ static int rti_wdt_start(struct watchdog_device *wdd)
>   	u32 timer_margin;
>   	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
>   
> +	if (pm_runtime_suspended(wdd->parent))
> +		pm_runtime_get_sync(wdd->parent);
> +
>   	/* set timeout period */
>   	timer_margin = (u64)wdd->timeout * wdt->freq;
>   	timer_margin >>= WDT_PRELOAD_SHIFT;
> @@ -337,6 +340,9 @@ static int rti_wdt_probe(struct platform_device *pdev)
>   	if (last_ping)
>   		watchdog_set_last_hw_keepalive(wdd, last_ping);
>   
> +	if (!watchdog_hw_running(wdd))
> +		pm_runtime_put_sync(&pdev->dev);
> +

You will have to explain why this is needed here, but not as error handling,
and why it is added in this patch after the changes in patch 1 of the series
which essentially declared that no error cleanup would be needed under
any circumstances.

Guenter

>   	return 0;
>   }
>   
> @@ -345,6 +351,9 @@ static void rti_wdt_remove(struct platform_device *pdev)
>   	struct rti_wdt_device *wdt = platform_get_drvdata(pdev);
>   
>   	watchdog_unregister_device(&wdt->wdd);
> +
> +	if (!pm_runtime_suspended(&pdev->dev))
> +		pm_runtime_put_sync(&pdev->dev);
>   }
>   
>   static const struct of_device_id rti_wdt_of_match[] = {
diff mbox series

Patch

diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index 163bdeb6929a..87f2c333a41d 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -78,6 +78,9 @@  static int rti_wdt_start(struct watchdog_device *wdd)
 	u32 timer_margin;
 	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
 
+	if (pm_runtime_suspended(wdd->parent))
+		pm_runtime_get_sync(wdd->parent);
+
 	/* set timeout period */
 	timer_margin = (u64)wdd->timeout * wdt->freq;
 	timer_margin >>= WDT_PRELOAD_SHIFT;
@@ -337,6 +340,9 @@  static int rti_wdt_probe(struct platform_device *pdev)
 	if (last_ping)
 		watchdog_set_last_hw_keepalive(wdd, last_ping);
 
+	if (!watchdog_hw_running(wdd))
+		pm_runtime_put_sync(&pdev->dev);
+
 	return 0;
 }
 
@@ -345,6 +351,9 @@  static void rti_wdt_remove(struct platform_device *pdev)
 	struct rti_wdt_device *wdt = platform_get_drvdata(pdev);
 
 	watchdog_unregister_device(&wdt->wdd);
+
+	if (!pm_runtime_suspended(&pdev->dev))
+		pm_runtime_put_sync(&pdev->dev);
 }
 
 static const struct of_device_id rti_wdt_of_match[] = {