[PATCH 06/13] clk: implement clk clk_hw_get_parent_by_index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is the inverse operation to clk_get_parent_index and is already
implemented inline in clk_get_parent. Factor that code out for use by
the incoming STM32MP13 clock driver.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 drivers/clk/clk.c   | 25 +++++++++++++++++++++----
 include/linux/clk.h |  1 +
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 25d32e9e12f9..acd90e6e5889 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -318,6 +318,26 @@ int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *newparent)
 	return clk_set_parent(&hw->clk, &newparent->clk);
 }
 
+static struct clk *clk_get_parent_by_index(struct clk *clk, u8 idx)
+{
+	if (IS_ERR_OR_NULL(clk->parents[idx]))
+		clk->parents[idx] = clk_lookup(clk->parent_names[idx]);
+
+	return clk->parents[idx];
+}
+
+struct clk_hw *
+clk_hw_get_parent_by_index(const struct clk_hw *hw, unsigned int idx)
+{
+	struct clk *clk = clk_hw_to_clk(hw);
+
+	if (!clk || idx >= clk->num_parents || !clk->parents)
+		return NULL;
+
+	return clk_to_clk_hw(clk_get_parent_by_index(clk, idx));
+}
+EXPORT_SYMBOL_GPL(clk_hw_get_parent_by_index);
+
 struct clk *clk_get_parent(struct clk *clk)
 {
 	struct clk_hw *hw;
@@ -343,10 +363,7 @@ struct clk *clk_get_parent(struct clk *clk)
 		idx = 0;
 	}
 
-	if (IS_ERR_OR_NULL(clk->parents[idx]))
-		clk->parents[idx] = clk_lookup(clk->parent_names[idx]);
-
-	return clk->parents[idx];
+	return clk_get_parent_by_index(clk, idx);
 }
 
 struct clk_hw *clk_hw_get_parent(struct clk_hw *hw)
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 269664b0ba63..6a33f28ee60a 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -129,6 +129,7 @@ int clk_hw_set_rate(struct clk_hw *hw, unsigned long rate);
  */
 int clk_set_parent(struct clk *clk, struct clk *parent);
 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *hwp);
+struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw, unsigned int idx);
 
 /**
  * clk_get_parent - get the parent clock source for this clock
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux