public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Igor Opaniuk <igor.opaniuk@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v1 6/9] verdin-imx8mm: implement hardware version detection
Date: Wed, 28 Oct 2020 11:58:13 +0200	[thread overview]
Message-ID: <20201028095816.23906-6-igor.opaniuk@gmail.com> (raw)
In-Reply-To: <20201028095816.23906-1-igor.opaniuk@gmail.com>

From: Max Krummenacher <max.krummenacher@toradex.com>

And select the correct devicetree accordingly by setting the variant
environment variable.

Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
---

 board/toradex/verdin-imx8mm/verdin-imx8mm.c | 71 +++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/board/toradex/verdin-imx8mm/verdin-imx8mm.c b/board/toradex/verdin-imx8mm/verdin-imx8mm.c
index 66950ed218..9c6f35e778 100644
--- a/board/toradex/verdin-imx8mm/verdin-imx8mm.c
+++ b/board/toradex/verdin-imx8mm/verdin-imx8mm.c
@@ -8,12 +8,22 @@
 #include <asm/arch/clock.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/io.h>
+#include <i2c.h>
 #include <miiphy.h>
 #include <netdev.h>
 #include <micrel.h>
 
+#include "../common/tdx-cfg-block.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
+#define I2C_PMIC	0
+
+enum pcb_rev_t {
+	PCB_VERSION_1_0,
+	PCB_VERSION_1_1
+};
+
 #if IS_ENABLED(CONFIG_FEC_MXC)
 static int setup_fec(void)
 {
@@ -104,8 +114,69 @@ int board_mmc_get_env_dev(int devno)
 	return devno;
 }
 
+static enum pcb_rev_t get_pcb_revision(void)
+{
+	struct udevice *bus;
+	struct udevice *i2c_dev = NULL;
+	int ret;
+	u8 is_bd71837 = 0;
+
+	ret = uclass_get_device_by_seq(UCLASS_I2C, I2C_PMIC, &bus);
+	if (!ret)
+		ret = dm_i2c_probe(bus, 0x4b, 0, &i2c_dev);
+	if (!ret)
+		ret = dm_i2c_read(i2c_dev, 0x0, &is_bd71837, 1);
+
+	/* BD71837_REV, High Nibble is major version, fix 1010 */
+	is_bd71837 = !ret && ((is_bd71837 & 0xf0) == 0xa0);
+	return is_bd71837 ? PCB_VERSION_1_0 : PCB_VERSION_1_1;
+}
+
+static void select_dt_from_module_version(void)
+{
+	char variant[32];
+	char *env_variant = env_get("variant");
+	int is_wifi = 0;
+
+	if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) {
+		/*
+		 * If we have a valid config block and it says we are a
+		 * module with Wi-Fi/Bluetooth make sure we use the -wifi
+		 * device tree.
+		 */
+		is_wifi = (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT) ||
+			  (tdx_hw_tag.prodid == VERDIN_IMX8MMDL_WIFI_BT_IT);
+	}
+
+	switch (get_pcb_revision()) {
+	case PCB_VERSION_1_0:
+		printf("Detected a V1.0 module\n");
+		if (is_wifi)
+			strncpy(&variant[0], "wifi", sizeof(variant));
+		else
+			strncpy(&variant[0], "nonwifi", sizeof(variant));
+		break;
+	default:
+		if (is_wifi)
+			strncpy(&variant[0], "wifi-v1.1", sizeof(variant));
+		else
+			strncpy(&variant[0], "nonwifi-v1.1", sizeof(variant));
+		break;
+	}
+
+	if (strcmp(variant, env_variant)) {
+		printf("Setting variant to %s\n", variant);
+		env_set("variant", variant);
+
+		if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
+			env_save();
+	}
+}
+
 int board_late_init(void)
 {
+	select_dt_from_module_version();
+
 	return 0;
 }
 
-- 
2.17.1

  parent reply	other threads:[~2020-10-28  9:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28  9:58 [PATCH v1 1/9] toradex: tdx-cfg-clock: add new i.mx 8m mini/plus skus Igor Opaniuk
2020-10-28  9:58 ` [PATCH v1 2/9] pca9450a: fix i2c address Igor Opaniuk
2020-10-28 21:49   ` Jaehoon Chung
2020-12-08  8:00   ` sbabic at denx.de
2020-10-28  9:58 ` [PATCH v1 3/9] power: pmic: add SPL_DM_PMIC_PCA9450 symbol to Kconfig Igor Opaniuk
2020-10-28 21:49   ` Jaehoon Chung
2020-12-08  7:58   ` sbabic at denx.de
2020-10-28  9:58 ` [PATCH v1 4/9] ARM: dts: imx8mm-verdin: follow changed pmic Igor Opaniuk
2020-10-29 14:43   ` Marcel Ziswiler
2020-10-29 16:19     ` Oleksandr Suvorov
2020-12-08  7:59   ` sbabic at denx.de
2020-10-28  9:58 ` [PATCH v1 5/9] verdin-imx8mm: spl: switch to pca9450 pmic Igor Opaniuk
2020-10-29 14:44   ` Marcel Ziswiler
2020-10-29 16:27     ` Oleksandr Suvorov
2020-12-08  7:59   ` sbabic at denx.de
2020-10-28  9:58 ` Igor Opaniuk [this message]
2020-10-29 14:48   ` [PATCH v1 6/9] verdin-imx8mm: implement hardware version detection Marcel Ziswiler
2020-12-08  7:58   ` sbabic at denx.de
2020-10-28  9:58 ` [PATCH v1 7/9] verdin-imx8mm: spl: enable pca9450 i2c level translator Igor Opaniuk
2020-10-29 14:49   ` Marcel Ziswiler
2020-10-29 16:16     ` Oleksandr Suvorov
2020-12-08  7:59   ` sbabic at denx.de
2020-10-28  9:58 ` [PATCH v1 8/9] toradex: tdx-cfg-clock: fix i.mx 8m mini interactive Igor Opaniuk
2020-10-29 16:32   ` Oleksandr Suvorov
2020-12-08  7:59   ` sbabic at denx.de
2020-10-28  9:58 ` [PATCH v1 9/9] verdin-imx8mm: automatic ram size detection Igor Opaniuk
2020-10-29 16:15   ` Oleksandr Suvorov
2020-12-08  7:58   ` sbabic at denx.de
2020-10-29 14:52 ` [PATCH v1 1/9] toradex: tdx-cfg-clock: add new i.mx 8m mini/plus skus Marcel Ziswiler
2020-12-08  8:00 ` sbabic at denx.de

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=20201028095816.23906-6-igor.opaniuk@gmail.com \
    --to=igor.opaniuk@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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