]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: clk: Define clk_get_parent_rate() for clk operations
authorLukasz Majewski <lukma@denx.de>
Mon, 24 Jun 2019 13:50:43 +0000 (15:50 +0200)
committerStefano Babic <sbabic@denx.de>
Fri, 19 Jul 2019 12:50:30 +0000 (14:50 +0200)
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>
drivers/clk/clk-uclass.c
include/clk.h

index 4346c61eea16e62c5b06c79b88d6ce1c39aa5675..899b2dda6f318e26d865fdfc60288e6ff5c356ec 100644 (file)
@@ -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);
index e20641ee982877fe1f19bb4e83fc38d50ae251c6..7b2ff8ebe602fbcb4c1e32778c40fe8a95d75f14 100644 (file)
@@ -267,6 +267,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.
  *