[PATCH 4/4] common: Add LX TestBox checks

Benedikt Spranger b.spranger at linutronix.de
Fri May 29 18:28:39 CEST 2020


The TestBox board is an open hardware enhancement for the Lamobo R1 router
board. The Testbox board is used in the CI-RT project to manage devices
under test (https://ci-rt.linutronix.de).

The hardware project is located at https://github.com/ci-rt/testbox-shield
Check if the hardware is present and use the appropriate device tree file.

Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
Reviewed-by: Kurt Kanzenbach <kurt at linutronix.de>
---
 arch/arm/mach-sunxi/Kconfig | 15 ++++++++++++
 board/sunxi/board.c         | 47 +++++++++++++++++++++++++++++++++++++
 configs/Lamobo_R1_defconfig |  1 +
 3 files changed, 63 insertions(+)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index be0822bfb7..970fa0fae2 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -1010,4 +1010,19 @@ config PINE64_DT_SELECTION
 	  option, the device tree selection code specific to Pine64 which
 	  utilizes the DRAM size will be enabled.
 
+config LXTESTBOX
+	bool "Support for LX TestBox"
+	depends on MACH_SUN7I
+	select I2C2_ENABLE
+	select DM_I2C
+	help
+	  The LX TestBox board is an open hardware enhancement for the
+	  Lamobo R1 router board. The TestBox board is used in the CI-RT
+	  project to manage devices under test (https://ci-rt.linutronix.de).
+
+config LXTESTBOX_DEVICE_TREE
+	string "LX TestBox default device tree"
+	default "sun7i-a20-linutronix-testbox-v2.dtb"
+	help
+	  LX TestBox default device tree name.
 endif
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index f32e8f582f..4645798bcd 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -43,6 +43,17 @@
 #include <spl.h>
 #include <sy8106a.h>
 #include <asm/setup.h>
+#include <dm/uclass.h>
+#include <i2c.h>
+
+struct lxtestbox_eeprom {
+	u32 magic;
+	u8 version;
+	char serial[7];
+	u32 crc;
+} __packed;
+
+#define LXTESTBOX_I2C_EEPROM_MAGIC 0x6274584c
 
 #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
 /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
@@ -839,6 +850,42 @@ static void setup_environment(const void *fdt)
 			env_set("serial#", serial_string);
 		}
 	}
+
+#ifdef CONFIG_LXTESTBOX
+	debug("Check for LX TestBox...");
+	if (!strcmp(env_get("fdtfile"), CONFIG_DEFAULT_DEVICE_TREE ".dtb")) {
+		struct lxtestbox_eeprom moep;
+		struct udevice *bus, *dev;
+		int ret;
+
+		ret = uclass_get_device_by_name(UCLASS_I2C,
+						"i2c at 1c2b400", &bus);
+		if (ret) {
+			printf("Cannot get I2C bus: %i\n", ret);
+			return;
+		}
+
+		ret = i2c_get_chip(bus, 0x50, 1, &dev);
+		if (ret) {
+			printf("Cannot get I2C chip: %i\n", ret);
+			return;
+		}
+
+		ret = dm_i2c_read(dev, 0, (u8 *)&moep, sizeof(moep));
+		if (ret) {
+			printf("cannot read EEPROM: %i\n", ret);
+			return;
+		}
+
+		if (moep.magic != LXTESTBOX_I2C_EEPROM_MAGIC) {
+			printf("bad EEPROM magic number (%08x, should be %08x)\n",
+			       moep.magic, LXTESTBOX_I2C_EEPROM_MAGIC);
+			return;
+		}
+		debug("found.\n");
+		env_set("fdtfile", CONFIG_LXTESTBOX_DEVICE_TREE);
+	}
+#endif
 }
 
 int misc_init_r(void)
diff --git a/configs/Lamobo_R1_defconfig b/configs/Lamobo_R1_defconfig
index 34db56f79b..d74032e1e5 100644
--- a/configs/Lamobo_R1_defconfig
+++ b/configs/Lamobo_R1_defconfig
@@ -7,6 +7,7 @@ CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_SATAPWR="PB3"
 CONFIG_GMAC_TX_DELAY=4
+CONFIG_LXTESTBOX=y
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL_I2C_SUPPORT=y
-- 
2.19.0



More information about the U-Boot mailing list