dwc_otg: Force host or device mode when not using OTG

The dwc_otg driver determines the USB mode (host/device) based on the
bit CurMod in the interrupt status register. This bit is driven by the
OTG id pin which is floating on gfsc100. If the controller is
initialized very early in the boot process the pin somtimes has a high
level, in consequence CurMod is not set and the driver configures the
controller for device mode. Over time the voltage level apparently
decreases below the "high" threshold. If the driver initializes the
controller beyond this point the CurMod bit is set and the controller is
configured for host mode.

Boot timing differs between gfsc100 prod and dev builds, on prod builds
the issue described above is encountered frequently. Work around it by
ignoring CurMod when host or device-only mode is configured.

Google-Bug-Id: 25875347

Change-Id: Ib778592dd8756a7934f7af0be0d29199b8cf4073
diff --git a/drivers/usb/dwc_otg/dwc_otg_cil.c b/drivers/usb/dwc_otg/dwc_otg_cil.c
index b5de301..4bc4151 100644
--- a/drivers/usb/dwc_otg/dwc_otg_cil.c
+++ b/drivers/usb/dwc_otg/dwc_otg_cil.c
@@ -6654,9 +6654,15 @@
 
 uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
 {
+#if defined(CONFIG_DWC_OTG_HOST_ONLY)
+	return DWC_HOST_MODE;
+#elif defined(CONFIG_DWC_OTG_DEVICE_ONLY)
+	return 0;
+#else
 	gintsts_data_t gintsts;
 	gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
 	return gintsts.b.curmode;
+#endif
 }
 
 uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
diff --git a/drivers/usb/dwc_otg/dwc_otg_cil.h b/drivers/usb/dwc_otg/dwc_otg_cil.h
index 9957861..0ca2c55 100644
--- a/drivers/usb/dwc_otg/dwc_otg_cil.h
+++ b/drivers/usb/dwc_otg/dwc_otg_cil.h
@@ -1292,7 +1292,7 @@
  */
 static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
 {
-	return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
+	return dwc_otg_get_mode(_core_if);
 }
 
 /**@}*/