From patchwork Wed May 10 13:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minda Chen X-Patchwork-Id: 92097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3629337vqo; Wed, 10 May 2023 06:36:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6J/GSTQlIoXBxtlC1O+R+SlkZrgqkj90aVARNZtBp4aSU8HE+WG3+VBknO21w0WqbjmpT3 X-Received: by 2002:a17:90a:9b15:b0:250:54a0:c6b5 with SMTP id f21-20020a17090a9b1500b0025054a0c6b5mr14008560pjp.43.1683725787592; Wed, 10 May 2023 06:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683725787; cv=none; d=google.com; s=arc-20160816; b=JRJ1H1uRvguPYKLVGS2U2/H/1PMz2j11WFShzXN6tZR/u4sE0E20RrKInqh5YF6vza 47j0Q5eGDu2Oz3L+7wwTuYsvmVlAgo8X/CnHnAgVjv+O4i0HpDb5o7DwNl36A9qZ9fGh 1IaLC4T2HP+p+lppng8ZHnXSZHWVy5WLk/qaHCv+NQgDJUdczj5vpRqzG96GpSmhyd3g eNa9mnv40MskJPgpfD8b8OWBmF5UcD6XfjI2Y4JhUi7NBtL7XRHzz7Jyzcy254NVW6fg eT8P7k5kFsay9e3rEeNibqY3AR2MDRoMTTC1xy5k6J1CRdGGeDad1asKciOsu8KJYO5G 0kRg== 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=LGEXP+3/WuwSWAxOXNWbYZp4j1IisJ1deBO12iuGOm8=; b=G2C/0MkCFSRVrmoZSL/BS9loRvhTRKJKmfMLYLTtFvCo+7Hhe4ROWRnZGrqJiMavo0 YIX18Qtcf7xEAd58s5Tcyz8QaQZ2pZHopW9r9epqMCVLO03Lpum1b+FXsb+OMJBJ6BHh gephDQfnBC4RKQUSBKrqP62uLrATf3Z6cWEJ3+yNstOgJavOkbeX0t59Bh9bc8HSsGHP QBtvv8YxTPX8LKayvZQUs0IgdNB9QjDEfNoIyTEMfV6eGxjZYiGSceIxgXQF6whA067E kD9DDACM+ZX1prss7XmmcZAbfPxJWClXVCGddoujUb/kLMTJFVKKRE+T8aaEJ8+w4o/T spDg== 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 me14-20020a17090b17ce00b0023fbb212145si31691165pjb.175.2023.05.10.06.36.14; Wed, 10 May 2023 06:36:27 -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 S237098AbjEJN2e (ORCPT + 99 others); Wed, 10 May 2023 09:28:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237082AbjEJN2c (ORCPT ); Wed, 10 May 2023 09:28:32 -0400 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0CB861B2; Wed, 10 May 2023 06:28:22 -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 D411D24E143; Wed, 10 May 2023 21:28:18 +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; Wed, 10 May 2023 21:28:18 +0800 Received: from ubuntu.localdomain (183.27.98.219) by EXMBX171.cuchost.com (172.16.6.91) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 10 May 2023 21:28:17 +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 v2 1/2] dt-bindings: cdns,usb3: Add clock and reset Date: Wed, 10 May 2023 21:28:15 +0800 Message-ID: <20230510132816.108820-2-minda.chen@starfivetech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230510132816.108820-1-minda.chen@starfivetech.com> References: <20230510132816.108820-1-minda.chen@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [183.27.98.219] 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?1765514451458231475?= X-GMAIL-MSGID: =?utf-8?q?1765514451458231475?= To support generic clock and reset init in Cadence USBSS controller, add clock and reset dts configuration. Signed-off-by: Minda Chen --- .../devicetree/bindings/usb/cdns,usb3.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/cdns,usb3.yaml b/Documentation/devicetree/bindings/usb/cdns,usb3.yaml index cae46c4982ad..623c6b34dee3 100644 --- a/Documentation/devicetree/bindings/usb/cdns,usb3.yaml +++ b/Documentation/devicetree/bindings/usb/cdns,usb3.yaml @@ -42,6 +42,18 @@ properties: - const: otg - const: wakeup + clocks: + minItems: 1 + maxItems: 8 + description: + USB controller clocks. + + resets: + minItems: 1 + maxItems: 8 + description: + USB controller generic resets. + dr_mode: enum: [host, otg, peripheral] @@ -98,5 +110,7 @@ examples: interrupt-names = "host", "peripheral", "otg"; maximum-speed = "super-speed"; dr_mode = "otg"; + clocks = <&clk 1>, <&clk 2>, <&clk 3>; + resets = <&rst 1>, <&rst 2>, <&rst 3>; }; }; From patchwork Wed May 10 13:28:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minda Chen X-Patchwork-Id: 92090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3627828vqo; Wed, 10 May 2023 06:34:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Ui9eXHjNTrMZArPuI/1HooH9HtlWw0TLk3DBv8QJmtUWoNgIgyjqOzva0aWqEtLWvBnWu X-Received: by 2002:a05:6a20:840a:b0:f1:8f7:eeb6 with SMTP id c10-20020a056a20840a00b000f108f7eeb6mr22969658pzd.59.1683725664713; Wed, 10 May 2023 06:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683725664; cv=none; d=google.com; s=arc-20160816; b=0HNnRv9I5JpR94ja78NWB/fTwHJ7czBWxhyt9W6bssJ2cPTIabotsGHvbPUBFNn1Fz I3k0OEaSBL6LSF9tFp4LeiNLfHm1ozI8MCwaeoFoYIZfJ42rwK2H/zdxMD4kUXN2yet3 ryeB96l2bDNzvgfspdxCcf4YqDnBhtzJssYiYPso9JdkGhdJcuz3HVec2I6CUBBFjC6C IavpJXZDkseBlPDmX+LyqIqRHQiNgCJ8F8d4chp2Kvoy9FhanB2sHHzxUw2HBN4ki9+Q OLXgNTSX9mDAYv6XCBHJJP3iAyRkpVxJltNeNRF3p5+mXgjH2XGit6ZN2LRyM1lvfjd6 AytA== 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=OWDHCVleqSwrcFjjxrSPXj9PoUSN82iLCGdHIm2TWnQ=; b=LwkJmDG08kOF1TOatzyQmkWJAI/88QL+FpLKxgY+GxcABlcVQZBTBj3FIB9D/uR9Bc jvw4syZUhLaa9JNyUMnvKTxvm4tXG78C/ALTUdRzOfweddl81sOTLZu7RDsFVXYyzoDh JQ2ta4qOb882Px6zXajw3xEdw9Ti7SuLMzAk3EdQ7sBdrEsfCDc0l5TU+NL+YJDYT672 0xvje/s9xjVYicKO031gtP1B3pk4BpAQS1NKmpfFyH5IsLl3hEfEQfhYAYMxvtwWlww7 ICh0cCt8/tbKjpYOxlWf7dOMxS+d0tB9m3JVgc/kApjvXRB61KSiPsOWM3CL29l/21ao SKZQ== 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 h132-20020a636c8a000000b004fc257265cfsi3949156pgc.267.2023.05.10.06.34.08; Wed, 10 May 2023 06:34:24 -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 S237082AbjEJN2h (ORCPT + 99 others); Wed, 10 May 2023 09:28:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237083AbjEJN2c (ORCPT ); Wed, 10 May 2023 09:28:32 -0400 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2D5E44A8; Wed, 10 May 2023 06:28:25 -0700 (PDT) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id 74C4124E1B7; Wed, 10 May 2023 21:28:19 +0800 (CST) Received: from EXMBX171.cuchost.com (172.16.6.91) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 10 May 2023 21:28:19 +0800 Received: from ubuntu.localdomain (183.27.98.219) by EXMBX171.cuchost.com (172.16.6.91) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 10 May 2023 21:28:18 +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 v2 2/2] usb: cdns3: cdns3-plat: Add clk and reset init Date: Wed, 10 May 2023 21:28:16 +0800 Message-ID: <20230510132816.108820-3-minda.chen@starfivetech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230510132816.108820-1-minda.chen@starfivetech.com> References: <20230510132816.108820-1-minda.chen@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [183.27.98.219] 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?1765514322630232071?= X-GMAIL-MSGID: =?utf-8?q?1765514322630232071?= 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 | 58 ++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/core.h | 3 ++ 2 files changed, 61 insertions(+) diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c index 2bc5d094548b..30da808e0a2f 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,40 @@ static void set_phy_power_off(struct cdns *cdns) phy_power_off(cdns->usb2_phy); } +static int cdns3_clk_rst_init(struct cdns *cdns, bool clk_only) +{ + int ret = 0; + + if (cdns->num_clks) { + ret = clk_bulk_prepare_enable(cdns->num_clks, cdns->clks); + if (ret) + return ret; + } + + if (clk_only) + return ret; + + ret = reset_control_deassert(cdns->resets); + if (ret) + goto err_clk_init; + + return ret; + +err_clk_init: + if (cdns->num_clks) + clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks); + return ret; +} + +static void cdns3_clk_rst_deinit(struct cdns *cdns, bool clk_only) +{ + if (!clk_only) + 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 +152,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 +174,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, false); + if (ret) + return ret; + ret = phy_init(cdns->usb3_phy); if (ret) goto err_phy3_init; @@ -165,6 +215,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, false); return ret; } @@ -187,6 +238,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, false); + return 0; } @@ -220,6 +273,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, true); spin_lock_irqsave(&cdns->lock, flags); cdns->in_lpm = true; spin_unlock_irqrestore(&cdns->lock, flags); @@ -237,6 +292,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, true); + 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;