Skip to contentSkip to conversation

Add XHCI, EHCI and OHCI support for Broadcom STB SoS's

PATCH Superseded Al Cooper 6 participants 22 messages Nov 5, 2018 – Nov 13, 2018

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Al Cooper

author maintainer
#0 lore raw

v3 cover Add XHCI, EHCI and OHCI support for Broadcom STB SoS's

V3 - Based on feedback
- Patch 3/6
In xhci-brcm.h, fixed incorrect function name when CONFIG_USB_XHCI_BRCM is not defined. Found by kbuild test robot.
- Patch 4/6
In ohci-platform.c, use devm_kmemdup() instead of demv_kzalloc().
- Patch 5/6
In ehci-platform.c, use dma_coerce_mask_and_coherent() instead of dma_coerce_mask_and_coherent(). Remove unneeded #ifdef CONFIG_OF.

V2 - Based on feedback, the functionality for XHCI and OHCI was
moved from Broadcom platform drivers into the standard XHCI and OHCI platform drivers. The EHCI functionality still uses a Broadcom EHCI driver because of the workarounds needed for bugs in the EHCI controller.

This adds support for the XHCI, EHCI and OHCI host controllers found in Broadcom STB SoC's. These drivers depend on getting access to the new Broadcom STB USB PHY driver through a device-tree phandle and will fail if the driver is not available.

Al Cooper (6):
dt-bindings: Add Broadcom STB OHCI, EHCI and XHCI binding document
usb: core: Add ability to skip phy exit on suspend and init on resume
usb: xhci: xhci-plat: Add support for Broadcom STB SoC's
usb: ohci-platform: Add support for Broadcom STB SoC's
usb: ehci: Add new EHCI driver for Broadcom STB SoC's
usb: host: Add ability to build new Broadcom STB USB drivers

 .../devicetree/bindings/usb/brcm,bcm7445-ehci.txt  |  22 ++
 .../devicetree/bindings/usb/brcm,bcm7445-ohci.txt  |  22 ++
 .../devicetree/bindings/usb/brcm,bcm7445-xhci.txt  |  23 ++
 MAINTAINERS                                        |   9 +
 drivers/usb/core/hcd.c                             |   8 +-
 drivers/usb/core/phy.c                             |  18 +-
 drivers/usb/core/phy.h                             |   9 +-
 drivers/usb/host/Kconfig                           |  29 +++
 drivers/usb/host/Makefile                          |  18 +-
 drivers/usb/host/ehci-brcm.c                       | 287 +++++++++++++++++++++
 drivers/usb/host/ohci-platform.c                   |  34 ++-
 drivers/usb/host/xhci-brcm.c                       |  17 ++
 drivers/usb/host/xhci-brcm.h                       |  16 ++
 drivers/usb/host/xhci-plat.c                       |   8 +
 include/linux/usb/hcd.h                            |   3 +
 include/linux/usb/ohci_pdriver.h                   |   1 +
 16 files changed, 499 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt
 create mode 100644 drivers/usb/host/ehci-brcm.c
 create mode 100644 drivers/usb/host/xhci-brcm.c
 create mode 100644 drivers/usb/host/xhci-brcm.h
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#1 lore raw

PATCH v3 1/6 dt-bindings: Add Broadcom STB OHCI, EHCI and XHCI binding document

Add DT bindings document for Broadcom STB USB OHCI, EHCI and XHCI drivers.

---
 .../devicetree/bindings/usb/brcm,bcm7445-ehci.txt  | 22 +++++++++++++++++++++
 .../devicetree/bindings/usb/brcm,bcm7445-ohci.txt  | 22 +++++++++++++++++++++
 .../devicetree/bindings/usb/brcm,bcm7445-xhci.txt  | 23 ++++++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt
Documentation/devicetree/bindings/usb/brcm,bcm7445-ehci.txt new file +22 -0
new file mode 100644
index 000000000000..824f4bf5d07c
@@ -0,0 +1,22 @@
+Broadcom STB USB EHCI controller
+
+Required properties:
+- compatible: should be "brcm,bcm7445-ehci"
+- reg: should contain one register range i.e. start and length
+- interrupts: description of the interrupt line
+- phys: phandle + phy specifier pair
+  The specifier should be 0 for the OHCI/EHCI PHY
+
+Optional properties:
+- clocks: A phandle for the EHCI clock
+
+Example:
+
+ehci@f0b00300 {
+	compatible = "brcm,bcm7445-ehci";
+	reg = <0xf0b00300 0xa8>;
+	interrupts = <0x0 0x5a 0x0>;
+	interrupt-names = "usb0_ehci_0";
+	phys = <&usbphy_0 0x0>;
+	clocks = <&usb20>
+};
Documentation/devicetree/bindings/usb/brcm,bcm7445-ohci.txt new file +22 -0
new file mode 100644
index 000000000000..de5a22b3d138
@@ -0,0 +1,22 @@
+Broadcom STB USB OHCI controller
+
+Required properties:
+- compatible: should be "brcm,bcm7445-ohci"
+- reg: should contain one register range i.e. start and length
+- interrupts: description of the interrupt line
+- phys: phandle + phy specifier pair
+  The specifier should be 0 for the OHCI/EHCI PHY
+
+Optional properties:
+- clocks: A phandle for the OHCI clock
+
+Example:
+
+ohci@f0b00400 {
+	compatible = "brcm,bcm7445-ohci";
+	reg = <0xf0b00400 0x58>;
+	interrupts = <0x0 0x5b 0x0>;
+	interrupt-names = "usb0_ohci_0";
+	phys = <&usbphy_0 0x0>;
+	clocks = <&usb20>;
+};
Documentation/devicetree/bindings/usb/brcm,bcm7445-xhci.txt new file +23 -0
new file mode 100644
index 000000000000..c41f3f8d836d
@@ -0,0 +1,23 @@
+Broadcom STB USB XHCI controller
+
+Required properties:
+- compatible: should be "brcm,bcm7445-xhci"
+- reg: should contain one register range i.e. start and length
+- interrupts: description of the interrupt line
+- phys: phandle + phy specifier pair
+  The specifier should be 1 for the XHCI PHY
+
+Optional properties:
+- clocks: A phandle for the XHCI clock
+- usb3-lpm-capable: determines if platform is USB3 LPM capable
+
+Example:
+
+xhci_0_0: xhci@f0b01000 {
+	compatible = "brcm,bcm7445-xhci";
+	reg = <0xf0b01000 0x1000>;
+	interrupts = <0x0 0x5c 0x0>;
+	interrupt-names = "usb0_xhci_0";
+	phys = <&usbphy_0 0x1>;
+	clocks = <&usb30>;
+};
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#2 lore raw

PATCH v3 2/6 usb: core: Add ability to skip phy exit on suspend and init on resume

In reply to Al Cooper

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

This is enabled with the HCD flag "suspend_without_phy_exit" which can be set from any HCD driver.

---
 drivers/usb/core/hcd.c  |  8 ++++----
 drivers/usb/core/phy.c  | 18 ++++++++++++------
 drivers/usb/core/phy.h  |  9 ++++++---
 include/linux/usb/hcd.h |  3 +++
 4 files changed, 25 insertions(+), 13 deletions(-)
drivers/usb/core/hcd.c +4 -4
index 487025d31d44..5ebc82a69403 100644
@@ -2249,7 +2249,7 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
 		hcd->state = HC_STATE_SUSPENDED;
 
 		if (!PMSG_IS_AUTO(msg))
-			usb_phy_roothub_suspend(hcd->self.sysdev,
+			usb_phy_roothub_suspend(hcd,
 						hcd->phy_roothub);
 
 		/* Did we race with a root-hub wakeup event? */
@@ -2290,7 +2290,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
 	}
 
 	if (!PMSG_IS_AUTO(msg)) {
-		status = usb_phy_roothub_resume(hcd->self.sysdev,
+		status = usb_phy_roothub_resume(hcd,
 						hcd->phy_roothub);
 		if (status)
 			return status;
@@ -2333,7 +2333,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
 		}
 	} else {
 		hcd->state = old_state;
-		usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
+		usb_phy_roothub_suspend(hcd, hcd->phy_roothub);
 		dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
 				"resume", status);
 		if (status != -ESHUTDOWN)
@@ -2730,7 +2730,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	struct usb_device *rhdev;
 
 	if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
-		hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
+		hcd->phy_roothub = usb_phy_roothub_alloc(hcd);
 		if (IS_ERR(hcd->phy_roothub))
 			return PTR_ERR(hcd->phy_roothub);
 
drivers/usb/core/phy.c +12 -6
index 38b2c776c4b4..308d716304da 100644
@@ -46,10 +46,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index,
 	return 0;
 }
 
-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
+struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd)
 {
 	struct usb_phy_roothub *phy_roothub;
 	int i, num_phys, err;
+	struct device *dev = hcd->self.sysdev;
 
 	if (!IS_ENABLED(CONFIG_GENERIC_PHY))
 		return NULL;
@@ -162,26 +163,30 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub)
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
 
-int usb_phy_roothub_suspend(struct device *controller_dev,
+int usb_phy_roothub_suspend(struct usb_hcd *hcd,
 			    struct usb_phy_roothub *phy_roothub)
 {
+	struct device *controller_dev = hcd->self.sysdev;
+
 	usb_phy_roothub_power_off(phy_roothub);
 
 	/* keep the PHYs initialized so the device can wake up the system */
-	if (device_may_wakeup(controller_dev))
+	if (device_may_wakeup(controller_dev) || hcd->suspend_without_phy_exit)
 		return 0;
 
 	return usb_phy_roothub_exit(phy_roothub);
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
 
-int usb_phy_roothub_resume(struct device *controller_dev,
+int usb_phy_roothub_resume(struct usb_hcd *hcd,
 			   struct usb_phy_roothub *phy_roothub)
 {
+	struct device *controller_dev = hcd->self.sysdev;
 	int err;
 
 	/* if the device can't wake up the system _exit was called */
-	if (!device_may_wakeup(controller_dev)) {
+	if (!device_may_wakeup(controller_dev) &&
+	    !hcd->suspend_without_phy_exit) {
 		err = usb_phy_roothub_init(phy_roothub);
 		if (err)
 			return err;
@@ -190,7 +195,8 @@ int usb_phy_roothub_resume(struct device *controller_dev,
 	err = usb_phy_roothub_power_on(phy_roothub);
 
 	/* undo _init if _power_on failed */
-	if (err && !device_may_wakeup(controller_dev))
+	if (err && !device_may_wakeup(controller_dev)
+	    && !hcd->suspend_without_phy_exit)
 		usb_phy_roothub_exit(phy_roothub);
 
 	return err;
drivers/usb/core/phy.h +6 -3
index 88a3c037e9df..34293e11a917 100644
@@ -5,13 +5,16 @@
  * Copyright (C) 2018 Martin Blumenstingl <[email protected]>
  */
 
+#include <linux/usb.h>
+#include <linux/usb/hcd.h>
+
 #ifndef __USB_CORE_PHY_H_
 #define __USB_CORE_PHY_H_
 
 struct device;
 struct usb_phy_roothub;
 
-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev);
+struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd);
 
 int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub);
 int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);
@@ -19,9 +22,9 @@
 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_suspend(struct device *controller_dev,
+int usb_phy_roothub_suspend(struct usb_hcd *hcd,
 			    struct usb_phy_roothub *phy_roothub);
-int usb_phy_roothub_resume(struct device *controller_dev,
+int usb_phy_roothub_resume(struct usb_hcd *hcd,
 			   struct usb_phy_roothub *phy_roothub);
 
 #endif /* __USB_CORE_PHY_H_ */
include/linux/usb/hcd.h +3 -0
index 97e2ddec18b1..87a104055b5e 100644
@@ -157,6 +157,9 @@ struct usb_hcd {
 	 */
 	unsigned		skip_phy_initialization:1;
 
+	/* Some phys don't want the phy's exit/init called on suspend/resume */
+	unsigned		suspend_without_phy_exit:1;
+
 	/* The next flag is a stopgap, to be removed when all the HCDs
 	 * support the new root-hub polling mechanism. */
 	unsigned		uses_new_polling:1;
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#3 lore raw

PATCH v3 3/6 usb: xhci: xhci-plat: Add support for Broadcom STB SoC's

In reply to Al Cooper

Add support for Broadcom STB SoC's to the xhci platform driver

---
 drivers/usb/host/xhci-brcm.c | 17 +++++++++++++++++
 drivers/usb/host/xhci-brcm.h | 16 ++++++++++++++++
 drivers/usb/host/xhci-plat.c |  8 ++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 drivers/usb/host/xhci-brcm.c
 create mode 100644 drivers/usb/host/xhci-brcm.h
drivers/usb/host/xhci-brcm.c new file +17 -0
new file mode 100644
index 000000000000..a7220126f6af
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018, Broadcom */
+
+#include <linux/usb.h>
+#include <linux/usb/hcd.h>
+
+#include "xhci.h"
+
+int xhci_plat_brcm_init_quirk(struct usb_hcd *hcd)
+{
+	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
+
+	xhci->quirks |= XHCI_RESET_ON_RESUME;
+	hcd->suspend_without_phy_exit = 1;
+	return 0;
+}
+
drivers/usb/host/xhci-brcm.h new file +16 -0
new file mode 100644
index 000000000000..e64800fae4d5
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018, Broadcom */
+
+#ifndef _XHCI_BRCM_H
+#define _XHCI_BRCM_H
+
+#if IS_ENABLED(CONFIG_USB_XHCI_BRCM)
+int xhci_plat_brcm_init_quirk(struct usb_hcd *hcd);
+#else
+static inline int xhci_plat_brcm_init_quirk(struct usb_hcd *hcd)
+{
+	return 0;
+}
+#endif
+#endif /* _XHCI_BRCM_H */
+
drivers/usb/host/xhci-plat.c +8 -0
index 32b5574ad5c5..5372d4040be6 100644
@@ -24,6 +24,7 @@
 #include "xhci-plat.h"
 #include "xhci-mvebu.h"
 #include "xhci-rcar.h"
+#include "xhci-brcm.h"
 
 static struct hc_driver __read_mostly xhci_plat_hc_driver;
 
@@ -112,6 +113,10 @@ static int xhci_plat_start(struct usb_hcd *hcd)
 	.resume_quirk = xhci_rcar_resume_quirk,
 };
 
+static const struct xhci_plat_priv xhci_plat_brcm = {
+	.init_quirk = xhci_plat_brcm_init_quirk
+};
+
 static const struct of_device_id usb_xhci_of_match[] = {
 	{
 		.compatible = "generic-xhci",
@@ -144,6 +149,9 @@ static int xhci_plat_start(struct usb_hcd *hcd)
 	}, {
 		.compatible = "renesas,rcar-gen3-xhci",
 		.data = &xhci_plat_renesas_rcar_gen3,
+	}, {
+		.compatible = "brcm,bcm7445-xhci",
+		.data = &xhci_plat_brcm,
 	},
 	{},
 };
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#4 lore raw

PATCH v3 4/6 usb: ohci-platform: Add support for Broadcom STB SoC's

In reply to Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---
 drivers/usb/host/ohci-platform.c | 34 ++++++++++++++++++++++++++++------
 include/linux/usb/ohci_pdriver.h |  1 +
 2 files changed, 29 insertions(+), 6 deletions(-)
drivers/usb/host/ohci-platform.c +28 -6
index 65a1c3fdc88c..f425168238e6 100644
@@ -22,6 +22,7 @@
 #include <linux/module.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
@@ -99,12 +100,23 @@ static int ohci_platform_probe(struct platform_device *dev)
 	if (usb_disabled())
 		return -ENODEV;
 
-	/*
-	 * Use reasonable defaults so platforms don't have to provide these
-	 * with DT probing on ARM.
-	 */
-	if (!pdata)
-		pdata = &ohci_platform_defaults;
+	if (!pdata) {
+		const struct usb_ohci_pdata *match_pdata;
+
+		match_pdata = of_device_get_match_data(&dev->dev);
+		if (match_pdata) {
+			pdata = devm_kmemdup(&dev->dev, match_pdata,
+					     sizeof(*pdata), GFP_KERNEL);
+			if (!pdata)
+				return -ENOMEM;
+		} else {
+			/*
+			 * Use reasonable defaults so platforms don't have
+			 * to provide these with DT probing on ARM.
+			 */
+			pdata = &ohci_platform_defaults;
+		}
+	}
 
 	err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
 	if (err)
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct platform_device *dev)
 		ohci->flags |= OHCI_QUIRK_FRAME_NO;
 	if (pdata->num_ports)
 		ohci->num_ports = pdata->num_ports;
+	if (pdata->suspend_without_phy_exit)
+		hcd->suspend_without_phy_exit = 1;
 
 #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
 	if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
@@ -305,10 +319,18 @@ static int ohci_platform_resume(struct device *dev)
 }
 #endif /* CONFIG_PM_SLEEP */
 
+static const struct usb_ohci_pdata ohci_plat_brcm_bcm7445_ohci = {
+	.power_on =		ohci_platform_power_on,
+	.power_suspend =	ohci_platform_power_off,
+	.power_off =		ohci_platform_power_off,
+	.suspend_without_phy_exit = 1,
+};
+
 static const struct of_device_id ohci_platform_ids[] = {
 	{ .compatible = "generic-ohci", },
 	{ .compatible = "cavium,octeon-6335-ohci", },
 	{ .compatible = "ti,ohci-omap3", },
+	{ .compatible = "brcm,bcm7445-ohci", &ohci_plat_brcm_bcm7445_ohci},
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ohci_platform_ids);
include/linux/usb/ohci_pdriver.h +1 -0
index 7eb16cf587ee..16b24ea1e3bb 100644
@@ -35,6 +35,7 @@ struct usb_ohci_pdata {
 	unsigned	big_endian_desc:1;
 	unsigned	big_endian_mmio:1;
 	unsigned	no_big_frame_no:1;
+	unsigned	suspend_without_phy_exit:1;
 	unsigned int	num_ports;
 
 	/* Turn on all power and clocks */
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#16 lore raw

PATCH v3 5/6 usb: ehci: Add new EHCI driver for Broadcom STB SoC's

In reply to Al Cooper

Add a new EHCI driver for Broadcom STB SoC's. A new EHCI driver was created instead of adding support to the existing ehci platform driver because of the code required to workaround bugs in the EHCI controller.

---
 drivers/usb/host/ehci-brcm.c | 287 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 287 insertions(+)
 create mode 100644 drivers/usb/host/ehci-brcm.c
drivers/usb/host/ehci-brcm.c new file +287 -0
new file mode 100644
index 000000000000..f36ce240538b
@@ -0,0 +1,287 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018, Broadcom */
+
+#include <linux/acpi.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/usb.h>
+#include <linux/usb/hcd.h>
+
+#include "ehci.h"
+
+#define BRCM_DRIVER_DESC "EHCI Broadcom STB driver"
+
+#define hcd_to_ehci_priv(h) ((struct brcm_priv *)hcd_to_ehci(h)->priv)
+
+struct brcm_priv {
+	struct clk *clk;
+};
+
+static const char brcm_hcd_name[] = "ehci-brcm";
+
+static int (*org_hub_control)(struct usb_hcd *hcd,
+			u16 typeReq, u16 wValue, u16 wIndex,
+			char *buf, u16 wLength);
+
+/* ehci_brcm_wait_for_sof
+ * Wait for start of next microframe, then wait extra delay microseconds
+ */
+static inline void ehci_brcm_wait_for_sof(struct ehci_hcd *ehci, u32 delay)
+{
+	int frame_idx = ehci_readl(ehci, &ehci->regs->frame_index);
+
+	while (frame_idx == ehci_readl(ehci, &ehci->regs->frame_index))
+		;
+	udelay(delay);
+}
+
+/*
+ * ehci_brcm_hub_control
+ * Intercept echi-hcd request to complete RESUME and align it to the start
+ * of the next microframe.
+ * If RESUME is complete too late in the microframe, host controller
+ * detects babble on suspended port and resets the port afterwards.
+ * This s/w workaround allows to avoid this problem.
+ * See SWLINUX-1909 for more details
+ */
+static int ehci_brcm_hub_control(
+	struct usb_hcd	*hcd,
+	u16		typeReq,
+	u16		wValue,
+	u16		wIndex,
+	char		*buf,
+	u16		wLength)
+{
+	struct ehci_hcd	*ehci = hcd_to_ehci(hcd);
+	int		ports = HCS_N_PORTS(ehci->hcs_params);
+	u32 __iomem	*status_reg = &ehci->regs->port_status[
+				(wIndex & 0xff) - 1];
+	unsigned long flags;
+	int retval, irq_disabled = 0;
+
+	/*
+	 * RESUME is cleared when GetPortStatus() is called 20ms after start
+	 * of RESUME
+	 */
+	if ((typeReq == GetPortStatus) &&
+	    (wIndex && wIndex <= ports) &&
+	    ehci->reset_done[wIndex-1] &&
+	    time_after_eq(jiffies, ehci->reset_done[wIndex-1]) &&
+	    (ehci_readl(ehci, status_reg) & PORT_RESUME)) {
+
+		/*
+		 * to make sure we are not interrupted until RESUME bit
+		 * is cleared, disable interrupts on current CPU
+		 */
+		ehci_dbg(ehci, "SOF alignment workaround\n");
+		irq_disabled = 1;
+		local_irq_save(flags);
+		ehci_brcm_wait_for_sof(ehci, 5);
+	}
+	retval = (*org_hub_control)(hcd, typeReq, wValue, wIndex, buf, wLength);
+	if (irq_disabled)
+		local_irq_restore(flags);
+	return retval;
+}
+
+static int ehci_brcm_reset(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+
+	ehci->big_endian_mmio = 1;
+	hcd->suspend_without_phy_exit = 1;
+
+	ehci->caps = (struct ehci_caps *) hcd->regs;
+	ehci->regs = (struct ehci_regs *) (hcd->regs +
+		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)));
+
+	/* This fixes the lockup during reboot due to prior interrupts */
+	ehci_writel(ehci, CMD_RESET, &ehci->regs->command);
+	mdelay(10);
+
+	/*
+	 * SWLINUX-1705: Avoid OUT packet underflows during high memory
+	 *   bus usage
+	 * port_status[0x0f] = Broadcom-proprietary USB_EHCI_INSNREG00 @ 0x90
+	 */
+	ehci_writel(ehci, 0x00800040, &ehci->regs->port_status[0x10]);
+	ehci_writel(ehci, 0x00000001, &ehci->regs->port_status[0x12]);
+
+	return ehci_setup(hcd);
+}
+
+static struct hc_driver __read_mostly ehci_brcm_hc_driver;
+
+static const struct ehci_driver_overrides brcm_overrides __initconst = {
+
+	.reset =	ehci_brcm_reset,
+	.extra_priv_size = sizeof(struct brcm_priv),
+};
+
+static int ehci_brcm_probe(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd;
+	struct resource *res_mem;
+	struct brcm_priv *priv;
+	int irq;
+	int err;
+
+	if (usb_disabled())
+		return -ENODEV;
+
+	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+	if (err)
+		return err;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "no irq provided");
+		return irq;
+	}
+
+	/* Hook the hub control routine to work around a bug */
+	if (org_hub_control == NULL)
+		org_hub_control = ehci_brcm_hc_driver.hub_control;
+	ehci_brcm_hc_driver.hub_control = ehci_brcm_hub_control;
+
+	/* initialize hcd */
+	hcd = usb_create_hcd(&ehci_brcm_hc_driver,
+			&pdev->dev, dev_name(&pdev->dev));
+	if (!hcd)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, hcd);
+	priv = hcd_to_ehci_priv(hcd);
+
+	priv->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(priv->clk)) {
+		dev_err(&pdev->dev, "Clock not found in Device Tree\n");
+		priv->clk = NULL;
+	}
+	err = clk_prepare_enable(priv->clk);
+	if (err)
+		goto err_hcd;
+
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	hcd->regs = devm_ioremap_resource(&pdev->dev, res_mem);
+	if (IS_ERR(hcd->regs)) {
+		err = PTR_ERR(hcd->regs);
+		goto err_clk;
+	}
+	hcd->rsrc_start = res_mem->start;
+	hcd->rsrc_len = resource_size(res_mem);
+	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (err)
+		goto err_clk;
+
+	device_wakeup_enable(hcd->self.controller);
+	device_enable_async_suspend(hcd->self.controller);
+	platform_set_drvdata(pdev, hcd);
+
+	return err;
+
+err_clk:
+	clk_disable_unprepare(priv->clk);
+err_hcd:
+	usb_put_hcd(hcd);
+
+	return err;
+}
+
+static int ehci_brcm_remove(struct platform_device *dev)
+{
+	struct usb_hcd *hcd = platform_get_drvdata(dev);
+	struct brcm_priv *priv = hcd_to_ehci_priv(hcd);
+
+	usb_remove_hcd(hcd);
+	clk_disable_unprepare(priv->clk);
+	usb_put_hcd(hcd);
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+
+static int ehci_brcm_suspend(struct device *dev)
+{
+	int ret;
+	struct usb_hcd *hcd = dev_get_drvdata(dev);
+	struct brcm_priv *priv = hcd_to_ehci_priv(hcd);
+	bool do_wakeup = device_may_wakeup(dev);
+
+	ret = ehci_suspend(hcd, do_wakeup);
+	clk_disable_unprepare(priv->clk);
+	return ret;
+}
+
+static int ehci_brcm_resume(struct device *dev)
+{
+	struct usb_hcd *hcd = dev_get_drvdata(dev);
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	struct brcm_priv *priv = hcd_to_ehci_priv(hcd);
+	int err;
+
+	err = clk_prepare_enable(priv->clk);
+	if (err)
+		return err;
+	/*
+	 * SWLINUX-1705: Avoid OUT packet underflows during high memory
+	 *   bus usage
+	 * port_status[0x0f] = Broadcom-proprietary USB_EHCI_INSNREG00
+	 * @ 0x90
+	 */
+	ehci_writel(ehci, 0x00800040, &ehci->regs->port_status[0x10]);
+	ehci_writel(ehci, 0x00000001, &ehci->regs->port_status[0x12]);
+
+	ehci_resume(hcd, false);
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(ehci_brcm_pm_ops, ehci_brcm_suspend,
+		ehci_brcm_resume);
+
+static const struct of_device_id brcm_ehci_of_match[] = {
+	{ .compatible = "brcm,bcm7445-ehci", },
+	{}
+};
+
+static struct platform_driver ehci_brcm_driver = {
+	.probe		= ehci_brcm_probe,
+	.remove		= ehci_brcm_remove,
+	.shutdown	= usb_hcd_platform_shutdown,
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= "ehci-brcm",
+		.pm	= &ehci_brcm_pm_ops,
+		.of_match_table = brcm_ehci_of_match,
+	}
+};
+
+static int __init ehci_brcm_init(void)
+{
+	if (usb_disabled())
+		return -ENODEV;
+
+	pr_info("%s: " BRCM_DRIVER_DESC "\n", brcm_hcd_name);
+
+	ehci_init_driver(&ehci_brcm_hc_driver, &brcm_overrides);
+	return platform_driver_register(&ehci_brcm_driver);
+}
+module_init(ehci_brcm_init);
+
+static void __exit ehci_brcm_exit(void)
+{
+	platform_driver_unregister(&ehci_brcm_driver);
+}
+module_exit(ehci_brcm_exit);
+
+MODULE_ALIAS("platform:ehci-brcm");
+MODULE_DESCRIPTION(BRCM_DRIVER_DESC);
+MODULE_AUTHOR("Al Cooper");
+MODULE_LICENSE("GPL");
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#17 lore raw

PATCH v3 6/6 usb: host: Add ability to build new Broadcom STB USB drivers

In reply to Al Cooper

Add the build system changes needed to get the Broadcom STB XHCI, EHCI and OHCI functionality working. The link order for XHCI was changed in the Makefile because of the way STB XHCI, EHCI and OHCI controllers share a port which requires that the XHCI driver be initialized first. Also update MAINTAINERS.

---
 MAINTAINERS               |  9 +++++++++
 drivers/usb/host/Kconfig  | 29 +++++++++++++++++++++++++++++
 drivers/usb/host/Makefile | 18 ++++++++++++------
 3 files changed, 50 insertions(+), 6 deletions(-)
MAINTAINERS +9 -0
index e8e1d86bd505..c4e7bcb7f992 100644
@@ -2991,6 +2991,15 @@ S:	Supported
 F:	drivers/i2c/busses/i2c-brcmstb.c
 F:	Documentation/devicetree/bindings/i2c/i2c-brcmstb.txt
 
+BROADCOM BRCMSTB USB XHCI, EHCI and OHCI DRIVERS
+M:	Al Cooper <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	drivers/usb/host/xhci-brcm.*
+F:	drivers/usb/host/ohci-brcm.c
+F:	Documentation/devicetree/bindings/usb/brcm,bcm7445-*.txt
+
 BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER
 M:	Al Cooper <[email protected]>
 L:	[email protected]
drivers/usb/host/Kconfig +29 -0
index 16758b12a5e9..ec6b4582ab12 100644
@@ -94,6 +94,35 @@ config USB_XHCI_TEGRA
 	  Say 'Y' to enable the support for the xHCI host controller
 	  found in NVIDIA Tegra124 and later SoCs.
 
+config USB_OHCI_BRCM
+       tristate
+
+config USB_EHCI_BRCM
+       tristate
+
+config USB_XHCI_BRCM
+       tristate
+
+config BRCM_USB_PHY
+       tristate
+
+config USB_BRCM
+	tristate "Broadcom STB USB support"
+	depends on ARCH_BRCMSTB
+	select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
+	select USB_EHCI_BRCM if USB_EHCI_HCD
+	select USB_XHCI_BRCM if USB_XHCI_HCD
+	select USB_XHCI_PLATFORM if USB_XHCI_HCD
+	select BRCM_USB_PHY if USB_OHCI_HCD || USB_EHCI_HCD || USB_XHCI_HCD
+	select GENERIC_PHY if BRCM_USB_PHY
+	default ARCH_BRCMSTB
+	help
+	  Say Y to enable support for XHCI, EHCI and OHCI host controllers
+	  found in Broadcom STB SoC's.
+
+	  Disabling this will keep the controllers and corresponding
+	  PHYs powered down.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
drivers/usb/host/Makefile +12 -6
index 84514f71ae44..9bdd64b710ee 100644
@@ -31,6 +31,10 @@ ifneq ($(CONFIG_USB_XHCI_RCAR), )
 	xhci-plat-hcd-y		+= xhci-rcar.o
 endif
 
+ifneq ($(CONFIG_USB_XHCI_BRCM), )
+	xhci-plat-hcd-y		+= xhci-brcm.o
+endif
+
 ifneq ($(CONFIG_DEBUG_FS),)
 	xhci-hcd-y		+= xhci-debugfs.o
 endif
@@ -39,6 +43,13 @@ obj-$(CONFIG_USB_WHCI_HCD)	+= whci/
 
 obj-$(CONFIG_USB_PCI)	+= pci-quirks.o
 
+obj-$(CONFIG_USB_XHCI_HCD)	+= xhci-hcd.o
+obj-$(CONFIG_USB_XHCI_PCI)	+= xhci-pci.o
+obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
+obj-$(CONFIG_USB_XHCI_HISTB)	+= xhci-histb.o
+obj-$(CONFIG_USB_XHCI_MTK)	+= xhci-mtk.o
+obj-$(CONFIG_USB_XHCI_TEGRA)	+= xhci-tegra.o
+
 obj-$(CONFIG_USB_EHCI_HCD)	+= ehci-hcd.o
 obj-$(CONFIG_USB_EHCI_PCI)	+= ehci-pci.o
 obj-$(CONFIG_USB_EHCI_HCD_PLATFORM)	+= ehci-platform.o
@@ -52,6 +63,7 @@ obj-$(CONFIG_USB_EHCI_EXYNOS)	+= ehci-exynos.o
 obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
 obj-$(CONFIG_USB_EHCI_TEGRA)	+= ehci-tegra.o
 obj-$(CONFIG_USB_W90X900_EHCI)	+= ehci-w90x900.o
+obj-$(CONFIG_USB_EHCI_BRCM)	+= ehci-brcm.o
 
 obj-$(CONFIG_USB_OXU210HP_HCD)	+= oxu210hp-hcd.o
 obj-$(CONFIG_USB_ISP116X_HCD)	+= isp116x-hcd.o
@@ -72,12 +84,6 @@ obj-$(CONFIG_USB_OHCI_HCD_DAVINCI)	+= ohci-da8xx.o
 
 obj-$(CONFIG_USB_UHCI_HCD)	+= uhci-hcd.o
 obj-$(CONFIG_USB_FHCI_HCD)	+= fhci.o
-obj-$(CONFIG_USB_XHCI_HCD)	+= xhci-hcd.o
-obj-$(CONFIG_USB_XHCI_PCI)	+= xhci-pci.o
-obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o
-obj-$(CONFIG_USB_XHCI_HISTB)	+= xhci-histb.o
-obj-$(CONFIG_USB_XHCI_MTK)	+= xhci-mtk.o
-obj-$(CONFIG_USB_XHCI_TEGRA)	+= xhci-tegra.o
 obj-$(CONFIG_USB_SL811_HCD)	+= sl811-hcd.o
 obj-$(CONFIG_USB_SL811_CS)	+= sl811_cs.o
 obj-$(CONFIG_USB_U132_HCD)	+= u132-hcd.o
Signature · 1 line
1.9.0.138.g2de3478
#18 lore raw

Re: [PATCH V3 6/6] usb: host: Add ability to build new Broadcom STB USB drivers

drivers/usb/host/Kconfig config USB_XHCI_TEGRA · line 118

Quoted 11 lines · Al Cooper
drivers/usb/host/Kconfig +11 -0
+
+config USB_BRCM
+	tristate "Broadcom STB USB support"
+	depends on ARCH_BRCMSTB
+	select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
+	select USB_EHCI_BRCM if USB_EHCI_HCD
+	select USB_XHCI_BRCM if USB_XHCI_HCD
+	select USB_XHCI_PLATFORM if USB_XHCI_HCD
+	select BRCM_USB_PHY if USB_OHCI_HCD || USB_EHCI_HCD || USB_XHCI_HCD
+	select GENERIC_PHY if BRCM_USB_PHY
+	default ARCH_BRCMSTB

Is there a build time dependency on the PHY layer? If not, I would suggest dropping the last two 'select' statements. I would also suggest making the dependency 'depends on ARCH_BRCMSTB || COMPILE_TEST' to allow building it on other architecture for better build testing, and dropping the 'default' line. Just add this to the defconfig like the other drivers you have.

Arnd

author maintainer
#19 lore raw

Re: [PATCH V3 6/6] usb: host: Add ability to build new Broadcom STB USB drivers

Quoted 13 lines · Arnd Bergmann
Quoted 10 lines · Al Cooper
drivers/usb/host/Kconfig +10 -0
+
+config USB_BRCM
+     tristate "Broadcom STB USB support"
+     depends on ARCH_BRCMSTB
+     select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
+     select USB_EHCI_BRCM if USB_EHCI_HCD
+     select USB_XHCI_BRCM if USB_XHCI_HCD
+     select USB_XHCI_PLATFORM if USB_XHCI_HCD
+     select BRCM_USB_PHY if USB_OHCI_HCD || USB_EHCI_HCD || USB_XHCI_HCD
+     select GENERIC_PHY if BRCM_USB_PHY
Quoted 8 lines
Quoted 1 line

+ default ARCH_BRCMSTB

Is there a build time dependency on the PHY layer? If not, I would suggest dropping the last two 'select' statements. I would also suggest making the dependency 'depends on ARCH_BRCMSTB || COMPILE_TEST' to allow building it on other architecture for better build testing, and dropping the 'default' line. Just add this to the defconfig like the other drivers you have.

I added COMPILE_TEST and dropped the last 2 select lines. Most of our other drivers default to "y" for "ARCH_BRCMSTB", would it be better if I changed it to "default y"?

Thanks
Al

Quoted 2 lines

Arnd

maintainer
#5 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

In reply to Al Cooper

drivers/usb/host/ohci-platform.c static int ohci_platform_probe(struct platform_device *dev) · line 193

Quoted 11 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

drivers/usb/host/ohci-platform.c +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct platform_device *dev)
 		ohci->flags |= OHCI_QUIRK_FRAME_NO;
 	if (pdata->num_ports)
 		ohci->num_ports = pdata->num_ports;
+	if (pdata->suspend_without_phy_exit)
+		hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions... Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Alan Stern

#20 lore raw

Re: [PATCH V3 6/6] usb: host: Add ability to build new Broadcom STB USB drivers

In reply to Alan Cooper
Quoted 26 lines · Alan Cooper
Quoted 16 lines · Arnd Bergmann

drivers/usb/host/Kconfig config USB_XHCI_TEGRA · line 118

Quoted 12 lines · Al Cooper
drivers/usb/host/Kconfig +9 -0
+
+config USB_BRCM
+     tristate "Broadcom STB USB support"
+     depends on ARCH_BRCMSTB
+     select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
+     select USB_EHCI_BRCM if USB_EHCI_HCD
+     select USB_XHCI_BRCM if USB_XHCI_HCD
+     select USB_XHCI_PLATFORM if USB_XHCI_HCD
+     select BRCM_USB_PHY if USB_OHCI_HCD || USB_EHCI_HCD ||

USB_XHCI_HCD

drivers/usb/host/Kconfig +2 -0
+     select GENERIC_PHY if BRCM_USB_PHY
+     default ARCH_BRCMSTB
Quoted 8 lines

Is there a build time dependency on the PHY layer? If not, I would suggest
dropping the last two 'select' statements. I would also suggest making the dependency 'depends on ARCH_BRCMSTB || COMPILE_TEST' to allow building it on other architecture for better build testing, and dropping the 'default' line. Just add this to the defconfig like the other
drivers you have.

Quoted 3 lines

I added COMPILE_TEST and dropped the last 2 select lines. Most of our other drivers default to "y" for "ARCH_BRCMSTB", would it be better if I changed it to "default y"?

No, "default ARCH_BRCMSTB" is better than "default y", but I'd recommend to just not have non-essential drivers default-on.

Arnd

author maintainer
#21 lore raw

Re: [PATCH V3 6/6] usb: host: Add ability to build new Broadcom STB USB drivers

Quoted 28 lines · Arnd Bergmann
Quoted 26 lines · Alan Cooper
Quoted 24 lines · Arnd Bergmann

drivers/usb/host/Kconfig config USB_XHCI_TEGRA · line 118

Quoted 12 lines · Al Cooper
drivers/usb/host/Kconfig +9 -0
+
+config USB_BRCM
+     tristate "Broadcom STB USB support"
+     depends on ARCH_BRCMSTB
+     select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
+     select USB_EHCI_BRCM if USB_EHCI_HCD
+     select USB_XHCI_BRCM if USB_XHCI_HCD
+     select USB_XHCI_PLATFORM if USB_XHCI_HCD
+     select BRCM_USB_PHY if USB_OHCI_HCD || USB_EHCI_HCD ||

USB_XHCI_HCD

drivers/usb/host/Kconfig +2 -0
+     select GENERIC_PHY if BRCM_USB_PHY
+     default ARCH_BRCMSTB

Is there a build time dependency on the PHY layer? If not, I would suggest
dropping the last two 'select' statements. I would also suggest making the dependency 'depends on ARCH_BRCMSTB || COMPILE_TEST' to allow building it on other architecture for better build testing, and dropping the 'default' line. Just add this to the defconfig like the other
drivers you have.

Quoted 8 lines
Quoted 3 lines

I added COMPILE_TEST and dropped the last 2 select lines. Most of our other drivers default to "y" for "ARCH_BRCMSTB", would it be better if I changed it to "default y"?

No, "default ARCH_BRCMSTB" is better than "default y", but I'd recommend to just not have non-essential drivers default-on.

Arnd

Okay.

Thanks
Al

#6 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

In reply to Alan Stern
Quoted 18 lines · Alan Stern

Review static int ohci_platform_probe(struct platform_device *dev) · line 193

Quoted 11 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct platform_device *dev)
  		ohci->flags |= OHCI_QUIRK_FRAME_NO;
  	if (pdata->num_ports)
  		ohci->num_ports = pdata->num_ports;
+	if (pdata->suspend_without_phy_exit)
+		hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions... Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 2 lines

Alan Stern

Alan,

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:
[PATCH V3 2/6] usb: core: Add ability to skip phy exit on suspend and init on resume
With this patch I can then use ohci_platform.c without any modifications. Could you let me know what you think?

Thanks
Al

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

This is enabled with the HCD flag "suspend_without_phy_exit" which can be set from any HCD driver or from the device-tree property "suspend-without-phy-exit".

---
 drivers/usb/core/hcd.c  |  8 ++++----
 drivers/usb/core/phy.c  | 21 +++++++++++++++------
 drivers/usb/core/phy.h  |  9 ++++++---
 include/linux/usb/hcd.h |  3 +++
 4 files changed, 28 insertions(+), 13 deletions(-)
drivers/usb/core/hcd.c +4 -4
index 1c21955fe7c0..e67e4d6b3d21 100644
@@ -2263,7 +2263,7 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
 		hcd->state = HC_STATE_SUSPENDED;
 
 		if (!PMSG_IS_AUTO(msg))
-			usb_phy_roothub_suspend(hcd->self.sysdev,
+			usb_phy_roothub_suspend(hcd,
 						hcd->phy_roothub);
 
 		/* Did we race with a root-hub wakeup event? */
@@ -2304,7 +2304,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
 	}
 
 	if (!PMSG_IS_AUTO(msg)) {
-		status = usb_phy_roothub_resume(hcd->self.sysdev,
+		status = usb_phy_roothub_resume(hcd,
 						hcd->phy_roothub);
 		if (status)
 			return status;
@@ -2347,7 +2347,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
 		}
 	} else {
 		hcd->state = old_state;
-		usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
+		usb_phy_roothub_suspend(hcd, hcd->phy_roothub);
 		dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
 				"resume", status);
 		if (status != -ESHUTDOWN)
@@ -2744,7 +2744,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	struct usb_device *rhdev;
 
 	if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
-		hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
+		hcd->phy_roothub = usb_phy_roothub_alloc(hcd);
 		if (IS_ERR(hcd->phy_roothub))
 			return PTR_ERR(hcd->phy_roothub);
 
drivers/usb/core/phy.c +15 -6
index 9879767452a2..0eb12566f1c3 100644
@@ -45,10 +45,11 @@ static int usb_phy_roothub_add_phy(struct device *dev, int index,
 	return 0;
 }
 
-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
+struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd)
 {
 	struct usb_phy_roothub *phy_roothub;
 	int i, num_phys, err;
+	struct device *dev = hcd->self.sysdev;
 
 	if (!IS_ENABLED(CONFIG_GENERIC_PHY))
 		return NULL;
@@ -58,6 +59,9 @@ struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
 	if (num_phys <= 0)
 		return NULL;
 
+	if (device_property_read_bool(dev, "suspend-without-phy-exit"))
+		hcd->suspend_without_phy_exit = 1;
+
 	phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL);
 	if (!phy_roothub)
 		return ERR_PTR(-ENOMEM);
@@ -161,26 +165,30 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub)
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
 
-int usb_phy_roothub_suspend(struct device *controller_dev,
+int usb_phy_roothub_suspend(struct usb_hcd *hcd,
 			    struct usb_phy_roothub *phy_roothub)
 {
+	struct device *controller_dev = hcd->self.sysdev;
+
 	usb_phy_roothub_power_off(phy_roothub);
 
 	/* keep the PHYs initialized so the device can wake up the system */
-	if (device_may_wakeup(controller_dev))
+	if (device_may_wakeup(controller_dev) || hcd->suspend_without_phy_exit)
 		return 0;
 
 	return usb_phy_roothub_exit(phy_roothub);
 }
 EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
 
-int usb_phy_roothub_resume(struct device *controller_dev,
+int usb_phy_roothub_resume(struct usb_hcd *hcd,
 			   struct usb_phy_roothub *phy_roothub)
 {
+	struct device *controller_dev = hcd->self.sysdev;
 	int err;
 
 	/* if the device can't wake up the system _exit was called */
-	if (!device_may_wakeup(controller_dev)) {
+	if (!device_may_wakeup(controller_dev) &&
+	    !hcd->suspend_without_phy_exit) {
 		err = usb_phy_roothub_init(phy_roothub);
 		if (err)
 			return err;
@@ -189,7 +197,8 @@ int usb_phy_roothub_resume(struct device *controller_dev,
 	err = usb_phy_roothub_power_on(phy_roothub);
 
 	/* undo _init if _power_on failed */
-	if (err && !device_may_wakeup(controller_dev))
+	if (err && !device_may_wakeup(controller_dev)
+	    && !hcd->suspend_without_phy_exit)
 		usb_phy_roothub_exit(phy_roothub);
 
 	return err;
drivers/usb/core/phy.h +0 -0
index 88a3c037e9df..34293e11a917 100644
@@ -5,13 +5,16 @@
  * Copyright (C) 2018 Martin Blumenstingl 

<[email protected]>
*/

+#include <linux/usb.h>
+#include <linux/usb/hcd.h>
+
#ifndef __USB_CORE_PHY_H_
#define __USB_CORE_PHY_H_

struct device;
struct usb_phy_roothub;

-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev); +struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd);

int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub); int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);
@@ -19,9 +22,9 @@
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_suspend(struct device *controller_dev, +int usb_phy_roothub_suspend(struct usb_hcd *hcd,
struct usb_phy_roothub *phy_roothub);
-int usb_phy_roothub_resume(struct device *controller_dev, +int usb_phy_roothub_resume(struct usb_hcd *hcd,
struct usb_phy_roothub *phy_roothub);

#endif /* __USB_CORE_PHY_H_ */

include/linux/usb/hcd.h +3 -0
index 97e2ddec18b1..87a104055b5e 100644
@@ -157,6 +157,9 @@ struct usb_hcd {
 	 */
 	unsigned		skip_phy_initialization:1;
 
+	/* Some phys don't want the phy's exit/init called on suspend/resume */
+	unsigned		suspend_without_phy_exit:1;
+
 	/* The next flag is a stopgap, to be removed when all the HCDs
 	 * support the new root-hub polling mechanism. */
 	unsigned		uses_new_polling:1;
Signature · 1 line
1.9.0.138.g2de3478
#7 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 20 lines · Al Cooper
Quoted 19 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
           ohci->flags |= OHCI_QUIRK_FRAME_NO;
       if (pdata->num_ports)
           ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 7 lines
Quoted 2 lines

Alan Stern

Alan,

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:

And the reason for that suggestion was really because it was percevied as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Quoted 197 lines

[PATCH V3 2/6] usb: core: Add ability to skip phy exit on suspend and init on resume
With this patch I can then use ohci_platform.c without any modifications. Could you let me know what you think?

Thanks
Al

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

This is enabled with the HCD flag "suspend_without_phy_exit" which can be set from any HCD driver or from the device-tree property "suspend-without-phy-exit".

---

 drivers/usb/core/hcd.c  |  8 ++++----
 drivers/usb/core/phy.c  | 21 +++++++++++++++------
 drivers/usb/core/phy.h  |  9 ++++++---
 include/linux/usb/hcd.h |  3 +++
 4 files changed, 28 insertions(+), 13 deletions(-)
drivers/usb/core/hcd.c +1 -1
index 1c21955fe7c0..e67e4d6b3d21 100644
@@ -2263,7 +2263,7 @@ int hcd_bus_suspend(struct usb_device *rhdev,
 pm_message_t msg)
          hcd->state = HC_STATE_SUSPENDED;
 
          if (!PMSG_IS_AUTO(msg))
-            usb_phy_roothub_suspend(hcd->self.sysdev,
+            usb_phy_roothub_suspend(hcd,
                          hcd->phy_roothub);
 

         /* Did we race with a root-hub wakeup event? */

drivers/usb/core/hcd.c +1 -1
@@ -2304,7 +2304,7 @@ int hcd_bus_resume(struct usb_device *rhdev,
 pm_message_t msg)
      }
 
      if (!PMSG_IS_AUTO(msg)) {
-        status = usb_phy_roothub_resume(hcd->self.sysdev,
+        status = usb_phy_roothub_resume(hcd,
                          hcd->phy_roothub);
          if (status)

             return status;

drivers/usb/core/hcd.c +1 -1
@@ -2347,7 +2347,7 @@ int hcd_bus_resume(struct usb_device *rhdev,
 pm_message_t msg)
          }
      } else {
          hcd->state = old_state;
-        usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
+        usb_phy_roothub_suspend(hcd, hcd->phy_roothub);
          dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
                  "resume", status);

         if (status != -ESHUTDOWN)

drivers/usb/core/hcd.c +1 -1
@@ -2744,7 +2744,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
      struct usb_device *rhdev;
 
      if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
-        hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
+        hcd->phy_roothub = usb_phy_roothub_alloc(hcd);
          if (IS_ERR(hcd->phy_roothub))
              return PTR_ERR(hcd->phy_roothub);
 
drivers/usb/core/phy.c +2 -1
index 9879767452a2..0eb12566f1c3 100644
@@ -45,10 +45,11 @@ static int usb_phy_roothub_add_phy(struct device
 *dev, int index,
      return 0;
  }
 
-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
+struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd)
  {
      struct usb_phy_roothub *phy_roothub;
      int i, num_phys, err;
+    struct device *dev = hcd->self.sysdev;
 
      if (!IS_ENABLED(CONFIG_GENERIC_PHY))

         return NULL;

drivers/usb/core/phy.c +3 -0
@@ -58,6 +59,9 @@ struct usb_phy_roothub *usb_phy_roothub_alloc(struct
 device *dev)
      if (num_phys <= 0)
          return NULL;
 
+    if (device_property_read_bool(dev, "suspend-without-phy-exit"))
+        hcd->suspend_without_phy_exit = 1;
+
      phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL);
      if (!phy_roothub)

         return ERR_PTR(-ENOMEM);

drivers/usb/core/phy.c +8 -4
@@ -161,26 +165,30 @@ void usb_phy_roothub_power_off(struct
 usb_phy_roothub *phy_roothub)
  }
  EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
 
-int usb_phy_roothub_suspend(struct device *controller_dev,
+int usb_phy_roothub_suspend(struct usb_hcd *hcd,
                  struct usb_phy_roothub *phy_roothub)
  {
+    struct device *controller_dev = hcd->self.sysdev;
+
      usb_phy_roothub_power_off(phy_roothub);
 
      /* keep the PHYs initialized so the device can wake up the system */
-    if (device_may_wakeup(controller_dev))
+    if (device_may_wakeup(controller_dev) ||
 hcd->suspend_without_phy_exit)
          return 0;
 
      return usb_phy_roothub_exit(phy_roothub);
  }
  EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
 
-int usb_phy_roothub_resume(struct device *controller_dev,
+int usb_phy_roothub_resume(struct usb_hcd *hcd,
                 struct usb_phy_roothub *phy_roothub)
  {
+    struct device *controller_dev = hcd->self.sysdev;
      int err;
 
      /* if the device can't wake up the system _exit was called */
-    if (!device_may_wakeup(controller_dev)) {
+    if (!device_may_wakeup(controller_dev) &&
+        !hcd->suspend_without_phy_exit) {
          err = usb_phy_roothub_init(phy_roothub);

         if (err)
             return err;

drivers/usb/core/phy.c +2 -1
@@ -189,7 +197,8 @@ int usb_phy_roothub_resume(struct device
 *controller_dev,
      err = usb_phy_roothub_power_on(phy_roothub);
 
      /* undo _init if _power_on failed */
-    if (err && !device_may_wakeup(controller_dev))
+    if (err && !device_may_wakeup(controller_dev)
+        && !hcd->suspend_without_phy_exit)
          usb_phy_roothub_exit(phy_roothub);
 

     return err;

drivers/usb/core/phy.h +0 -0
index 88a3c037e9df..34293e11a917 100644
@@ -5,13 +5,16 @@
   * Copyright (C) 2018 Martin Blumenstingl

<[email protected]>
  */

drivers/usb/core/phy.h +3 -0
+#include <linux/usb.h>
+#include <linux/usb/hcd.h>
+

 #ifndef __USB_CORE_PHY_H_
 #define __USB_CORE_PHY_H_

 struct device;
 struct usb_phy_roothub;

drivers/usb/core/phy.h +1 -1
-struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev);
+struct usb_phy_roothub *usb_phy_roothub_alloc(struct usb_hcd *hcd);

 int usb_phy_roothub_init(struct usb_phy_roothub *phy_roothub); int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);

drivers/usb/core/phy.h +2 -2
@@ -19,9 +22,9 @@
  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_suspend(struct device *controller_dev,
+int usb_phy_roothub_suspend(struct usb_hcd *hcd,
                  struct usb_phy_roothub *phy_roothub);
-int usb_phy_roothub_resume(struct device *controller_dev,
+int usb_phy_roothub_resume(struct usb_hcd *hcd,
                 struct usb_phy_roothub *phy_roothub);
 
  #endif /* __USB_CORE_PHY_H_ */
include/linux/usb/hcd.h +1 -0
index 97e2ddec18b1..87a104055b5e 100644
@@ -157,6 +157,9 @@ struct usb_hcd {
       */
      unsigned        skip_phy_initialization:1;
 
+    /* Some phys don't want the phy's exit/init called on

suspend/resume */
+    unsigned        suspend_without_phy_exit:1;
+
     /* The next flag is a stopgap, to be removed when all the HCDs
      * support the new root-hub polling mechanism. */ unsigned        uses_new_polling:1;

Signature · 1 line
Florian
maintainer
#8 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Al Cooper
Quoted 19 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
           ohci->flags |= OHCI_QUIRK_FRAME_NO;
       if (pdata->num_ports)
           ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 2 lines

Alan Stern

Alan,

Quoted 7 lines
Quoted 2 lines

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:

And the reason for that suggestion was really because it was percevied as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right. The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary. Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 6 lines
Quoted 6 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY? Why does the exit function mess the PHY up? Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY? Will just calling the power_off function be good enough? If not, then why not?

Alan Stern

#9 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 52 lines · Alan Stern
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Al Cooper
Quoted 19 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
           ohci->flags |= OHCI_QUIRK_FRAME_NO;
       if (pdata->num_ports)
           ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 2 lines

Alan Stern

Alan,

Quoted 7 lines
Quoted 2 lines

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:

And the reason for that suggestion was really because it was percevied as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right. The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary. Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 6 lines
Quoted 6 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY? Why does the exit function mess the PHY up? Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY? Will just calling the power_off function be good enough? If not, then why not?

Alan Stern

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Al

maintainer
#10 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 60 lines · Al Cooper
Quoted 52 lines · Alan Stern
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Al Cooper
Quoted 19 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
           ohci->flags |= OHCI_QUIRK_FRAME_NO;
       if (pdata->num_ports)
           ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 2 lines

Alan Stern

Alan,

Quoted 7 lines
Quoted 2 lines

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:

And the reason for that suggestion was really because it was percevied as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right. The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary. Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 6 lines
Quoted 6 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY? Why does the exit function mess the PHY up? Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY? Will just calling the power_off function be good enough? If not, then why not?

Alan Stern

Quoted 9 lines

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Then in theory you should be able to add a Device Tree property which says that the PHY provides a clock for the USB host controller. That is strictly a property of the hardware; it has nothing to do with the driver. Therefore it is appropriate for DT.

Wouldn't this solve your issue?

Alan Stern

#11 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 72 lines · Alan Stern
Quoted 60 lines · Al Cooper
Quoted 52 lines · Alan Stern
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Al Cooper
Quoted 19 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
           ohci->flags |= OHCI_QUIRK_FRAME_NO;
       if (pdata->num_ports)
           ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 2 lines

Alan Stern

Alan,

Quoted 7 lines
Quoted 2 lines

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:

And the reason for that suggestion was really because it was percevied as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right. The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary. Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 6 lines
Quoted 6 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY? Why does the exit function mess the PHY up? Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY? Will just calling the power_off function be good enough? If not, then why not?

Alan Stern

Quoted 9 lines

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Quoted 4 lines

Then in theory you should be able to add a Device Tree property which says that the PHY provides a clock for the USB host controller. That is strictly a property of the hardware; it has nothing to do with the driver. Therefore it is appropriate for DT.

The very compatible string that is being allocated/defined for this controller carries that information already, that is, if you probe a "brcm,bcm7445-ohci" compatible then that means the controller has a dependency on the PHY to supply its clock.

Adding a property vs. keying on the compatible string makes sense if you know there is at least a second consumer of that property (unless we make it a broadcom specific property, in which case, it really is redundant with the compatible string).

Anyway, my grudge with that property was the name chosen initially, which included an action to be performed by an implementation as opposed to something purely descriptive. E.g: 'phy-supplies-clock' might be okay.

Quoted 2 lines

Wouldn't this solve your issue?

It would not change much except that there is no need to much with ohci-platform.c anymore, but ultimately that property needs to be read by ohci-hcd.c and acted on, which would likely lead to the same amount of changes as those present in patch #2 currently.

Signature · 1 line
Florian
#12 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 93 lines · Florian Fainelli
Quoted 72 lines · Alan Stern
Quoted 60 lines · Al Cooper
Quoted 52 lines · Alan Stern
Quoted 26 lines · Florian Fainelli
Quoted 25 lines · Al Cooper
Quoted 19 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
            ohci->flags |= OHCI_QUIRK_FRAME_NO;
        if (pdata->num_ports)
            ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement, instead of putting it in the platform data?

Quoted 2 lines

Alan Stern

Alan,

Quoted 7 lines
Quoted 2 lines

That was my original approach but internal review suggested that I use pdata instead. Below is my original patch for:

And the reason for that suggestion was really because it was percevied as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right. The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary. Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 6 lines
Quoted 6 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY? Why does the exit function mess the PHY up? Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY? Will just calling the power_off function be good enough? If not, then why not?

Alan Stern

Quoted 9 lines

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Quoted 4 lines

Then in theory you should be able to add a Device Tree property which says that the PHY provides a clock for the USB host controller. That is strictly a property of the hardware; it has nothing to do with the driver. Therefore it is appropriate for DT.

The very compatible string that is being allocated/defined for this controller carries that information already, that is, if you probe a "brcm,bcm7445-ohci" compatible then that means the controller has a dependency on the PHY to supply its clock.

Adding a property vs. keying on the compatible string makes sense if you know there is at least a second consumer of that property (unless we make it a broadcom specific property, in which case, it really is redundant with the compatible string).

Anyway, my grudge with that property was the name chosen initially, which included an action to be performed by an implementation as opposed to something purely descriptive. E.g: 'phy-supplies-clock' might be okay.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Wouldn't this solve your issue?

It would not change much except that there is no need to much with ohci-platform.c anymore, but ultimately that property needs to be read by ohci-hcd.c and acted on, which would likely lead to the same amount of changes as those present in patch #2 currently.

We also need this functionality in the EHCI and XHCI drivers and it's not the ohci-hcd.c module that needs to know, it's the core/phy.c module called from core/hcd.c.

Al

#13 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 103 lines · Al Cooper
Quoted 102 lines · Florian Fainelli
Quoted 79 lines · Alan Stern
Quoted 66 lines · Al Cooper
Quoted 58 lines · Alan Stern
Quoted 31 lines · Florian Fainelli
Quoted 21 lines · Al Cooper
Quoted 20 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
             ohci->flags |= OHCI_QUIRK_FRAME_NO;
         if (pdata->num_ports)
             ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...  Is there any possibility of adding a DT binding that could express this requirement,
instead of putting it in the platform data?

Quoted 8 lines
Quoted 2 lines

Alan Stern

Alan,

That was my original approach but internal review suggested that I use
pdata instead. Below is my original patch for:

Quoted 5 lines

And the reason for that suggestion was really because it was percevied
as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right.  The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary.
Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 7 lines
Quoted 7 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot
have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY?  Why does the exit function mess the PHY
up?  Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY?  Will just calling the power_off function be good enough?  If not, then why not?

Alan Stern

Quoted 10 lines

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI
and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Quoted 4 lines

Then in theory you should be able to add a Device Tree property which says that the PHY provides a clock for the USB host controller.  That is strictly a property of the hardware; it has nothing to do with the driver.  Therefore it is appropriate for DT.

The very compatible string that is being allocated/defined for this controller carries that information already, that is, if you probe a "brcm,bcm7445-ohci" compatible then that means the controller has a dependency on the PHY to supply its clock.

Adding a property vs. keying on the compatible string makes sense if you know there is at least a second consumer of that property (unless we make it a broadcom specific property, in which case, it really is redundant with the compatible string).

Anyway, my grudge with that property was the name chosen initially, which included an action to be performed by an implementation as opposed to something purely descriptive. E.g: 'phy-supplies-clock' might be okay.

Quoted 2 lines

Wouldn't this solve your issue?

Quoted 8 lines
Quoted 5 lines

It would not change much except that there is no need to much with ohci-platform.c anymore, but ultimately that property needs to be read by ohci-hcd.c and acted on, which would likely lead to the same amount of changes as those present in patch #2 currently.

We also need this functionality in the EHCI and XHCI drivers and it's not the ohci-hcd.c module that needs to know, it's the core/phy.c module called from core/hcd.c.

So in that regard the Device Tree property would actually scale a bit better in that you would no longer need to modify the various *hci-plat*.c files, if that is the way to go, then sure.

Signature · 1 line
Florian
maintainer
#14 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 109 lines · Florian Fainelli
Quoted 108 lines · Al Cooper
Quoted 107 lines · Florian Fainelli
Quoted 79 lines · Alan Stern
Quoted 66 lines · Al Cooper
Quoted 58 lines · Alan Stern
Quoted 31 lines · Florian Fainelli
Quoted 21 lines · Al Cooper
Quoted 20 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
 � ��������� ohci->flags |= OHCI_QUIRK_FRAME_NO;
 � ����� if (pdata->num_ports)
 � ��������� ohci->num_ports = pdata->num_ports;
+��� if (pdata->suspend_without_phy_exit)
+������� hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions...� Is there any possibility of adding a DT binding that could express this requirement,
instead of putting it in the platform data?

Quoted 8 lines
Quoted 2 lines

Alan Stern

Alan,

That was my original approach but internal review suggested that I use
pdata instead. Below is my original patch for:

Quoted 5 lines

And the reason for that suggestion was really because it was percevied
as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right.� The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary.
Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 7 lines
Quoted 7 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot
have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY?� Why does the exit function mess the PHY
up?� Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY?� Will just calling the power_off function be good enough?� If not, then why not?

Alan Stern

Quoted 10 lines

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI
and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Quoted 4 lines

Then in theory you should be able to add a Device Tree property which says that the PHY provides a clock for the USB host controller.� That is strictly a property of the hardware; it has nothing to do with the driver.� Therefore it is appropriate for DT.

The very compatible string that is being allocated/defined for this controller carries that information already, that is, if you probe a "brcm,bcm7445-ohci" compatible then that means the controller has a dependency on the PHY to supply its clock.

Adding a property vs. keying on the compatible string makes sense if you know there is at least a second consumer of that property (unless we make it a broadcom specific property, in which case, it really is redundant with the compatible string).

Anyway, my grudge with that property was the name chosen initially, which included an action to be performed by an implementation as opposed to something purely descriptive. E.g: 'phy-supplies-clock' might be okay.

Quoted 2 lines

Wouldn't this solve your issue?

It would not change much except that there is no need to much with ohci-platform.c anymore, but ultimately that property needs to be read by ohci-hcd.c and acted on, which would likely lead to the same amount of changes as those present in patch #2 currently.

Quoted 7 lines
Quoted 3 lines

We also need this functionality in the EHCI and XHCI drivers and it's not the ohci-hcd.c module that needs to know, it's the core/phy.c module called from core/hcd.c.

So in that regard the Device Tree property would actually scale a bit better in that you would no longer need to modify the various *hci-plat*.c files, if that is the way to go, then sure.

Sounds like the phy needs to be a clock provider to the USB controller. Maybe that's a bit of overkill, but would be the most accurate.

Otherwise, my preference is using the compatible string. IOW, we already have properties to handle this. If you don't want to use them, then use compatible rather than inventing something new and custom.

At least last time I looked, there's a lack of support in the PHY API to handle various handshakes needed between phys and controllers like this. It's fairly easy for the controller to fetch info from a phy node, but the opposite is not so easy. It seems to me some API for controllers to set flags in the phy driver is needed.

Rob

author maintainer
#15 lore raw

Re: [PATCH V3 4/6] usb: ohci-platform: Add support for Broadcom STB SoC's

Quoted 119 lines · Rob Herring
Quoted 109 lines · Florian Fainelli
Quoted 108 lines · Al Cooper
Quoted 107 lines · Florian Fainelli
Quoted 79 lines · Alan Stern
Quoted 66 lines · Al Cooper
Quoted 58 lines · Alan Stern
Quoted 31 lines · Florian Fainelli
Quoted 21 lines · Al Cooper
Quoted 20 lines · Alan Stern

Review static int ohci_platform_probe(struct · line 194

Quoted 12 lines · Al Cooper

Add support for Broadcom STB SoC's to the ohci platform driver.

---

(quoted diff) +2 -0
@@ -177,6 +189,8 @@ static int ohci_platform_probe(struct
 platform_device *dev)
            ohci->flags |= OHCI_QUIRK_FRAME_NO;
        if (pdata->num_ports)
            ohci->num_ports = pdata->num_ports;
+    if (pdata->suspend_without_phy_exit)
+        hcd->suspend_without_phy_exit = 1;

Sorry if I missed this in the earlier discussions... Is there any possibility of adding a DT binding that could express this requirement,
instead of putting it in the platform data?

Quoted 8 lines
Quoted 2 lines

Alan Stern

Alan,

That was my original approach but internal review suggested that I use
pdata instead. Below is my original patch for:

Quoted 5 lines

And the reason for that suggestion was really because it was percevied
as encoding a driver behavior as a Device Tree property as opposed to describing something that was inherently and strictly a hardware behavior (therefore suitable for Device Tree).

Right. The best way to approach this problem is to identify and characterize the hardware behavior which makes this override necessary.
Then _that_ can be added to DT, since it will be a property of the hardware rather than of the driver.

Quoted 7 lines
Quoted 7 lines

Add the ability to skip calling the PHY's exit routine on suspend and the PHY's init routine on resume. This is to handle a USB PHY that should have it's power_off function called on suspend but cannot
have it's exit function called because on exit it will disable the PHY to the point where register accesses to the Host Controllers using the PHY will be disabled and the host drivers will crash.

What's special about this PHY? Why does the exit function mess the PHY
up? Or to put it another way, why doesn't the exit function mess up other PHYs in the same way?

Quoted 6 lines

For that matter, can we change the code so that suspend doesn't call the exit function for _any_ PHY? Will just calling the power_off function be good enough? If not, then why not?

Alan Stern

Quoted 10 lines

In our USB hardware the USB PHY supplies a clock for the EHCI/OHCI and XHCI host controllers and if the PHY is totally shut down the EHCI, OHCI
and XHCI registers will cause an exception if accessed and cause the EHCI, OHCI and XHCI drivers to crash. There is always talk of fixing this in the hardware by adding an aux clock that will takeover when the PHY clock is shut down, but this hasn't happened yet. It seems like "exit on suspend" still makes sense on systems that don't have this problem (additional power savings?) so removing the exit on suspend for all systems is not a good idea.

Quoted 4 lines

Then in theory you should be able to add a Device Tree property which says that the PHY provides a clock for the USB host controller. That is strictly a property of the hardware; it has nothing to do with the driver. Therefore it is appropriate for DT.

The very compatible string that is being allocated/defined for this controller carries that information already, that is, if you probe a "brcm,bcm7445-ohci" compatible then that means the controller has a dependency on the PHY to supply its clock.

Adding a property vs. keying on the compatible string makes sense if you know there is at least a second consumer of that property (unless we make it a broadcom specific property, in which case, it really is redundant with the compatible string).

Anyway, my grudge with that property was the name chosen initially, which included an action to be performed by an implementation as opposed to something purely descriptive. E.g: 'phy-supplies-clock' might be okay.

Quoted 2 lines

Wouldn't this solve your issue?

It would not change much except that there is no need to much with ohci-platform.c anymore, but ultimately that property needs to be read by ohci-hcd.c and acted on, which would likely lead to the same amount of changes as those present in patch #2 currently.

Quoted 7 lines
Quoted 3 lines

We also need this functionality in the EHCI and XHCI drivers and it's not the ohci-hcd.c module that needs to know, it's the core/phy.c module called from core/hcd.c.

So in that regard the Device Tree property would actually scale a bit better in that you would no longer need to modify the various *hci-plat*.c files, if that is the way to go, then sure.

Quoted 6 lines

Sounds like the phy needs to be a clock provider to the USB controller. Maybe that's a bit of overkill, but would be the most accurate.

Otherwise, my preference is using the compatible string. IOW, we already have properties to handle this. If you don't want to use them, then use compatible rather than inventing something new and custom.

My previous commit used the compatible string to set the HCD flag instead of a device tree property, but Alan Stern ask me to use a DT binding instead. This has the advantage of having the code in one place in the phy.c module instead of having to add it to the OHCI, EHCI and XHCI platform drivers.

Quoted 6 lines

At least last time I looked, there's a lack of support in the PHY API to handle various handshakes needed between phys and controllers like this. It's fairly easy for the controller to fetch info from a phy node, but the opposite is not so easy. It seems to me some API for controllers to set flags in the phy driver is needed.

The Generic PHY subsystem allows the PHY provider to export phy_power_on/phy_power_off and phy_init/phy_exit functions for use by the PHY consumer. The exact functionality of these routines seems to vary among the different PHY provider drivers. The Broadcom USB PHY driver expects the phy_power_on/phy_power_off to be used on suspend/resume and the phy_init/phy_exit to be used by the consumer driver's probe/remove routines. The new USB PHY consumer code does not do this, instead it calls both power_off AND exit for both suspend (not wakable) and remove. If you look at other PHY provider/consumer implementations in the kernel tree you'll find examples of both these methods but there are more examples that behave like the Broadcom PHY. What I was trying to do was to use a DT property to tell the USB PHY consumer code which method to use.

I guess the problem is that the current generic PHY api only allows the consumer to put the PHY in 1 of 3 states, EXIT, OFF or ON. The current USB PHY consumer code is using OFF for "suspend with wakeup" and EXIT for "suspend without wakeup". The Broadcom PHY driver wants OFF for either "suspend with wakeup" or "suspend without wakeup" and EXIT when there are no consumers using the PHY. If the PHY API allowed for 4 states, EXIT, OFF_NOT_WAKABLE, OFF_WAKABLE and ON then the individual PHY provider could hide the differences, but this seems hard to retrofit into the PHY subsystem.

Al

Quoted 3 lines

Rob