From patchwork Tue May 2 08:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minda Chen X-Patchwork-Id: 89275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp443778vqo; Tue, 2 May 2023 01:31:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6y8+Rp8+qdekdxav5tGkclrBLX5rDOMkGEdRcvrxsJTzh7LOdYDtY0tVVNM+UBaoZwz5nz X-Received: by 2002:a05:6a20:d704:b0:f0:f4cf:fcf0 with SMTP id iz4-20020a056a20d70400b000f0f4cffcf0mr18184010pzb.11.1683016277690; Tue, 02 May 2023 01:31:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683016277; cv=none; d=google.com; s=arc-20160816; b=YFCBxGXn3Riozr4b5eotihA5c8AHBXBLnCQGk2jRtdeQ7LGHhUfIT2jH6ZuUXvEBOF /HQHhnuw6nJH3Nq/ZXhEIwvYV+eQoEHJPQ2ZUxJh/yDUTnKLDaoQ9VE1qPCAT0WP4rbT rYeNB1hYR95/566vXkbLUKDSt4EPWjLd7VvFiZtmy6EUbuFQ88mpq6JM34ck5fBdn82s wTWb9S3fmyrsVzL5qM6KBpP7n/hYAyzNV1YdUwF8GPJhSxfQy1EGdry6QDIOPkQsU274 JzO4llw1vdNq10Gl6tXYaaKFwYFf4SIp2ec9+JzMU/d4HWUVd37509AfgXQPCALOL8dP XjVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=hyXZ6srSH0kwgpvPyAqEDiKJGf5Va8tr8mTxk4weF9U=; b=lcMwe3HPEGpGlQ7giNWNgcFaQa47F9xqwxrL4IDzYGKtLgPtpsWVzFv9ToWwBnCfX3 8jJxT0C0NeF5lA7JbBK+ywoWVOAKCn724OKIyAUv1yga8Dy6ChhXCpr8SIXXB7Y/MEFx MimKzbj4hX1eNacruaX/IW1rlEA4R6rPQczStW2EzfCibWHmm2gzgkUhHlsLQra6dzfD W08F7vTVX2mGdkxiurUqwPIUL9bdjyVBtOc9QE5o/8woVp91dXdGRC21wtnjzD4E2iXw vWrD3IeYmVfyOtbxsPxq+efHjLVZ1cEZnYmrj50Mwt3V5WgECurJs2E08BFbciS7jegL CMFA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a63e54b000000b0051b15b58764si26654252pgj.343.2023.05.02.01.31.05; Tue, 02 May 2023 01:31:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233459AbjEBITl (ORCPT + 99 others); Tue, 2 May 2023 04:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233693AbjEBITi (ORCPT ); Tue, 2 May 2023 04:19:38 -0400 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76526170A; Tue, 2 May 2023 01:19:20 -0700 (PDT) Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id 67EC924E156; Tue, 2 May 2023 16:18:08 +0800 (CST) Received: from EXMBX171.cuchost.com (172.16.6.91) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 2 May 2023 16:18:08 +0800 Received: from ubuntu.localdomain (183.27.99.121) by EXMBX171.cuchost.com (172.16.6.91) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 2 May 2023 16:18:07 +0800 From: Minda Chen To: Rob Herring , Krzysztof Kozlowski , Pawel Laszczak , Greg Kroah-Hartman , Peter Chen , Roger Quadros , Philipp Zabel CC: , , , Minda Chen Subject: [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init Date: Tue, 2 May 2023 16:18:05 +0800 Message-ID: <20230502081805.112149-3-minda.chen@starfivetech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502081805.112149-1-minda.chen@starfivetech.com> References: <20230502081805.112149-1-minda.chen@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [183.27.99.121] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) To EXMBX171.cuchost.com (172.16.6.91) X-YovoleRuleAgent: yovoleflag X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1764770476408439776?= X-GMAIL-MSGID: =?utf-8?q?1764770476408439776?= Add gereric clk and reset init codes to Cadence USBSS controller. The codes has been tested by starfive vf2 board. Signed-off-by: Minda Chen --- drivers/usb/cdns3/cdns3-plat.c | 52 ++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/core.h | 3 ++ 2 files changed, 55 insertions(+) diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c index 2bc5d094548b..1820844c74d2 100644 --- a/drivers/usb/cdns3/cdns3-plat.c +++ b/drivers/usb/cdns3/cdns3-plat.c @@ -12,11 +12,13 @@ * Roger Quadros */ +#include #include #include #include #include #include +#include #include "core.h" #include "gadget-export.h" @@ -43,6 +45,34 @@ static void set_phy_power_off(struct cdns *cdns) phy_power_off(cdns->usb2_phy); } +static int cdns3_clk_rst_init(struct cdns *cdns) +{ + int ret; + + if (cdns->num_clks) { + ret = clk_bulk_prepare_enable(cdns->num_clks, cdns->clks); + if (ret) + return ret; + } + + ret = reset_control_deassert(cdns->resets); + if (ret && cdns->num_clks) + goto err_clk_init; + + return ret; + +err_clk_init: + clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks); + return ret; +} + +static void cdns3_clk_rst_deinit(struct cdns *cdns) +{ + reset_control_assert(cdns->resets); + if (cdns->num_clks) + clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks); +} + /** * cdns3_plat_probe - probe for cdns3 core device * @pdev: Pointer to cdns3 core platform device @@ -116,6 +146,16 @@ static int cdns3_plat_probe(struct platform_device *pdev) cdns->wakeup_irq = 0x0; } + ret = devm_clk_bulk_get_all(dev, &cdns->clks); + if (ret < 0) + return ret; + + cdns->num_clks = ret; + + cdns->resets = devm_reset_control_array_get_optional_exclusive(dev); + if (IS_ERR(cdns->resets)) + return PTR_ERR(cdns->resets); + cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy"); if (IS_ERR(cdns->usb2_phy)) return PTR_ERR(cdns->usb2_phy); @@ -128,6 +168,10 @@ static int cdns3_plat_probe(struct platform_device *pdev) if (IS_ERR(cdns->usb3_phy)) return PTR_ERR(cdns->usb3_phy); + ret = cdns3_clk_rst_init(cdns); + if (ret) + return ret; + ret = phy_init(cdns->usb3_phy); if (ret) goto err_phy3_init; @@ -165,6 +209,7 @@ static int cdns3_plat_probe(struct platform_device *pdev) phy_exit(cdns->usb3_phy); err_phy3_init: phy_exit(cdns->usb2_phy); + cdns3_clk_rst_deinit(cdns); return ret; } @@ -187,6 +232,8 @@ static int cdns3_plat_remove(struct platform_device *pdev) set_phy_power_off(cdns); phy_exit(cdns->usb2_phy); phy_exit(cdns->usb3_phy); + cdns3_clk_rst_deinit(cdns); + return 0; } @@ -220,6 +267,8 @@ static int cdns3_controller_suspend(struct device *dev, pm_message_t msg) cdns3_set_platform_suspend(cdns->dev, true, wakeup); set_phy_power_off(cdns); + if (!PMSG_IS_AUTO(msg)) + cdns3_clk_rst_deinit(cdns); spin_lock_irqsave(&cdns->lock, flags); cdns->in_lpm = true; spin_unlock_irqrestore(&cdns->lock, flags); @@ -237,6 +286,9 @@ static int cdns3_controller_resume(struct device *dev, pm_message_t msg) if (!cdns->in_lpm) return 0; + if (!PMSG_IS_AUTO(msg)) + cdns3_clk_rst_init(cdns); + if (cdns_power_is_lost(cdns)) { phy_exit(cdns->usb2_phy); ret = phy_init(cdns->usb2_phy); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h index 2d332a788871..b894768ee485 100644 --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h @@ -111,6 +111,9 @@ struct cdns { struct mutex mutex; enum usb_dr_mode dr_mode; struct usb_role_switch *role_sw; + struct reset_control *resets; + struct clk_bulk_data *clks; + int num_clks; bool in_lpm; bool wakeup_pending; struct cdns3_platform_data *pdata;