usb3: a38x: add FDT update for USB3 Device

	When USB3 device is enabled (SatR field 'usb3port0' or 'usb3port1' is 1)
	disabled corresponding 'usb3' DT node, and enable 'u3d@50000' and 'udc@54100' nodes.

Change-Id: Icba23f5949d9204db8ac4127746991b0cbd26c9b
Signed-off-by: Bassel Saba <basselsa@marvell.com>
Reviewed-on: http://vgitil04.il.marvell.com:8080/20260
Tested-by: Star_Automation <star@marvell.com>
Reviewed-by: Omri Itach <omrii@marvell.com>
diff --git a/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.c b/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.c
index 9ca9347..8282375 100644
--- a/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.c
+++ b/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.c
@@ -3130,3 +3130,18 @@
 	/* TDM is not supported on a375 */
 	return MV_FALSE;
 }
+
+/*******************************************************************************
+* mvBoardIsUsb3PortDevice
+* DESCRIPTION: return true USB3 port is in device mode
+*
+* INPUT:  port		- port number
+* OUTPUT: None.
+* RETURN: MV_TRUE: if port is set to device mode
+*         MV_FALSE: otherwise
+*******************************************************************************/
+MV_BOOL mvBoardIsUsb3PortDevice(MV_U32 port)
+{
+	/* Since usb3 device is not supported on current board return false */
+	return MV_FALSE;
+}
diff --git a/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.h b/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.h
index f2fb651..e1739de 100644
--- a/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.h
+++ b/board/mv_ebu/a375/armada_375_family/boardEnv/mvBoardEnvLib.h
@@ -522,6 +522,7 @@
 MV_BOOL mvBoardIsUsbPortConnected(MV_UNIT_ID usbTypeID, MV_U8 usbPortNumber);
 MV_U8 mvBoardPICGpioGet(MV_U32 *picGpioMppInfo);
 MV_BOOL mvBoardIsTdmConnected(void);
+MV_BOOL mvBoardIsUsb3PortDevice(MV_U32 port);
 
 #ifdef __cplusplus
 }
diff --git a/board/mv_ebu/a375/armada_375_family/ctrlEnv/mvCtrlEnvSpec.h b/board/mv_ebu/a375/armada_375_family/ctrlEnv/mvCtrlEnvSpec.h
index 5fbd31a..420deda 100644
--- a/board/mv_ebu/a375/armada_375_family/ctrlEnv/mvCtrlEnvSpec.h
+++ b/board/mv_ebu/a375/armada_375_family/ctrlEnv/mvCtrlEnvSpec.h
@@ -130,6 +130,8 @@
 #define MV_USB3_PHYS_OFFSET(dev)                (0x58000)
 #define MV_USB2_USB3_REGS_OFFSET(unitType, dev) (unitType == USB_UNIT_ID ? \
 							MV_USB_REGS_OFFSET(dev) : MV_USB3_PHYS_OFFSET(dev))
+#define MV_USB3_DEVICE_REGS_OFFSET		MV_USB_REGS_OFFSET(0)
+#define MV_USB3_DEVICE_USB2_REGS_OFFSET		(0x54100)
 #define MV_XOR_REGS_OFFSET(unit)                (0x60800)
 #define MV_CESA_TDMA_REGS_OFFSET(chanNum)       (0x90000 + (chanNum * 0x2000))
 #define MV_CESA_REGS_OFFSET(chanNum)            (0x9D000 + (chanNum * 0x2000))
diff --git a/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib.h b/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib.h
index 8dcbf67..dd6c1fb 100644
--- a/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib.h
+++ b/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib.h
@@ -623,6 +623,7 @@
 MV_BOARD_INFO *mvBoardInfoStructureGet(MV_VOID);
 MV_BOOL mvBoardIsAudioConnected(void);
 void mvBoardAudioConnectionSet(MV_BOOL isConnected);
+MV_BOOL mvBoardIsUsb3PortDevice(MV_U32 port);
 
 #ifdef CONFIG_SWITCHING_SERVICES
 MV_BOOL mvBoardisAmc(void);
diff --git a/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib38x.c b/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib38x.c
index 223ef8e..089333c 100644
--- a/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib38x.c
+++ b/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib38x.c
@@ -119,6 +119,27 @@
 	return MV_FALSE;
 }
 #endif
+
+/*******************************************************************************
+* mvBoardIsUsb3PortDevice
+* DESCRIPTION: return true USB3 port is in device mode
+*
+* INPUT:  port		- port number
+* OUTPUT: None.
+* RETURN: MV_TRUE: if port is set to device mode
+*         MV_FALSE: otherwise
+*******************************************************************************/
+MV_BOOL mvBoardIsUsb3PortDevice(MV_U32 port)
+{
+	if (port < 0 || port >= MV_USB3_MAX_HOST_PORTS)
+		return MV_FALSE;
+
+	if (mvBoardSatRRead((MV_U32)MV_SATR_DB_USB3_PORT0 + port))
+		return MV_TRUE;
+
+	return MV_FALSE;
+}
+
 /*******************************************************************************
 * mvBoardIsPortInSgmii -
 *
diff --git a/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib39x.c b/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib39x.c
index 1928edf..7de1ac1 100644
--- a/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib39x.c
+++ b/board/mv_ebu/a38x/armada_38x_family/boardEnv/mvBoardEnvLib39x.c
@@ -625,3 +625,18 @@
 			mvOsOutput("|     In-Band  |\n");
 	}
 }
+
+/*******************************************************************************
+* mvBoardIsUsb3PortDevice
+* DESCRIPTION: return true USB3 port is in device mode
+*
+* INPUT:  port		- port number
+* OUTPUT: None.
+* RETURN: MV_TRUE: if port is set to device mode
+*         MV_FALSE: otherwise
+*******************************************************************************/
+MV_BOOL mvBoardIsUsb3PortDevice(MV_U32 port)
+{
+	/* Since usb3 device is not supported on current board return false */
+	return MV_FALSE;
+}
diff --git a/board/mv_ebu/a38x/armada_38x_family/ctrlEnv/mvCtrlEnvSpec.h b/board/mv_ebu/a38x/armada_38x_family/ctrlEnv/mvCtrlEnvSpec.h
index c47bc01..e1f0d4c 100644
--- a/board/mv_ebu/a38x/armada_38x_family/ctrlEnv/mvCtrlEnvSpec.h
+++ b/board/mv_ebu/a38x/armada_38x_family/ctrlEnv/mvCtrlEnvSpec.h
@@ -124,6 +124,8 @@
 #define MV_USB3_REGS_OFFSET(dev)                (0xF0000 + (dev * 0x8000))
 #define MV_USB2_USB3_REGS_OFFSET(unitType, dev) (unitType == USB_UNIT_ID ? \
 							MV_USB_REGS_OFFSET(dev) : MV_USB3_REGS_OFFSET(dev))
+#define MV_USB3_DEVICE_REGS_OFFSET		(0x50000)
+#define MV_USB3_DEVICE_USB2_REGS_OFFSET		(0x54100)
 #define MV_XOR_REGS_OFFSET(unit)                (0x60800 + (unit)*0x100)
 #define MV_CESA_TDMA_REGS_OFFSET(chanNum)       (0x90000 + (chanNum * 0x2000))
 #define MV_CESA_REGS_OFFSET(chanNum)            (0x9D000 + (chanNum * 0x2000))
diff --git a/board/mv_ebu/common/USP/mv_fdt.c b/board/mv_ebu/common/USP/mv_fdt.c
index 28c37f5..c326021 100644
--- a/board/mv_ebu/common/USP/mv_fdt.c
+++ b/board/mv_ebu/common/USP/mv_fdt.c
@@ -134,6 +134,7 @@
 #ifdef MV_USB_VBUS_CYCLE
 static int mv_fdt_update_usb_vbus(void *fdt);
 #endif
+static int mv_fdt_update_usb_device(void *fdt);
 
 #if 0 /* not compiled, since this routine is currently not in use  */
 static int mv_fdt_remove_prop(void *fdt, const char *path,
@@ -172,6 +173,7 @@
 #ifdef MV_INCLUDE_SWITCH
 	mv_fdt_update_switch,
 #endif
+	mv_fdt_update_usb_device,
 	NULL,
 };
 
@@ -872,6 +874,58 @@
 }
 
 /*******************************************************************************
+* mv_fdt_update_usb_device
+*
+* DESCRIPTION: usb3 device status
+* target		: update status field of u3d and udc nodes.
+* node, properties	: property status @ nodes usb3@X, udc@X and udc@X.
+* dependencies		: S@R field 'usb3port0' or 'usb3port1'.
+*
+* INPUT: fdt.
+* OUTPUT: None.
+* RETURN: -1 on error os 0 otherwise.
+*******************************************************************************/
+static int mv_fdt_update_usb_device(void *fdt)
+{
+	char propval[10];				/* property value */
+	const char *prop = "status";			/* property name */
+	char node[64];					/* node name */
+	int i;
+	MV_BOOL isDevice = MV_FALSE;
+
+	/* disable usb3 nodes */
+	for (i = 0; i < MV_USB3_MAX_HOST_PORTS; i++) {
+		if (mvBoardIsUsb3PortDevice(i)) {
+			/* if Port is Device, disable corresponding Host node */
+			sprintf(propval, "disabled");
+			isDevice = MV_TRUE;
+			break;
+		}
+	}
+
+	if (isDevice == MV_FALSE)
+		return 0;
+
+	sprintf(node, "usb3@%x", MV_USB2_USB3_REGS_OFFSET(USB3_UNIT_ID, i));
+	if (mv_fdt_set_node_prop(fdt, node, prop, propval) < 0)
+		mv_fdt_dprintf("Failed to set property '%s' of node '%s' in device tree\n", prop, node);
+
+	/* enable 'u3d' and 'udc' nodes */
+	sprintf(propval, "okay");
+	sprintf(node, "u3d@%x", MV_USB3_DEVICE_REGS_OFFSET);
+	if (mv_fdt_set_node_prop(fdt, node, prop, propval) < 0) {
+		mv_fdt_dprintf("Failed to set property '%s' of node '%s' in device tree\n", prop, node);
+		return 0;
+	}
+	sprintf(node, "udc@%x", MV_USB3_DEVICE_USB2_REGS_OFFSET);
+	if (mv_fdt_set_node_prop(fdt, node, prop, propval) < 0) {
+		mv_fdt_dprintf("Failed to set property '%s' of node '%s' in device tree\n", prop, node);
+		return 0;
+	}
+	return 0;
+}
+
+/*******************************************************************************
 * mv_fdt_update_pinctrl
 *
 * DESCRIPTION: