[RFC] dm: uclass: add functions to get device by platdata

Simon Glass sjg at chromium.org
Thu Mar 5 00:11:27 CET 2020

Hi Walter,

On Wed, 4 Mar 2020 at 12:40, Walter Lozano <walter.lozano at collabora.com> wrote:
> When OF_PLATDATA is enabled DT information is parsed and platdata
> structures are populated. In this context the links between DT nodes are
> represented as pointers to platdata structures, and there is no clear way
> to access to the device which owns the structure.
> This patch implements a set of functions:
> - device_find_by_platdata
> - uclass_find_device_by_platdata
> to access to the device.
> Signed-off-by: Walter Lozano <walter.lozano at collabora.com>
> ---
>  drivers/core/device.c        | 19 +++++++++++++++++++
>  drivers/core/uclass.c        | 34 ++++++++++++++++++++++++++++++++++
>  include/dm/device.h          |  2 ++
>  include/dm/uclass-internal.h |  3 +++
>  include/dm/uclass.h          |  2 ++
>  5 files changed, 60 insertions(+)

This is interesting. Could you also add the motivation for this? It's
not clear to me who would call this function.

Also it relates to another thing I've been thinking about for a while,
which is to validate that all the structs pointed to are correct.

E.g. if every struct had a magic number like:

struct tpm_platdata {
    fields here

then we could check the structure pointers are correct.

DM_STRUCT() would define to nothing if we were not building with
CONFIG_DM_DEBUG or similar.

Anyway, I wonder whether you could expand your definition a bit so you
have an enum for the different types of struct you can request:

enum dm_struct_t {


and modify the function so it can request it via the enum?


More information about the U-Boot mailing list