Re: [PATCH v6 01/18] clk: introduce clk_hw_get_index_of_parent new API

Stephen Boyd
2022-03-25T01:22:07Z

Quoting Ansuel Smith (2022-03-21 16:15:31)
> Clk can have multiple parents. Some clk may require to get the cached
> index of other parent that are not current associated with the clk.
> We have clk_hw_get_parent_index() that returns the index of the current
> parent but we can't get the index of other parents of the provided clk.
> Introduce clk_hw_get_index_of_parent() to get the cached index of the
> parent of the provided clk. This permits a direct access of the internal
> clk_fetch_parent_index().
>
> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> ---
> drivers/clk/clk.c | 14 ++++++++++++++
> include/linux/clk-provider.h | 1 +
> 2 files changed, 15 insertions(+)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 8de6a22498e7..bdd70a88394c 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1726,6 +1726,20 @@ int clk_hw_get_parent_index(struct clk_hw *hw)
> }
> EXPORT_SYMBOL_GPL(clk_hw_get_parent_index);
>
> +/**
> + * clk_hw_get_index_of_parent - return the index of the parent clock

s/return/get/

> + * @hw: clk_hw associated with the clk being consumed
> + * @parent: clk_hw of the parent to be fetched the index of

s/to be fetched/to fetch/

> + *
> + * Fetches and returns the index of parent clock provided.
> + * Returns -EINVAL if the given parent index can't be provided.

I know this is copied from clk_hw_get_parent_index, but it can be
improved.

Return: The index corresponding to @parent for @hw or -EINVAL if
@parent isn't a possible parent of @hw.

> + */
> +int clk_hw_get_index_of_parent(struct clk_hw *hw, const struct clk_hw *parent)
> +{
> + return clk_fetch_parent_index(hw->core, parent->core);
> +}
> +EXPORT_SYMBOL_GPL(clk_hw_get_index_of_parent);
> +
> /*
> * Update the orphan status of @core and all its children.
> */