arm: mvebu: turris_mox: Extend to support RIPE Atlas Probe

Extend Turris Mox board code to support CZ.NIC's RIPE Atlas Probe.

Signed-off-by: Marek BehĂșn <kabel@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c
index 370c266..63b8699 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -15,6 +15,7 @@
 #include <dm.h>
 #include <dm/of_extra.h>
 #include <env.h>
+#include <env_internal.h>
 #include <event.h>
 #include <fdt_support.h>
 #include <init.h>
@@ -45,6 +46,26 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+int board_fit_config_name_match(const char *name)
+{
+	if (!gd->board_type) {
+		enum cznic_a3720_board board;
+
+		if (mbox_sp_get_board_info(NULL, NULL, NULL, NULL, NULL,
+					   &board) < 0) {
+			printf("Cannot determine board, defaulting to Turris MOX!\n");
+			board = BOARD_TURRIS_MOX;
+		}
+
+		gd->board_type = board;
+	}
+
+	return !((gd->board_type == BOARD_TURRIS_MOX &&
+		  !strcmp(name, "armada-3720-turris-mox")) ||
+		 (gd->board_type == BOARD_RIPE_ATLAS &&
+		  !strcmp(name, "armada-3720-ripe-atlas")));
+}
+
 #if defined(CONFIG_OF_BOARD_FIXUP)
 int board_fix_fdt(void *blob)
 {
@@ -53,6 +74,9 @@
 	int i, size, ret;
 	bool eth1_sgmii;
 
+	if (gd->board_type != BOARD_TURRIS_MOX)
+		return 0;
+
 	/*
 	 * SPI driver is not loaded in driver model yet, but we have to find out
 	 * if pcie should be enabled in U-Boot's device tree. Therefore we have
@@ -388,16 +412,23 @@
 
 int misc_init_r(void)
 {
+	int i, ret, addrcnt;
 	u8 mac[2][6];
-	int i, ret;
 
-	ret = mbox_sp_get_board_info(NULL, mac[0], mac[1], NULL, NULL);
+	ret = mbox_sp_get_board_info(NULL, mac[0], mac[1], NULL, NULL, NULL);
 	if (ret < 0) {
 		printf("Cannot read data from OTP!\n");
 		return 0;
 	}
 
+	if (gd->board_type == BOARD_TURRIS_MOX)
+		addrcnt = 2;
+	else if (gd->board_type == BOARD_RIPE_ATLAS)
+		addrcnt = 1;
+	else
+		addrcnt = 0;
+
-	for (i = 0; i < 2; ++i) {
+	for (i = 0; i < addrcnt; ++i) {
 		u8 oldmac[6];
 
 		if (is_valid_ethaddr(mac[i]) &&
@@ -405,7 +436,13 @@
 			eth_env_set_enetaddr_by_index("eth", i, mac[i]);
 	}
 
-	load_spi_dtb();
+	if (gd->board_type == BOARD_RIPE_ATLAS) {
+		env_set("board", "ripe_atlas");
+		env_set("board_name", "ripe_atlas");
+		env_set("fdtfile", "marvell/armada-3720-ripe-atlas.dtb");
+	} else {
+		load_spi_dtb();
+	}
 
 	return 0;
 }
@@ -528,14 +565,15 @@
 int show_board_info(void)
 {
 	int i, ret, board_version, ram_size, is_sd;
-	const char *pub_key;
+	const char *pub_key, *model;
 	const u8 *topology;
 	u64 serial_number;
 
-	printf("Model: CZ.NIC Turris Mox Board\n");
+	model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+	printf("Model: %s\n", model);
 
 	ret = mbox_sp_get_board_info(&serial_number, NULL, NULL, &board_version,
-				     &ram_size);
+				     &ram_size, NULL);
 	if (ret < 0) {
 		printf("  Cannot read board info: %i\n", ret);
 	} else {
@@ -550,6 +588,9 @@
 	else
 		printf("  Cannot read ECDSA Public Key\n");
 
+	if (gd->board_type != BOARD_TURRIS_MOX)
+		return 0;
+
 	ret = mox_get_topology(&topology, &module_count, &is_sd);
 	if (ret)
 		printf("Cannot read module topology!\n");
@@ -668,10 +709,24 @@
 	return NULL;
 }
 
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+	if (prio > 0)
+		return ENVL_UNKNOWN;
+
+	if (gd->board_type == BOARD_RIPE_ATLAS)
+		return ENVL_MMC;
+
+	return ENVL_SPI_FLASH;
+}
+
 static int last_stage_init(void)
 {
 	struct gpio_desc reset_gpio = {};
 
+	if (gd->board_type != BOARD_TURRIS_MOX)
+		return 0;
+
 	/* configure modules */
 	if (get_reset_gpio(&reset_gpio) < 0)
 		goto handle_reset_btn;
@@ -801,6 +856,9 @@
 {
 	int res;
 
+	if (gd->board_type != BOARD_TURRIS_MOX)
+		return 0;
+
 	/*
 	 * If MOX B (PCI), MOX F (USB) or MOX G (Passthrough PCI) modules are
 	 * connected, enable the PCIe node.