diff mbox series

[U-Boot,v5,09/18] dm: clk: Define clk_get_parent_rate() for clk operations

Message ID 20190624135052.2699-10-lukma@denx.de
State Accepted
Commit 4aa78300a025b7e09aa8e902b2178b1870ef1ec5
Delegated to: Stefano Babic
Headers show
Series clk: Port Linux common clock framework [CCF] to U-boot (tag: v5.1.12) | expand

Commit Message

Lukasz Majewski June 24, 2019, 1:50 p.m. UTC
This commit adds the clk_get_parent_rate() function, which is responsible
for getting the rate of parent clock.
Unfortunately, u-boot's DM support for getting parent is different
(the parent relationship is in udevice) than the one in Common Clock
Framework [CCF] in Linux.

To alleviate this problem - the clk_get_parent_rate() function has been
introduced to clk-uclass.c.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

---

Changes in v6: None
Changes in v5:
- Replace ulong with long long (to accommodate large freqs and return
  errors)

Changes in v4: None
Changes in v3:
- The rate information is now cached into struct clk field
- The clk_get_parent() is used to get pointer to the parent struct clk

 drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++
 include/clk.h            |  9 +++++++++
 2 files changed, 31 insertions(+)

Comments

Stefano Babic July 20, 2019, 8:51 a.m. UTC | #1
> This commit adds the clk_get_parent_rate() function, which is responsible
> for getting the rate of parent clock.
> Unfortunately, u-boot's DM support for getting parent is different
> (the parent relationship is in udevice) than the one in Common Clock
> Framework [CCF] in Linux.
> To alleviate this problem - the clk_get_parent_rate() function has been
> introduced to clk-uclass.c.
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 4346c61eea..899b2dda6f 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -395,6 +395,28 @@  struct clk *clk_get_parent(struct clk *clk)
 	return pclk;
 }
 
+long long clk_get_parent_rate(struct clk *clk)
+{
+	const struct clk_ops *ops;
+	struct clk *pclk;
+
+	debug("%s(clk=%p)\n", __func__, clk);
+
+	pclk = clk_get_parent(clk);
+	if (IS_ERR(pclk))
+		return -ENODEV;
+
+	ops = clk_dev_ops(pclk->dev);
+	if (!ops->get_rate)
+		return -ENOSYS;
+
+	/* Read the 'rate' if not already set */
+	if (!pclk->rate)
+		pclk->rate = clk_get_rate(pclk);
+
+	return pclk->rate;
+}
+
 ulong clk_set_rate(struct clk *clk, ulong rate)
 {
 	const struct clk_ops *ops = clk_dev_ops(clk->dev);
diff --git a/include/clk.h b/include/clk.h
index e20641ee98..7b2ff8ebe6 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -268,6 +268,15 @@  ulong clk_get_rate(struct clk *clk);
 struct clk *clk_get_parent(struct clk *clk);
 
 /**
+ * clk_get_parent_rate() - Get parent of current clock rate.
+ *
+ * @clk:	A clock struct that was previously successfully requested by
+ *		clk_request/get_by_*().
+ * @return clock rate in Hz, or -ve error code.
+ */
+long long clk_get_parent_rate(struct clk *clk);
+
+/**
  * clk_set_rate() - Set current clock rate.
  *
  * @clk:	A clock struct that was previously successfully requested by