linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/2] Add clock and reset in cdns3 platform
@ 2023-05-02  8:18 Minda Chen
  2023-05-02  8:18 ` [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset Minda Chen
  2023-05-02  8:18 ` [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init Minda Chen
  0 siblings, 2 replies; 9+ messages in thread
From: Minda Chen @ 2023-05-02  8:18 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Roger Quadros, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb, Minda Chen

The patchset is add generic clock and reset init codes in
Cadence USBSS controller.

This patchset is base on v6.3-rc4.

patch 1 is add clock and reset dts in cdns3 dt-binding doc.
patch 2 is cdns3 platform codes changes.

Minda Chen (2):
  dt-binding: cdns,usb3: Add clock and reset
  usb: cdns3: cdns3-plat: Add clk and reset init

 .../devicetree/bindings/usb/cdns,usb3.yaml    | 12 +++++
 drivers/usb/cdns3/cdns3-plat.c                | 52 +++++++++++++++++++
 drivers/usb/cdns3/core.h                      |  3 ++
 3 files changed, 67 insertions(+)


base-commit: 197b6b60ae7bc51dd0814953c562833143b292aa
-- 
2.17.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset
  2023-05-02  8:18 [PATCH v1 0/2] Add clock and reset in cdns3 platform Minda Chen
@ 2023-05-02  8:18 ` Minda Chen
  2023-05-02 20:08   ` Krzysztof Kozlowski
  2023-05-02 20:10   ` Krzysztof Kozlowski
  2023-05-02  8:18 ` [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init Minda Chen
  1 sibling, 2 replies; 9+ messages in thread
From: Minda Chen @ 2023-05-02  8:18 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Roger Quadros, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb, Minda Chen

To support generic clock and reset init in Cadence USBSS
controller. Add clock and reset dts configuration.

Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
---
 Documentation/devicetree/bindings/usb/cdns,usb3.yaml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/cdns,usb3.yaml b/Documentation/devicetree/bindings/usb/cdns,usb3.yaml
index cae46c4982ad..7bffd8fb1e38 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
+
+  clock-names:
+    minItems: 1
+
+  resets:
+    minItems: 1
+
+  reset-names:
+    minItems: 1
+
   dr_mode:
     enum: [host, otg, peripheral]
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init
  2023-05-02  8:18 [PATCH v1 0/2] Add clock and reset in cdns3 platform Minda Chen
  2023-05-02  8:18 ` [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset Minda Chen
@ 2023-05-02  8:18 ` Minda Chen
  2023-05-04 12:45   ` Roger Quadros
  1 sibling, 1 reply; 9+ messages in thread
From: Minda Chen @ 2023-05-02  8:18 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Roger Quadros, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb, Minda Chen

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 | 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 <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,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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset
  2023-05-02  8:18 ` [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset Minda Chen
@ 2023-05-02 20:08   ` Krzysztof Kozlowski
  2023-05-06  1:36     ` Minda Chen
  2023-05-02 20:10   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-02 20:08 UTC (permalink / raw)
  To: Minda Chen, Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Roger Quadros, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb

On 02/05/2023 10:18, Minda Chen wrote:
> To support generic clock and reset init in Cadence USBSS
> controller. Add clock and reset dts configuration.
> 
> Signed-off-by: Minda Chen <minda.chen@starfivetech.com>

Subject prefix: dt-bindings

> ---
>  Documentation/devicetree/bindings/usb/cdns,usb3.yaml | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/cdns,usb3.yaml b/Documentation/devicetree/bindings/usb/cdns,usb3.yaml
> index cae46c4982ad..7bffd8fb1e38 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

no, this must maxItems.

> +
> +  clock-names:
> +    minItems: 1

Drop entire property, not useful without descriptive name.

> +
> +  resets:
> +    minItems: 1

instead maxItems.

> +
> +  reset-names:
> +    minItems: 1

Drop entire property, not useful without descriptive name.

> +
>    dr_mode:
>      enum: [host, otg, peripheral]
>  

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset
  2023-05-02  8:18 ` [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset Minda Chen
  2023-05-02 20:08   ` Krzysztof Kozlowski
@ 2023-05-02 20:10   ` Krzysztof Kozlowski
  2023-05-06  1:34     ` Minda Chen
  1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-02 20:10 UTC (permalink / raw)
  To: Minda Chen, Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Roger Quadros, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb

On 02/05/2023 10:18, Minda Chen wrote:
> To support generic clock and reset init in Cadence USBSS
> controller. Add clock and reset dts configuration.

s/. Add/, add/
(although still weird sentence)

> 
> Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
> ---
>  Documentation/devicetree/bindings/usb/cdns,usb3.yaml | 12 ++++++++++++

Also update the example or any in-tree DTS. Why existing users do not
need it? Aren't you duplicating clocks with wrapping node?

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init
  2023-05-02  8:18 ` [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init Minda Chen
@ 2023-05-04 12:45   ` Roger Quadros
  2023-05-06  1:50     ` Minda Chen
  0 siblings, 1 reply; 9+ messages in thread
From: Roger Quadros @ 2023-05-04 12:45 UTC (permalink / raw)
  To: Minda Chen, Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb

Hi,

On 02/05/2023 11:18, Minda Chen wrote:
> 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 | 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 <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,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;

if (ret)
	goto err_clk_init;

> +
> +	return ret;
> +
> +err_clk_init:
> +	clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks);

if (cdns->num_clks)
	clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks);

This way is more nicer I think.

> +	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);

If you reset the controller here all state will be lost.
How is it expected to work on system resume?

>  	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;

cheers,
-roger

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset
  2023-05-02 20:10   ` Krzysztof Kozlowski
@ 2023-05-06  1:34     ` Minda Chen
  0 siblings, 0 replies; 9+ messages in thread
From: Minda Chen @ 2023-05-06  1:34 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Pawel Laszczak, Greg Kroah-Hartman, Peter Chen, Roger Quadros,
	Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb



On 2023/5/3 4:10, Krzysztof Kozlowski wrote:
> On 02/05/2023 10:18, Minda Chen wrote:
>> To support generic clock and reset init in Cadence USBSS
>> controller. Add clock and reset dts configuration.
> 
> s/. Add/, add/
> (although still weird sentence)
> 
ok
>> 
>> Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
>> ---
>>  Documentation/devicetree/bindings/usb/cdns,usb3.yaml | 12 ++++++++++++
> 
> Also update the example or any in-tree DTS. Why existing users do not
> need it? Aren't you duplicating clocks with wrapping node?
> 
> Best regards,
> Krzysztof
> 
I will update the example. Exiting users are NXP and TI. NXP codes do not contain clock and resets, TI usb2 refclk require to set clock rate,
TI codes can't direct use it. And I don't know TI's hardware. Maybe Roger can take into account to use it.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset
  2023-05-02 20:08   ` Krzysztof Kozlowski
@ 2023-05-06  1:36     ` Minda Chen
  0 siblings, 0 replies; 9+ messages in thread
From: Minda Chen @ 2023-05-06  1:36 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Pawel Laszczak, Greg Kroah-Hartman, Peter Chen, Roger Quadros,
	Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb



On 2023/5/3 4:08, Krzysztof Kozlowski wrote:
> On 02/05/2023 10:18, Minda Chen wrote:
>> To support generic clock and reset init in Cadence USBSS
>> controller. Add clock and reset dts configuration.
>> 
>> Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
> 
> Subject prefix: dt-bindings
> 
ok
>> ---
>>  Documentation/devicetree/bindings/usb/cdns,usb3.yaml | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>> 
>> diff --git a/Documentation/devicetree/bindings/usb/cdns,usb3.yaml b/Documentation/devicetree/bindings/usb/cdns,usb3.yaml
>> index cae46c4982ad..7bffd8fb1e38 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
> 
> no, this must maxItems.
> 
ok
>> +
>> +  clock-names:
>> +    minItems: 1
> 
> Drop entire property, not useful without descriptive name.
> 
So I will delete clock-names and reset-names in my starfive codes.
>> +
>> +  resets:
>> +    minItems: 1
> 
> instead maxItems.
> 
>> +
>> +  reset-names:
>> +    minItems: 1
> 
> Drop entire property, not useful without descriptive name.
> 
>> +
>>    dr_mode:
>>      enum: [host, otg, peripheral]
>>  
> 
> Best regards,
> Krzysztof
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init
  2023-05-04 12:45   ` Roger Quadros
@ 2023-05-06  1:50     ` Minda Chen
  0 siblings, 0 replies; 9+ messages in thread
From: Minda Chen @ 2023-05-06  1:50 UTC (permalink / raw)
  To: Roger Quadros, Rob Herring, Krzysztof Kozlowski, Pawel Laszczak,
	Greg Kroah-Hartman, Peter Chen, Philipp Zabel
  Cc: devicetree, linux-kernel, linux-usb



On 2023/5/4 20:45, Roger Quadros wrote:
> Hi,
> 
> On 02/05/2023 11:18, Minda Chen wrote:
>> 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 | 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 <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,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;
> 
> if (ret)
> 	goto err_clk_init;
> 
>> +
>> +	return ret;
>> +
>> +err_clk_init:
>> +	clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks);
> 
> if (cdns->num_clks)
> 	clk_bulk_disable_unprepare(cdns->num_clks, cdns->clks);
> 
> This way is more nicer I think.
> 
OK, thanks.
>> +	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);
> 
> If you reset the controller here all state will be lost.
> How is it expected to work on system resume?
> 
I will delete them. This is platform codes. 
>>  	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;
> 
> cheers,
> -roger

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-06  1:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-02  8:18 [PATCH v1 0/2] Add clock and reset in cdns3 platform Minda Chen
2023-05-02  8:18 ` [PATCH v1 1/2] dt-binding: cdns,usb3: Add clock and reset Minda Chen
2023-05-02 20:08   ` Krzysztof Kozlowski
2023-05-06  1:36     ` Minda Chen
2023-05-02 20:10   ` Krzysztof Kozlowski
2023-05-06  1:34     ` Minda Chen
2023-05-02  8:18 ` [PATCH v1 2/2] usb: cdns3: cdns3-plat: Add clk and reset init Minda Chen
2023-05-04 12:45   ` Roger Quadros
2023-05-06  1:50     ` Minda Chen

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).