From patchwork Tue Apr 4 07:25:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 78882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2838038vqo; Tue, 4 Apr 2023 00:32:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZOKYNIHYYBZcvvoaxLismyn1kS2m70cjgCxu3MpOnAnFr31VXvVwVoe+bebiw0GOxBn7Wx X-Received: by 2002:a05:6a20:ce17:b0:d9:896b:8c0f with SMTP id ic23-20020a056a20ce1700b000d9896b8c0fmr1624529pzb.24.1680593561494; Tue, 04 Apr 2023 00:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680593561; cv=none; d=google.com; s=arc-20160816; b=axNFslk3e6otQLyeQuyNsD0jyFUpRXwKTxUq6ASmp9bGdqzhXw66bEBGkzfCbpCOdC ag50/NPBCu0UQtrLsVeGFzZ1ZTtBjIHMtktGI028hddzyUKz+m9mniYFm9N/Wvz7B7qs y1mo9fEYBEgHGfCgJe5rIofWH2Ix83bJZ6N+I3HRT1xt0u96HkszSVuzRCh/y2dlqTEK zCkL4Lzd1N5I2Rto8YKE/1hikjwRvGagLGl9VUnlbnplDKxmo5pSMffID/lf1rIz1Teq i1oOemHkRjgty+ko6hsvLlntNgxghU8yWJmtZmsZbSdyIbFeSSfJoKyFAkKrshq39yWv /7qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=//kvBgJckE+uBdHDPeyzjWKVXDE8HSGk3tuWGKaj1is=; b=i2982h5NUcRlxDXqp0Zp8LLa9AGAAKKddkcpFxZ1JvcbMIQxYG6Jval42Y9LpeIUL4 d8NsjWGFXZlUrGyjE/86ZoLgVLkdME1oibpMxd9ySwy+6mLB6uoVuEG4BCH4wTqq2R52 YKJHTpiRPVdP9d32iG6bFAgHGNzhmLFDbBHz8Hx15UZSXZGnoPYJQteNissX2RaD4+Uh b2fDgCBBDe585zZsKkMZhAAKegA6T3ws93DRbvhIWdpiAH+w8Zk965kJQwKUddOddnwh jo3Qo7dh/p7nhnVfYkwMO2VZMa+Navo661jLTyqHgnAbgp4X9QYTrrBo1fZMvAhjAkRv /X5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMcjkIsz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q29-20020a635c1d000000b0050beb3fe627si9590373pgb.459.2023.04.04.00.32.28; Tue, 04 Apr 2023 00:32:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMcjkIsz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234034AbjDDH0f (ORCPT + 99 others); Tue, 4 Apr 2023 03:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233878AbjDDHZ4 (ORCPT ); Tue, 4 Apr 2023 03:25:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 640482D79; Tue, 4 Apr 2023 00:25:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1FEA462F86; Tue, 4 Apr 2023 07:25:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11739C433AC; Tue, 4 Apr 2023 07:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680593146; bh=wye9SQxSeebraYd3ht27KtushVWGDMc8EdiWMbnNa1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMcjkIsz5SaJi++v1fTzoMJTkPEi/sku57cnjuoAWXjhvQI9jjgiuTN8oo6e07bJ+ beT5beBA/Oq7jNOu3EudLHnMpZoJT2nv8V4ymI5ZHQ9Wfb9vbwNRGRWlmpOVcCIy2g jZ9ubAq7r0Ej9gsYfIeYOHWfcTsCHGowksHkrbRKqT+LG3IOytg8UzUzZgguqJEGGQ 9ju1dvEm4RkroGz3XaT/l9L+q8cMJjAscOYtoRKPgfqTD7BFbM650U+/AQVv9COyH7 Ah/z39XEOMAZSVy1tN3DHsW3CZwtAKJzxf5QRvZkMqvOXOi57pg7Jbu7DQDqVkGGDK yZVaWZXYWeohQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pjb3V-0004xr-GS; Tue, 04 Apr 2023 09:26:13 +0200 From: Johan Hovold To: Thinh Nguyen Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 10/11] USB: dwc3: refactor clock lookups Date: Tue, 4 Apr 2023 09:25:23 +0200 Message-Id: <20230404072524.19014-11-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404072524.19014-1-johan+linaro@kernel.org> References: <20230404072524.19014-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762230074366244734?= X-GMAIL-MSGID: =?utf-8?q?1762230074366244734?= 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 Acked-by: Thinh Nguyen --- 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)