public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH next v2] i2c: hisi: Add support to get clock frequency from clock property
@ 2022-09-23  1:14 Weilong Chen
  2022-09-26  8:48 ` Yicong Yang
  0 siblings, 1 reply; 2+ messages in thread
From: Weilong Chen @ 2022-09-23  1:14 UTC (permalink / raw)
  To: chenweilong, yangyicong; +Cc: linux-i2c, linux-kernel

Support the driver to obtain clock information by clk_rate or
clock property. Find clock first, if not, fall back to clk_rate.

Signed-off-by: Weilong Chen <chenweilong@huawei.com>
---
Change since v1:
- Ordered struct field to inverted triangle.
- Use devm_clk_get_optional_enabled().
- Use IS_ERR_OR_NULL.
Link: https://lore.kernel.org/lkml/20220921101540.352553-1-chenweilong@huawei.com/

 drivers/i2c/busses/i2c-hisi.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c
index 67031024217c..b3bcce71dd2c 100644
--- a/drivers/i2c/busses/i2c-hisi.c
+++ b/drivers/i2c/busses/i2c-hisi.c
@@ -8,6 +8,7 @@
 #include <linux/acpi.h>
 #include <linux/bits.h>
 #include <linux/bitfield.h>
+#include <linux/clk.h>
 #include <linux/completion.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
@@ -90,6 +91,7 @@ struct hisi_i2c_controller {
 	struct i2c_adapter adapter;
 	void __iomem *iobase;
 	struct device *dev;
+	struct clk *clk;
 	int irq;
 
 	/* Intermediates for recording the transfer process */
@@ -456,10 +458,16 @@ static int hisi_i2c_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = device_property_read_u64(dev, "clk_rate", &clk_rate_hz);
-	if (ret) {
-		dev_err(dev, "failed to get clock frequency, ret = %d\n", ret);
-		return ret;
+	ctlr->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
+	if (IS_ERR_OR_NULL(ctlr->clk)) {
+		ret = device_property_read_u64(dev, "clk_rate", &clk_rate_hz);
+		if (ret) {
+			dev_err(dev, "failed to get clock frequency, ret = %d\n", ret);
+			return ret;
+		}
+	} else {
+
+		clk_rate_hz = clk_get_rate(ctlr->clk);
 	}
 
 	ctlr->clk_rate_khz = DIV_ROUND_UP_ULL(clk_rate_hz, HZ_PER_KHZ);
-- 
2.31.GIT


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

* Re: [PATCH next v2] i2c: hisi: Add support to get clock frequency from clock property
  2022-09-23  1:14 [PATCH next v2] i2c: hisi: Add support to get clock frequency from clock property Weilong Chen
@ 2022-09-26  8:48 ` Yicong Yang
  0 siblings, 0 replies; 2+ messages in thread
From: Yicong Yang @ 2022-09-26  8:48 UTC (permalink / raw)
  To: Weilong Chen; +Cc: linux-i2c, linux-kernel, yangyicong

On 2022/9/23 9:14, Weilong Chen wrote:
> Support the driver to obtain clock information by clk_rate or
> clock property. Find clock first, if not, fall back to clk_rate.
> 
> Signed-off-by: Weilong Chen <chenweilong@huawei.com>
> ---
> Change since v1:
> - Ordered struct field to inverted triangle.
> - Use devm_clk_get_optional_enabled().
> - Use IS_ERR_OR_NULL.
> Link: https://lore.kernel.org/lkml/20220921101540.352553-1-chenweilong@huawei.com/
> 
>  drivers/i2c/busses/i2c-hisi.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c
> index 67031024217c..b3bcce71dd2c 100644
> --- a/drivers/i2c/busses/i2c-hisi.c
> +++ b/drivers/i2c/busses/i2c-hisi.c
> @@ -8,6 +8,7 @@
>  #include <linux/acpi.h>
>  #include <linux/bits.h>
>  #include <linux/bitfield.h>
> +#include <linux/clk.h>
>  #include <linux/completion.h>
>  #include <linux/i2c.h>
>  #include <linux/interrupt.h>
> @@ -90,6 +91,7 @@ struct hisi_i2c_controller {
>  	struct i2c_adapter adapter;
>  	void __iomem *iobase;
>  	struct device *dev;
> +	struct clk *clk;
>  	int irq;
>  
>  	/* Intermediates for recording the transfer process */
> @@ -456,10 +458,16 @@ static int hisi_i2c_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	ret = device_property_read_u64(dev, "clk_rate", &clk_rate_hz);
> -	if (ret) {
> -		dev_err(dev, "failed to get clock frequency, ret = %d\n", ret);
> -		return ret;
> +	ctlr->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
> +	if (IS_ERR_OR_NULL(ctlr->clk)) {
> +		ret = device_property_read_u64(dev, "clk_rate", &clk_rate_hz);
> +		if (ret) {
> +			dev_err(dev, "failed to get clock frequency, ret = %d\n", ret);
> +			return ret;
> +		}
> +	} else {
> +

redundant blank line? with this addressed:

Acked-by: Yicong Yang <yangyicong@hisilicon.com>

> +		clk_rate_hz = clk_get_rate(ctlr->clk);
>  	}
>  
>  	ctlr->clk_rate_khz = DIV_ROUND_UP_ULL(clk_rate_hz, HZ_PER_KHZ);
> 

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

end of thread, other threads:[~2022-09-26  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-23  1:14 [PATCH next v2] i2c: hisi: Add support to get clock frequency from clock property Weilong Chen
2022-09-26  8:48 ` Yicong Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox