board: asus: transformer: implement multi-DTB support

Use board revision detection mechanism to choose correct DTB.
Adjust documentation and build setup accordingly.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
diff --git a/board/asus/transformer-t30/MAINTAINERS b/board/asus/transformer-t30/MAINTAINERS
index 071a9c0..869cc5a 100644
--- a/board/asus/transformer-t30/MAINTAINERS
+++ b/board/asus/transformer-t30/MAINTAINERS
@@ -4,5 +4,4 @@
 F:	board/asus/transformer-t30/
 F:	configs/transformer_t30_defconfig
 F:	doc/board/asus/transformer_t30.rst
-F:	include/configs/transformer-common.h
 F:	include/configs/transformer-t30.h
diff --git a/board/asus/transformer-t30/Makefile b/board/asus/transformer-t30/Makefile
index c083f22..22b6160 100644
--- a/board/asus/transformer-t30/Makefile
+++ b/board/asus/transformer-t30/Makefile
@@ -7,5 +7,6 @@
 #  Svyatoslav Ryhel <clamor95@gmail.com>
 
 obj-$(CONFIG_SPL_BUILD) += transformer-t30-spl.o
+obj-$(CONFIG_MULTI_DTB_FIT) += board-info.o
 
 obj-y += transformer-t30.o
diff --git a/board/asus/transformer-t30/board-info.c b/board/asus/transformer-t30/board-info.c
new file mode 100644
index 0000000..a2b540c
--- /dev/null
+++ b/board/asus/transformer-t30/board-info.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  (C) Copyright 2024
+ *  Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <env.h>
+#include <spl_gpio.h>
+
+#include <asm/gpio.h>
+#include <asm/arch/pinmux.h>
+
+/*
+ *	PCB_ID[1] is kb_row5_pr5
+ *	PCB_ID[3] is kb_col7_pq7
+ *	PCB_ID[4] is kb_row2_pr2
+ *	PCB_ID[5] is kb_col5_pq5
+ *
+ *			  Project ID
+ *	=====================================================
+ *	PCB_ID[1] PCB_ID[5] PCB_ID[4] PCB_ID[3]	Project
+ *	0	  0	    0	      0		TF201
+ *	0	  0	    0	      1		P1801
+ *	0	  0	    1	      0		TF300T
+ *	0	  0	    1	      1		TF300TG
+ *	0	  1	    0	      0		TF700T
+ *	0	  1	    0	      1		TF300TL
+ *	0	  1	    1	      0		Extension
+ *	0	  1	    1	      1		TF500T
+ *	1	  0	    0	      0		TF502T/TF600T
+ *	=====================================================
+ */
+enum project_rev {
+	TF201, P1801, TF300T, TF300TG, TF700T,
+	TF300TL, EXT, TF500T, TF600T
+};
+
+static const char * const project_id_to_fdt[] = {
+	[TF201] = "tegra30-asus-tf201",
+	[P1801] = "tegra30-asus-p1801-t",
+	[TF300T] = "tegra30-asus-tf300t",
+	[TF300TG] = "tegra30-asus-tf300tg",
+	[TF700T] = "tegra30-asus-tf700t",
+	[TF300TL] = "tegra30-asus-tf300tl",
+	[TF600T] = "tegra30-asus-tf600t",
+};
+
+static int id_gpio_get_value(u32 pingrp, u32 pin)
+{
+	/* Configure pinmux */
+	pinmux_set_func(pingrp, PMUX_FUNC_KBC);
+	pinmux_set_pullupdown(pingrp, PMUX_PULL_DOWN);
+	pinmux_tristate_enable(pingrp);
+	pinmux_set_io(pingrp, PMUX_PIN_INPUT);
+
+	/*
+	 * Since this function may be called
+	 * during DM reload we should use SPL
+	 * GPIO functions which do not depend
+	 * on DM.
+	 */
+	spl_gpio_input(NULL, pin);
+	return spl_gpio_get_value(NULL, pin);
+}
+
+static int get_project_id(void)
+{
+	u32 pcb_id1, pcb_id3, pcb_id4, pcb_id5;
+
+	pcb_id1 = id_gpio_get_value(PMUX_PINGRP_KB_ROW5_PR5,
+				    TEGRA_GPIO(R, 5));
+	pcb_id3 = id_gpio_get_value(PMUX_PINGRP_KB_COL7_PQ7,
+				    TEGRA_GPIO(Q, 7));
+	pcb_id4 = id_gpio_get_value(PMUX_PINGRP_KB_ROW2_PR2,
+				    TEGRA_GPIO(R, 2));
+	pcb_id5 = id_gpio_get_value(PMUX_PINGRP_KB_COL5_PQ5,
+				    TEGRA_GPIO(Q, 5));
+
+	/* Construct board ID */
+	int proj_id = pcb_id1 << 3 | pcb_id5 << 2 |
+		      pcb_id4 << 1 | pcb_id3;
+
+	log_debug("[TRANSFORMER]: project id %d (%s)\n", proj_id,
+		  project_id_to_fdt[proj_id]);
+
+	/* Mark tablet with SPI flash */
+	if (proj_id == TF600T)
+		env_set_hex("spiflash", true);
+	else
+		env_set_hex("spiflash", false);
+
+	return proj_id & 0xf;
+}
+
+int board_fit_config_name_match(const char *name)
+{
+	if (!strcmp(name, project_id_to_fdt[get_project_id()]))
+		return 0;
+
+	return -1;
+}
+
+void nvidia_board_late_init(void)
+{
+	char dt_path[64] = { 0 };
+
+	snprintf(dt_path, sizeof(dt_path), "%s.dtb",
+		 project_id_to_fdt[get_project_id()]);
+	env_set("fdtfile", dt_path);
+}
diff --git a/board/asus/transformer-t30/configs/p1801-t.config b/board/asus/transformer-t30/configs/p1801-t.config
deleted file mode 100644
index f378f54..0000000
--- a/board/asus/transformer-t30/configs/p1801-t.config
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-p1801-t"
-# CONFIG_I2C_MUX is not set
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4cb0
diff --git a/board/asus/transformer-t30/configs/tf201.config b/board/asus/transformer-t30/configs/tf201.config
deleted file mode 100644
index e4fd303..0000000
--- a/board/asus/transformer-t30/configs/tf201.config
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-tf201"
-# CONFIG_I2C_MUX is not set
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4d00
diff --git a/board/asus/transformer-t30/configs/tf300t.config b/board/asus/transformer-t30/configs/tf300t.config
deleted file mode 100644
index 9ad2ebd..0000000
--- a/board/asus/transformer-t30/configs/tf300t.config
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-tf300t"
-# CONFIG_I2C_MUX is not set
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4d00
diff --git a/board/asus/transformer-t30/configs/tf300tg.config b/board/asus/transformer-t30/configs/tf300tg.config
deleted file mode 100644
index 7b44a91..0000000
--- a/board/asus/transformer-t30/configs/tf300tg.config
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-tf300tg"
-# CONFIG_I2C_MUX is not set
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4c80
diff --git a/board/asus/transformer-t30/configs/tf300tl.config b/board/asus/transformer-t30/configs/tf300tl.config
deleted file mode 100644
index 81e96d5..0000000
--- a/board/asus/transformer-t30/configs/tf300tl.config
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-tf300tl"
-# CONFIG_I2C_MUX is not set
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4d00
diff --git a/board/asus/transformer-t30/configs/tf600t.config b/board/asus/transformer-t30/configs/tf600t.config
deleted file mode 100644
index a452a19..0000000
--- a/board/asus/transformer-t30/configs/tf600t.config
+++ /dev/null
@@ -1,7 +0,0 @@
-CONFIG_ENV_SOURCE_FILE="tf600t"
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-tf600t"
-CONFIG_BOOTCOMMAND="setenv gpio_button 222; if run check_button; then poweroff; fi; setenv gpio_button 132; if run check_button; then echo Starting SPI flash update ...; run update_spi; fi; run bootcmd_usb0; run bootcmd_mmc1; run bootcmd_mmc0; poweroff;"
-# CONFIG_I2C_MUX is not set
-CONFIG_TEGRA20_SLINK=y
-CONFIG_SPI_FLASH_WINBOND=y
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4d00
diff --git a/board/asus/transformer-t30/configs/tf700t.config b/board/asus/transformer-t30/configs/tf700t.config
deleted file mode 100644
index 887c25f..0000000
--- a/board/asus/transformer-t30/configs/tf700t.config
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG_DEFAULT_DEVICE_TREE="tegra30-asus-tf700t"
-CONFIG_CLK_GPIO=y
-CONFIG_USB_GADGET_PRODUCT_NUM=0x4c90
-CONFIG_VIDEO_BRIDGE_TOSHIBA_TC358768=y
diff --git a/board/asus/transformer-t30/tf600t.env b/board/asus/transformer-t30/tf600t.env
deleted file mode 100644
index 7bc2b80..0000000
--- a/board/asus/transformer-t30/tf600t.env
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <env/nvidia/prod_upd.env>
-
-button_cmd_0_name=Volume Down
-button_cmd_0=bootmenu
-button_cmd_1_name=Lid sensor
-button_cmd_1=poweroff
-partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}
-
-bootmenu_0=mount internal storage=usb start && ums 0 mmc 0; bootmenu
-bootmenu_1=mount external storage=usb start && ums 0 mmc 1; bootmenu
-bootmenu_2=fastboot=echo Starting Fastboot protocol ...; fastboot usb 0; bootmenu
-bootmenu_3=update bootloader=run update_spi
-bootmenu_4=reboot RCM=enterrcm
-bootmenu_5=reboot=reset
-bootmenu_6=power off=poweroff
-bootmenu_delay=-1
diff --git a/board/asus/transformer-t30/transformer-t30.env b/board/asus/transformer-t30/transformer-t30.env
index 2f7e820..9b6f407 100644
--- a/board/asus/transformer-t30/transformer-t30.env
+++ b/board/asus/transformer-t30/transformer-t30.env
@@ -1,7 +1,7 @@
 #include <env/nvidia/prod_upd.env>
 
 button_cmd_0_name=Volume Down
-button_cmd_0=bootmenu
+button_cmd_0=if spiflash; then run update_spi; else bootmenu; fi
 button_cmd_1_name=Lid sensor
 button_cmd_1=poweroff
 partitions=name=emmc,start=0,size=-,uuid=${uuid_gpt_rootfs}