mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1 5/8] ARM: imx6sx: udoo-neo: add version detection support
Date: Fri, 13 Jan 2023 12:34:04 +0100	[thread overview]
Message-ID: <20230113113407.2684725-5-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20230113113407.2684725-1-o.rempel@pengutronix.de>

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

Signed-off-by: Oleksij Rempel <o.rempel@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@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




  parent reply	other threads:[~2023-01-13 11:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 11:34 [PATCH v1 1/8] ARM: imx6sx: udoo-neo: port to driver model Oleksij Rempel
2023-01-13 11:34 ` [PATCH v1 2/8] ARM: imx6sx: udoo-neo: enable deep probe support Oleksij Rempel
2023-01-13 11:34 ` [PATCH v1 3/8] ARM: imx6sx: udoo-neo: fix board compatible Oleksij Rempel
2023-01-13 11:34 ` [PATCH v1 4/8] ARM: imx6sx: udoo-neo: configure GPIO pins for board auto detection Oleksij Rempel
2023-01-13 11:34 ` Oleksij Rempel [this message]
2023-01-13 11:34 ` [PATCH v1 6/8] ARM: imx6sx: udoo-neo: enable memory size " Oleksij Rempel
2023-01-13 11:34 ` [PATCH v1 7/8] ARM: imx6sx: udoo-neo: fix gpt timer configuration Oleksij Rempel
2023-01-13 11:34 ` [PATCH v1 8/8] ARM: imx6sx: udoo-neo: add barebox update handler support Oleksij Rempel
2023-01-16 12:13 ` [PATCH v1 1/8] ARM: imx6sx: udoo-neo: port to driver model Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230113113407.2684725-5-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox