All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Johan Hovold <johan+linaro@kernel.org>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 10/11] USB: dwc3: refactor clock lookups
Date: Fri, 7 Apr 2023 00:47:53 +0000	[thread overview]
Message-ID: <20230407004740.ldyigffce7jldaug@synopsys.com> (raw)
In-Reply-To: <20230404072524.19014-11-johan+linaro@kernel.org>

On Tue, Apr 04, 2023, Johan Hovold wrote:
> The probe callback has become unwieldy so break out the clock lookups
> into a new helper function to improve readability.
> 
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---
>  drivers/usb/dwc3/core.c | 116 +++++++++++++++++++++-------------------
>  1 file changed, 61 insertions(+), 55 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 52cd5ddfebd5..08432e109a3f 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1692,6 +1692,64 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
>  	return edev;
>  }
>  
> +static int dwc3_get_clocks(struct dwc3 *dwc)
> +{
> +	struct device *dev = dwc->dev;
> +
> +	if (!dev->of_node)
> +		return 0;
> +
> +	/*
> +	 * Clocks are optional, but new DT platforms should support all clocks
> +	 * as required by the DT-binding.
> +	 * Some devices have different clock names in legacy device trees,
> +	 * check for them to retain backwards compatibility.
> +	 */
> +	dwc->bus_clk = devm_clk_get_optional(dev, "bus_early");
> +	if (IS_ERR(dwc->bus_clk)) {
> +		return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
> +				"could not get bus clock\n");
> +	}
> +
> +	if (dwc->bus_clk == NULL) {
> +		dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk");
> +		if (IS_ERR(dwc->bus_clk)) {
> +			return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
> +					"could not get bus clock\n");
> +		}
> +	}
> +
> +	dwc->ref_clk = devm_clk_get_optional(dev, "ref");
> +	if (IS_ERR(dwc->ref_clk)) {
> +		return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
> +				"could not get ref clock\n");
> +	}
> +
> +	if (dwc->ref_clk == NULL) {
> +		dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk");
> +		if (IS_ERR(dwc->ref_clk)) {
> +			return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
> +					"could not get ref clock\n");
> +		}
> +	}
> +
> +	dwc->susp_clk = devm_clk_get_optional(dev, "suspend");
> +	if (IS_ERR(dwc->susp_clk)) {
> +		return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
> +				"could not get suspend clock\n");
> +	}
> +
> +	if (dwc->susp_clk == NULL) {
> +		dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk");
> +		if (IS_ERR(dwc->susp_clk)) {
> +			return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
> +					"could not get suspend clock\n");
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  static int dwc3_probe(struct platform_device *pdev)
>  {
>  	struct device		*dev = &pdev->dev;
> @@ -1742,61 +1800,9 @@ static int dwc3_probe(struct platform_device *pdev)
>  		goto err_put_psy;
>  	}
>  
> -	if (dev->of_node) {
> -		/*
> -		 * Clocks are optional, but new DT platforms should support all
> -		 * clocks as required by the DT-binding.
> -		 * Some devices have different clock names in legacy device trees,
> -		 * check for them to retain backwards compatibility.
> -		 */
> -		dwc->bus_clk = devm_clk_get_optional(dev, "bus_early");
> -		if (IS_ERR(dwc->bus_clk)) {
> -			ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
> -					    "could not get bus clock\n");
> -			goto err_put_psy;
> -		}
> -
> -		if (dwc->bus_clk == NULL) {
> -			dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk");
> -			if (IS_ERR(dwc->bus_clk)) {
> -				ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
> -						    "could not get bus clock\n");
> -				goto err_put_psy;
> -			}
> -		}
> -
> -		dwc->ref_clk = devm_clk_get_optional(dev, "ref");
> -		if (IS_ERR(dwc->ref_clk)) {
> -			ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
> -					    "could not get ref clock\n");
> -			goto err_put_psy;
> -		}
> -
> -		if (dwc->ref_clk == NULL) {
> -			dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk");
> -			if (IS_ERR(dwc->ref_clk)) {
> -				ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
> -						    "could not get ref clock\n");
> -				goto err_put_psy;
> -			}
> -		}
> -
> -		dwc->susp_clk = devm_clk_get_optional(dev, "suspend");
> -		if (IS_ERR(dwc->susp_clk)) {
> -			ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
> -					    "could not get suspend clock\n");
> -			goto err_put_psy;
> -		}
> -
> -		if (dwc->susp_clk == NULL) {
> -			dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk");
> -			if (IS_ERR(dwc->susp_clk)) {
> -				ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
> -						    "could not get suspend clock\n");
> -				goto err_put_psy;
> -			}
> -		}
> -	}
> +	ret = dwc3_get_clocks(dwc);
> +	if (ret)
> +		goto err_put_psy;
>  
>  	ret = reset_control_deassert(dwc->reset);
>  	if (ret)
> -- 
> 2.39.2
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh

  reply	other threads:[~2023-04-07  0:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04  7:25 [PATCH 00/11] USB: dwc3: error handling fixes and cleanups Johan Hovold
2023-04-04  7:25 ` [PATCH 01/11] USB: dwc3: fix runtime pm imbalance on probe errors Johan Hovold
2023-04-11  1:22   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 02/11] USB: dwc3: fix runtime pm imbalance on unbind Johan Hovold
2023-04-11  1:22   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 03/11] USB: dwc3: disable autosuspend " Johan Hovold
2023-04-11  1:17   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 04/11] USB: dwc3: gadget: drop dead hibernation code Johan Hovold
2023-04-07  1:59   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 05/11] USB: dwc3: " Johan Hovold
2023-04-07  1:58   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 06/11] USB: dwc3: clean up probe error labels Johan Hovold
2023-04-07  0:49   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 07/11] USB: dwc3: clean up phy init error handling Johan Hovold
2023-04-07  1:00   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 08/11] USB: dwc3: clean up core " Johan Hovold
2023-04-07  0:56   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 09/11] USB: dwc3: refactor phy handling Johan Hovold
2023-04-07  1:31   ` Thinh Nguyen
2023-04-04  7:25 ` [PATCH 10/11] USB: dwc3: refactor clock lookups Johan Hovold
2023-04-07  0:47   ` Thinh Nguyen [this message]
2023-04-04  7:25 ` [PATCH 11/11] USB: dwc3: clean up probe declarations Johan Hovold
2023-04-07  0:46   ` Thinh Nguyen
2023-04-07  2:09 ` [PATCH 00/11] USB: dwc3: error handling fixes and cleanups Thinh 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=20230407004740.ldyigffce7jldaug@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan+linaro@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.