[PATCH 6/6] clk: Add a .get_parent operation

Samuel Holland samuel at sholland.org
Mon Feb 20 06:59:39 CET 2023


This allows clk_get_parent() to work with non-CCF clock drivers.

Signed-off-by: Samuel Holland <samuel at sholland.org>
---

 drivers/clk/clk-uclass.c | 18 ++++++++++++------
 include/clk-uclass.h     |  2 ++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 53cfd819779..d0f8906cd60 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -485,6 +485,7 @@ ulong clk_get_rate(struct clk *clk)
 
 struct clk *clk_get_parent(struct clk *clk)
 {
+	const struct clk_ops *ops;
 	struct udevice *pdev;
 	struct clk *pclk;
 
@@ -492,12 +493,17 @@ struct clk *clk_get_parent(struct clk *clk)
 	if (!clk_valid(clk))
 		return ERR_PTR(-ENODEV);
 
-	pdev = dev_get_parent(clk->dev);
-	if (!pdev)
-		return ERR_PTR(-ENODEV);
-	pclk = dev_get_clk_ptr(pdev);
-	if (!pclk)
-		return ERR_PTR(-ENODEV);
+	ops = clk_dev_ops(clk->dev);
+	if (ops->get_parent) {
+		pclk = ops->get_parent(clk);
+	} else {
+		pdev = dev_get_parent(clk->dev);
+		if (!pdev)
+			return ERR_PTR(-ENODEV);
+		pclk = dev_get_clk_ptr(pdev);
+		if (!pclk)
+			return ERR_PTR(-ENODEV);
+	}
 
 	return pclk;
 }
diff --git a/include/clk-uclass.h b/include/clk-uclass.h
index 65ebff9ed27..4d616720865 100644
--- a/include/clk-uclass.h
+++ b/include/clk-uclass.h
@@ -22,6 +22,7 @@ struct ofnode_phandle_args;
  * @round_rate: Adjust a rate to the exact rate a clock can provide.
  * @get_rate: Get current clock rate.
  * @set_rate: Set current clock rate.
+ * @get_parent: Get current clock parent
  * @set_parent: Set current clock parent
  * @enable: Enable a clock.
  * @disable: Disable a clock.
@@ -36,6 +37,7 @@ struct clk_ops {
 	ulong (*round_rate)(struct clk *clk, ulong rate);
 	ulong (*get_rate)(struct clk *clk);
 	ulong (*set_rate)(struct clk *clk, ulong rate);
+	struct clk *(*get_parent)(struct clk *clk);
 	int (*set_parent)(struct clk *clk, struct clk *parent);
 	int (*enable)(struct clk *clk);
 	int (*disable)(struct clk *clk);
-- 
2.39.2



More information about the U-Boot mailing list