dwc3: core: fix up handling of is_drd usage

When dwc3_probe() is called, USB controller is not out of low power
mode. Hence USB controller's registers can't read at this time to
see controller capability. Setting is_drd is required to prevent NULL
pointer dereference issue when gadget bind is trying to set pull up
although USB cable is not connected.

Once USB is resumed with cable connect case, it checks USB controller
capability and enabled support with USB software to decide allowed
mode of operation.

Change-Id: I08712b21472ca7d59c29db660c0d55b72a4c21cb
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index c397b87..98f277e 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -74,9 +74,8 @@
 	struct device *dev = dwc->dev;
 	unsigned int hw_mode;
 
-	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
-		dwc->dr_mode = USB_DR_MODE_OTG;
 
+	dwc->is_drd = 0;
 	mode = dwc->dr_mode;
 	hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
 
@@ -112,6 +111,9 @@
 		dwc->dr_mode = mode;
 	}
 
+	if (dwc->dr_mode == USB_DR_MODE_OTG)
+		dwc->is_drd = 1;
+
 	return 0;
 }
 
@@ -786,6 +788,10 @@
 	if (dwc->revision < DWC3_REVISION_190A)
 		reg |= DWC3_GCTL_U2RSTECN;
 
+	ret = dwc3_get_dr_mode(dwc);
+	if (ret)
+		goto err0;
+
 	dwc3_core_num_eps(dwc);
 
 	/*
@@ -1172,6 +1178,12 @@
 
 	dwc->maximum_speed = usb_get_maximum_speed(dev);
 	dwc->dr_mode = usb_get_dr_mode(dev);
+
+	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) {
+		dwc->dr_mode = USB_DR_MODE_OTG;
+		dwc->is_drd = 1;
+	}
+
 	dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
 
 	dwc->has_lpm_erratum = device_property_read_bool(dev,
@@ -1254,10 +1266,6 @@
 	pm_runtime_enable(dev);
 	pm_runtime_forbid(dev);
 
-	ret = dwc3_get_dr_mode(dwc);
-	if (ret)
-		goto err0;
-
 	/* Check the maximum_speed parameter */
 	switch (dwc->maximum_speed) {
 	case USB_SPEED_LOW: