[PATCH v1 5/8] ARM: imx6sx: udoo-neo: add version detection support

Oleksij Rempel o.rempel at pengutronix.de
Fri Jan 13 03:34:04 PST 2023


There are different board versions. Make use of it to be able to get
proper kernel devicetree.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 arch/arm/boards/udoo-neo/board.c | 91 +++++++++++++++++++++++++++++++-
 1 file changed, 89 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/udoo-neo/board.c b/arch/arm/boards/udoo-neo/board.c
index e2078e3395..ffdb70dfae 100644
--- a/arch/arm/boards/udoo-neo/board.c
+++ b/arch/arm/boards/udoo-neo/board.c
@@ -2,12 +2,99 @@
 // SPDX-FileCopyrightText: 2014 Sascha Hauer, Pengutronix
 
 #include <common.h>
-#include <init.h>
-#include <linux/clk.h>
 #include <deep-probe.h>
+#include <gpio.h>
+#include <mach/bbu.h>
+#include <mach/imx6.h>
+
+/**
+ * Detects the board model by checking the R184 and R185 resistors.
+ * A mounted resistor (0Ohm) connects the GPIO to ground, so the
+ * GPIO value will be 0.
+ *
+ * FULL     - Eth, WiFi, motion sensors, 1GB RAM         -> R184 not mounted - R185 mounted
+ * EXTENDED - NO Eth, WiFi, motion sensors, 1GB RAM      -> R184 not mounted - R185 not mounted
+ * BASE     - Eth, NO WiFi, NO motion sensors, 512MB RAM -> R184 mounted     - R185 mounted
+ * BASE KS  - NO Eth, WiFi, NO motion sensors, 512MB RAM -> R184 mounted     - R185 not mounted
+ */
+
+enum imx6sx_udoneo_board_type {
+	UDOO_NEO_BASIC = 0,
+	UDOO_NEO_BASIC_KS = 1,
+	UDOO_NEO_FULL = 2,
+	UDOO_NEO_EXTENDED = 3,
+	UDOO_NEO_UNKNOWN,
+};
+
+#define GPIO_R184 IMX_GPIO_NR(4, 13)
+#define GPIO_R185 IMX_GPIO_NR(4, 0)
+
+static enum imx6sx_udoneo_board_type imx6sx_udoneo_detect(struct device *dev)
+{
+	struct device_node *gpio_np = NULL;
+	int r184, r185;
+	int ret;
+
+	gpio_np = of_find_node_by_name_address(NULL, "gpio at 20a8000");
+	if (gpio_np) {
+		ret = of_device_ensure_probed(gpio_np);
+		if (ret) {
+			dev_warn(dev, "Can't probe GPIO node\n");
+			goto detect_error;
+		}
+	} else {
+		dev_warn(dev, "Can't get GPIO node\n");
+		goto detect_error;
+	}
+
+	ret = gpio_request(GPIO_R184, "version r184");
+	if (ret)
+		goto detect_error;
+
+	ret = gpio_request(GPIO_R185, "version r185");
+	if (ret)
+		goto detect_error;
+
+	ret = gpio_direction_input(GPIO_R184);
+	if (ret)
+		goto detect_error;
+
+	ret = gpio_direction_input(GPIO_R185);
+	if (ret)
+		goto detect_error;
+
+	r184 = gpio_get_value(GPIO_R184);
+	r185 = gpio_get_value(GPIO_R185);
+
+	return r184 << 1 | r185 << 0;
+
+detect_error:
+	dev_warn(dev, "Board detection failed\n");
+
+	return UDOO_NEO_UNKNOWN;
+}
 
 static int imx6sx_udoneo_probe(struct device *dev)
 {
+	enum imx6sx_udoneo_board_type type;
+	const char *model;
+
+	type = imx6sx_udoneo_detect(dev);
+	switch (type) {
+	case UDOO_NEO_FULL:
+		model = "UDOO Neo Full";
+		break;
+	case UDOO_NEO_EXTENDED:
+		model = "UDOO Neo Extended";
+		break;
+	case UDOO_NEO_BASIC:
+		model = "UDOO Neo Basic";
+		break;
+	default:
+		model = "UDOO Neo unknown";
+	}
+
+	barebox_set_model(model);
 	barebox_set_hostname("mx6sx-udooneo");
 
 	return 0;
-- 
2.30.2




More information about the barebox mailing list