Re: [PATCH] clk: add api to get clk consummer from clk_hw

From: Stephen Boyd
Date: Wed May 27 2020 - 05:17:41 EST


Quoting Jerome Brunet (2020-05-19 10:04:40)
> clk_register() is deprecated. Using 'clk' member of struct clk_hw is
> discouraged. With this constrainst, it is difficult for driver to

s/constrainst/constraint/

> register clocks using the clk_hw API and then use the clock with
> the consummer API

s/consummer/consumer/

>
> This add a simple helper, clk_hw_get_clk(), to get a struct clk from
> a struct clk_hw. Like other clk_get() variant, each call to this helper
> must be balanced with a call to clk_put().
>
> Cc: Martin Blumenstingl <martin.blumenstingl@xxxxxxxxxxxxxx>
> Signed-off-by: Jerome Brunet <jbrunet@xxxxxxxxxxxx>

I like it!

> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 6fd23ce3cb03..d9946e192cbc 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3625,6 +3625,23 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw,
> return clk;
> }
>
> +/**
> + * clk_hw_get_clk: get clk consummer given an clk_hw

s/consummer/consumer/

> + * @hw: clk_hw associated with the clk being consumed
> + *
> + * Returns: new clk consummer
> + * This is the function to be used by providers which need
> + * to get a consummer clk and act on the clock element

s/consummer/consumer/

> + * Calls to this function must be balanced with calls clk_put()

calls to clk_put()

> + */
> +struct clk *clk_hw_get_clk(struct clk_hw *hw)

Can it also take a const char *id argument? That will let us "name" the
clk structure for situations where we want to keep track of who is using
the clk pointer for things. If that doesn't seem useful then I suppose
we can pass a string like "clk_hw_get_clk" for con_id below and hope it
doesn't become useful later.

> +{
> + struct device *dev = hw->core->dev;
> +
> + return clk_hw_create_clk(dev, hw, dev_name(dev), NULL);
> +}
> +EXPORT_SYMBOL(clk_hw_get_clk);
> +
> static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist)
> {
> const char *dst;