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

Commit e39af88f authored by Marek Szyprowski's avatar Marek Szyprowski Committed by Felipe Balbi
Browse files

usb: dwc2: rework initialization of host and gadget in dual-role mode



If device is configured to work only in HOST or DEVICE mode, there is
no point in initializing both subdrivers. This patch also fixes
resource leakage if host subdriver fails to initialize.

Acked-by: default avatarJohn Youn <johnyoun@synopsys.com>
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 9024c495
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -593,6 +593,8 @@ struct dwc2_hsotg {
	struct dwc2_core_params *core_params;
	struct dwc2_core_params *core_params;
	enum usb_otg_state op_state;
	enum usb_otg_state op_state;
	enum usb_dr_mode dr_mode;
	enum usb_dr_mode dr_mode;
	unsigned int hcd_enabled:1;
	unsigned int gadget_enabled:1;


	struct phy *phy;
	struct phy *phy;
	struct usb_phy *uphy;
	struct usb_phy *uphy;
+21 −8
Original line number Original line Diff line number Diff line
@@ -121,7 +121,9 @@ static int dwc2_driver_remove(struct platform_device *dev)
{
{
	struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
	struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);


	if (hsotg->hcd_enabled)
		dwc2_hcd_remove(hsotg);
		dwc2_hcd_remove(hsotg);
	if (hsotg->gadget_enabled)
		s3c_hsotg_remove(hsotg);
		s3c_hsotg_remove(hsotg);


	return 0;
	return 0;
@@ -234,12 +236,23 @@ static int dwc2_driver_probe(struct platform_device *dev)


	spin_lock_init(&hsotg->lock);
	spin_lock_init(&hsotg->lock);
	mutex_init(&hsotg->init_mutex);
	mutex_init(&hsotg->init_mutex);

	if (hsotg->dr_mode != USB_DR_MODE_HOST) {
		retval = dwc2_gadget_init(hsotg, irq);
		retval = dwc2_gadget_init(hsotg, irq);
		if (retval)
		if (retval)
			return retval;
			return retval;
		hsotg->gadget_enabled = 1;
	}

	if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) {
		retval = dwc2_hcd_init(hsotg, irq, params);
		retval = dwc2_hcd_init(hsotg, irq, params);
	if (retval)
		if (retval) {
			if (hsotg->gadget_enabled)
				s3c_hsotg_remove(hsotg);
			return retval;
			return retval;
		}
		hsotg->hcd_enabled = 1;
	}


	platform_set_drvdata(dev, hsotg);
	platform_set_drvdata(dev, hsotg);