[U-Boot] [PATCH 1/2] drivers: Add devinfo uclass
Simon Glass
sjg at chromium.org
Fri Mar 30 08:40:45 UTC 2018
Hi Mario,
On 28 March 2018 at 20:36, Mario Six <mario.six at gdsys.cc> wrote:
> Some boards have encoded information, e.g. hard-wired GPIOs on a GPIO
> expander, read-only memory ICs, etc. that carry information about the
> hardware.
>
> Add a uclass that encapsulates device information of such a kind and
> makes them accessible in a uniform manner. The devices of this uclass
> expose methods to read generic data types (integers, strings, booleans)
> to encode the information provided by the hardware.
>
> Signed-off-by: Mario Six <mario.six at gdsys.cc>
> ---
> drivers/Kconfig | 2 ++
> drivers/Makefile | 1 +
> drivers/devinfo/Kconfig | 17 ++++++++++++
> drivers/devinfo/Makefile | 9 +++++++
> drivers/devinfo/devinfo-uclass.c | 55 +++++++++++++++++++++++++++++++++++++++
> include/devinfo.h | 56 ++++++++++++++++++++++++++++++++++++++++
> include/dm/uclass-id.h | 1 +
> 7 files changed, 141 insertions(+)
> create mode 100644 drivers/devinfo/Kconfig
> create mode 100644 drivers/devinfo/Makefile
> create mode 100644 drivers/devinfo/devinfo-uclass.c
> create mode 100644 include/devinfo.h
Please can you add a sandbox driver for this and a test?
>
> diff --git a/drivers/Kconfig b/drivers/Kconfig
> index c2e813f5ad..34777d9013 100644
> --- a/drivers/Kconfig
> +++ b/drivers/Kconfig
> @@ -22,6 +22,8 @@ source "drivers/ddr/Kconfig"
>
> source "drivers/demo/Kconfig"
>
> +source "drivers/devinfo/Kconfig"
> +
> source "drivers/ddr/fsl/Kconfig"
>
> source "drivers/dfu/Kconfig"
> diff --git a/drivers/Makefile b/drivers/Makefile
> index 6846d181aa..208b68081e 100644
> --- a/drivers/Makefile
> +++ b/drivers/Makefile
> @@ -72,6 +72,7 @@ obj-y += block/
> obj-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount/
> obj-$(CONFIG_CPU) += cpu/
> obj-y += crypto/
> +obj-y += devinfo/
> obj-y += firmware/
> obj-$(CONFIG_FPGA) += fpga/
> obj-y += misc/
> diff --git a/drivers/devinfo/Kconfig b/drivers/devinfo/Kconfig
> new file mode 100644
> index 0000000000..0de70b410e
> --- /dev/null
> +++ b/drivers/devinfo/Kconfig
> @@ -0,0 +1,17 @@
> +menuconfig DEVINFO
> + bool "Device Information"
> + help
> + Support methods to query hardware configurations from internal
> + mechanisms (e.g. reading GPIO values, determining the presence of
> + devices on busses, etc.). This enables the usage of U-Boot with
> + modular board architectures.
> +
> +if DEVINFO
> +
> +
> +config DEVINFO_GAZERBEAM
> + bool "Enable device information for the Gazerbeam board"
> + help
> + Support querying device information for the gdsys Gazerbeam board.
> +
> +endif
> diff --git a/drivers/devinfo/Makefile b/drivers/devinfo/Makefile
> new file mode 100644
> index 0000000000..0a9cad4a15
> --- /dev/null
> +++ b/drivers/devinfo/Makefile
> @@ -0,0 +1,9 @@
> +#
> +# (C) Copyright 2017
> +# Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc
> +#
> +# SPDX-License-Identifier: GPL-2.0+
> +#
> +
> +obj-$(CONFIG_DEVINFO) += devinfo-uclass.o
> +obj-$(CONFIG_DEVINFO_GAZERBEAM) += gazerbeam.o
> diff --git a/drivers/devinfo/devinfo-uclass.c b/drivers/devinfo/devinfo-uclass.c
> new file mode 100644
> index 0000000000..89bbe8f343
> --- /dev/null
> +++ b/drivers/devinfo/devinfo-uclass.c
> @@ -0,0 +1,55 @@
> +/*
> + * (C) Copyright 2017
> + * Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <devinfo.h>
> +
> +int devinfo_detect(struct udevice *dev)
> +{
> + struct devinfo_ops *ops = devinfo_get_ops(dev);
> +
> + if (!ops->detect)
> + return -ENOSYS;
> +
> + return ops->detect(dev);
> +}
> +
> +int devinfo_get_bool(struct udevice *dev, int id, bool *val)
> +{
> + struct devinfo_ops *ops = devinfo_get_ops(dev);
> +
> + if (!ops->get_bool)
> + return -ENOSYS;
> +
> + return ops->get_bool(dev, id, val);
> +}
> +
> +int devinfo_get_int(struct udevice *dev, int id, int *val)
> +{
> + struct devinfo_ops *ops = devinfo_get_ops(dev);
> +
> + if (!ops->get_int)
> + return -ENOSYS;
> +
> + return ops->get_int(dev, id, val);
> +}
> +
> +int devinfo_get_str(struct udevice *dev, int id, char *val)
> +{
> + struct devinfo_ops *ops = devinfo_get_ops(dev);
> +
> + if (!ops->get_str)
> + return -ENOSYS;
> +
> + return ops->get_str(dev, id, val);
> +}
> +
> +UCLASS_DRIVER(devinfo) = {
> + .id = UCLASS_DEVINFO,
> + .name = "devinfo",
> +};
> diff --git a/include/devinfo.h b/include/devinfo.h
> new file mode 100644
> index 0000000000..90014c27c4
> --- /dev/null
> +++ b/include/devinfo.h
> @@ -0,0 +1,56 @@
> +/*
> + * (C) Copyright 2017
> + * Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +struct devinfo_ops {
> + int (*detect)(struct udevice *dev);
Need comments for these functions
> + int (*get_bool)(struct udevice *dev, int id, bool *val);
Who allocates the id? Is this a board-specific header file? In any
case, please explain this somewhere.
> + int (*get_int)(struct udevice *dev, int id, int *val);
> + int (*get_str)(struct udevice *dev, int id, char *val);
This should have a length param so you can check that the buffer
provided is big enough.
> +};
> +
> +#define devinfo_get_ops(dev) ((struct devinfo_ops *)(dev)->driver->ops)
> +
> +/**
> + * devinfo_detect() - Run the hardware info detection procedure for this device.
> + *
> + * @dev: The devinfo instance to gather the data.
The device containing the information
> + * @return 0 if OK, -ve on error.
> + */
> +int devinfo_detect(struct udevice *dev);
> +
> +/**
> + * devinfo_get_bool() - Read a specific bool data value that describes the
> + * hardware setup.
> + *
> + * @dev: The devinfo instance to gather the data.
> + * @id: A unique identifier for the bool value to be read.
> + * @val: Pointer to a buffer that receives the value read.
> + * @return 0 if OK, -ve on error.
> + */
> +int devinfo_get_bool(struct udevice *dev, int id, bool *val);
> +
> +/**
> + * devinfo_get_int() - Read a specific int data value that describes the
> + * hardware setup.
> + *
> + * @dev: The devinfo instance to gather the data.
> + * @id: A unique identifier for the int value to be read.
> + * @val: Pointer to a buffer that receives the value read.
> + * @return 0 if OK, -ve on error.
> + */
> +int devinfo_get_int(struct udevice *dev, int id, int *val);
> +
> +/**
> + * devinfo_get_str() - Read a specific string data value that describes the
> + * hardware setup.
> + *
> + * @dev: The devinfo instance to gather the data.
> + * @id: A unique identifier for the string value to be read.
> + * @val: Pointer to a buffer that receives the value read.
> + * @return 0 if OK, -ve on error.
> + */
> +int devinfo_get_str(struct udevice *dev, int id, char *val);
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index 07fabc3ce6..58925be037 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -33,6 +33,7 @@ enum uclass_id {
> UCLASS_CPU, /* CPU, typically part of an SoC */
> UCLASS_CROS_EC, /* Chrome OS EC */
> UCLASS_DISPLAY, /* Display (e.g. DisplayPort, HDMI) */
> + UCLASS_DEVINFO, /* Device information from hardware */
> UCLASS_DMA, /* Direct Memory Access */
> UCLASS_EFI, /* EFI managed devices */
> UCLASS_ETH, /* Ethernet device */
> --
> 2.16.1
>
Regards,
Simon
More information about the U-Boot
mailing list