arm: mach-k3: Add support for device type detection

K3 SoCs are available in a number of device types such as
GP, HS-FS, EMU, etc. Like OMAP SoCs we can detect this at runtime
and should print this out as part of the SoC information line.
We add this as part of the common.c file as it will be used
to also modify our security state early in the device boot.

Signed-off-by: Andrew Davis <afd@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 70f6444..ac14975 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -396,7 +396,54 @@
 }
 #endif
 
+enum k3_device_type get_device_type(void)
+{
+	u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS);
+
+	u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >>
+			SYS_STATUS_DEV_TYPE_SHIFT;
+
+	u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >>
+			SYS_STATUS_SUB_TYPE_SHIFT;
+
+	switch (sys_dev_type) {
+	case SYS_STATUS_DEV_TYPE_GP:
+		return K3_DEVICE_TYPE_GP;
+	case SYS_STATUS_DEV_TYPE_TEST:
+		return K3_DEVICE_TYPE_TEST;
+	case SYS_STATUS_DEV_TYPE_EMU:
+		return K3_DEVICE_TYPE_EMU;
+	case SYS_STATUS_DEV_TYPE_HS:
+		if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS)
+			return K3_DEVICE_TYPE_HS_FS;
+		else
+			return K3_DEVICE_TYPE_HS_SE;
+	default:
+		return K3_DEVICE_TYPE_BAD;
+	}
+}
+
 #if defined(CONFIG_DISPLAY_CPUINFO)
+static const char *get_device_type_name(void)
+{
+	enum k3_device_type type = get_device_type();
+
+	switch (type) {
+	case K3_DEVICE_TYPE_GP:
+		return "GP";
+	case K3_DEVICE_TYPE_TEST:
+		return "TEST";
+	case K3_DEVICE_TYPE_EMU:
+		return "EMU";
+	case K3_DEVICE_TYPE_HS_FS:
+		return "HS-FS";
+	case K3_DEVICE_TYPE_HS_SE:
+		return "HS-SE";
+	default:
+		return "BAD";
+	}
+}
+
 int print_cpuinfo(void)
 {
 	struct udevice *soc;
@@ -418,9 +465,11 @@
 
 	ret = soc_get_revision(soc, name, 64);
 	if (!ret) {
-		printf("%s\n", name);
+		printf("%s ", name);
 	}
 
+	printf("%s\n", get_device_type_name());
+
 	return 0;
 }
 #endif