public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
To: dinguyen@opensource.altera.com
Cc: paulz@synopsys.com, gregkh@linuxfoundation.org, balbi@ti.com,
	dinh.linux@gmail.com, swarren@wwwdotorg.org, matthijs@stdin.nl,
	r.baldyga@samsung.com, jg1.han@samsung.com,
	sachin.kamat@linaro.org, ben-linux@fluff.org,
	dianders@chromium.org, kever.yang@rock-chips.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCHv4 08/12] usb: dwc2: gadget: Do not fail probe if there isn't a clock node
Date: Fri, 12 Sep 2014 18:28:58 +0200	[thread overview]
Message-ID: <3825627.ZuOPzBNWiB@amdc1032> (raw)
In-Reply-To: <1409070003-21195-9-git-send-email-dinguyen@opensource.altera.com>


[ added linux-kernel ML to cc: ]

Hi,

On Tuesday, August 26, 2014 11:19:59 AM dinguyen@opensource.altera.com wrote:
> From: Dinh Nguyen <dinguyen@opensource.altera.com>
> 
> Since the dwc2 hcd driver is currently not looking for a clock node during
> init, we should not completely fail if there isn't a clock provided.
> Add a check for a valid clock before calling clock functions.

This doesn't look correct at least for the case when we are really missing
the clock and USB_DWC2_PERIPHERAL=y (moreover it just looks wrong to access
gadget functionalities when clock is disabled). It seems that it would be
better to just disable gadget functionality on dwc2_gadget_init() failure
in hcd and not call gadget functions later from hcd if gadget functionality
is disabled.

> Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
> Acked-by: Paul Zimmerman <paulz@synopsys.com>
> ---
>  drivers/usb/dwc2/gadget.c | 36 ++++++++++++++++++++++--------------
>  1 file changed, 22 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index a1c93bf..aab1b45 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -2852,7 +2852,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
>  	hsotg->gadget.dev.of_node = hsotg->dev->of_node;
>  	hsotg->gadget.speed = USB_SPEED_UNKNOWN;
>  
> -	clk_enable(hsotg->clk);
> +	if (!IS_ERR(hsotg->clk))
> +		clk_enable(hsotg->clk);
>  
>  	ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
>  				    hsotg->supplies);
> @@ -2903,7 +2904,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
>  	regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
>  				hsotg->supplies);
>  
> -	clk_disable(hsotg->clk);
> +	if (!IS_ERR(hsotg->clk))
> +		clk_disable(hsotg->clk);
>  
>  	return 0;
>  }
> @@ -2936,10 +2938,12 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)
>  	spin_lock_irqsave(&hsotg->lock, flags);
>  	if (is_on) {
>  		s3c_hsotg_phy_enable(hsotg);
> -		clk_enable(hsotg->clk);
> +		if (!IS_ERR(hsotg->clk))
> +			clk_enable(hsotg->clk);
>  		s3c_hsotg_core_init(hsotg);
>  	} else {
> -		clk_disable(hsotg->clk);
> +		if (!IS_ERR(hsotg->clk))
> +			clk_disable(hsotg->clk);
>  		s3c_hsotg_phy_disable(hsotg);
>  	}
>  
> @@ -3410,16 +3414,15 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
>  	}
>  
>  	hsotg->clk = devm_clk_get(dev, "otg");
> -	if (IS_ERR(hsotg->clk)) {
> -		dev_err(dev, "cannot get otg clock\n");
> -		return PTR_ERR(hsotg->clk);
> -	}
> +	if (IS_ERR(hsotg->clk))
> +		dev_warn(dev, "cannot get otg clock\n");
>  
>  	hsotg->gadget.max_speed = USB_SPEED_HIGH;
>  	hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
>  	hsotg->gadget.name = dev_name(dev);
>  
> -	clk_prepare_enable(hsotg->clk);
> +	if (!IS_ERR(hsotg->clk))
> +		clk_prepare_enable(hsotg->clk);
>  
>  	/* regulators */
>  
> @@ -3452,7 +3455,8 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
>  			dev_name(dev), hsotg);
>  	if (ret < 0) {
>  		s3c_hsotg_phy_disable(hsotg);
> -		clk_disable_unprepare(hsotg->clk);
> +		if (!IS_ERR(hsotg->clk))
> +			clk_disable_unprepare(hsotg->clk);
>  		regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
>  				       hsotg->supplies);
>  		dev_err(dev, "cannot claim IRQ\n");
> @@ -3521,7 +3525,8 @@ err_ep_mem:
>  err_supplies:
>  	s3c_hsotg_phy_disable(hsotg);
>  err_clk:
> -	clk_disable_unprepare(hsotg->clk);
> +	if (!IS_ERR(hsotg->clk))
> +		clk_disable_unprepare(hsotg->clk);
>  
>  	return ret;
>  }
> @@ -3541,7 +3546,8 @@ int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
>  		usb_gadget_unregister_driver(hsotg->driver);
>  	}
>  
> -	clk_disable_unprepare(hsotg->clk);
> +	if (!IS_ERR(hsotg->clk))
> +		clk_disable_unprepare(hsotg->clk);
>  
>  	return 0;
>  }
> @@ -3568,7 +3574,8 @@ static int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
>  
>  		ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
>  					     hsotg->supplies);
> -		clk_disable(hsotg->clk);
> +		if (!IS_ERR(hsotg->clk))
> +			clk_disable(hsotg->clk);
>  	}
>  
>  	return ret;
> @@ -3583,7 +3590,8 @@ static int s3c_hsotg_resume(struct dwc2_hsotg *hsotg)
>  		dev_info(hsotg->dev, "resuming usb gadget %s\n",
>  			 hsotg->driver->driver.name);
>  
> -		clk_enable(hsotg->clk);
> +		if (!IS_ERR(hsotg->clk))
> +			clk_enable(hsotg->clk);
>  		ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
>  					   hsotg->supplies);
>  	}

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics


  parent reply	other threads:[~2014-09-12 16:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1409070003-21195-1-git-send-email-dinguyen@opensource.altera.com>
     [not found] ` <1409070003-21195-2-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 15:49   ` [PATCHv4 01/12] usb: dwc2: Update Kconfig to support dual-role Bartlomiej Zolnierkiewicz
2014-09-18 15:54     ` Dinh Nguyen
2014-09-18 19:59       ` Paul Zimmerman
2014-09-19 14:49       ` Bartlomiej Zolnierkiewicz
2014-09-19 19:02         ` Paul Zimmerman
2014-09-22 16:10           ` Bartlomiej Zolnierkiewicz
     [not found] ` <1409070003-21195-3-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 15:56   ` [PATCHv4 02/12] usb: dwc2: move "samsung,s3c6400-hsotg" into common platform Bartlomiej Zolnierkiewicz
     [not found] ` <1409070003-21195-4-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 16:08   ` [PATCHv4 03/12] usb: dwc2: Update the gadget driver to use common dwc2_hsotg structure Bartlomiej Zolnierkiewicz
     [not found] ` <1409070003-21195-5-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 16:18   ` [PATCHv4 04/12] usb: dwc2: Add the appropriate init calls in platform code Bartlomiej Zolnierkiewicz
2014-09-18 19:24     ` Dinh Nguyen
     [not found] ` <1409070003-21195-9-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 16:28   ` Bartlomiej Zolnierkiewicz [this message]
2014-09-19 14:29     ` [PATCHv4 08/12] usb: dwc2: gadget: Do not fail probe if there isn't a clock node Dinh Nguyen
     [not found] ` <1409070003-21195-10-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 16:34   ` [PATCHv4 09/12] usb: dwc2: initialize the spin_lock for both host and gadget Bartlomiej Zolnierkiewicz
     [not found] ` <1409070003-21195-11-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 16:36   ` [PATCHv4 10/12] usb: dwc2: Add suspend/resume for gadget Bartlomiej Zolnierkiewicz
     [not found] ` <1409070003-21195-12-git-send-email-dinguyen@opensource.altera.com>
2014-09-12 16:38   ` [PATCHv4 11/12] usb: dwc2: check that the host work queue is valid Bartlomiej Zolnierkiewicz
2014-09-12 16:44 ` [PATCHv4 00/12] usb: dwc2: Add support for dual role Bartlomiej Zolnierkiewicz
2014-09-12 18:29   ` Dinh Nguyen

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=3825627.ZuOPzBNWiB@amdc1032 \
    --to=b.zolnierkie@samsung.com \
    --cc=balbi@ti.com \
    --cc=ben-linux@fluff.org \
    --cc=dianders@chromium.org \
    --cc=dinguyen@opensource.altera.com \
    --cc=dinh.linux@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jg1.han@samsung.com \
    --cc=kever.yang@rock-chips.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=matthijs@stdin.nl \
    --cc=paulz@synopsys.com \
    --cc=r.baldyga@samsung.com \
    --cc=sachin.kamat@linaro.org \
    --cc=swarren@wwwdotorg.org \
    /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