[PATCH 5/7] rtc:rtc-sa1100:Use devm_clk_get_enabled() helpers

Liao Yuanhong posted 7 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH 5/7] rtc:rtc-sa1100:Use devm_clk_get_enabled() helpers
Posted by Liao Yuanhong 1 year, 5 months ago
Use devm_clk_get_enabled() instead of clk functions in rtc-sa1100.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 drivers/rtc/rtc-sa1100.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 0b2cfa8ca05b..2e72daa6a152 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -177,15 +177,12 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
 
 	spin_lock_init(&info->lock);
 
-	info->clk = devm_clk_get(&pdev->dev, NULL);
+	info->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(info->clk)) {
 		dev_err(&pdev->dev, "failed to find rtc clock source\n");
 		return PTR_ERR(info->clk);
 	}
 
-	ret = clk_prepare_enable(info->clk);
-	if (ret)
-		return ret;
 	/*
 	 * According to the manual we should be able to let RTTR be zero
 	 * and then a default diviser for a 32.768KHz clock is used.
@@ -206,10 +203,8 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
 	info->rtc->range_max = U32_MAX;
 
 	ret = devm_rtc_register_device(info->rtc);
-	if (ret) {
-		clk_disable_unprepare(info->clk);
+	if (ret)
 		return ret;
-	}
 
 	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
 	 * See also the comments in sa1100_rtc_interrupt().
@@ -305,7 +300,6 @@ static void sa1100_rtc_remove(struct platform_device *pdev)
 		spin_lock_irq(&info->lock);
 		writel_relaxed(0, info->rtsr);
 		spin_unlock_irq(&info->lock);
-		clk_disable_unprepare(info->clk);
 	}
 }
 
-- 
2.25.1
Re: [PATCH 5/7] rtc:rtc-sa1100:Use devm_clk_get_enabled() helpers
Posted by Christophe JAILLET 1 year, 5 months ago
Le 21/08/2024 à 11:28, Liao Yuanhong a écrit :
> Use devm_clk_get_enabled() instead of clk functions in rtc-sa1100.
> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
> ---
>   drivers/rtc/rtc-sa1100.c | 10 ++--------
>   1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
> index 0b2cfa8ca05b..2e72daa6a152 100644
> --- a/drivers/rtc/rtc-sa1100.c
> +++ b/drivers/rtc/rtc-sa1100.c
> @@ -177,15 +177,12 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
>   
>   	spin_lock_init(&info->lock);
>   
> -	info->clk = devm_clk_get(&pdev->dev, NULL);
> +	info->clk = devm_clk_get_enabled(&pdev->dev, NULL);

Hi,

the clk field in struct sa1100_rtc could also be easily removed now.

CJ

>   	if (IS_ERR(info->clk)) {
>   		dev_err(&pdev->dev, "failed to find rtc clock source\n");
>   		return PTR_ERR(info->clk);
>   	}
>   
> -	ret = clk_prepare_enable(info->clk);
> -	if (ret)
> -		return ret;
>   	/*
>   	 * According to the manual we should be able to let RTTR be zero
>   	 * and then a default diviser for a 32.768KHz clock is used.
> @@ -206,10 +203,8 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
>   	info->rtc->range_max = U32_MAX;
>   
>   	ret = devm_rtc_register_device(info->rtc);
> -	if (ret) {
> -		clk_disable_unprepare(info->clk);
> +	if (ret)
>   		return ret;
> -	}
>   
>   	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
>   	 * See also the comments in sa1100_rtc_interrupt().
> @@ -305,7 +300,6 @@ static void sa1100_rtc_remove(struct platform_device *pdev)
>   		spin_lock_irq(&info->lock);
>   		writel_relaxed(0, info->rtsr);
>   		spin_unlock_irq(&info->lock);
> -		clk_disable_unprepare(info->clk);
>   	}
>   }
>   

[PATCH v2 5/7] rtc:rtc-sa1100:Use devm_clk_get_enabled() helpers
Posted by Liao Yuanhong 1 year, 5 months ago
Use devm_clk_get_enabled() instead of clk functions in rtc-sa1100.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
v2:remove the clk field in struct sa1100_rtc.
---
 drivers/rtc/rtc-sa1100.c | 15 +++++----------
 drivers/rtc/rtc-sa1100.h |  2 --
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 0b2cfa8ca05b..c1e9ec40de18 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -174,18 +174,16 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
 int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
 {
 	int ret;
+	struct clk *clk;
 
 	spin_lock_init(&info->lock);
 
-	info->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(info->clk)) {
+	clk = devm_clk_get_enabled(&pdev->dev, NULL);
+	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to find rtc clock source\n");
-		return PTR_ERR(info->clk);
+		return PTR_ERR(clk);
 	}
 
-	ret = clk_prepare_enable(info->clk);
-	if (ret)
-		return ret;
 	/*
 	 * According to the manual we should be able to let RTTR be zero
 	 * and then a default diviser for a 32.768KHz clock is used.
@@ -206,10 +204,8 @@ int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
 	info->rtc->range_max = U32_MAX;
 
 	ret = devm_rtc_register_device(info->rtc);
-	if (ret) {
-		clk_disable_unprepare(info->clk);
+	if (ret)
 		return ret;
-	}
 
 	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
 	 * See also the comments in sa1100_rtc_interrupt().
@@ -305,7 +301,6 @@ static void sa1100_rtc_remove(struct platform_device *pdev)
 		spin_lock_irq(&info->lock);
 		writel_relaxed(0, info->rtsr);
 		spin_unlock_irq(&info->lock);
-		clk_disable_unprepare(info->clk);
 	}
 }
 
diff --git a/drivers/rtc/rtc-sa1100.h b/drivers/rtc/rtc-sa1100.h
index cc724f5b07bc..cb8c2959f560 100644
--- a/drivers/rtc/rtc-sa1100.h
+++ b/drivers/rtc/rtc-sa1100.h
@@ -4,7 +4,6 @@
 
 #include <linux/kernel.h>
 
-struct clk;
 struct platform_device;
 
 struct sa1100_rtc {
@@ -16,7 +15,6 @@ struct sa1100_rtc {
 	int			irq_1hz;
 	int			irq_alarm;
 	struct rtc_device	*rtc;
-	struct clk		*clk;
 };
 
 int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info);
-- 
2.25.1