Skip to contentSkip to conversation

Reset xHCI port PHY on disconnect

PATCH In review Srinath Mannam 2 participants 10 messages Jul 31, 2019 – Sep 3, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover Reset xHCI port PHY on disconnect

This patch set adds a quirk in xHCI driver to reset PHY of xHCI port on its disconnect event.

This patch set is based on Linux-5.2-rc4.

Changes from v1:
- Addressed Mathias's comments
- Modified mapping of HC ports and their corresponding PHYs
- Addressed Rob's comments
- Removed usb-phy-port-reset DT property.
- Added quirk in platform data using HCI compatible string.
- Add phy ports in phy attr structure to have enabled ports bitmask.
- Modified #phy-cells of sr-phy to pass phy ports bitmask.

Srinath Mannam (4):
phy: Add phy ports in attrs
dt-bindings: phy: Modify Stingray USB PHY #phy-cells
phy: sr-usb: Set phy ports
dt-bindings: usb-xhci: Add platform specific compatible for Stingray
xHCI
drivers: xhci: Add quirk to reset xHCI port PHY

 .../devicetree/bindings/phy/brcm,stingray-usb-phy.txt | 14 ++++++++------
 Documentation/devicetree/bindings/usb/usb-xhci.txt    |  1 +
 drivers/phy/broadcom/phy-bcm-sr-usb.c                 |  9 ++++++++-
 drivers/usb/core/hcd.c                                |  6 ++++++
 drivers/usb/core/phy.c                                | 19 +++++++++++++++++++
 drivers/usb/core/phy.h                                |  1 +
 drivers/usb/host/xhci-plat.c                          | 10 ++++++++++
 drivers/usb/host/xhci-plat.h                          |  1 +
 drivers/usb/host/xhci-ring.c                          |  9 ++++++---
 drivers/usb/host/xhci.h                               |  1 +
 include/linux/phy/phy.h                               | 10 ++++++++++
 include/linux/usb/hcd.h                               |  1 +
 12 files changed, 72 insertions(+), 10 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/5 phy: Add phy ports in attrs

Add phy ports bitmask to contain enabled PHY ports. set and get APIs added to set and get phy ports value.

---
 include/linux/phy/phy.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/phy/phy.h +10 -0
index 15032f14..b8bca1d 100644
@@ -109,10 +109,12 @@ struct phy_ops {
 /**
  * struct phy_attrs - represents phy attributes
  * @bus_width: Data path width implemented by PHY
+ * @phy_ports: Bitmask of enabled ports
  * @mode: PHY mode
  */
 struct phy_attrs {
 	u32			bus_width;
+	u32			phy_ports;
 	enum phy_mode		mode;
 };
 
@@ -225,6 +227,14 @@ static inline void phy_set_bus_width(struct phy *phy, int bus_width)
 {
 	phy->attrs.bus_width = bus_width;
 }
+static inline int phy_get_phy_ports(struct phy *phy)
+{
+	return phy->attrs.phy_ports;
+}
+static inline void phy_set_phy_ports(struct phy *phy, int phy_ports)
+{
+	phy->attrs.phy_ports |= phy_ports;
+}
 struct phy *phy_get(struct device *dev, const char *string);
 struct phy *phy_optional_get(struct device *dev, const char *string);
 struct phy *devm_phy_get(struct device *dev, const char *string);
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/5 dt-bindings: phy: Modify Stingray USB PHY #phy-cells

In reply to Srinath Mannam

Increase #phy-cells from 1 to 2 to have bitmask of PHY enabled ports.

---
 .../devicetree/bindings/phy/brcm,stingray-usb-phy.txt      | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt +8 -6
index 4ba2989..aeb0568 100644
@@ -6,9 +6,11 @@ Required properties:
 	- "brcm,sr-usb-hs-phy" is a single HS PHY.
  - reg: offset and length of the PHY blocks registers
  - #phy-cells:
-   - Must be 1 for brcm,sr-usb-combo-phy as it expects one argument to indicate
-     the PHY number of two PHYs. 0 for HS PHY and 1 for SS PHY.
-   - Must be 0 for brcm,sr-usb-hs-phy.
+   - Must be 2 for brcm,sr-usb-combo-phy.
+     - Cell 1 - PHY Number, 0 for HS PHY and 1 for SS PHY.
+     - Cell 2 - Bitmask of enabled ports connected to USB Host controller.
+   - Must be 1 for brcm,sr-usb-hs-phy to indicate Bit mask of ports connected
+     to USB Host controller.
 
 Refer to phy/phy-bindings.txt for the generic PHY binding properties
 
@@ -16,17 +18,17 @@ Example:
 	usbphy0: usb-phy@0 {
 		compatible = "brcm,sr-usb-combo-phy";
 		reg = <0x00000000 0x100>;
-		#phy-cells = <1>;
+		#phy-cells = <2>;
 	};
 
 	usbphy1: usb-phy@10000 {
 		compatible = "brcm,sr-usb-combo-phy";
 		reg = <0x00010000 0x100>,
-		#phy-cells = <1>;
+		#phy-cells = <2>;
 	};
 
 	usbphy2: usb-phy@20000 {
 		compatible = "brcm,sr-usb-hs-phy";
 		reg = <0x00020000 0x100>,
-		#phy-cells = <0>;
+		#phy-cells = <1>;
 	};
Signature · 1 line
2.7.4
#5 lore raw

PATCH v2 3/5 phy: sr-usb: Set phy ports

In reply to Srinath Mannam

set phy ports value in xlate handler which is taken from second argument of PHY phandle.

---
 drivers/phy/broadcom/phy-bcm-sr-usb.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/phy/broadcom/phy-bcm-sr-usb.c +8 -1
index fe6c589..5274e45 100644
@@ -278,9 +278,16 @@ static struct phy *bcm_usb_phy_xlate(struct device *dev,
 		if (WARN_ON(phy_idx > 1))
 			return ERR_PTR(-ENODEV);
 
+		if (args->args[1])
+			phy_set_phy_ports(phy_cfg[phy_idx].phy, args->args[1]);
+
 		return phy_cfg[phy_idx].phy;
-	} else
+	} else {
+		if (args->args[0])
+			phy_set_phy_ports(phy_cfg->phy, args->args[0]);
+
 		return phy_cfg->phy;
+	}
 }
 
 static int bcm_usb_phy_create(struct device *dev, struct device_node *node,
Signature · 1 line
2.7.4
#6 lore raw

PATCH v2 4/5 dt-bindings: usb-xhci: Add platform specific compatible for Stingray xHCI

In reply to Srinath Mannam

Add Platform specific compatible, because xHCI of this SoC has an issue with HS port which has to reset on disconnect event.

---
 Documentation/devicetree/bindings/usb/usb-xhci.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/usb/usb-xhci.txt +1 -0
index 97400e8..ee1f051 100644
@@ -22,6 +22,7 @@ Required properties:
       device
     - "renesas,rcar-gen3-xhci" for a generic R-Car Gen3 or RZ/G2 compatible
       device
+    - "brcm,sr-xhci" for Stingray SoC
     - "xhci-platform" (deprecated)
 
     When compatible with the generic version, nodes must list the
Signature · 1 line
2.7.4
#8 lore raw

PATCH v2 5/5 drivers: xhci: Add quirk to reset xHCI port PHY

In reply to Srinath Mannam

Stingray USB HS PHY has an issue, that USB High Speed device detects at Full Speed if the same port was connected to Full speed device. This problem can be resolved by resetting that port's PHY on disconnect. Add a quirk to reset xHCI port PHY on port disconnect event. XHCI_RESET_PHY_ON_DISCONNECT quirk is introduced with xhci_plat_brcm_sr platform data. New quirks parameter added in xhci_plat_priv structure to assign platform specific quirks.

---
 drivers/usb/core/hcd.c       |  6 ++++++
 drivers/usb/core/phy.c       | 19 +++++++++++++++++++
 drivers/usb/core/phy.h       |  1 +
 drivers/usb/host/xhci-plat.c | 10 ++++++++++
 drivers/usb/host/xhci-plat.h |  1 +
 drivers/usb/host/xhci-ring.c |  9 ++++++---
 drivers/usb/host/xhci.h      |  1 +
 include/linux/usb/hcd.h      |  1 +
 8 files changed, 45 insertions(+), 3 deletions(-)
drivers/usb/core/hcd.c +6 -0
index 94d2255..a23441b 100644
@@ -2675,6 +2675,12 @@ int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1)
 	return hcd->driver->find_raw_port_number(hcd, port1);
 }
 
+int usb_hcd_phy_port_reset(struct usb_hcd *hcd, int port)
+{
+	return usb_phy_roothub_port_reset(hcd->phy_roothub, port);
+}
+EXPORT_SYMBOL_GPL(usb_hcd_phy_port_reset);
+
 static int usb_hcd_request_irqs(struct usb_hcd *hcd,
 		unsigned int irqnum, unsigned long irqflags)
 {
drivers/usb/core/phy.c +19 -0
index 7580493..4d1ac31 100644
@@ -190,6 +190,25 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub)
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
 
+int usb_phy_roothub_port_reset(struct usb_phy_roothub *phy_roothub, int port)
+{
+	struct usb_phy_roothub *roothub_entry;
+	struct list_head *head;
+
+	if (!phy_roothub)
+		return -EINVAL;
+
+	head = &phy_roothub->list;
+
+	list_for_each_entry(roothub_entry, head, list) {
+		if (phy_get_phy_ports(roothub_entry->phy) & BIT(port))
+			return phy_reset(roothub_entry->phy);
+	}
+
+	return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(usb_phy_roothub_port_reset);
+
 int usb_phy_roothub_suspend(struct device *controller_dev,
 			    struct usb_phy_roothub *phy_roothub)
 {
drivers/usb/core/phy.h +1 -0
index dad564e..3f682e8 100644
@@ -20,6 +20,7 @@ int usb_phy_roothub_set_mode(struct usb_phy_roothub *phy_roothub,
 			     enum phy_mode mode);
 int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub);
 void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub);
+int usb_phy_roothub_port_reset(struct usb_phy_roothub *phy_roothub, int port);
 
 int usb_phy_roothub_suspend(struct device *controller_dev,
 			    struct usb_phy_roothub *phy_roothub);
drivers/usb/host/xhci-plat.c +10 -0
index 998241f..af23e92 100644
@@ -47,6 +47,9 @@ static void xhci_priv_plat_start(struct usb_hcd *hcd)
 static int xhci_priv_init_quirk(struct usb_hcd *hcd)
 {
 	struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
+	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
+
+	xhci->quirks |= priv->quirks;
 
 	if (!priv->init_quirk)
 		return 0;
@@ -116,6 +119,10 @@ static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = {
 	.resume_quirk = xhci_rcar_resume_quirk,
 };
 
+static const struct xhci_plat_priv xhci_plat_brcm_sr = {
+	.quirks = XHCI_RESET_PHY_ON_DISCONNECT,
+};
+
 static const struct of_device_id usb_xhci_of_match[] = {
 	{
 		.compatible = "generic-xhci",
@@ -151,6 +158,9 @@ static const struct of_device_id usb_xhci_of_match[] = {
 	}, {
 		.compatible = "renesas,rcar-gen3-xhci",
 		.data = &xhci_plat_renesas_rcar_gen3,
+	}, {
+		.compatible = "brcm,sr-xhci",
+		.data = &xhci_plat_brcm_sr,
 	},
 	{},
 };
drivers/usb/host/xhci-plat.h +1 -0
index ae29f22..0cd61c6 100644
@@ -15,6 +15,7 @@ struct xhci_plat_priv {
 	void (*plat_start)(struct usb_hcd *);
 	int (*init_quirk)(struct usb_hcd *);
 	int (*resume_quirk)(struct usb_hcd *);
+	unsigned long long	quirks;
 };
 
 #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
drivers/usb/host/xhci-ring.c +6 -3
index feffceb..77e94e8 100644
@@ -1696,9 +1696,12 @@ static void handle_port_status(struct xhci_hcd *xhci,
 
 	if (hcd->speed < HCD_USB3) {
 		xhci_test_and_clear_bit(xhci, port, PORT_PLC);
-		if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) &&
-		    (portsc & PORT_CSC) && !(portsc & PORT_CONNECT))
-			xhci_cavium_reset_phy_quirk(xhci);
+		if ((portsc & PORT_CSC) && !(portsc & PORT_CONNECT)) {
+			if (xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT)
+				xhci_cavium_reset_phy_quirk(xhci);
+			else if (xhci->quirks & XHCI_RESET_PHY_ON_DISCONNECT)
+				usb_hcd_phy_port_reset(hcd, port_id - 1);
+		}
 	}
 
 cleanup:
drivers/usb/host/xhci.h +1 -0
index 7f8b950..f3b336b 100644
@@ -1856,6 +1856,7 @@ struct xhci_hcd {
 #define XHCI_DEFAULT_PM_RUNTIME_ALLOW	BIT_ULL(33)
 #define XHCI_RESET_PLL_ON_DISCONNECT	BIT_ULL(34)
 #define XHCI_SNPS_BROKEN_SUSPEND    BIT_ULL(35)
+#define XHCI_RESET_PHY_ON_DISCONNECT	BIT_ULL(36)
 
 	unsigned int		num_active_eps;
 	unsigned int		limit_active_eps;
include/linux/usb/hcd.h +1 -0
index bb57b5a..2590666 100644
@@ -461,6 +461,7 @@ extern int usb_add_hcd(struct usb_hcd *hcd,
 		unsigned int irqnum, unsigned long irqflags);
 extern void usb_remove_hcd(struct usb_hcd *hcd);
 extern int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1);
+extern int usb_hcd_phy_port_reset(struct usb_hcd *hcd, int port);
 
 struct platform_device;
 extern void usb_hcd_platform_shutdown(struct platform_device *dev);
Signature · 1 line
2.7.4
maintainer
#3 lore raw

Re: [PATCH v2 2/5] dt-bindings: phy: Modify Stingray USB PHY #phy-cells

In reply to Srinath Mannam
Quoted 1 line · Srinath Mannam

Increase #phy-cells from 1 to 2 to have bitmask of PHY enabled ports.

And from 0 to 1...

Are you going to update all the dts files so when we convert this to schema we don't get a bunch of warnings? (Feel free to convert this to schema too).

Quoted 49 lines
---
 .../devicetree/bindings/phy/brcm,stingray-usb-phy.txt      | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt +8 -6
index 4ba2989..aeb0568 100644
@@ -6,9 +6,11 @@ Required properties:
 	- "brcm,sr-usb-hs-phy" is a single HS PHY.
  - reg: offset and length of the PHY blocks registers
  - #phy-cells:
-   - Must be 1 for brcm,sr-usb-combo-phy as it expects one argument to indicate
-     the PHY number of two PHYs. 0 for HS PHY and 1 for SS PHY.
-   - Must be 0 for brcm,sr-usb-hs-phy.
+   - Must be 2 for brcm,sr-usb-combo-phy.
+     - Cell 1 - PHY Number, 0 for HS PHY and 1 for SS PHY.
+     - Cell 2 - Bitmask of enabled ports connected to USB Host controller.
+   - Must be 1 for brcm,sr-usb-hs-phy to indicate Bit mask of ports connected
+     to USB Host controller.
 
 Refer to phy/phy-bindings.txt for the generic PHY binding properties
 
@@ -16,17 +18,17 @@ Example:
 	usbphy0: usb-phy@0 {
 		compatible = "brcm,sr-usb-combo-phy";
 		reg = <0x00000000 0x100>;
-		#phy-cells = <1>;
+		#phy-cells = <2>;
 	};
 
 	usbphy1: usb-phy@10000 {
 		compatible = "brcm,sr-usb-combo-phy";
 		reg = <0x00010000 0x100>,
-		#phy-cells = <1>;
+		#phy-cells = <2>;
 	};
 
 	usbphy2: usb-phy@20000 {
 		compatible = "brcm,sr-usb-hs-phy";
 		reg = <0x00020000 0x100>,
-		#phy-cells = <0>;
+		#phy-cells = <1>;
 	};
Signature · 1 line
2.7.4
maintainer Reviewed-by on v2 4/5
#7 lore raw

Re: [PATCH v2 4/5] dt-bindings: usb-xhci: Add platform specific compatible for Stingray xHCI

In reply to Srinath Mannam
Quoted 8 lines · Srinath Mannam

Add Platform specific compatible, because xHCI of this SoC has an issue with HS port which has to reset on disconnect event.

---
 Documentation/devicetree/bindings/usb/usb-xhci.txt | 1 +
 1 file changed, 1 insertion(+)
#4 lore raw

Re: [PATCH v2 2/5] dt-bindings: phy: Modify Stingray USB PHY #phy-cells

In reply to Rob Herring

Hi Rob,

Thanks for the review.
I will modify commit message and send new patch set.
We have a plan to upstream DTS files. We will send DTS changes in different patch set once this is done.

Regards,
Srinath.

Quoted 59 lines · Rob Herring
Quoted 1 line · Srinath Mannam

Increase #phy-cells from 1 to 2 to have bitmask of PHY enabled ports.

And from 0 to 1...

Are you going to update all the dts files so when we convert this to schema we don't get a bunch of warnings? (Feel free to convert this to schema too).

Quoted 49 lines
---
 .../devicetree/bindings/phy/brcm,stingray-usb-phy.txt      | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt +8 -7
index 4ba2989..aeb0568 100644
@@ -6,9 +6,11 @@ Required properties:
      - "brcm,sr-usb-hs-phy" is a single HS PHY.
  - reg: offset and length of the PHY blocks registers
  - #phy-cells:
-   - Must be 1 for brcm,sr-usb-combo-phy as it expects one argument to indicate
-     the PHY number of two PHYs. 0 for HS PHY and 1 for SS PHY.
-   - Must be 0 for brcm,sr-usb-hs-phy.
+   - Must be 2 for brcm,sr-usb-combo-phy.
+     - Cell 1 - PHY Number, 0 for HS PHY and 1 for SS PHY.
+     - Cell 2 - Bitmask of enabled ports connected to USB Host controller.
+   - Must be 1 for brcm,sr-usb-hs-phy to indicate Bit mask of ports connected
+     to USB Host controller.
 
 Refer to phy/phy-bindings.txt for the generic PHY binding properties
 
@@ -16,17 +18,17 @@ Example:
      usbphy0: usb-phy@0 {
              compatible = "brcm,sr-usb-combo-phy";
              reg = <0x00000000 0x100>;
-             #phy-cells = <1>;
+             #phy-cells = <2>;
      };
 
      usbphy1: usb-phy@10000 {
              compatible = "brcm,sr-usb-combo-phy";
              reg = <0x00010000 0x100>,
-             #phy-cells = <1>;
+             #phy-cells = <2>;
      };
 
      usbphy2: usb-phy@20000 {
              compatible = "brcm,sr-usb-hs-phy";
              reg = <0x00020000 0x100>,
-             #phy-cells = <0>;
+             #phy-cells = <1>;
      };
--

2.7.4

#9 lore raw
In reply to Srinath Mannam

Hi Mathias,

Could you please help to review this patch series?

Regards,
Srinath.

Quoted 40 lines · Srinath Mannam

This patch set adds a quirk in xHCI driver to reset PHY of xHCI port on its disconnect event.

This patch set is based on Linux-5.2-rc4.

Changes from v1:
- Addressed Mathias's comments
- Modified mapping of HC ports and their corresponding PHYs
- Addressed Rob's comments
- Removed usb-phy-port-reset DT property.
- Added quirk in platform data using HCI compatible string.
- Add phy ports in phy attr structure to have enabled ports bitmask.
- Modified #phy-cells of sr-phy to pass phy ports bitmask.

Srinath Mannam (4):
phy: Add phy ports in attrs
dt-bindings: phy: Modify Stingray USB PHY #phy-cells
phy: sr-usb: Set phy ports
dt-bindings: usb-xhci: Add platform specific compatible for Stingray
xHCI
drivers: xhci: Add quirk to reset xHCI port PHY

 .../devicetree/bindings/phy/brcm,stingray-usb-phy.txt | 14 ++++++++------
 Documentation/devicetree/bindings/usb/usb-xhci.txt    |  1 +
 drivers/phy/broadcom/phy-bcm-sr-usb.c                 |  9 ++++++++-
 drivers/usb/core/hcd.c                                |  6 ++++++
 drivers/usb/core/phy.c                                | 19 +++++++++++++++++++
 drivers/usb/core/phy.h                                |  1 +
 drivers/usb/host/xhci-plat.c                          | 10 ++++++++++
 drivers/usb/host/xhci-plat.h                          |  1 +
 drivers/usb/host/xhci-ring.c                          |  9 ++++++---
 drivers/usb/host/xhci.h                               |  1 +
 include/linux/phy/phy.h                               | 10 ++++++++++
 include/linux/usb/hcd.h                               |  1 +
 12 files changed, 72 insertions(+), 10 deletions(-)

--
2.7.4