aboutsummaryrefslogtreecommitdiffstats
path: root/roms/u-boot/drivers/sysinfo
diff options
context:
space:
mode:
Diffstat (limited to 'roms/u-boot/drivers/sysinfo')
-rw-r--r--roms/u-boot/drivers/sysinfo/Kconfig41
-rw-r--r--roms/u-boot/drivers/sysinfo/Makefile9
-rw-r--r--roms/u-boot/drivers/sysinfo/gazerbeam.c265
-rw-r--r--roms/u-boot/drivers/sysinfo/gazerbeam.h19
-rw-r--r--roms/u-boot/drivers/sysinfo/gpio.c141
-rw-r--r--roms/u-boot/drivers/sysinfo/sandbox.c107
-rw-r--r--roms/u-boot/drivers/sysinfo/sandbox.h12
-rw-r--r--roms/u-boot/drivers/sysinfo/smbios.c24
-rw-r--r--roms/u-boot/drivers/sysinfo/sysinfo-uclass.c98
9 files changed, 716 insertions, 0 deletions
diff --git a/roms/u-boot/drivers/sysinfo/Kconfig b/roms/u-boot/drivers/sysinfo/Kconfig
new file mode 100644
index 000000000..381dcd884
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/Kconfig
@@ -0,0 +1,41 @@
+menuconfig SYSINFO
+ bool "Device System 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 SYSINFO
+
+config SPL_SYSINFO
+ depends on SPL_DM
+ bool "Enable board driver support in SPL"
+
+config SYSINFO_GAZERBEAM
+ bool "Enable sysinfo driver for the Gazerbeam board"
+ help
+ Support querying device information for the gdsys Gazerbeam board.
+
+config SYSINFO_SANDBOX
+ bool "Enable sysinfo driver for the Sandbox board"
+ help
+ Support querying device information for the Sandbox boards.
+
+config SYSINFO_SMBIOS
+ bool "Provide a default sysinfo driver for SMBIOS information"
+ help
+ Some boards want to specify the manufacturer or product name but do
+ not need to have their own sysinfo driver. This includes a default
+ one which provides a way to specify this SMBIOS information in the
+ devicetree, without needing any board-specific functionality.
+
+config SYSINFO_GPIO
+ bool "Enable gpio sysinfo driver"
+ help
+ Support querying gpios to determine board revision. This uses gpios to
+ form a ternary number (when they are pulled-up, -down, or floating).
+ This ternary number is then mapped to a board revision name using
+ device tree properties.
+
+endif
diff --git a/roms/u-boot/drivers/sysinfo/Makefile b/roms/u-boot/drivers/sysinfo/Makefile
new file mode 100644
index 000000000..d9f708b7e
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2017
+# Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+obj-y += sysinfo-uclass.o
+obj-$(CONFIG_SYSINFO_GAZERBEAM) += gazerbeam.o
+obj-$(CONFIG_SYSINFO_GPIO) += gpio.o
+obj-$(CONFIG_SYSINFO_SANDBOX) += sandbox.o
+obj-$(CONFIG_SYSINFO_SMBIOS) += smbios.o
diff --git a/roms/u-boot/drivers/sysinfo/gazerbeam.c b/roms/u-boot/drivers/sysinfo/gazerbeam.c
new file mode 100644
index 000000000..c1fae6ccf
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/gazerbeam.c
@@ -0,0 +1,265 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2017
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sysinfo.h>
+#include <i2c.h>
+#include <log.h>
+#include <asm/gpio.h>
+
+#include "gazerbeam.h"
+
+/* Sequence number of I2C bus that holds the GPIO expanders */
+static const int I2C_BUS_SEQ_NO = 1;
+
+/* I2C address of SC/MC2 expander */
+static const int MC2_EXPANDER_ADDR = 0x20;
+/* I2C address of MC4 expander */
+static const int MC4_EXPANDER_ADDR = 0x22;
+
+/* Number of the GPIO to read the SC data from */
+static const int SC_GPIO_NO;
+/* Number of the GPIO to read the CON data from */
+static const int CON_GPIO_NO = 1;
+
+/**
+ * struct sysinfo_gazerbeam_priv - Private data structure for the gazerbeam
+ * sysinfo driver
+ * @reset_gpios: GPIOs for the sysinfo's reset GPIOs.
+ * @var_gpios: GPIOs for the sysinfo's hardware variant GPIOs
+ * @ver_gpios: GPIOs for the sysinfo's hardware version GPIOs
+ * @variant: Container for the sysinfo's hardware variant (CON/CPU)
+ * @multichannel: Container for the sysinfo's multichannel variant (MC4/MC2/SC)
+ * @hwversion: Container for the sysinfo's hardware version
+ */
+struct sysinfo_gazerbeam_priv {
+ struct gpio_desc reset_gpios[2];
+ struct gpio_desc var_gpios[2];
+ struct gpio_desc ver_gpios[4];
+ int variant;
+ int multichannel;
+ int hwversion;
+};
+
+/**
+ * _read_sysinfo_variant_data() - Read variant information from the hardware.
+ * @dev: The sysinfo device for which to determine the multichannel and device
+ * type information.
+ *
+ * The data read from the sysinfo's hardware (mostly hard-wired GPIOs) is stored
+ * in the private data structure of the driver to be used by other driver
+ * methods.
+ *
+ * Return: 0 if OK, -ve on error.
+ */
+static int _read_sysinfo_variant_data(struct udevice *dev)
+{
+ struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev);
+ struct udevice *i2c_bus;
+ struct udevice *dummy;
+ char *listname;
+ int mc4, mc2, sc, mc2_sc, con;
+ int gpio_num;
+ int res;
+
+ res = uclass_get_device_by_seq(UCLASS_I2C, I2C_BUS_SEQ_NO, &i2c_bus);
+ if (res) {
+ debug("%s: Could not get I2C bus %d (err = %d)\n",
+ dev->name, I2C_BUS_SEQ_NO, res);
+ return res;
+ }
+
+ if (!i2c_bus) {
+ debug("%s: Could not get I2C bus %d\n",
+ dev->name, I2C_BUS_SEQ_NO);
+ return -EIO;
+ }
+
+ mc2_sc = !dm_i2c_probe(i2c_bus, MC2_EXPANDER_ADDR, 0, &dummy);
+ mc4 = !dm_i2c_probe(i2c_bus, MC4_EXPANDER_ADDR, 0, &dummy);
+
+ if (mc2_sc && mc4) {
+ debug("%s: Board hardware configuration inconsistent.\n",
+ dev->name);
+ return -EINVAL;
+ }
+
+ listname = mc2_sc ? "var-gpios-mc2" : "var-gpios-mc4";
+
+ gpio_num = gpio_request_list_by_name(dev, listname, priv->var_gpios,
+ ARRAY_SIZE(priv->var_gpios),
+ GPIOD_IS_IN);
+ if (gpio_num < 0) {
+ debug("%s: Requesting gpio list %s failed (err = %d).\n",
+ dev->name, listname, gpio_num);
+ return gpio_num;
+ }
+
+ sc = dm_gpio_get_value(&priv->var_gpios[SC_GPIO_NO]);
+ if (sc < 0) {
+ debug("%s: Error while reading 'sc' GPIO (err = %d)",
+ dev->name, sc);
+ return sc;
+ }
+
+ mc2 = mc2_sc ? (sc ? 0 : 1) : 0;
+
+ if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) {
+ debug("%s: Board hardware configuration inconsistent.\n",
+ dev->name);
+ return -EINVAL;
+ }
+
+ con = dm_gpio_get_value(&priv->var_gpios[CON_GPIO_NO]);
+ if (con < 0) {
+ debug("%s: Error while reading 'con' GPIO (err = %d)",
+ dev->name, con);
+ return con;
+ }
+
+ priv->variant = con ? VAR_CON : VAR_CPU;
+
+ priv->multichannel = mc4 ? 4 : (mc2 ? 2 : (sc ? 1 : 0));
+
+ return 0;
+}
+
+/**
+ * _read_hwversion() - Read the hardware version from the sysinfo.
+ * @dev: The sysinfo device for which to read the hardware version.
+ *
+ * The hardware version read from the sysinfo (from hard-wired GPIOs) is stored
+ * in the private data structure of the driver to be used by other driver
+ * methods.
+ *
+ * Return: 0 if OK, -ve on error.
+ */
+static int _read_hwversion(struct udevice *dev)
+{
+ struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev);
+ int res;
+
+ res = gpio_request_list_by_name(dev, "ver-gpios", priv->ver_gpios,
+ ARRAY_SIZE(priv->ver_gpios),
+ GPIOD_IS_IN);
+ if (res < 0) {
+ debug("%s: Error getting GPIO list 'ver-gpios' (err = %d)\n",
+ dev->name, res);
+ return -ENODEV;
+ }
+
+ res = dm_gpio_get_values_as_int(priv->ver_gpios,
+ ARRAY_SIZE(priv->ver_gpios));
+ if (res < 0) {
+ debug("%s: Error reading HW version from expander (err = %d)\n",
+ dev->name, res);
+ return res;
+ }
+
+ priv->hwversion = res;
+
+ res = gpio_free_list(dev, priv->ver_gpios, ARRAY_SIZE(priv->ver_gpios));
+ if (res < 0) {
+ debug("%s: Error freeing HW version GPIO list (err = %d)\n",
+ dev->name, res);
+ return res;
+ }
+
+ return 0;
+}
+
+static int sysinfo_gazerbeam_detect(struct udevice *dev)
+{
+ int res;
+
+ res = _read_sysinfo_variant_data(dev);
+ if (res) {
+ debug("%s: Error reading multichannel variant (err = %d)\n",
+ dev->name, res);
+ return res;
+ }
+
+ res = _read_hwversion(dev);
+ if (res) {
+ debug("%s: Error reading hardware version (err = %d)\n",
+ dev->name, res);
+ return res;
+ }
+
+ return 0;
+}
+
+static int sysinfo_gazerbeam_get_int(struct udevice *dev, int id, int *val)
+{
+ struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev);
+
+ switch (id) {
+ case BOARD_MULTICHANNEL:
+ *val = priv->multichannel;
+ break;
+ case BOARD_VARIANT:
+ *val = priv->variant;
+ break;
+ case BOARD_HWVERSION:
+ *val = priv->hwversion;
+ break;
+ default:
+ debug("%s: Integer value %d unknown\n", dev->name, id);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static const struct udevice_id sysinfo_gazerbeam_ids[] = {
+ { .compatible = "gdsys,sysinfo-gazerbeam" },
+ { /* sentinel */ }
+};
+
+static const struct sysinfo_ops sysinfo_gazerbeam_ops = {
+ .detect = sysinfo_gazerbeam_detect,
+ .get_int = sysinfo_gazerbeam_get_int,
+};
+
+static int sysinfo_gazerbeam_probe(struct udevice *dev)
+{
+ struct sysinfo_gazerbeam_priv *priv = dev_get_priv(dev);
+ int gpio_num, i;
+
+ gpio_num = gpio_request_list_by_name(dev, "reset-gpios",
+ priv->reset_gpios,
+ ARRAY_SIZE(priv->reset_gpios),
+ GPIOD_IS_OUT);
+
+ if (gpio_num < 0) {
+ debug("%s: Error getting GPIO list 'reset-gpios' (err = %d)\n",
+ dev->name, gpio_num);
+ return gpio_num;
+ }
+
+ /* Set startup-finished GPIOs */
+ for (i = 0; i < ARRAY_SIZE(priv->reset_gpios); i++) {
+ int res = dm_gpio_set_value(&priv->reset_gpios[i], 0);
+
+ if (res) {
+ debug("%s: Error while setting GPIO %d (err = %d)\n",
+ dev->name, i, res);
+ return res;
+ }
+ }
+
+ return 0;
+}
+
+U_BOOT_DRIVER(sysinfo_gazerbeam) = {
+ .name = "sysinfo_gazerbeam",
+ .id = UCLASS_SYSINFO,
+ .of_match = sysinfo_gazerbeam_ids,
+ .ops = &sysinfo_gazerbeam_ops,
+ .priv_auto = sizeof(struct sysinfo_gazerbeam_priv),
+ .probe = sysinfo_gazerbeam_probe,
+};
diff --git a/roms/u-boot/drivers/sysinfo/gazerbeam.h b/roms/u-boot/drivers/sysinfo/gazerbeam.h
new file mode 100644
index 000000000..6bf3c0098
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/gazerbeam.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2017
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ *
+ */
+
+#include <sysinfo.h>
+
+enum {
+ BOARD_HWVERSION = SYSINFO_ID_BOARD_MODEL,
+ BOARD_MULTICHANNEL = SYSINFO_ID_USER,
+ BOARD_VARIANT
+};
+
+enum {
+ VAR_CON,
+ VAR_CPU,
+};
diff --git a/roms/u-boot/drivers/sysinfo/gpio.c b/roms/u-boot/drivers/sysinfo/gpio.c
new file mode 100644
index 000000000..1d7f05099
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/gpio.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Sean Anderson <sean.anderson@seco.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <log.h>
+#include <sysinfo.h>
+#include <asm/gpio.h>
+#include <dm/device_compat.h>
+
+/**
+ * struct sysinfo_gpio_priv - GPIO sysinfo private data
+ * @gpios: List of GPIOs used to detect the revision
+ * @gpio_num: The number of GPIOs in @gpios
+ * @revision: The revision as detected from the GPIOs.
+ */
+struct sysinfo_gpio_priv {
+ struct gpio_desc *gpios;
+ int gpio_num, revision;
+};
+
+static int sysinfo_gpio_detect(struct udevice *dev)
+{
+ int ret;
+ struct sysinfo_gpio_priv *priv = dev_get_priv(dev);
+
+ ret = dm_gpio_get_values_as_int_base3(priv->gpios, priv->gpio_num);
+ if (ret < 0)
+ return ret;
+
+ priv->revision = ret;
+ return 0;
+}
+
+static int sysinfo_gpio_get_int(struct udevice *dev, int id, int *val)
+{
+ struct sysinfo_gpio_priv *priv = dev_get_priv(dev);
+
+ switch (id) {
+ case SYSINFO_ID_BOARD_MODEL:
+ *val = priv->revision;
+ return 0;
+ default:
+ return -EINVAL;
+ };
+}
+
+static int sysinfo_gpio_get_str(struct udevice *dev, int id, size_t size, char *val)
+{
+ struct sysinfo_gpio_priv *priv = dev_get_priv(dev);
+
+ switch (id) {
+ case SYSINFO_ID_BOARD_MODEL: {
+ const char *name = NULL;
+ int i, ret;
+ u32 revision;
+
+ for (i = 0; i < priv->gpio_num; i++) {
+ ret = dev_read_u32_index(dev, "revisions", i,
+ &revision);
+ if (ret) {
+ if (ret != -EOVERFLOW)
+ return ret;
+ break;
+ }
+
+ if (revision == priv->revision) {
+ ret = dev_read_string_index(dev, "names", i,
+ &name);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ }
+ if (!name)
+ name = "unknown";
+
+ strncpy(val, name, size);
+ val[size - 1] = '\0';
+ return 0;
+ } default:
+ return -EINVAL;
+ };
+}
+
+static const struct sysinfo_ops sysinfo_gpio_ops = {
+ .detect = sysinfo_gpio_detect,
+ .get_int = sysinfo_gpio_get_int,
+ .get_str = sysinfo_gpio_get_str,
+};
+
+static int sysinfo_gpio_probe(struct udevice *dev)
+{
+ int ret;
+ struct sysinfo_gpio_priv *priv = dev_get_priv(dev);
+
+ priv->gpio_num = gpio_get_list_count(dev, "gpios");
+ if (priv->gpio_num < 0) {
+ dev_err(dev, "could not get gpios length (err = %d)\n",
+ priv->gpio_num);
+ return priv->gpio_num;
+ }
+
+ priv->gpios = calloc(priv->gpio_num, sizeof(*priv->gpios));
+ if (!priv->gpios) {
+ dev_err(dev, "could not allocate memory for %d gpios\n",
+ priv->gpio_num);
+ return -ENOMEM;
+ }
+
+ ret = gpio_request_list_by_name(dev, "gpios", priv->gpios,
+ priv->gpio_num, GPIOD_IS_IN);
+ if (ret != priv->gpio_num) {
+ dev_err(dev, "could not get gpios (err = %d)\n",
+ priv->gpio_num);
+ return ret;
+ }
+
+ if (!dev_read_bool(dev, "revisions") || !dev_read_bool(dev, "names")) {
+ dev_err(dev, "revisions or names properties missing\n");
+ return -ENOENT;
+ }
+
+ return 0;
+}
+
+static const struct udevice_id sysinfo_gpio_ids[] = {
+ { .compatible = "gpio-sysinfo" },
+ { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sysinfo_gpio) = {
+ .name = "sysinfo_gpio",
+ .id = UCLASS_SYSINFO,
+ .of_match = sysinfo_gpio_ids,
+ .ops = &sysinfo_gpio_ops,
+ .priv_auto = sizeof(struct sysinfo_gpio_priv),
+ .probe = sysinfo_gpio_probe,
+};
diff --git a/roms/u-boot/drivers/sysinfo/sandbox.c b/roms/u-boot/drivers/sysinfo/sandbox.c
new file mode 100644
index 000000000..d270a26aa
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/sandbox.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sysinfo.h>
+
+#include "sandbox.h"
+
+struct sysinfo_sandbox_priv {
+ bool called_detect;
+ int test_i1;
+ int test_i2;
+};
+
+char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng",
+ "Carcosa", "Yuggoth", "The Nameless City"};
+
+int sysinfo_sandbox_detect(struct udevice *dev)
+{
+ struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
+
+ priv->called_detect = true;
+ priv->test_i2 = 100;
+
+ return 0;
+}
+
+int sysinfo_sandbox_get_bool(struct udevice *dev, int id, bool *val)
+{
+ struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
+
+ switch (id) {
+ case BOOL_CALLED_DETECT:
+ /* Checks if the dectect method has been called */
+ *val = priv->called_detect;
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
+int sysinfo_sandbox_get_int(struct udevice *dev, int id, int *val)
+{
+ struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
+
+ switch (id) {
+ case INT_TEST1:
+ *val = priv->test_i1;
+ /* Increments with every call */
+ priv->test_i1++;
+ return 0;
+ case INT_TEST2:
+ *val = priv->test_i2;
+ /* Decrements with every call */
+ priv->test_i2--;
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
+int sysinfo_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val)
+{
+ struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
+ int i1 = priv->test_i1;
+ int i2 = priv->test_i2;
+ int index = (i1 * i2) % ARRAY_SIZE(vacation_spots);
+
+ switch (id) {
+ case STR_VACATIONSPOT:
+ /* Picks a vacation spot depending on i1 and i2 */
+ snprintf(val, size, vacation_spots[index]);
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
+static const struct udevice_id sysinfo_sandbox_ids[] = {
+ { .compatible = "sandbox,sysinfo-sandbox" },
+ { /* sentinel */ }
+};
+
+static const struct sysinfo_ops sysinfo_sandbox_ops = {
+ .detect = sysinfo_sandbox_detect,
+ .get_bool = sysinfo_sandbox_get_bool,
+ .get_int = sysinfo_sandbox_get_int,
+ .get_str = sysinfo_sandbox_get_str,
+};
+
+int sysinfo_sandbox_probe(struct udevice *dev)
+{
+ return 0;
+}
+
+U_BOOT_DRIVER(sysinfo_sandbox) = {
+ .name = "sysinfo_sandbox",
+ .id = UCLASS_SYSINFO,
+ .of_match = sysinfo_sandbox_ids,
+ .ops = &sysinfo_sandbox_ops,
+ .priv_auto = sizeof(struct sysinfo_sandbox_priv),
+ .probe = sysinfo_sandbox_probe,
+};
diff --git a/roms/u-boot/drivers/sysinfo/sandbox.h b/roms/u-boot/drivers/sysinfo/sandbox.h
new file mode 100644
index 000000000..d9c5804c2
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/sandbox.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+enum {
+ BOOL_CALLED_DETECT = SYSINFO_ID_USER,
+ INT_TEST1,
+ INT_TEST2,
+ STR_VACATIONSPOT,
+};
diff --git a/roms/u-boot/drivers/sysinfo/smbios.c b/roms/u-boot/drivers/sysinfo/smbios.c
new file mode 100644
index 000000000..80ebd1921
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/smbios.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2020 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sysinfo.h>
+
+static const struct udevice_id sysinfo_smbios_ids[] = {
+ { .compatible = "u-boot,sysinfo-smbios" },
+ { /* sentinel */ }
+};
+
+static const struct sysinfo_ops sysinfo_smbios_ops = {
+};
+
+U_BOOT_DRIVER(sysinfo_smbios) = {
+ .name = "sysinfo_smbios",
+ .id = UCLASS_SYSINFO,
+ .of_match = sysinfo_smbios_ids,
+ .ops = &sysinfo_smbios_ops,
+};
diff --git a/roms/u-boot/drivers/sysinfo/sysinfo-uclass.c b/roms/u-boot/drivers/sysinfo/sysinfo-uclass.c
new file mode 100644
index 000000000..4a660dfd1
--- /dev/null
+++ b/roms/u-boot/drivers/sysinfo/sysinfo-uclass.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2017
+ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <sysinfo.h>
+
+struct sysinfo_priv {
+ bool detected;
+};
+
+int sysinfo_get(struct udevice **devp)
+{
+ return uclass_first_device_err(UCLASS_SYSINFO, devp);
+}
+
+int sysinfo_detect(struct udevice *dev)
+{
+ int ret;
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!ops->detect)
+ return -ENOSYS;
+
+ ret = ops->detect(dev);
+ if (!ret)
+ priv->detected = true;
+
+ return ret;
+}
+
+int sysinfo_get_fit_loadable(struct udevice *dev, int index, const char *type,
+ const char **strp)
+{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!priv->detected)
+ return -EPERM;
+
+ if (!ops->get_fit_loadable)
+ return -ENOSYS;
+
+ return ops->get_fit_loadable(dev, index, type, strp);
+}
+
+int sysinfo_get_bool(struct udevice *dev, int id, bool *val)
+{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!priv->detected)
+ return -EPERM;
+
+ if (!ops->get_bool)
+ return -ENOSYS;
+
+ return ops->get_bool(dev, id, val);
+}
+
+int sysinfo_get_int(struct udevice *dev, int id, int *val)
+{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!priv->detected)
+ return -EPERM;
+
+ if (!ops->get_int)
+ return -ENOSYS;
+
+ return ops->get_int(dev, id, val);
+}
+
+int sysinfo_get_str(struct udevice *dev, int id, size_t size, char *val)
+{
+ struct sysinfo_priv *priv = dev_get_uclass_priv(dev);
+ struct sysinfo_ops *ops = sysinfo_get_ops(dev);
+
+ if (!priv->detected)
+ return -EPERM;
+
+ if (!ops->get_str)
+ return -ENOSYS;
+
+ return ops->get_str(dev, id, size, val);
+}
+
+UCLASS_DRIVER(sysinfo) = {
+ .id = UCLASS_SYSINFO,
+ .name = "sysinfo",
+ .post_bind = dm_scan_fdt_dev,
+ .per_device_auto = sizeof(bool),
+};