[U-Boot] [PATCH v2 04/17] dm: clk: Define clk_get_by_id() for clk operations

Simon Glass sjg at chromium.org
Thu Jan 31 10:05:09 UTC 2019


On Thu, 31 Jan 2019 at 02:04, Lukasz Majewski <lukma at denx.de> wrote:
>
> This commit adds the clk_get_by_id() function, which is responsible
> for getting the udevice with matching clk->id. Such approach allows
> re-usage of inherit DM list relationship for the same class (UCLASS_CLK).
> As a result - we don't need any other external list - it is just enough
> to look for UCLASS_CLK related udevices.
>
> Signed-off-by: Lukasz Majewski <lukma at denx.de>
> ---
>
> Changes in v2: None
>
>  drivers/clk/clk-uclass.c | 22 ++++++++++++++++++++++
>  include/clk.h            | 11 +++++++++++
>  2 files changed, 33 insertions(+)
>

Please add a test that calls this.

> diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
> index f1640dda67..12ec0baa74 100644
> --- a/drivers/clk/clk-uclass.c
> +++ b/drivers/clk/clk-uclass.c
> @@ -455,6 +455,28 @@ int clk_disable_bulk(struct clk_bulk *bulk)
>         return 0;
>  }
>
> +int clk_get_by_id(ulong id, struct clk **c)

Can you use clkp instead of c?

> +{
> +       struct udevice *dev;
> +       struct uclass *uc;
> +       int ret;
> +
> +       ret = uclass_get(UCLASS_CLK, &uc);
> +       if (ret)
> +               return ret;
> +
> +       uclass_foreach_dev(dev, uc) {
> +               struct clk *clk = (struct clk *)dev_get_driver_data(dev);
> +
> +               if (clk->id == id) {
> +                       *c = clk;
> +                       return 0;
> +               }
> +       }
> +
> +       return -ENODEV;

I wonder if -ENOENT would be better?

> +}
> +
>  UCLASS_DRIVER(clk) = {
>         .id             = UCLASS_CLK,
>         .name           = "clk",
> diff --git a/include/clk.h b/include/clk.h
> index 8224295ec3..045e60357d 100644
> --- a/include/clk.h
> +++ b/include/clk.h
> @@ -315,4 +315,15 @@ static inline bool clk_valid(struct clk *clk)
>  {
>         return !!clk->dev;
>  }
> +
> +/**
> + * clk_get_by_id() - Get the clock by knowing its ID
> + *
> + * @id:        The clock ID to search for
> + *
> + * @c: A pointer to clock struct that has been found among added clocks
> + *      to UCLASS_CLK
> + * @return zero on success, or -ve error code.

-NOENT on error? I think you can be specific here

> + */
> +int clk_get_by_id(ulong id, struct clk **c);
>  #endif
> --
> 2.11.0
>

Regards,
Simon


More information about the U-Boot mailing list