At some places a clk name may be known without having a struct clk * directly. Add some convenience functions to handle this situation and use them in the clk commands. Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> Link: https://lore.barebox.org/20210615141641.31577-2-s.hauer@xxxxxxxxxxxxxx Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- commands/clk.c | 18 ++---------------- drivers/clk/clk.c | 22 ++++++++++++++++++++++ include/linux/clk.h | 4 ++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/commands/clk.c b/commands/clk.c index 2e21e9df58..4d124807bd 100644 --- a/commands/clk.c +++ b/commands/clk.c @@ -54,19 +54,14 @@ BAREBOX_CMD_END static int do_clk_set_rate(int argc, char *argv[]) { - struct clk *clk; unsigned long rate; if (argc != 3) return COMMAND_ERROR_USAGE; - clk = clk_lookup(argv[1]); - if (IS_ERR(clk)) - return PTR_ERR(clk); - rate = simple_strtoul(argv[2], NULL, 0); - return clk_set_rate(clk, rate); + return clk_name_set_rate(argv[1], rate); } BAREBOX_CMD_HELP_START(clk_set_rate) @@ -214,19 +209,10 @@ BAREBOX_CMD_END static int do_clk_set_parent(int argc, char *argv[]) { - struct clk *clk, *parent; - if (argc != 3) return COMMAND_ERROR_USAGE; - clk = clk_lookup(argv[1]); - if (IS_ERR(clk)) - return PTR_ERR(clk); - parent = clk_lookup(argv[2]); - if (IS_ERR(parent)) - return PTR_ERR(parent); - - return clk_set_parent(clk, parent); + return clk_name_set_parent(argv[1], argv[2]); } BAREBOX_CMD_START(clk_set_parent) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ba726c342c..8932cfe54b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -525,6 +525,28 @@ int clk_parent_set_rate(struct clk_hw *hw, unsigned long rate, return clk_set_rate(clk_get_parent(clk), rate); } +int clk_name_set_parent(const char *clkname, const char *clkparentname) +{ + struct clk *clk = clk_lookup(clkname); + struct clk *parent = clk_lookup(clkparentname); + + if (IS_ERR(clk)) + return -ENOENT; + if (IS_ERR(parent)) + return -ENOENT; + return clk_set_parent(clk, parent); +} + +int clk_name_set_rate(const char *clkname, unsigned long rate) +{ + struct clk *clk = clk_lookup(clkname); + + if (IS_ERR(clk)) + return -ENOENT; + + return clk_set_rate(clk, rate); +} + #if defined(CONFIG_COMMON_CLK_OF_PROVIDER) /** * struct of_clk_provider - Clock provider registration structure diff --git a/include/linux/clk.h b/include/linux/clk.h index e54acdd918..6565429a9b 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -681,6 +681,9 @@ static inline const char *clk_hw_get_name(struct clk_hw *hw) return hw->clk.name; } +int clk_name_set_parent(const char *clkname, const char *clkparentname); +int clk_name_set_rate(const char *clkname, unsigned long rate); + #endif struct device_node; @@ -722,6 +725,7 @@ static inline unsigned int clk_get_num_parents(const struct clk *hw) { return hw->num_parents; } + #else -- 2.29.2 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox