[U-Boot] [PATCH v2 2/3] devinfo: Add gazerbeam board driver
Mario Six
mario.six at gdsys.cc
Fri Apr 27 12:51:33 UTC 2018
Add a board driver for the upcoming gdsys Gazerbeam board.
Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
v1 -> v2:
* Improved error handling
* Renamed DT properties
* Moved the driver over to the board uclass
---
drivers/board/gazerbeam.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++
drivers/board/gazerbeam.h | 17 +++++
2 files changed, 190 insertions(+)
create mode 100644 drivers/board/gazerbeam.c
create mode 100644 drivers/board/gazerbeam.h
diff --git a/drivers/board/gazerbeam.c b/drivers/board/gazerbeam.c
new file mode 100644
index 0000000000..b4c2a01d76
--- /dev/null
+++ b/drivers/board/gazerbeam.c
@@ -0,0 +1,173 @@
+/*
+ * (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 <board.h>
+#include <i2c.h>
+#include <asm/gpio.h>
+
+#include "gazerbeam.h"
+
+const int VER_GPIOS_COUNT = 4;
+
+struct board_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 board_gazerbeam_priv *priv = dev_get_priv(dev);
+ struct udevice *i2c_bus;
+ struct udevice *dummy;
+ char *listname;
+ int mc4, mc2, sc, con;
+ int gpio_num;
+ int res;
+
+ res = uclass_get_device_by_seq(UCLASS_I2C, 1, &i2c_bus);
+ if (res) {
+ debug("Could not get I2C bus\n");
+ return res;
+ }
+
+ if (!i2c_bus) {
+ debug("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) {
+ debug("Board hardware configuration inconsistent.\n");
+ return -EINVAL;
+ }
+
+ listname = mc2 ? "var-gpios-mc2" : "var-gpios-mc4";
+
+ gpio_num = gpio_request_list_by_name(dev, listname, priv->var_gpios, 2,
+ GPIOD_IS_IN);
+ if (gpio_num < 0) {
+ debug("Requesting gpio list %s failed.\n", listname);
+ return gpio_num;
+ }
+
+ sc = dm_gpio_get_value(&priv->var_gpios[0]);
+ if (sc < 0) {
+ debug("Error while reading sc GPIO");
+ return sc;
+ }
+
+ con = dm_gpio_get_value(&priv->var_gpios[1]);
+ if (con < 0) {
+ debug("Error while reading con GPIO");
+ return con;
+ }
+
+ if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) {
+ debug("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 board_gazerbeam_priv *priv = dev_get_priv(dev);
+ int res;
+
+ if (!gpio_request_list_by_name(dev, "ver-gpios", priv->ver_gpios,
+ VER_GPIOS_COUNT, GPIOD_IS_IN))
+ return -ENODEV;
+
+ res = dm_gpio_get_values_as_int(priv->ver_gpios, VER_GPIOS_COUNT);
+
+ if (res < 0) {
+ debug("Error while reading HW version from GPIO expander\n");
+ return res;
+ }
+
+ priv->hwversion = res;
+
+ res = gpio_free_list(dev, priv->ver_gpios, VER_GPIOS_COUNT);
+ if (res < 0) {
+ debug("Error while freeing HW version GPIO list\n");
+ return res;
+ }
+
+ return 0;
+}
+
+int board_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 board_gazerbeam_get_int(struct udevice *dev, int id, int *val)
+{
+ struct board_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:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static const struct udevice_id board_gazerbeam_ids[] = {
+ { .compatible = "gdsys,board_gazerbeam" },
+ { /* sentinel */ }
+};
+
+static const struct board_ops board_gazerbeam_ops = {
+ .detect = board_gazerbeam_detect,
+ .get_int = board_gazerbeam_get_int,
+};
+
+int board_gazerbeam_probe(struct udevice *dev)
+{
+ return 0;
+}
+
+U_BOOT_DRIVER(board_gazerbeam) = {
+ .name = "board_gazerbeam",
+ .id = UCLASS_BOARD,
+ .of_match = board_gazerbeam_ids,
+ .ops = &board_gazerbeam_ops,
+ .priv_auto_alloc_size = sizeof(struct board_gazerbeam_priv),
+ .probe = board_gazerbeam_probe,
+};
diff --git a/drivers/board/gazerbeam.h b/drivers/board/gazerbeam.h
new file mode 100644
index 0000000000..532001a053
--- /dev/null
+++ b/drivers/board/gazerbeam.h
@@ -0,0 +1,17 @@
+/*
+ * (C) Copyright 2017
+ * Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+enum {
+ BOARD_MULTICHANNEL,
+ BOARD_VARIANT,
+ BOARD_HWVERSION,
+};
+
+enum {
+ VAR_CON,
+ VAR_CPU,
+};
--
2.16.1
More information about the U-Boot
mailing list