From: Minda Chen <minda.chen@starfivetech.com>
To: Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Pawel Laszczak <pawell@cadence.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Peter Chen <peter.chen@kernel.org>,
Roger Quadros <rogerq@kernel.org>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-usb@vger.kernel.org>,
Minda Chen <minda.chen@starfivetech.com>
Subject: [PATCH v2 2/2] usb: cdns3: cdns3-plat: Add clk and reset init
Date: Wed, 10 May 2023 21:28:16 +0800 [thread overview]
Message-ID: <20230510132816.108820-3-minda.chen@starfivetech.com> (raw)
In-Reply-To: <20230510132816.108820-1-minda.chen@starfivetech.com>
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 <minda.chen@starfivetech.com>
---
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 <rogerq@ti.com>
*/
+#include <linux/clk.h>
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/reset.h>
#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;
--
2.17.1
prev parent reply other threads:[~2023-05-10 13:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 13:28 [PATCH v2 0/2] Add clock and reset in cdns3 platform Minda Chen
2023-05-10 13:28 ` [PATCH v2 1/2] dt-bindings: cdns,usb3: Add clock and reset Minda Chen
2023-05-11 9:26 ` Krzysztof Kozlowski
2023-05-11 12:16 ` Roger Quadros
2023-05-11 14:49 ` Krzysztof Kozlowski
2023-05-12 10:22 ` Minda Chen
2023-05-13 18:42 ` Krzysztof Kozlowski
2023-05-12 11:08 ` Roger Quadros
2023-05-13 18:43 ` Krzysztof Kozlowski
2023-05-10 13:28 ` Minda Chen [this message]
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=20230510132816.108820-3-minda.chen@starfivetech.com \
--to=minda.chen@starfivetech.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pawell@cadence.com \
--cc=peter.chen@kernel.org \
--cc=robh+dt@kernel.org \
--cc=rogerq@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).