Re: [U-Boot] [PATCH 1/2] drivers: Add devinfo uclass
Hi Simon, On Fri, Mar 30, 2018 at 10:40 AM, Simon Glasswrote: > Hi Mario, > > On 28 March 2018 at 20:36, Mario Six 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 >> --- >> 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 00..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 00..0a9cad4a15 >> --- /dev/null >> +++ b/drivers/devinfo/Makefile >> @@ -0,0 +1,9 @@ >> +# >> +# (C) Copyright 2017 >> +# Mario Six, Guntermann & Drunck GmbH, mario@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 00..89bbe8f343 >> --- /dev/null >> +++ b/drivers/devinfo/devinfo-uclass.c >> @@ -0,0 +1,55 @@ >> +/* >> + * (C) Copyright 2017 >> + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc >> + * >> + * SPDX-License-Identifier:GPL-2.0+ >> + */ >> + >> +#include >> +#include >> +#include >> + >> +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 00..90014c27c4 >>
Re: [U-Boot] [PATCH 1/2] drivers: Add devinfo uclass
Hi Mario, On 28 March 2018 at 20:36, Mario Sixwrote: > 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 > --- > 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 00..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 00..0a9cad4a15 > --- /dev/null > +++ b/drivers/devinfo/Makefile > @@ -0,0 +1,9 @@ > +# > +# (C) Copyright 2017 > +# Mario Six, Guntermann & Drunck GmbH, mario@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 00..89bbe8f343 > --- /dev/null > +++ b/drivers/devinfo/devinfo-uclass.c > @@ -0,0 +1,55 @@ > +/* > + * (C) Copyright 2017 > + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc > + * > + * SPDX-License-Identifier:GPL-2.0+ > + */ > + > +#include > +#include > +#include > + > +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 00..90014c27c4 > --- /dev/null > +++ b/include/devinfo.h > @@ -0,0 +1,56 @@ > +/* > + * (C) Copyright 2017 > + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc > + * > + * SPDX-License-Identifier:GPL-2.0+ > + */ > + > +struct devinfo_ops { > + int
[U-Boot] [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. Signed-off-by: Mario Six--- 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 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 00..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 00..0a9cad4a15 --- /dev/null +++ b/drivers/devinfo/Makefile @@ -0,0 +1,9 @@ +# +# (C) Copyright 2017 +# Mario Six, Guntermann & Drunck GmbH, mario@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 00..89bbe8f343 --- /dev/null +++ b/drivers/devinfo/devinfo-uclass.c @@ -0,0 +1,55 @@ +/* + * (C) Copyright 2017 + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc + * + * SPDX-License-Identifier:GPL-2.0+ + */ + +#include +#include +#include + +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 00..90014c27c4 --- /dev/null +++ b/include/devinfo.h @@ -0,0 +1,56 @@ +/* + * (C) Copyright 2017 + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc + * + * SPDX-License-Identifier:GPL-2.0+ + */ + +struct devinfo_ops { + int (*detect)(struct udevice *dev); + int (*get_bool)(struct udevice *dev, int id, bool *val); + int (*get_int)(struct udevice *dev, int id, int *val); + int (*get_str)(struct udevice *dev, int id, char *val); +}; + +#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. + *