Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb9cd93d authored by Mayank Rana's avatar Mayank Rana
Browse files

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: default avatarMayank Rana <mrana@codeaurora.org>
parent 5c4400be
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -74,9 +74,8 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
	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 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
		dwc->dr_mode = mode;
	}

	if (dwc->dr_mode == USB_DR_MODE_OTG)
		dwc->is_drd = 1;

	return 0;
}

@@ -786,6 +788,10 @@ int dwc3_core_init(struct dwc3 *dwc)
	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 @@ static int dwc3_probe(struct platform_device *pdev)

	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 @@ static int dwc3_probe(struct platform_device *pdev)
	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: