[U-Boot] [PATCH 1/3] core: Add function to get device for ofnode

Simon Glass sjg at chromium.org
Thu Mar 29 22:43:13 UTC 2018


Hi Mario,

On 28 March 2018 at 20:37, Mario Six <mario.six at gdsys.cc> wrote:
> It's sometimes useful to get the device associated with a given ofnode.
> Implement a function to implement this lookup operation.

Where would you use this? Can you not use phandles to find the device?
Or uclass_get_device_by_ofnode() ?

>
> Signed-off-by: Mario Six <mario.six at gdsys.cc>
> ---
>  drivers/core/ofnode.c | 15 +++++++++++++++
>  include/dm/ofnode.h   |  8 ++++++++
>  2 files changed, 23 insertions(+)
>
> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
> index 4e4532651f..ca002063b3 100644
> --- a/drivers/core/ofnode.c
> +++ b/drivers/core/ofnode.c
> @@ -16,6 +16,21 @@
>  #include <linux/err.h>
>  #include <linux/ioport.h>
>
> +struct udevice *ofnode_dev(ofnode node)

Can you please add a test for this?

This seems like an internal function since it does not probe the
device. So how about putting it in device.h:

device_get_by_ofnode() - does probe the device it returns
device_find_by_ofnode() - doesn't probe

> +{
> +       struct uclass *uc;
> +       struct udevice *dev;
> +
> +       list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
> +               list_for_each_entry(dev, &uc->dev_head, uclass_node) {
> +                       if (ofnode_equal(dev_ofnode(dev), node))
> +                               return dev;
> +               }
> +       }
> +
> +       return NULL;
> +}
> +
>  int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
>  {
>         assert(ofnode_valid(node));
> diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
> index 0d008404f9..aec205eb80 100644
> --- a/include/dm/ofnode.h
> +++ b/include/dm/ofnode.h
> @@ -193,6 +193,14 @@ static inline ofnode ofnode_null(void)
>         return node;
>  }
>
> +/**
> + * ofnode_dev() - Get the device associated with a given ofnode
> + *
> + * @node:      valid node reference to get the corresponding device for
> + * @return a pointer to the udevice if OK, NULL on error
> + */
> +struct udevice *ofnode_dev(ofnode node);
> +
>  /**
>   * ofnode_read_u32() - Read a 32-bit integer from a property
>   *
> --
> 2.16.1
>

Regards,
Simon


More information about the U-Boot mailing list