linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks
@ 2021-01-25  9:38 Sascha Hauer
  2021-01-25  9:38 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sascha Hauer @ 2021-01-25  9:38 UTC (permalink / raw)
  To: linux-usb; +Cc: Minas Harutyunyan, devicetree, kernel, Sascha Hauer

Currently the dwc2 driver only supports a single clock. I have a board
here which has a dwc2 controller with a somewhat special clock routing
to the phy. Both the dwc2 controller and the ULPI phy get their phy
clock from a SI5351 clock generator. This clock generator has multiple
clock outputs which each is modelled as a separate clk in Linux.
Unfortunately the clock to the phy and the clock to the dwc2 core are on
two different output pins of the SI5351, so we have two clocks which
must be enabled.  The phy is driven by the usb-nop-xceiver driver which
supports a single clock. My first approach was to add support for a
second clock to that driver, but technically the other clock is
connected to the dwc2 core, so instead I added support for a second
clock to the dwc2 driver.  This can easily be archieved with the clk
bulk API as done in this series.

Changes since v1:
- Add minItems to dec2 clock/clock-names property to avoid
  dt_binding_check warning

Sascha Hauer (2):
  dt-bindings: usb: dwc2: Add support for additional clock
  usb: dwc2: use clk bulk API for supporting additional clocks

 .../devicetree/bindings/usb/dwc2.yaml          |  5 ++++-
 drivers/usb/dwc2/core.h                        |  2 ++
 drivers/usb/dwc2/platform.c                    | 18 ++++++++----------
 3 files changed, 14 insertions(+), 11 deletions(-)

-- 
2.20.1


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

* [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock
  2021-01-25  9:38 [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Sascha Hauer
@ 2021-01-25  9:38 ` Sascha Hauer
  2021-02-09 16:46   ` Rob Herring
  2021-01-25  9:38 ` [PATCH 2/2] usb: dwc2: use clk bulk API for supporting additional clocks Sascha Hauer
  2021-02-09 16:54 ` [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Rob Herring
  2 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2021-01-25  9:38 UTC (permalink / raw)
  To: linux-usb; +Cc: Minas Harutyunyan, devicetree, kernel, Sascha Hauer

This adds support for an additional clock for the dwc2 core in case
there is another clock to the phy which must be enabled.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/devicetree/bindings/usb/dwc2.yaml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.yaml b/Documentation/devicetree/bindings/usb/dwc2.yaml
index e5ee51b7b470..56dd0d18d535 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.yaml
+++ b/Documentation/devicetree/bindings/usb/dwc2.yaml
@@ -57,11 +57,14 @@ properties:
     maxItems: 1
 
   clocks:
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
 
   clock-names:
     items:
       - const: otg
+      - const: phy
+    minItems: 1
 
   resets:
     items:
-- 
2.20.1


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

* [PATCH 2/2] usb: dwc2: use clk bulk API for supporting additional clocks
  2021-01-25  9:38 [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Sascha Hauer
  2021-01-25  9:38 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
@ 2021-01-25  9:38 ` Sascha Hauer
  2021-02-09 16:54 ` [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Rob Herring
  2 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2021-01-25  9:38 UTC (permalink / raw)
  To: linux-usb; +Cc: Minas Harutyunyan, devicetree, kernel, Sascha Hauer

This switches to the clk bulk API for the dwc2 driver. With this
additional clocks can be supported.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/dwc2/core.h     |  2 ++
 drivers/usb/dwc2/platform.c | 18 ++++++++----------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 7161344c6522..4c9e2c75f3dd 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1075,6 +1075,8 @@ struct dwc2_hsotg {
 	spinlock_t lock;
 	void *priv;
 	int     irq;
+	struct clk_bulk_data *clocks;
+	int num_clocks;
 	struct clk *clk;
 	struct reset_control *reset;
 	struct reset_control *reset_ecc;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 5f18acac7406..d4a1a26103da 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -143,11 +143,9 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
 	if (ret)
 		return ret;
 
-	if (hsotg->clk) {
-		ret = clk_prepare_enable(hsotg->clk);
-		if (ret)
-			return ret;
-	}
+	ret = clk_bulk_prepare_enable(hsotg->num_clocks, hsotg->clocks);
+	if (ret)
+		return ret;
 
 	if (hsotg->uphy) {
 		ret = usb_phy_init(hsotg->uphy);
@@ -195,8 +193,7 @@ static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
 	if (ret)
 		return ret;
 
-	if (hsotg->clk)
-		clk_disable_unprepare(hsotg->clk);
+	clk_bulk_disable_unprepare(hsotg->num_clocks, hsotg->clocks);
 
 	return 0;
 }
@@ -281,11 +278,12 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
 	hsotg->plat = dev_get_platdata(hsotg->dev);
 
 	/* Clock */
-	hsotg->clk = devm_clk_get_optional(hsotg->dev, "otg");
-	if (IS_ERR(hsotg->clk)) {
+	ret = devm_clk_bulk_get_all(hsotg->dev, &hsotg->clocks);
+	if (ret < 0) {
 		dev_err(hsotg->dev, "cannot get otg clock\n");
-		return PTR_ERR(hsotg->clk);
+		return ret;
 	}
+	hsotg->num_clocks = ret;
 
 	/* Regulators */
 	for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
-- 
2.20.1


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

* Re: [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock
  2021-01-25  9:38 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
@ 2021-02-09 16:46   ` Rob Herring
  2021-02-10  8:39     ` Sascha Hauer
  0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2021-02-09 16:46 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: linux-usb, Minas Harutyunyan, devicetree, kernel

On Mon, Jan 25, 2021 at 10:38:24AM +0100, Sascha Hauer wrote:
> This adds support for an additional clock for the dwc2 core in case
> there is another clock to the phy which must be enabled.

to the phy? 'clocks' is inputs to DWC2. Shouldn't there be a phy 
device/driver?

> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  Documentation/devicetree/bindings/usb/dwc2.yaml | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/dwc2.yaml b/Documentation/devicetree/bindings/usb/dwc2.yaml
> index e5ee51b7b470..56dd0d18d535 100644
> --- a/Documentation/devicetree/bindings/usb/dwc2.yaml
> +++ b/Documentation/devicetree/bindings/usb/dwc2.yaml
> @@ -57,11 +57,14 @@ properties:
>      maxItems: 1
>  
>    clocks:
> -    maxItems: 1
> +    minItems: 1
> +    maxItems: 2
>  
>    clock-names:
>      items:
>        - const: otg
> +      - const: phy
> +    minItems: 1
>  
>    resets:
>      items:
> -- 
> 2.20.1
> 

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

* Re: [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks
  2021-01-25  9:38 [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Sascha Hauer
  2021-01-25  9:38 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
  2021-01-25  9:38 ` [PATCH 2/2] usb: dwc2: use clk bulk API for supporting additional clocks Sascha Hauer
@ 2021-02-09 16:54 ` Rob Herring
  2021-02-10  8:42   ` Sascha Hauer
  2 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2021-02-09 16:54 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: linux-usb, Minas Harutyunyan, devicetree, kernel

On Mon, Jan 25, 2021 at 10:38:23AM +0100, Sascha Hauer wrote:
> Currently the dwc2 driver only supports a single clock. I have a board
> here which has a dwc2 controller with a somewhat special clock routing
> to the phy. Both the dwc2 controller and the ULPI phy get their phy
> clock from a SI5351 clock generator. This clock generator has multiple
> clock outputs which each is modelled as a separate clk in Linux.
> Unfortunately the clock to the phy and the clock to the dwc2 core are on
> two different output pins of the SI5351, so we have two clocks which
> must be enabled.  The phy is driven by the usb-nop-xceiver driver which
> supports a single clock. My first approach was to add support for a
> second clock to that driver, but technically the other clock is
> connected to the dwc2 core, so instead I added support for a second
> clock to the dwc2 driver.  This can easily be archieved with the clk
> bulk API as done in this series.

Where is the usb-nop-xceiver single clock coming from? 

Maybe you shouldn't be using usb-nop-xceiver? There is a ULPI binding 
though that alone doesn't really help you.

Rob

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

* Re: [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock
  2021-02-09 16:46   ` Rob Herring
@ 2021-02-10  8:39     ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2021-02-10  8:39 UTC (permalink / raw)
  To: Rob Herring; +Cc: linux-usb, Minas Harutyunyan, devicetree, kernel

On Tue, Feb 09, 2021 at 10:46:59AM -0600, Rob Herring wrote:
> On Mon, Jan 25, 2021 at 10:38:24AM +0100, Sascha Hauer wrote:
> > This adds support for an additional clock for the dwc2 core in case
> > there is another clock to the phy which must be enabled.
> 
> to the phy? 'clocks' is inputs to DWC2. Shouldn't there be a phy 
> device/driver?

Maybe I should have said "from the phy". I have a USB3320 ULPI phy here
connected to the DWC2. The usual setup would look like this:

-----.    clk60M   .------------
DWC2 |<------------| USB3320 Phy
-----'             '------------

I don't think this clock is abstracted anywhere in this case, it's just
there and always enabled.

For reasons unknown to me our customer decided to not let the USB3320
generate the clock, but used an external clock generator instead, so
my setup looks like this:

        | SI5351a |
        '---------'
  clk60M_1 |  | clk60M_2
-----.     |  |    .------------
DWC2 |<----'  '--->| USB3320 Phy
-----'             '------------

The SI5351a is abstracted as a clock driver in Linux. Note that clk60M_1
and clk60M_2 are really two clocks which must both be enabled. clk60M_2
is handled by the phy driver (which is the usb-nop-xceiver in my case),
what I am trying to add here in this patch is support for clk60M_1.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks
  2021-02-09 16:54 ` [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Rob Herring
@ 2021-02-10  8:42   ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2021-02-10  8:42 UTC (permalink / raw)
  To: Rob Herring; +Cc: linux-usb, Minas Harutyunyan, devicetree, kernel

On Tue, Feb 09, 2021 at 10:54:24AM -0600, Rob Herring wrote:
> On Mon, Jan 25, 2021 at 10:38:23AM +0100, Sascha Hauer wrote:
> > Currently the dwc2 driver only supports a single clock. I have a board
> > here which has a dwc2 controller with a somewhat special clock routing
> > to the phy. Both the dwc2 controller and the ULPI phy get their phy
> > clock from a SI5351 clock generator. This clock generator has multiple
> > clock outputs which each is modelled as a separate clk in Linux.
> > Unfortunately the clock to the phy and the clock to the dwc2 core are on
> > two different output pins of the SI5351, so we have two clocks which
> > must be enabled.  The phy is driven by the usb-nop-xceiver driver which
> > supports a single clock. My first approach was to add support for a
> > second clock to that driver, but technically the other clock is
> > connected to the dwc2 core, so instead I added support for a second
> > clock to the dwc2 driver.  This can easily be archieved with the clk
> > bulk API as done in this series.
> 
> Where is the usb-nop-xceiver single clock coming from?

It's coming from the SI5351 clock generator

> 
> Maybe you shouldn't be using usb-nop-xceiver? There is a ULPI binding 
> though that alone doesn't really help you.

The clock that feeds the phy is handled by the usb-nop-xceiver just
fine, it's the clock that is fed to the DWC2 controller that I need
support for. I hope my other mail makes this clearer a bit.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock
  2021-01-11 17:41   ` Rob Herring
@ 2021-01-13  8:43     ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2021-01-13  8:43 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, linux-usb, Minas Harutyunyan

On Mon, Jan 11, 2021 at 11:41:09AM -0600, Rob Herring wrote:
> On Mon, 11 Jan 2021 16:13:36 +0100, Sascha Hauer wrote:
> > This adds support for an additional clock for the dwc2 core in case
> > there is another clock to the phy which must be enabled.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  Documentation/devicetree/bindings/usb/dwc2.yaml | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> 
> My bot found errors running 'make dt_binding_check' on your patch:
> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/amlogic,meson-g12a-usb-ctrl.example.dt.yaml: usb@ff400000: clocks: [[4294967295]] is too short
> 	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.yaml
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/amlogic,meson-g12a-usb-ctrl.example.dt.yaml: usb@ff400000: clock-names: ['otg'] is too short
> 	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.yaml
> /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.example.dt.yaml: usb@101c0000: clocks: [[4294967295]] is too short

Ok, this can be fixed by adding a "minItems" property to clocks and
clock-names. Will do next round.

Anything more to say to this series?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock
  2021-01-11 15:13 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
@ 2021-01-11 17:41   ` Rob Herring
  2021-01-13  8:43     ` Sascha Hauer
  0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2021-01-11 17:41 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: devicetree, linux-usb, Minas Harutyunyan

On Mon, 11 Jan 2021 16:13:36 +0100, Sascha Hauer wrote:
> This adds support for an additional clock for the dwc2 core in case
> there is another clock to the phy which must be enabled.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  Documentation/devicetree/bindings/usb/dwc2.yaml | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/amlogic,meson-g12a-usb-ctrl.example.dt.yaml: usb@ff400000: clocks: [[4294967295]] is too short
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/amlogic,meson-g12a-usb-ctrl.example.dt.yaml: usb@ff400000: clock-names: ['otg'] is too short
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.example.dt.yaml: usb@101c0000: clocks: [[4294967295]] is too short
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.example.dt.yaml: usb@101c0000: clock-names: ['otg'] is too short
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/usb/dwc2.yaml

See https://patchwork.ozlabs.org/patch/1424674

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


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

* [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock
  2021-01-11 15:13 [PATCH " Sascha Hauer
@ 2021-01-11 15:13 ` Sascha Hauer
  2021-01-11 17:41   ` Rob Herring
  0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2021-01-11 15:13 UTC (permalink / raw)
  To: linux-usb; +Cc: Minas Harutyunyan, devicetree, Sascha Hauer

This adds support for an additional clock for the dwc2 core in case
there is another clock to the phy which must be enabled.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/devicetree/bindings/usb/dwc2.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.yaml b/Documentation/devicetree/bindings/usb/dwc2.yaml
index e5ee51b7b470..20d0847c7b01 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.yaml
+++ b/Documentation/devicetree/bindings/usb/dwc2.yaml
@@ -57,11 +57,12 @@ properties:
     maxItems: 1
 
   clocks:
-    maxItems: 1
+    maxItems: 2
 
   clock-names:
     items:
       - const: otg
+      - const: phy
 
   resets:
     items:
-- 
2.20.1


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

end of thread, other threads:[~2021-02-10  8:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25  9:38 [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Sascha Hauer
2021-01-25  9:38 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
2021-02-09 16:46   ` Rob Herring
2021-02-10  8:39     ` Sascha Hauer
2021-01-25  9:38 ` [PATCH 2/2] usb: dwc2: use clk bulk API for supporting additional clocks Sascha Hauer
2021-02-09 16:54 ` [PATCH v2 0/2] usb: dwc2: Use clk bulk API for supporting multiple clocks Rob Herring
2021-02-10  8:42   ` Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2021-01-11 15:13 [PATCH " Sascha Hauer
2021-01-11 15:13 ` [PATCH 1/2] dt-bindings: usb: dwc2: Add support for additional clock Sascha Hauer
2021-01-11 17:41   ` Rob Herring
2021-01-13  8:43     ` Sascha Hauer

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