Linux Samsung SOC development
 help / color / mirror / Atom feed
From: John Youn <John.Youn@synopsys.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-samsung-soc@vger.kernel.org"
	<linux-samsung-soc@vger.kernel.org>
Cc: Robert Baldyga <r.baldyga@samsung.com>,
	Paul Zimmerman <paulz@synopsys.com>, Felipe Balbi <balbi@ti.com>,
	John Youn <John.Youn@synopsys.com>
Subject: Re: [PATCH RESEND] usb: dwc2: rework initialization of host and gadget in dual-role mode
Date: Wed, 11 Mar 2015 15:51:21 -0700	[thread overview]
Message-ID: <5500C6E9.9010105@synopsys.com> (raw)
In-Reply-To: <1425991270-30629-1-git-send-email-m.szyprowski@samsung.com>

On 3/10/2015 5:41 AM, Marek Szyprowski wrote:
> 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.
> 
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>  drivers/usb/dwc2/core.h     |  2 ++
>  drivers/usb/dwc2/platform.c | 29 +++++++++++++++++++++--------
>  2 files changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index 7a70a1349334..f93b06daef97 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -570,6 +570,8 @@ struct dwc2_hsotg {
>  	struct dwc2_core_params *core_params;
>  	enum usb_otg_state op_state;
>  	enum usb_dr_mode dr_mode;
> +	unsigned int hcd_enabled:1;
> +	unsigned int gadget_enabled:1;
>  
>  	struct phy *phy;
>  	struct usb_phy *uphy;
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 6a795aa2ff05..ee0b0b06d0fc 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -121,8 +121,10 @@ static int dwc2_driver_remove(struct platform_device *dev)
>  {
>  	struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
>  
> -	dwc2_hcd_remove(hsotg);
> -	s3c_hsotg_remove(hsotg);
> +	if (hsotg->hcd_enabled)
> +		dwc2_hcd_remove(hsotg);
> +	if (hsotg->gadget_enabled)
> +		s3c_hsotg_remove(hsotg);
>  
>  	return 0;
>  }
> @@ -214,12 +216,23 @@ static int dwc2_driver_probe(struct platform_device *dev)
>  
>  	spin_lock_init(&hsotg->lock);
>  	mutex_init(&hsotg->init_mutex);
> -	retval = dwc2_gadget_init(hsotg, irq);
> -	if (retval)
> -		return retval;
> -	retval = dwc2_hcd_init(hsotg, irq, params);
> -	if (retval)
> -		return retval;
> +
> +	if (hsotg->dr_mode != USB_DR_MODE_HOST) {
> +		retval = dwc2_gadget_init(hsotg, irq);
> +		if (retval)
> +			return retval;
> +		hsotg->gadget_enabled = 1;
> +	}
> +
> +	if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) {
> +		retval = dwc2_hcd_init(hsotg, irq, params);
> +		if (retval) {
> +			if (hsotg->gadget_enabled)
> +				s3c_hsotg_remove(hsotg);
> +			return retval;
> +		}
> +		hsotg->hcd_enabled = 1;
> +	}
>  
>  	platform_set_drvdata(dev, hsotg);
>  
> 

Acked-by: John Youn <johnyoun@synopsys.com>

      reply	other threads:[~2015-03-11 22:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-10 12:41 [PATCH RESEND] usb: dwc2: rework initialization of host and gadget in dual-role mode Marek Szyprowski
2015-03-11 22:51 ` John Youn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5500C6E9.9010105@synopsys.com \
    --to=john.youn@synopsys.com \
    --cc=balbi@ti.com \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=paulz@synopsys.com \
    --cc=r.baldyga@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox