2022-09-29 07:12:35

by chenweilong

[permalink] [raw]
Subject: [PATCH next v4] i2c: hisi: Add support to get clock frequency from clock property

The clk_rate attribute is not generic device tree bindings for I2C
busses described in Documentation/devicetree/bindings/i2c/i2c.txt.
It can be managed by clock binding.

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 <[email protected]>
Acked-by: Yicong Yang <[email protected]>
---
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/[email protected]/

Change since v2:
- Remove redundant blank line
Link: https://lore.kernel.org/all/[email protected]/

Change since v3:
- Commit message update
Link: https://lore.kernel.org/lkml/[email protected]/T/

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

diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c
index 67031024217c..e4b0ebe54f6f 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,15 @@ 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


2022-10-05 19:22:58

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH next v4] i2c: hisi: Add support to get clock frequency from clock property

On Thu, Sep 29, 2022 at 03:15:47PM +0800, Weilong Chen wrote:
> The clk_rate attribute is not generic device tree bindings for I2C
> busses described in Documentation/devicetree/bindings/i2c/i2c.txt.
> It can be managed by clock binding.
>
> 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 <[email protected]>
> Acked-by: Yicong Yang <[email protected]>

Applied to for-current, thanks!


Attachments:
(No filename) (528.00 B)
signature.asc (849.00 B)
Download all attachments

2022-10-05 19:25:50

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH next v4] i2c: hisi: Add support to get clock frequency from clock property

On Wed, Oct 05, 2022 at 09:09:52PM +0200, Wolfram Sang wrote:
> On Thu, Sep 29, 2022 at 03:15:47PM +0800, Weilong Chen wrote:
> > The clk_rate attribute is not generic device tree bindings for I2C
> > busses described in Documentation/devicetree/bindings/i2c/i2c.txt.
> > It can be managed by clock binding.
> >
> > 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 <[email protected]>
> > Acked-by: Yicong Yang <[email protected]>
>
> Applied to for-current, thanks!

Ah, sorry, wrong branch. Not applied because the dependency "i2c: hisi:
Add initial device tree support" is not applied yet (needs changes)


Attachments:
(No filename) (759.00 B)
signature.asc (849.00 B)
Download all attachments