Skip to contentSkip to conversation

dwc3: Changes for HiKey960 support

RFC PATCH Superseded John Stultz 2 participants 10 messages Sep 25, 2019 – Oct 2, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover dwc3: Changes for HiKey960 support

I've been carrying for awhile some patches that Yu Chen was previously pushing upstream to enable USB on the HiKey960 board and I wanted to try to nudge them forward as I'm not sure as to what his plans are.

I've reviewed some of the feedback from his last series, and tried to clean things up a little bit. However, there are still some dt binding bits between the misc switch driver and how it interacts with the rt1711 and dwc3 driver that I'm unsure of.

However, there were some simpler parts of the patch set that I wanted to send out to see if we could make some progress on those parts while I continue to work on the more complex bits.

You can find the full set of changes to get USB working on the board here:
https://git.linaro.org/people/john.stultz/android-dev.git/log/?id=e2f983603b4d89c021929842142ca7c3370422cf

This series is just the more trivial changes, along with some missing binding documentation that I've added.

I'd greatly appreciate any review or feedback on this series!

thanks
-john

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>

John Stultz (2):
dt-bindings: usb: dwc3: Add a property to do a CGTL soft reset on mode
switching
dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

Yu Chen (3):
usb: dwc3: Execute GCTL Core Soft Reset while switch mode for
Hisilicon Kirin Soc
usb: dwc3: Increase timeout for CmdAct cleared by device controller
usb: dwc3: dwc3-of-simple: Add support for dwc3 of Hisilicon Soc
Platform

 .../devicetree/bindings/usb/dwc3.txt          |  2 +
 .../devicetree/bindings/usb/hisi,dwc3.txt     | 52 +++++++++++++++++++
 drivers/usb/dwc3/core.c                       | 20 +++++++
 drivers/usb/dwc3/core.h                       |  3 ++
 drivers/usb/dwc3/dwc3-of-simple.c             |  4 +-
 drivers/usb/dwc3/gadget.c                     |  2 +-
 6 files changed, 81 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/hisi,dwc3.txt
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 dt-bindings: usb: dwc3: Add a property to do a CGTL soft reset on mode switching

Provide a dt-binding for quirk needed to do a GCTL soft reset on mode switching

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>
---
 Documentation/devicetree/bindings/usb/dwc3.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/dwc3.txt +2 -0
index 66780a47ad85..cf4ef6c22fb3 100644
@@ -77,6 +77,8 @@ Optional properties:
 			during HS transmit.
  - snps,dis_metastability_quirk: when set, disable metastability workaround.
 			CAUTION: use only if you are absolutely sure of it.
+ - snps,gctl-reset-quirk: when set, GCTL soft reset will be executed on mode
+			switch.
  - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
 			utmi_l1_suspend_n, false when asserts utmi_sleep_n
  - snps,hird-threshold: HIRD threshold
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/5 usb: dwc3: Execute GCTL Core Soft Reset while switch mode for Hisilicon Kirin Soc

In reply to John Stultz

From: Yu Chen <[email protected]>

A GCTL soft reset should be executed when switch mode for dwc3 core of Hisilicon Kirin Soc.

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>
---
 drivers/usb/dwc3/core.c | 20 ++++++++++++++++++++
 drivers/usb/dwc3/core.h |  3 +++
 2 files changed, 23 insertions(+)
drivers/usb/dwc3/core.c +20 -0
index 999ce5e84d3c..440261432421 100644
@@ -112,6 +112,19 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
 	dwc->current_dr_role = mode;
 }
 
+static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc)
+{
+	u32 reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg |= DWC3_GCTL_CORESOFTRESET;
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg &= ~DWC3_GCTL_CORESOFTRESET;
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
+
 static void __dwc3_set_mode(struct work_struct *work)
 {
 	struct dwc3 *dwc = work_to_dwc(work);
@@ -156,6 +169,10 @@ static void __dwc3_set_mode(struct work_struct *work)
 
 	dwc3_set_prtcap(dwc, dwc->desired_dr_role);
 
+	/* Execute a GCTL Core Soft Reset when switch mode */
+	if (dwc->gctl_reset_quirk)
+		dwc3_gctl_core_soft_reset(dwc);
+
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
 	switch (dwc->desired_dr_role) {
@@ -1316,6 +1333,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	dwc->dis_metastability_quirk = device_property_read_bool(dev,
 				"snps,dis_metastability_quirk");
 
+	dwc->gctl_reset_quirk = device_property_read_bool(dev,
+				"snps,gctl-reset-quirk");
+
 	dwc->lpm_nyet_threshold = lpm_nyet_threshold;
 	dwc->tx_de_emphasis = tx_de_emphasis;
 
drivers/usb/dwc3/core.h +3 -0
index 1c8b349379af..b3cb6eec3f8f 100644
@@ -1029,6 +1029,7 @@ struct dwc3_scratchpad_array {
  * 	2	- No de-emphasis
  * 	3	- Reserved
  * @dis_metastability_quirk: set to disable metastability quirk.
+ * @gctl_reset_quirk: set to do a gctl soft-reset while switch operation mode.
  * @imod_interval: set the interrupt moderation interval in 250ns
  *                 increments or 0 to disable.
  */
@@ -1219,6 +1220,8 @@ struct dwc3 {
 
 	unsigned		dis_metastability_quirk:1;
 
+	unsigned		gctl_reset_quirk:1;
+
 	u16			imod_interval;
 };
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/5 usb: dwc3: Increase timeout for CmdAct cleared by device controller

In reply to John Stultz

From: Yu Chen <[email protected]>

It needs more time for the device controller to clear the CmdAct of DEPCMD on Hisilicon Kirin Soc.

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>
---
 drivers/usb/dwc3/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +1 -1
index 8adb59f8e4f1..81907e163252 100644
@@ -270,7 +270,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
 {
 	const struct usb_endpoint_descriptor *desc = dep->endpoint.desc;
 	struct dwc3		*dwc = dep->dwc;
-	u32			timeout = 1000;
+	u32			timeout = 5000;
 	u32			saved_config = 0;
 	u32			reg;
 
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/5 dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

In reply to John Stultz

Add necessary compatible flag for HiSi's DWC3 so
dwc3-of-simple will probe.

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>
---
 .../devicetree/bindings/usb/hisi,dwc3.txt     | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hisi,dwc3.txt
Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +52 -0
new file mode 100644
index 000000000000..dc31b8a3c006
@@ -0,0 +1,52 @@
+HiSi SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:		should contain "hisilicon,hi3660-dwc3" for HiSi SoC
+- clocks:		A list of phandle + clock-specifier pairs for the
+			clocks listed in clock-names
+- clock-names:		Should contain the following:
+  "clk_usb3phy_ref"	Phy reference clk
+  "aclk_usb3otg"	USB3 OTG aclk
+
+- assigned-clocks:	Should be:
+				HI3660_ACLK_GATE_USB3OTG
+- assigned-clock-rates: Should be:
+				229Mhz (229000000) for HI3660_ACLK_GATE_USB3OTG
+
+Optional properties:
+- resets:		Phandle to reset control that resets core and wrapper.
+
+Required child node:
+A child node must exist to represent the core DWC3 IP block. The name of
+the node is not important. The content of the node is defined in dwc3.txt.
+
+Example device nodes:
+
+	usb3: hisi_dwc3 {
+		compatible = "hisilicon,hi3660-dwc3";
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
+			 <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+		clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
+
+		assigned-clocks = <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+		assigned-clock-rates = <229 000 000>;
+		resets = <&crg_rst 0x90 8>,
+			 <&crg_rst 0x90 7>,
+			 <&crg_rst 0x90 6>,
+			 <&crg_rst 0x90 5>;
+
+		dwc3: dwc3@ff100000 {
+			compatible = "snps,dwc3";
+			reg = <0x0 0xff100000 0x0 0x100000>;
+			interrupts = <0 159 4>, <0 161 4>;
+			phys = <&usb_phy>;
+			phy-names = "usb3-phy";
+			dr_mode = "otg";
+
+			...
+		};
+	};
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 4/5] dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

Quoted 25 lines · John Stultz

Add necessary compatible flag for HiSi's DWC3 so
dwc3-of-simple will probe.

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>
---
 .../devicetree/bindings/usb/hisi,dwc3.txt     | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hisi,dwc3.txt
Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +0 -0
new file mode 100644
index 000000000000..dc31b8a3c006

Documentation/devicetree/bindings/usb/hisi,dwc3.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +8 -0
@@ -0,0 +1,52 @@
+HiSi SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:		should contain "hisilicon,hi3660-dwc3" for HiSi SoC
+- clocks:		A list of phandle + clock-specifier pairs for the
+			clocks listed in clock-names
+- clock-names:		Should contain the following:
+  "clk_usb3phy_ref"	Phy reference clk

It's not good idea to apply phy's clock in dwc3's node

Quoted 44 lines
Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +44 -0
+  "aclk_usb3otg"	USB3 OTG aclk
+
+- assigned-clocks:	Should be:
+				HI3660_ACLK_GATE_USB3OTG
+- assigned-clock-rates: Should be:
+				229Mhz (229000000) for HI3660_ACLK_GATE_USB3OTG
+
+Optional properties:
+- resets:		Phandle to reset control that resets core and wrapper.
+
+Required child node:
+A child node must exist to represent the core DWC3 IP block. The name of
+the node is not important. The content of the node is defined in dwc3.txt.
+
+Example device nodes:
+
+	usb3: hisi_dwc3 {
+		compatible = "hisilicon,hi3660-dwc3";
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
+			 <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+		clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
+
+		assigned-clocks = <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+		assigned-clock-rates = <229 000 000>;
+		resets = <&crg_rst 0x90 8>,
+			 <&crg_rst 0x90 7>,
+			 <&crg_rst 0x90 6>,
+			 <&crg_rst 0x90 5>;
+
+		dwc3: dwc3@ff100000 {
+			compatible = "snps,dwc3";
+			reg = <0x0 0xff100000 0x0 0x100000>;
+			interrupts = <0 159 4>, <0 161 4>;
+			phys = <&usb_phy>;
+			phy-names = "usb3-phy";
+			dr_mode = "otg";
+
+			...
+		};
+	};
#6 lore raw

Re: [PATCH 4/5] dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

Quoted 12 lines · Chunfeng Yun

Documentation/devicetree/bindings/usb/hisi,dwc3.txt line 8

Quoted 10 lines · John Stultz

+++ b/Documentation/devicetree/bindings/usb/hisi,dwc3.txt

Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +8 -0
@@ -0,0 +1,52 @@
+HiSi SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:                should contain "hisilicon,hi3660-dwc3" for HiSi SoC
+- clocks:            A list of phandle + clock-specifier pairs for the
+                     clocks listed in clock-names
+- clock-names:               Should contain the following:
+  "clk_usb3phy_ref"  Phy reference clk

It's not good idea to apply phy's clock in dwc3's node

Hey! Thanks for taking a look at this!

So first, my apologies, I'm not the driver author and I don't have any real specs on the hardware other then what's in the source tree I'm working on. Not the ideal person to be documenting the binding, but I realized we still needed some binding documentation (although a few other dwc-of-simple compat entries are undocumented), so this is my rough stab at it. :/

Given the name clk_usb3phy_ref I'm assuming its a phy reference clock, but I honestly don't know if I'm getting that wrong. It all seems to be leveraging the fact that the dwc-of-simple driver batch enables and disables all the clocks w/o really looking at the names.

Do you have a recommendation for what would be best here? I suspect it's necessary to enable/disable the clk in a similar path(though I'm unfortunately traveling this week so I can't validate that). Do I try to move the clk_usb3phy_ref clock enable/disable handling to somewhere else?

thanks
-john

#7 lore raw

Re: [PATCH 4/5] dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

Quoted 28 lines · John Stultz
Quoted 12 lines · Chunfeng Yun

Documentation/devicetree/bindings/usb/hisi,dwc3.txt line 8

Quoted 10 lines · John Stultz

+++ b/Documentation/devicetree/bindings/usb/hisi,dwc3.txt

Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +8 -0
@@ -0,0 +1,52 @@
+HiSi SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:                should contain "hisilicon,hi3660-dwc3" for HiSi SoC
+- clocks:            A list of phandle + clock-specifier pairs for the
+                     clocks listed in clock-names
+- clock-names:               Should contain the following:
+  "clk_usb3phy_ref"  Phy reference clk

It's not good idea to apply phy's clock in dwc3's node

Hey! Thanks for taking a look at this!

So first, my apologies, I'm not the driver author and I don't have any real specs on the hardware other then what's in the source tree I'm working on. Not the ideal person to be documenting the binding, but I realized we still needed some binding documentation (although a few other dwc-of-simple compat entries are undocumented), so this is my rough stab at it. :/

Given the name clk_usb3phy_ref I'm assuming its a phy reference clock, but I honestly don't know if I'm getting that wrong. It all seems to be leveraging the fact that the dwc-of-simple driver batch enables and disables all the clocks w/o really looking at the names.

Quoted 5 lines

Do you have a recommendation for what would be best here? I suspect it's necessary to enable/disable the clk in a similar path(though I'm unfortunately traveling this week so I can't validate that). Do I try to move the clk_usb3phy_ref clock enable/disable handling to somewhere else?

If it's phy clock, we should enable/disable it in phy driver, maybe we'd better ask for help from Yu Chen

Quoted 3 lines

thanks
-john

#8 lore raw

Re: [PATCH 4/5] dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

Quoted 14 lines · Chunfeng Yun
Quoted 13 lines · John Stultz
Quoted 12 lines · Chunfeng Yun

Documentation/devicetree/bindings/usb/hisi,dwc3.txt line 8

Quoted 10 lines · John Stultz

+++ b/Documentation/devicetree/bindings/usb/hisi,dwc3.txt

Documentation/devicetree/bindings/usb/hisi,dwc3.txt new file +8 -0
@@ -0,0 +1,52 @@
+HiSi SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:                should contain "hisilicon,hi3660-dwc3" for HiSi SoC
+- clocks:            A list of phandle + clock-specifier pairs for the
+                     clocks listed in clock-names
+- clock-names:               Should contain the following:
+  "clk_usb3phy_ref"  Phy reference clk

It's not good idea to apply phy's clock in dwc3's node

...

Quoted 5 lines
Quoted 5 lines

Given the name clk_usb3phy_ref I'm assuming its a phy reference clock, but I honestly don't know if I'm getting that wrong. It all seems to be leveraging the fact that the dwc-of-simple driver batch enables and disables all the clocks w/o really looking at the names.

...

Quoted 2 lines

If it's phy clock, we should enable/disable it in phy driver, maybe we'd better ask for help from Yu Chen

So I've been looking around the existing code and I'm not sure how we got to clk_usb3phy_ref here.

Really it is the HI3660_CLK_ABB_USB, who's name is "clk_abb_usb" and who's parent is "clk_gate_usb_tcxo_en"

So I'm thinking just specifying clk_abb_usb is more accurate here?

Does that sound reasonable?

thanks
-john

#9 lore raw

PATCH 5/5 usb: dwc3: dwc3-of-simple: Add support for dwc3 of Hisilicon Soc Platform

In reply to John Stultz

From: Yu Chen <[email protected]>

This patch adds support for the poweron and shutdown of dwc3 core on Hisilicon Soc Platform.

Cc Greg Kroah-Hartman <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Yu Chen <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc Chunfeng Yun <[email protected]>
---
 drivers/usb/dwc3/dwc3-of-simple.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-of-simple.c +3 -1
index bdac3e7d7b18..78617500edee 100644
@@ -51,7 +51,8 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 	 * Some controllers need to toggle the usb3-otg reset before trying to
 	 * initialize the PHY, otherwise the PHY times out.
 	 */
-	if (of_device_is_compatible(np, "rockchip,rk3399-dwc3"))
+	if (of_device_is_compatible(np, "rockchip,rk3399-dwc3") ||
+	    of_device_is_compatible(np, "hisilicon,hi3660-dwc3"))
 		simple->need_reset = true;
 
 	if (of_device_is_compatible(np, "amlogic,meson-axg-dwc3") ||
@@ -183,6 +184,7 @@ static const struct of_device_id of_dwc3_simple_match[] = {
 	{ .compatible = "amlogic,meson-axg-dwc3" },
 	{ .compatible = "amlogic,meson-gxl-dwc3" },
 	{ .compatible = "allwinner,sun50i-h6-dwc3" },
+	{ .compatible = "hisilicon,hi3660-dwc3" },
 	{ /* Sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
Signature · 1 line
2.17.1