drivers: Add devinfo uclass
PATCH 1/2 drivers: Add devinfo uclass
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.
--- 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
drivers/Kconfig +2 -0
@@ -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"
drivers/Makefile +1 -0
@@ -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/
drivers/devinfo/Kconfig new file +17 -0
@@ -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
drivers/devinfo/Makefile new file +9 -0
@@ -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
drivers/devinfo/devinfo-uclass.c new file +55 -0
55 lines not on this page · raw message
include/devinfo.h new file +56 -0
56 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -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 */
Signature · 1 line
2.16.1
PATCH 2/2 devinfo: Add gazerbeam info driver
Add a device information driver for the upcoming gdsys Gazerbeam board.
--- drivers/devinfo/gazerbeam.c | 151 ++++++++++++++++++++++++++++++++++++++++++++ drivers/devinfo/gazerbeam.h | 17 +++++ 2 files changed, 168 insertions(+) create mode 100644 drivers/devinfo/gazerbeam.c create mode 100644 drivers/devinfo/gazerbeam.h
drivers/devinfo/gazerbeam.c new file +151 -0
@@ -0,0 +1,151 @@ +/* +* (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> +#include <i2c.h> +#include <asm/gpio.h> + +#include "gazerbeam.h" + +const int VER_GPIOS_COUNT =4 ; + +struct devinfo_gazerbeam_priv { +struct gpio_desc var_gpios[2 ]; +struct gpio_desc ver_gpios[4 ]; +int variant; +int multichannel; +int hwversion; +}; + +static int _read_multichannel_variant (struct udevice *dev) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); +struct udevice *i2c_bus; +struct udevice *dummy; +char *listname; +bool mc4, mc2, sc, con; + +uclass_get_device_by_seq (UCLASS_I2C ,1 , &i2c_bus); + +if (!i2c_bus) { +puts ("Could not get I2C bus\n" ); +return -EIO ; + } + + mc2 = !dm_i2c_probe (i2c_bus,0x20 ,0 , &dummy); + mc4 = !dm_i2c_probe (i2c_bus,0x22 ,0 , &dummy); + +if (mc2 && mc4) { +puts ("Board hardware configuration inconsistent.\n" ); +return -EINVAL ; + } + + listname = mc2 ?"var_gpios_mc2" :"var_gpios_mc4" ; + +if (!gpio_request_list_by_name (dev, listname, priv->var_gpios, +2 ,GPIOD_IS_IN )) { +printf ("Requesting gpio list %s failed.\n" , listname); +return -ENODEV ; + } + + sc =dm_gpio_get_value (&priv->var_gpios[0 ]); + con =dm_gpio_get_value (&priv->var_gpios[1 ]); + +if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) { +puts ("Board hardware configuration inconsistent.\n" ); +return -EINVAL ; + } + + priv->variant = con ?VAR_CON :VAR_CPU ; + + priv->multichannel = mc4 ?4 : (mc2 ?2 : (sc ?1 :0 )); + +return 0 ; +} + +static int _read_hwversion (struct udevice *dev) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); +int value; + +if (!gpio_request_list_by_name (dev,"ver_gpios" , priv->ver_gpios, +VER_GPIOS_COUNT ,GPIOD_IS_IN )) +return -ENODEV ; + + value =dm_gpio_get_values_as_int (priv->ver_gpios,VER_GPIOS_COUNT ); + +if (value <0 ) +return value; + + priv->hwversion = value; + +gpio_free_list (dev, priv->ver_gpios,VER_GPIOS_COUNT ); + +return 0 ; +} + +int devinfo_gazerbeam_detect (struct udevice *dev) +{ +int res; + + res =_read_multichannel_variant (dev); +if (res) +return res; + + res =_read_hwversion (dev); +if (res) +return res; + +return 0 ; +} + +int devinfo_gazerbeam_get_int (struct udevice *dev,int id,int *val) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); + +switch (id) { +case DEVINFO_MULTICHANNEL : + *val = priv->multichannel; +break ; +case DEVINFO_VARIANT : + *val = priv->variant; +break ; +case DEVINFO_HWVERSION : + *val = priv->hwversion; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct udevice_id devinfo_gazerbeam_ids[] = { + { .compatible ="gdsys,devinfo_gazerbeam" }, + {/* sentinel */ } +}; + +static const struct devinfo_ops devinfo_gazerbeam_ops = { + .detect = devinfo_gazerbeam_detect, + .get_int = devinfo_gazerbeam_get_int, +}; + +int devinfo_gazerbeam_probe (struct udevice *dev) +{ +return 0 ; +} + +U_BOOT_DRIVER (devinfo_gazerbeam) = { + .name ="devinfo_gazerbeam" , + .id =UCLASS_DEVINFO , + .of_match = devinfo_gazerbeam_ids, + .ops = &devinfo_gazerbeam_ops, + .priv_auto_alloc_size =sizeof (struct devinfo_gazerbeam_priv ), + .probe = devinfo_gazerbeam_probe, +};
drivers/devinfo/gazerbeam.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* (C) Copyright 2017 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +enum { +DEVINFO_MULTICHANNEL , +DEVINFO_VARIANT , +DEVINFO_HWVERSION , +}; + +enum { +VAR_CON , +VAR_CPU , +};
Signature · 1 line
2.16.1
PATCH 2/2 devinfo: Add gazerbeam info driver
Hi Mario,
Quoted 40 lines · Mario Six
Add a device information driver for the upcoming gdsys Gazerbeam board.
Signed-off-by Mario Six <[email protected]>--- drivers/devinfo/gazerbeam.c | 151 ++++++++++++++++++++++++++++++++++++++++++++ drivers/devinfo/gazerbeam.h | 17 +++++ 2 files changed, 168 insertions(+) create mode 100644 drivers/devinfo/gazerbeam.c create mode 100644 drivers/devinfo/gazerbeam.hdrivers/devinfo/gazerbeam.c new file +24
-0@@ -0,0 +1,151 @@ +/* +* (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> +#include <i2c.h> +#include <asm/gpio.h> + +#include "gazerbeam.h" + +const int VER_GPIOS_COUNT =4 ; + +struct devinfo_gazerbeam_priv { +struct gpio_desc var_gpios[2 ]; +struct gpio_desc ver_gpios[4 ]; +int variant; +int multichannel; +int hwversion; +};
drivers/devinfo/gazerbeam.c line 34
Quoted 10 lines
drivers/devinfo/gazerbeam.c new file +10
-0+ +static int _read_multichannel_variant (struct udevice *dev) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); +struct udevice *i2c_bus; +struct udevice *dummy; +char *listname; +bool mc4, mc2, sc, con; + +uclass_get_device_by_seq (UCLASS_I2C ,1 , &i2c_bus);
Please pass the error through unless there is a good reason not to.
ret = uclass ...
if (ret) {
debug(...)
return ret
}
drivers/devinfo/gazerbeam.c line 42
Quoted 8 lines
drivers/devinfo/gazerbeam.c new file +8
-0+ +if (!i2c_bus) { +puts ("Could not get I2C bus\n" ); +return -EIO ; + } + + mc2 = !dm_i2c_probe (i2c_bus,0x20 ,0 , &dummy); + mc4 = !dm_i2c_probe (i2c_bus,0x22 ,0 , &dummy);
Same here
drivers/devinfo/gazerbeam.c line 49
Quoted 7 lines
drivers/devinfo/gazerbeam.c new file +7
-0+ +if (mc2 && mc4) { +puts ("Board hardware configuration inconsistent.\n" ); +return -EINVAL ; + } + + listname = mc2 ?"var_gpios_mc2" :"var_gpios_mc4" ;
If these are DT properties they should use hyphen instead of underscore
drivers/devinfo/gazerbeam.c line 54
Quoted 5 lines
drivers/devinfo/gazerbeam.c new file +5
-0+ +if (!gpio_request_list_by_name (dev, listname, priv->var_gpios, +2 ,GPIOD_IS_IN )) { +printf ("Requesting gpio list %s failed.\n" , listname); +return -ENODEV ;
Return correct error
drivers/devinfo/gazerbeam.c line 58
Quoted 4 lines
drivers/devinfo/gazerbeam.c new file +4
-0+ } + + sc =dm_gpio_get_value (&priv->var_gpios[0 ]); + con =dm_gpio_get_value (&priv->var_gpios[1 ]);
And here
Quoted 9 lines
drivers/devinfo/gazerbeam.c new file +9
-0+ +if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) { +puts ("Board hardware configuration inconsistent.\n" ); +return -EINVAL ; + } + + priv->variant = con ?VAR_CON :VAR_CPU ; + + priv->multichannel = mc4 ?4 : (mc2 ?2 : (sc ?1 :0 ));
drivers/devinfo/gazerbeam.c line 77
Quoted 10 lines
drivers/devinfo/gazerbeam.c new file +10
-0+ +return 0 ; +} + +static int _read_hwversion(struct udevice *dev) +{ + struct devinfo_gazerbeam_priv *priv = dev_get_priv(dev); + int value; + + if (!gpio_request_list_by_name(dev, "ver_gpios", priv->ver_gpios,
ver-gpios ?
Quoted 98 lines
drivers/devinfo/gazerbeam.c new file +74
-0+ VER_GPIOS_COUNT, GPIOD_IS_IN)) +return -ENODEV ; + + value =dm_gpio_get_values_as_int (priv->ver_gpios,VER_GPIOS_COUNT ); + +if (value <0 ) +return value; + + priv->hwversion = value; + +gpio_free_list (dev, priv->ver_gpios,VER_GPIOS_COUNT ); + +return 0 ; +} + +int devinfo_gazerbeam_detect (struct udevice *dev) +{ +int res; + + res =_read_multichannel_variant (dev); +if (res) +return res; + + res =_read_hwversion (dev); +if (res) +return res; + +return 0 ; +} + +int devinfo_gazerbeam_get_int (struct udevice *dev,int id,int *val) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); + +switch (id) { +case DEVINFO_MULTICHANNEL : + *val = priv->multichannel; +break ; +case DEVINFO_VARIANT : + *val = priv->variant; +break ; +case DEVINFO_HWVERSION : + *val = priv->hwversion; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct udevice_id devinfo_gazerbeam_ids[] = { + { .compatible ="gdsys,devinfo_gazerbeam" }, + {/* sentinel */ } +}; + +static const struct devinfo_ops devinfo_gazerbeam_ops = { + .detect = devinfo_gazerbeam_detect, + .get_int = devinfo_gazerbeam_get_int, +}; + +int devinfo_gazerbeam_probe (struct udevice *dev) +{ +return 0 ; +} + +U_BOOT_DRIVER (devinfo_gazerbeam) = { + .name ="devinfo_gazerbeam" , + .id =UCLASS_DEVINFO , + .of_match = devinfo_gazerbeam_ids, + .ops = &devinfo_gazerbeam_ops, + .priv_auto_alloc_size =sizeof (struct devinfo_gazerbeam_priv ), + .probe = devinfo_gazerbeam_probe, +};drivers/devinfo/gazerbeam.h new file +17
-1@@ -0,0 +1,17 @@ +/* +* (C) Copyright 2017 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +enum { +DEVINFO_MULTICHANNEL , +DEVINFO_VARIANT , +DEVINFO_HWVERSION , +}; + +enum { +VAR_CON , +VAR_CPU , +}; --
Quoted 2 lines
2.16.1
Regards,
Simon
PATCH 2/2 devinfo: Add gazerbeam info driver
Hi Simon,
Quoted 213 lines · Simon Glass
Hi Mario,
Quoted 40 lines · Mario Six
Add a device information driver for the upcoming gdsys Gazerbeam board.
Signed-off-by Mario Six <[email protected]>--- drivers/devinfo/gazerbeam.c | 151 ++++++++++++++++++++++++++++++++++++++++++++ drivers/devinfo/gazerbeam.h | 17 +++++ 2 files changed, 168 insertions(+) create mode 100644 drivers/devinfo/gazerbeam.c create mode 100644 drivers/devinfo/gazerbeam.hdrivers/devinfo/gazerbeam.c new file +24
-0@@ -0,0 +1,151 @@ +/* +* (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> +#include <i2c.h> +#include <asm/gpio.h> + +#include "gazerbeam.h" + +const int VER_GPIOS_COUNT =4 ; + +struct devinfo_gazerbeam_priv { +struct gpio_desc var_gpios[2 ]; +struct gpio_desc ver_gpios[4 ]; +int variant; +int multichannel; +int hwversion; +};drivers/devinfo/gazerbeam.c line 34
Quoted 10 lines
drivers/devinfo/gazerbeam.c new file +10
-0+ +static int _read_multichannel_variant (struct udevice *dev) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); +struct udevice *i2c_bus; +struct udevice *dummy; +char *listname; +bool mc4, mc2, sc, con; + +uclass_get_device_by_seq (UCLASS_I2C ,1 , &i2c_bus);Please pass the error through unless there is a good reason not to.
ret = uclass ...
if (ret) { debug(...) return ret }drivers/devinfo/gazerbeam.c line 42
Quoted 8 lines
drivers/devinfo/gazerbeam.c new file +8
-0+ +if (!i2c_bus) { +puts ("Could not get I2C bus\n" ); +return -EIO ; + } + + mc2 = !dm_i2c_probe (i2c_bus,0x20 ,0 , &dummy); + mc4 = !dm_i2c_probe (i2c_bus,0x22 ,0 , &dummy);Same here
drivers/devinfo/gazerbeam.c line 49
Quoted 7 lines
drivers/devinfo/gazerbeam.c new file +7
-0+ +if (mc2 && mc4) { +puts ("Board hardware configuration inconsistent.\n" ); +return -EINVAL ; + } + + listname = mc2 ?"var_gpios_mc2" :"var_gpios_mc4" ;If these are DT properties they should use hyphen instead of underscore
drivers/devinfo/gazerbeam.c line 54
Quoted 5 lines
drivers/devinfo/gazerbeam.c new file +5
-0+ +if (!gpio_request_list_by_name (dev, listname, priv->var_gpios, +2 ,GPIOD_IS_IN )) { +printf ("Requesting gpio list %s failed.\n" , listname); +return -ENODEV ;Return correct error
drivers/devinfo/gazerbeam.c line 58
Quoted 4 lines
drivers/devinfo/gazerbeam.c new file +4
-0+ } + + sc =dm_gpio_get_value (&priv->var_gpios[0 ]); + con =dm_gpio_get_value (&priv->var_gpios[1 ]);And here
Quoted 9 lines
drivers/devinfo/gazerbeam.c new file +9
-0+ +if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) { +puts ("Board hardware configuration inconsistent.\n" ); +return -EINVAL ; + } + + priv->variant = con ?VAR_CON :VAR_CPU ; + + priv->multichannel = mc4 ?4 : (mc2 ?2 : (sc ?1 :0 ));drivers/devinfo/gazerbeam.c line 77
Quoted 10 lines
drivers/devinfo/gazerbeam.c new file +10
-0+ +return 0 ; +} + +static int _read_hwversion(struct udevice *dev) +{ + struct devinfo_gazerbeam_priv *priv = dev_get_priv(dev); + int value; + + if (!gpio_request_list_by_name(dev, "ver_gpios", priv->ver_gpios,ver-gpios ?
Quoted 95 lines
drivers/devinfo/gazerbeam.c new file +74
-0+ VER_GPIOS_COUNT, GPIOD_IS_IN)) +return -ENODEV ; + + value =dm_gpio_get_values_as_int (priv->ver_gpios,VER_GPIOS_COUNT ); + +if (value <0 ) +return value; + + priv->hwversion = value; + +gpio_free_list (dev, priv->ver_gpios,VER_GPIOS_COUNT ); + +return 0 ; +} + +int devinfo_gazerbeam_detect (struct udevice *dev) +{ +int res; + + res =_read_multichannel_variant (dev); +if (res) +return res; + + res =_read_hwversion (dev); +if (res) +return res; + +return 0 ; +} + +int devinfo_gazerbeam_get_int (struct udevice *dev,int id,int *val) +{ +struct devinfo_gazerbeam_priv *priv =dev_get_priv (dev); + +switch (id) { +case DEVINFO_MULTICHANNEL : + *val = priv->multichannel; +break ; +case DEVINFO_VARIANT : + *val = priv->variant; +break ; +case DEVINFO_HWVERSION : + *val = priv->hwversion; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct udevice_id devinfo_gazerbeam_ids[] = { + { .compatible ="gdsys,devinfo_gazerbeam" }, + {/* sentinel */ } +}; + +static const struct devinfo_ops devinfo_gazerbeam_ops = { + .detect = devinfo_gazerbeam_detect, + .get_int = devinfo_gazerbeam_get_int, +}; + +int devinfo_gazerbeam_probe (struct udevice *dev) +{ +return 0 ; +} + +U_BOOT_DRIVER (devinfo_gazerbeam) = { + .name ="devinfo_gazerbeam" , + .id =UCLASS_DEVINFO , + .of_match = devinfo_gazerbeam_ids, + .ops = &devinfo_gazerbeam_ops, + .priv_auto_alloc_size =sizeof (struct devinfo_gazerbeam_priv ), + .probe = devinfo_gazerbeam_probe, +};drivers/devinfo/gazerbeam.h new file +15
-0@@ -0,0 +1,17 @@ +/* +* (C) Copyright 2017 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +enum { +DEVINFO_MULTICHANNEL , +DEVINFO_VARIANT , +DEVINFO_HWVERSION , +}; + +enum { +VAR_CON ,
Quoted 9 lines
Quoted 5 lines
drivers/devinfo/gazerbeam.h new file +2
-1+ VAR_CPU, +}; --2.16.1
Regards,
Simon
I'll address all problems in v2. Thanks for reviewing!
Best regards,
Mario
PATCH 1/2 drivers: Add devinfo uclass
In reply to Mario SixHi Mario,
Quoted 10 lines · Mario Six
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 <[email protected]>
Quoted 13 lines
--- 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?
Quoted 131 lines
drivers/Kconfig +2
-0@@ -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"drivers/Makefile +1
-0@@ -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/drivers/devinfo/Kconfig new file +17
-0@@ -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. + +endifdrivers/devinfo/Makefile new file +9
-0@@ -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.odrivers/devinfo/devinfo-uclass.c new file +55
-0@@ -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" , +};include/devinfo.h new file +0
-0
include/devinfo.h line 9
Quoted 9 lines
include/devinfo.h new file +9
-0@@ -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
include/devinfo.h line 10
Quoted 1 line
include/devinfo.h new file +1
-0+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.
include/devinfo.h line 12
Quoted 2 lines
include/devinfo.h new file +2
-0+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.
include/devinfo.h line 20
Quoted 8 lines
include/devinfo.h new file +8
-0+}; + +#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
Quoted 49 lines
include/devinfo.h new file +36
-0+* @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);include/dm/uclass-id.h +1
-1@@ -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 */ --
Quoted 2 lines
2.16.1
Regards,
Simon
PATCH 1/2 drivers: Add devinfo uclass
Hi Simon,
Quoted 240 lines · Simon Glass
Hi Mario,
Quoted 10 lines · Mario Six
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 <[email protected]>Quoted 13 lines
--- 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.hPlease can you add a sandbox driver for this and a test?
Quoted 131 lines
drivers/Kconfig +2
-0@@ -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"drivers/Makefile +1
-0@@ -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/drivers/devinfo/Kconfig new file +17
-0@@ -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. + +endifdrivers/devinfo/Makefile new file +9
-0@@ -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.odrivers/devinfo/devinfo-uclass.c new file +55
-0@@ -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" , +};include/devinfo.h new file +0
-0include/devinfo.h line 9
Quoted 9 lines
include/devinfo.h new file +9
-0@@ -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
include/devinfo.h line 10
Quoted 1 line
include/devinfo.h new file +1
-0+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.
include/devinfo.h line 12
Quoted 2 lines
include/devinfo.h new file +2
-0+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.
include/devinfo.h line 20
Quoted 8 lines
include/devinfo.h new file +8
-0+}; + +#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
Quoted 46 lines
include/devinfo.h new file +36
-0+* @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);include/dm/uclass-id.h +1
-0@@ -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 */
Quoted 8 lines
Quoted 5 lines
include/dm/uclass-id.h +0
-1UCLASS_EFI ,/* EFI managed devices */ UCLASS_ETH, /* Ethernet device */ --2.16.1
Regards,
Simon
I'll address all problems in v2. Thanks for reviewing!
Best regards,
Mario