Skip to contentSkip to conversation

imx: Add a common way for detecting NXP boards revision

PATCH Superseded Fabio Estevam 1 participant 2 messages Nov 27, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v2 1/2 imx: Add a common way for detecting NXP boards revision

From: Fabio Estevam <[email protected]>

NXP development boards based on i.MX6/i.MX7 contain the board revision information stored in the fuses.

Introduce a common function that can be shared by different boards and convert mx6sabreauto to use this new mechanism.

---
Changes since v1:
- Fix nxp_board_rev_string() - Stefano

 arch/arm/include/asm/mach-imx/sys_proto.h   |  3 ++
 arch/arm/mach-imx/Kconfig                   |  8 +++++
 arch/arm/mach-imx/cpu.c                     | 27 +++++++++++++++++
 board/freescale/mx6sabreauto/mx6sabreauto.c | 47 ++---------------------------
 configs/mx6sabreauto_defconfig              |  1 +
 5 files changed, 41 insertions(+), 45 deletions(-)
arch/arm/include/asm/mach-imx/sys_proto.h +3 -0
index a80a392..d789de1 100644
@@ -109,6 +109,9 @@ void imx_wdog_disable_powerdown(void);
 
 int board_mmc_get_env_dev(int devno);
 
+int nxp_board_rev(void);
+const char *nxp_board_rev_string(void);
+
 /*
  * Initializes on-chip ethernet controllers.
  * to override, implement board_eth_init()
arch/arm/mach-imx/Kconfig +8 -0
index cd8b8d2..81ab125 100644
@@ -61,3 +61,11 @@ config CMD_HDMIDETECT
 	help
 	  This enables the 'hdmidet' command which detects if an HDMI monitor
 	  is connected.
+
+config NXP_BOARD_REVISION
+	bool "Read NXP board revision from fuses"
+	depends on ARCH_MX6 || ARCH_MX7
+	help
+	  NXP boards based on i.MX6/7 contain the board revision information
+	  stored in the fuses. Select this option if you want to be able to
+	  retrieve the board revision information.
arch/arm/mach-imx/cpu.c +27 -0
index 18205dc..662ac82 100644
@@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size)
 
 	writel(reg, &iomuxc_regs->gpr[1]);
 }
+
+#ifdef CONFIG_NXP_BOARD_REVISION
+int nxp_board_rev(void)
+{
+	/*
+	 * Get Board ID information from OCOTP_GP1[15:8]
+	 * RevA: 0x1
+	 * RevB: 0x2
+	 * RevC: 0x3
+	 */
+	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
+	struct fuse_bank *bank = &ocotp->bank[4];
+	struct fuse_bank4_regs *fuse =
+			(struct fuse_bank4_regs *)bank->fuse_regs;
+
+	return (readl(&fuse->gp1) >> 8 & 0x0F);
+}
+
+const char *nxp_board_rev_string(void)
+{
+	char *rev = "A";
+
+	*rev += nxp_board_rev() - 1;
+
+	return rev;
+}
+#endif
board/freescale/mx6sabreauto/mx6sabreauto.c +2 -45

61 lines not on this page · raw message

configs/mx6sabreauto_defconfig +1 -0
index 98c39bb..7c23452 100644
@@ -8,6 +8,7 @@ CONFIG_SPL_MMC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_SPL_WATCHDOG_SUPPORT=y
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
 CONFIG_BOOTDELAY=3
 # CONFIG_CONSOLE_MUX is not set
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

PATCH v2 2/2 mx6sxsabresd: Load the correct dtb for revA board

From: Fabio Estevam <[email protected]>

Currently only imx6sx-sdb.dtb is loaded, but if revA board is used the correct dtb is imx6sx-sdb-reva.dtb, so make this possible.

While at it, remove an extra 'mmc dev'.

---
Changes since v1:
- Add CONFIG_NXP_BOARD_REVISION=y into mx6sxsabresd_spl_defconfig (Stefano)

 arch/arm/mach-imx/mx6/Kconfig               |  1 +
 board/freescale/mx6sxsabresd/mx6sxsabresd.c | 16 +++++++++++++++-
 configs/mx6sxsabresd_defconfig              |  1 +
 configs/mx6sxsabresd_spl_defconfig          |  1 +
 include/configs/mx6sxsabresd.h              |  8 ++++++--
 5 files changed, 24 insertions(+), 3 deletions(-)
arch/arm/mach-imx/mx6/Kconfig +1 -0
index bee7eab..44d2db4 100644
@@ -255,6 +255,7 @@ config TARGET_MX6SLLEVK
 
 config TARGET_MX6SXSABRESD
 	bool "mx6sxsabresd"
+	select BOARD_LATE_INIT
 	select MX6SX
 	select SUPPORT_SPL
 	select DM
board/freescale/mx6sxsabresd/mx6sxsabresd.c +15 -1
index 2aeef61..8a918a5 100644
@@ -540,9 +540,23 @@ int board_init(void)
 	return 0;
 }
 
+static bool is_reva(void)
+{
+	return (nxp_board_rev() == 1);
+}
+
+int board_late_init(void)
+{
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+	if (is_reva())
+		env_set("board_rev", "REVA");
+#endif
+	return 0;
+}
+
 int checkboard(void)
 {
-	puts("Board: MX6SX SABRE SDB\n");
+	printf("Board: MX6SX SABRE SDB rev%s\n", nxp_board_rev_string());
 
 	return 0;
 }
configs/mx6sxsabresd_defconfig +1 -0
index 2c184f6..f489908 100644
@@ -2,6 +2,7 @@ CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_TARGET_MX6SXSABRESD=y
 # CONFIG_CMD_BMODE is not set
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6sxsabresd/imximage.cfg"
 CONFIG_BOOTDELAY=3
 # CONFIG_CONSOLE_MUX is not set
configs/mx6sxsabresd_spl_defconfig +1 -0
index 5dca33d..2f57773 100644
@@ -9,6 +9,7 @@ CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_SPL_WATCHDOG_SUPPORT=y
 # CONFIG_CMD_BMODE is not set
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
 CONFIG_BOOTDELAY=3
 # CONFIG_CONSOLE_MUX is not set
include/configs/mx6sxsabresd.h +6 -2
index f4c9c28..906e677 100644
@@ -43,6 +43,7 @@
 #define UPDATE_M4_ENV ""
 #endif
 
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	UPDATE_M4_ENV \
 	"script=boot.scr\0" \
@@ -105,10 +106,13 @@
 			"fi; " \
 		"else " \
 			"bootz; " \
-		"fi;\0"
+		"fi;\0" \
+	"findfdt="\
+		"if test test $board_rev = REVA ; then " \
+			"setenv fdt_file imx6sx-sdb-reva.dtb; fi; " \
 
 #define CONFIG_BOOTCOMMAND \
-	   "mmc dev ${mmcdev};" \
+	   "run findfdt; " \
 	   "mmc dev ${mmcdev}; if mmc rescan; then " \
 		   "if run loadbootscript; then " \
 			   "run bootscript; " \
Signature · 1 line
2.7.4