diff mbox series

[U-Boot,v2,2/5] clk: refactor clk_get_by_index() into clk_get_by_indexed_prop()

Message ID 1516911131-51397-3-git-send-email-philipp.tomsich@theobroma-systems.com
State Accepted
Delegated to: Philipp Tomsich
Headers show
Series clk: support assigned-clock, assigned-clock-parents, assigned-clock-rates | expand

Commit Message

Philipp Tomsich Jan. 25, 2018, 8:12 p.m. UTC
The logic in clk_get_by_index() may be useful for other properties
than 'clocks': e.g. 'assigned-clocks' and 'assigned-clock-parents'
follows the same model.

This commit refactors clk_get_by_index() by introducing an internal
function clk_get_by_indexed_prop() that allows to specify the name
of the property to process.  The original clk_get_by_index() call
is simply directed through this helper function with the property
name fixed to "clocks".

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Tested-by: David Wu <david.wu@rock-chips.com>

---

Changes in v2:
- Fixed David's email address.

 drivers/clk/clk-uclass.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Philipp Tomsich Jan. 28, 2018, 4:12 p.m. UTC | #1
> The logic in clk_get_by_index() may be useful for other properties
> than 'clocks': e.g. 'assigned-clocks' and 'assigned-clock-parents'
> follows the same model.
> 
> This commit refactors clk_get_by_index() by introducing an internal
> function clk_get_by_indexed_prop() that allows to specify the name
> of the property to process.  The original clk_get_by_index() call
> is simply directed through this helper function with the property
> name fixed to "clocks".
> 
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> Tested-by: David Wu <david.wu@rock-chips.com>
> ---
> 
> Changes in v2:
> - Fixed David's email address.
> 
>  drivers/clk/clk-uclass.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 

Applied to u-boot-rockchip, thanks!
diff mbox series

Patch

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 20ee0c5..7fdf16d 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -53,7 +53,8 @@  static int clk_of_xlate_default(struct clk *clk,
 	return 0;
 }
 
-int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
+static int clk_get_by_indexed_prop(struct udevice *dev, const char *prop_name,
+				   int index, struct clk *clk)
 {
 	int ret;
 	struct ofnode_phandle_args args;
@@ -65,7 +66,7 @@  int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
 	assert(clk);
 	clk->dev = NULL;
 
-	ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
+	ret = dev_read_phandle_with_args(dev, prop_name, "#clock-cells", 0,
 					 index, &args);
 	if (ret) {
 		debug("%s: fdtdec_parse_phandle_with_args failed: err=%d\n",
@@ -95,6 +96,11 @@  int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
 
 	return clk_request(dev_clk, clk);
 }
+
+int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
+{
+	return clk_get_by_indexed_prop(dev, "clocks", index, clk);
+}
 # endif /* OF_PLATDATA */
 
 int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)