From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v2 07/10] ARM: i.MX8MP: skov: Add hardware variant support
Date: Mon, 2 Oct 2023 12:16:51 +0200 [thread overview]
Message-ID: <20231002101654.2373000-8-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20231002101654.2373000-1-o.rempel@pengutronix.de>
Introduce hardware variant detection in skov-imx8mp board. This
addition uses GPIOs to identify hardware versions and set the
appropriate device tree compatible strings accordingly.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
arch/arm/boards/skov-imx8mp/board.c | 128 ++++++++++++++++++++++++++++
1 file changed, 128 insertions(+)
diff --git a/arch/arm/boards/skov-imx8mp/board.c b/arch/arm/boards/skov-imx8mp/board.c
index 58aca69236..3a1cd83bbd 100644
--- a/arch/arm/boards/skov-imx8mp/board.c
+++ b/arch/arm/boards/skov-imx8mp/board.c
@@ -1,14 +1,30 @@
// SPDX-License-Identifier: GPL-2.0
+#include "linux/kernel.h"
#include <bootsource.h>
#include <common.h>
#include <deep-probe.h>
#include <envfs.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <gpio.h>
#include <init.h>
#include <io.h>
#include <mach/imx/bbu.h>
+#include <mach/imx/generic.h>
#include <mach/imx/iomux-mx8mp.h>
+#define GPIO_HW_VARIANT {\
+ {IMX_GPIO_NR(1, 8), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var0"}, \
+ {IMX_GPIO_NR(1, 9), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var1"}, \
+ {IMX_GPIO_NR(1, 10), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var2"}, \
+ {IMX_GPIO_NR(1, 11), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var3"}, \
+ {IMX_GPIO_NR(1, 12), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var4"}, \
+ {IMX_GPIO_NR(1, 13), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var5"}, \
+ {IMX_GPIO_NR(1, 14), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var6"}, \
+ {IMX_GPIO_NR(1, 15), GPIOF_DIR_IN | GPIOF_ACTIVE_HIGH, "var7"}, \
+}
+
struct skov_imx8mp_storage {
const char *name;
const char *env_path;
@@ -43,6 +59,116 @@ static const struct skov_imx8mp_storage skov_imx8mp_storages[] = {
},
};
+struct board_description {
+ const char *dts_compatible;
+ const char *dts_compatible_hdmi;
+ unsigned flags;
+};
+
+#define SKOV_IMX8MP_HAS_HDMI BIT(0)
+
+static const struct board_description imx8mp_variants[] = {
+ [0] = {
+ .dts_compatible = "skov,imx8mp-skov-revb-lt6",
+ },
+ [1] = {
+ .dts_compatible = "skov,imx8mp-skov-revb-mi1010ait-1cp1",
+ .dts_compatible_hdmi = "skov,imx8mp-skov-revb-hdmi",
+ .flags = SKOV_IMX8MP_HAS_HDMI,
+ },
+};
+
+static int skov_imx8mp_get_variant_id(uint *id)
+{
+ struct gpio gpios_rev[] = GPIO_HW_VARIANT;
+ struct device_node *gpio_np;
+ u32 hw_rev;
+ int ret;
+
+ gpio_np = of_find_node_by_name_address(NULL, "gpio@30200000");
+ if (!gpio_np)
+ return -ENODEV;
+
+ ret = of_device_ensure_probed(gpio_np);
+ if (ret)
+ return ret;
+
+ ret = gpio_array_to_id(gpios_rev, ARRAY_SIZE(gpios_rev), &hw_rev);
+ if (ret)
+ goto exit_get_id;
+
+ *id = hw_rev;
+
+ return 0;
+exit_get_id:
+ pr_err("Failed to read gpio ID: %pe\n", ERR_PTR(ret));
+ return ret;
+}
+
+static int skov_imx8mp_get_hdmi(struct device *dev)
+{
+ const char *env = "state.display.external";
+ struct device_node *state_np;
+ unsigned int val = 0;
+ int ret;
+
+ state_np = of_find_node_by_name_address(NULL, "state");
+ if (!state_np) {
+ dev_err(dev, "Failed to find state node\n");
+ return -ENODEV;
+ }
+
+ ret = of_device_ensure_probed(state_np);
+ if (ret) {
+ dev_err(dev, "Failed to probe state node: %pe\n", ERR_PTR(ret));
+ return ret;
+ }
+
+ ret = getenv_uint(env, &val);
+ if (ret) {
+ dev_err(dev, "Failed to read %s: %pe\n", env, ERR_PTR(ret));
+ return ret;
+ }
+
+ return val;
+}
+
+static int skov_imx8mp_init_variant(struct device *dev)
+{
+ const struct board_description *variant;
+ const char *compatible;
+ unsigned int v = 0;
+ int ret;
+
+ ret = skov_imx8mp_get_variant_id(&v);
+ if (ret)
+ return ret;
+
+ if (v >= ARRAY_SIZE(imx8mp_variants)) {
+ dev_err(dev, "Invalid variant %u\n", v);
+ return -EINVAL;
+ }
+
+ variant = &imx8mp_variants[v];
+
+ if (variant->flags & SKOV_IMX8MP_HAS_HDMI) {
+ ret = skov_imx8mp_get_hdmi(dev);
+ if (ret < 0)
+ return ret;
+
+ if (ret)
+ compatible = variant->dts_compatible_hdmi;
+ else
+ compatible = variant->dts_compatible;
+ } else {
+ compatible = variant->dts_compatible;
+ }
+
+ of_prepend_machine_compatible(NULL, compatible);
+
+ return 0;
+}
+
static void skov_imx8mp_enable_env(struct device *dev,
const struct skov_imx8mp_storage *st,
bool *enabled)
@@ -110,6 +236,8 @@ static int skov_imx8mp_probe(struct device *dev)
{
skov_imx8mp_init_storage(dev);
+ skov_imx8mp_init_variant(dev);
+
return 0;
}
--
2.39.2
next prev parent reply other threads:[~2023-10-02 10:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 10:16 [PATCH v2 00/10] SKOV maintenance Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 01/10] arm: dts: imx8mp-skov: Add reserved-memory for ramoops pstore Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 02/10] arm: dts: imx8mp-skov: Add pins for hardware variant detection Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 03/10] arm: dts: imx8mp-skov: Switch to GPT for eMMC partitioning Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 04/10] arm: dts: imx8mp-skov: Switch to GPT for SD partitioning Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 05/10] arm: dts: imx8mp-skov: Add barebox state backend in DTS Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 06/10] ARM: i.MX8MP: skov: refactor bootsource and BBU handlers Oleksij Rempel
2023-10-02 10:16 ` Oleksij Rempel [this message]
2023-10-02 10:16 ` [PATCH v2 08/10] ARM: i.MX8MP: skov: fixup skov,imx8mp-board-version DT property for the kernel Oleksij Rempel
2023-10-02 10:16 ` [PATCH v2 09/10] net: lib: add ether_addr_inc() helper Oleksij Rempel
2023-10-04 6:41 ` Sascha Hauer
2023-10-05 6:48 ` Ahmad Fatoum
2023-10-05 7:07 ` Oleksij Rempel
2023-10-06 11:44 ` Sascha Hauer
2023-10-02 10:16 ` [PATCH v2 10/10] ARM: i.MX8MP: skov: assign Ethernet addresses to all ports Oleksij Rempel
2023-10-05 6:52 ` Ahmad Fatoum
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=20231002101654.2373000-8-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