linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] watchdog: sp805: Use devm_clk_get_optional()
@ 2021-05-17 17:44 Andy Shevchenko
  2021-05-17 21:48 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2021-05-17 17:44 UTC (permalink / raw)
  To: Guenter Roeck, Andy Shevchenko, linux-watchdog, linux-kernel
  Cc: Wim Van Sebroeck, Srinath Mannam

Replace open coded variants of devm_clk_get_optional().

While at it, drop unneeded OF and ACPI dependency as the APIs in use
are provider agnostic.

Cc: Srinath Mannam <srinath.mannam@broadcom.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/watchdog/sp805_wdt.c | 40 +++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
index 58a00e1ab23b..531551216c8c 100644
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -11,7 +11,6 @@
  * warranty of any kind, whether express or implied.
  */
 
-#include <linux/acpi.h>
 #include <linux/device.h>
 #include <linux/resource.h>
 #include <linux/amba/bus.h>
@@ -23,8 +22,8 @@
 #include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
-#include <linux/of.h>
 #include <linux/pm.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
@@ -231,6 +230,7 @@ static int
 sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
 {
 	struct sp805_wdt *wdt;
+	u64 rate = 0;
 	int ret = 0;
 
 	wdt = devm_kzalloc(&adev->dev, sizeof(*wdt), GFP_KERNEL);
@@ -243,25 +243,23 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
 	if (IS_ERR(wdt->base))
 		return PTR_ERR(wdt->base);
 
-	if (adev->dev.of_node) {
-		wdt->clk = devm_clk_get(&adev->dev, NULL);
-		if (IS_ERR(wdt->clk)) {
-			dev_err(&adev->dev, "Clock not found\n");
-			return PTR_ERR(wdt->clk);
-		}
-		wdt->rate = clk_get_rate(wdt->clk);
-	} else if (has_acpi_companion(&adev->dev)) {
-		/*
-		 * When Driver probe with ACPI device, clock devices
-		 * are not available, so watchdog rate get from
-		 * clock-frequency property given in _DSD object.
-		 */
-		device_property_read_u64(&adev->dev, "clock-frequency",
-					 &wdt->rate);
-		if (!wdt->rate) {
-			dev_err(&adev->dev, "no clock-frequency property\n");
-			return -ENODEV;
-		}
+	/*
+	 * When driver probe with ACPI device, clock devices
+	 * are not available, so watchdog rate get from
+	 * clock-frequency property given in _DSD object.
+	 */
+	device_property_read_u64(&adev->dev, "clock-frequency", &rate);
+
+	wdt->clk = devm_clk_get_optional(&adev->dev, NULL);
+	if (IS_ERR(wdt->clk))
+		return dev_err_probe(&adev->dev, PTR_ERR(wdt->clk), "Clock not found\n");
+
+	wdt->rate = clk_get_rate(wdt->clk);
+	if (!wdt->rate)
+		wdt->rate = rate;
+	if (!wdt->rate) {
+		dev_err(&adev->dev, "no clock-frequency property\n");
+		return -ENODEV;
 	}
 
 	wdt->adev = adev;
-- 
2.30.2


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

* Re: [PATCH v1 1/1] watchdog: sp805: Use devm_clk_get_optional()
  2021-05-17 17:44 [PATCH v1 1/1] watchdog: sp805: Use devm_clk_get_optional() Andy Shevchenko
@ 2021-05-17 21:48 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-05-17 21:48 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-watchdog, linux-kernel, Wim Van Sebroeck, Srinath Mannam

On Mon, May 17, 2021 at 08:44:56PM +0300, Andy Shevchenko wrote:
> Replace open coded variants of devm_clk_get_optional().
> 
> While at it, drop unneeded OF and ACPI dependency as the APIs in use
> are provider agnostic.
> 
> Cc: Srinath Mannam <srinath.mannam@broadcom.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/watchdog/sp805_wdt.c | 40 +++++++++++++++++-------------------
>  1 file changed, 19 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
> index 58a00e1ab23b..531551216c8c 100644
> --- a/drivers/watchdog/sp805_wdt.c
> +++ b/drivers/watchdog/sp805_wdt.c
> @@ -11,7 +11,6 @@
>   * warranty of any kind, whether express or implied.
>   */
>  
> -#include <linux/acpi.h>
>  #include <linux/device.h>
>  #include <linux/resource.h>
>  #include <linux/amba/bus.h>
> @@ -23,8 +22,8 @@
>  #include <linux/math64.h>
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
> -#include <linux/of.h>
>  #include <linux/pm.h>
> +#include <linux/property.h>
>  #include <linux/slab.h>
>  #include <linux/spinlock.h>
>  #include <linux/types.h>
> @@ -231,6 +230,7 @@ static int
>  sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
>  {
>  	struct sp805_wdt *wdt;
> +	u64 rate = 0;
>  	int ret = 0;
>  
>  	wdt = devm_kzalloc(&adev->dev, sizeof(*wdt), GFP_KERNEL);
> @@ -243,25 +243,23 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
>  	if (IS_ERR(wdt->base))
>  		return PTR_ERR(wdt->base);
>  
> -	if (adev->dev.of_node) {
> -		wdt->clk = devm_clk_get(&adev->dev, NULL);
> -		if (IS_ERR(wdt->clk)) {
> -			dev_err(&adev->dev, "Clock not found\n");
> -			return PTR_ERR(wdt->clk);
> -		}
> -		wdt->rate = clk_get_rate(wdt->clk);
> -	} else if (has_acpi_companion(&adev->dev)) {
> -		/*
> -		 * When Driver probe with ACPI device, clock devices
> -		 * are not available, so watchdog rate get from
> -		 * clock-frequency property given in _DSD object.
> -		 */
> -		device_property_read_u64(&adev->dev, "clock-frequency",
> -					 &wdt->rate);
> -		if (!wdt->rate) {
> -			dev_err(&adev->dev, "no clock-frequency property\n");
> -			return -ENODEV;
> -		}
> +	/*
> +	 * When driver probe with ACPI device, clock devices
> +	 * are not available, so watchdog rate get from
> +	 * clock-frequency property given in _DSD object.
> +	 */
> +	device_property_read_u64(&adev->dev, "clock-frequency", &rate);
> +
> +	wdt->clk = devm_clk_get_optional(&adev->dev, NULL);
> +	if (IS_ERR(wdt->clk))
> +		return dev_err_probe(&adev->dev, PTR_ERR(wdt->clk), "Clock not found\n");
> +
> +	wdt->rate = clk_get_rate(wdt->clk);
> +	if (!wdt->rate)
> +		wdt->rate = rate;
> +	if (!wdt->rate) {
> +		dev_err(&adev->dev, "no clock-frequency property\n");
> +		return -ENODEV;
>  	}
>  
>  	wdt->adev = adev;
> -- 
> 2.30.2
> 

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

end of thread, other threads:[~2021-05-17 21:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 17:44 [PATCH v1 1/1] watchdog: sp805: Use devm_clk_get_optional() Andy Shevchenko
2021-05-17 21:48 ` Guenter Roeck

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).