From: Weilong Chen <chenweilong@huawei.com>
To: <chenweilong@huawei.com>, <yangyicong@hisilicon.com>
Cc: <linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] i2c: hisi: Add support to get clock frequency from clock property
Date: Wed, 21 Sep 2022 18:15:40 +0800 [thread overview]
Message-ID: <20220921101540.352553-1-chenweilong@huawei.com> (raw)
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>
---
drivers/i2c/busses/i2c-hisi.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c
index 67031024217c..5e48d4ee0c6d 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>
@@ -91,6 +92,7 @@ struct hisi_i2c_controller {
void __iomem *iobase;
struct device *dev;
int irq;
+ struct clk *clk;
/* Intermediates for recording the transfer process */
struct completion *completion;
@@ -456,10 +458,21 @@ 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(&pdev->dev, NULL);
+ if (IS_ERR(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 {
+ ret = clk_prepare_enable(ctlr->clk);
+ if (ret) {
+ dev_err(dev, "failed to enable clock, ret = %d\n", ret);
+ return ret;
+ }
+
+ clk_rate_hz = clk_get_rate(ctlr->clk);
}
ctlr->clk_rate_khz = DIV_ROUND_UP_ULL(clk_rate_hz, HZ_PER_KHZ);
@@ -475,8 +488,10 @@ static int hisi_i2c_probe(struct platform_device *pdev)
i2c_set_adapdata(adapter, ctlr);
ret = devm_i2c_add_adapter(dev, adapter);
- if (ret)
+ if (ret) {
+ clk_disable_unprepare(ctlr->clk);
return ret;
+ }
hw_version = readl(ctlr->iobase + HISI_I2C_VERSION);
dev_info(ctlr->dev, "speed mode is %s. hw version 0x%x\n",
--
2.31.GIT
next reply other threads:[~2022-09-21 10:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 10:15 Weilong Chen [this message]
2022-09-22 11:49 ` [PATCH] i2c: hisi: Add support to get clock frequency from clock property Yicong Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220921101540.352553-1-chenweilong@huawei.com \
--to=chenweilong@huawei.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yangyicong@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).