Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework
@ 2020-06-08 19:26 Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset Nicolas Saenz Julienne
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi,
	Nicolas Saenz Julienne

On the Raspberry Pi 4, after a PCI reset, VL805's firmware may either be
loaded directly from an EEPROM or, if not present, by the SoC's
co-processor, VideoCore. This series reworks how we handle this.

The previous solution makes use of PCI quirks and exporting platform
specific functions. Albeit functional it feels pretty shoehorned. This
proposes an alternative way of handling the triggering of the xHCI chip
initialization trough means of a reset controller.

The benefits are pretty evident: less platform churn in core xHCI code,
and no explicit device dependency management in pcie-brcmstb.

Note that patch #1 depend on another series[1].

The series is based on next-20200605.

[1] https://lwn.net/ml/linux-kernel/cover.662a8d401787ef33780d91252a352de91dc4be10.1590594293.git-series.maxime@cerno.tech/

---

Nicolas Saenz Julienne (9):
  dt-bindings: reset: Add a binding for the RPi Firmware USB reset
  reset: Add Raspberry Pi 4 firmware USB reset controller
  ARM: dts: bcm2711: Add firmware usb reset node
  ARM: dts: bcm2711: Add reset controller to xHCI node
  usb: xhci-pci: Add support for reset controllers
  Revert "USB: pci-quirks: Add Raspberry Pi 4 quirk"
  usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4
  Revert "firmware: raspberrypi: Introduce vl805 init routine"
  Revert "PCI: brcmstb: Wait for Raspberry Pi's firmware when present"

 .../arm/bcm/raspberrypi,bcm2835-firmware.yaml |  21 +++
 arch/arm/boot/dts/bcm2711-rpi-4-b.dts         |  12 ++
 drivers/firmware/Kconfig                      |   3 +-
 drivers/firmware/raspberrypi.c                |  61 ---------
 drivers/pci/controller/pcie-brcmstb.c         |  17 ---
 drivers/reset/Kconfig                         |   9 ++
 drivers/reset/Makefile                        |   1 +
 drivers/reset/reset-raspberrypi-usb.c         | 122 ++++++++++++++++++
 drivers/usb/host/pci-quirks.c                 |  22 ++--
 drivers/usb/host/xhci-pci.c                   |   9 ++
 include/soc/bcm2835/raspberrypi-firmware.h    |   7 -
 11 files changed, 184 insertions(+), 100 deletions(-)
 create mode 100644 drivers/reset/reset-raspberrypi-usb.c

-- 
2.26.2


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

* [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 19:58   ` Florian Fainelli
  2020-06-08 19:26 ` [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller Nicolas Saenz Julienne
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Nicolas Saenz Julienne,
	Ray Jui, Scott Branden
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi, Rob Herring

The firmware running on the RPi VideoCore can be used to reset and
initialize the board's xHCI controller. The reset controller is passed
to the PCI device through the DT, hence this binding.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 .../arm/bcm/raspberrypi,bcm2835-firmware.yaml | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
index b48ed875eb8e..8f9d0986c28f 100644
--- a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
+++ b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
@@ -39,6 +39,22 @@ properties:
       - compatible
       - "#clock-cells"
 
+  usb-reset:
+    type: object
+
+    properties:
+      compatible:
+        const: raspberrypi,firmware-usb-reset
+
+      "#clock-cells":
+        const: 0
+        description: >
+          There is only one reset line available, so no need for cell decoding.
+
+    required:
+      - compatible
+      - "#reset-cells"
+
     additionalProperties: false
 
 required:
@@ -55,5 +71,10 @@ examples:
             compatible = "raspberrypi,firmware-clocks";
             #clock-cells = <1>;
         };
+
+        usb_reset: usb-reset {
+            compatible = "raspberrypi,firmware-usb-reset";
+            #reset-cells = <0>;
+        };
     };
 ...
-- 
2.26.2


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

* [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 20:13   ` Florian Fainelli
  2020-06-08 19:26 ` [PATCH 3/9] ARM: dts: bcm2711: Add firmware usb reset node Nicolas Saenz Julienne
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Philipp Zabel
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi,
	Nicolas Saenz Julienne

The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip
that implements the xHCI. After a PCI fundamental reset, VL805's
firmware may either be loaded directly from an EEPROM or, if not
present, by the SoC's co-processor, VideoCore. RPi4's VideoCore OS
contains both the non public firmware load logic and the VL805 firmware
blob.

We control this trough a reset controller device that's able to trigger
the aforementioned process when relevant.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/reset/Kconfig                 |   9 ++
 drivers/reset/Makefile                |   1 +
 drivers/reset/reset-raspberrypi-usb.c | 122 ++++++++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 drivers/reset/reset-raspberrypi-usb.c

diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index d9efbfd29646..80e07190cd04 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -140,6 +140,15 @@ config RESET_QCOM_PDC
 	  to control reset signals provided by PDC for Modem, Compute,
 	  Display, GPU, Debug, AOP, Sensors, Audio, SP and APPS.
 
+config RESET_RASPBERRYPI_USB
+	tristate "Raspberry Pi 4 USB Reset Driver"
+	depends on RASPBERRYPI_FIRMWARE || (RASPBERRYPI_FIRMWARE=n && COMPILE_TEST)
+	default USB_XHCI_PCI
+	help
+	  This driver provides support for resetting the USB HW available in
+	  the Raspberry Pi 4. This reset process is controlled by firmware
+	  through a custom interface (see drivers/firmware/raspberrypi.c).
+
 config RESET_SCMI
 	tristate "Reset driver controlled via ARM SCMI interface"
 	depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 249ed357c997..49cd2868c7ab 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
 obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o
 obj-$(CONFIG_RESET_QCOM_AOSS) += reset-qcom-aoss.o
 obj-$(CONFIG_RESET_QCOM_PDC) += reset-qcom-pdc.o
+obj-$(CONFIG_RESET_RASPBERRYPI_USB) += reset-raspberrypi-usb.o
 obj-$(CONFIG_RESET_SCMI) += reset-scmi.o
 obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o
 obj-$(CONFIG_RESET_STM32MP157) += reset-stm32mp1.o
diff --git a/drivers/reset/reset-raspberrypi-usb.c b/drivers/reset/reset-raspberrypi-usb.c
new file mode 100644
index 000000000000..e9a6e7018c6d
--- /dev/null
+++ b/drivers/reset/reset-raspberrypi-usb.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Raspberry Pi 4 USB reset driver
+ *
+ * The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip that
+ * implements xHCI. After a PCI reset, VL805's firmware may either be loaded
+ * directly from an EEPROM or, if not present, by the SoC's co-processor,
+ * VideoCore. rpi's VideoCore OS contains both the non public firmware load
+ * logic and the VL805 firmware blob. This driver triggers the aforementioned
+ * process.
+ *
+ * Copyright (C) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
+ */
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/reset-controller.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+struct rpi_usb_reset {
+	struct reset_controller_dev rcdev;
+	struct rpi_firmware *fw;
+};
+
+static inline
+struct rpi_usb_reset *to_rpi_usb(struct reset_controller_dev *rcdev)
+{
+	return container_of(rcdev, struct rpi_usb_reset, rcdev);
+}
+
+static int rpi_usb_reset_reset(struct reset_controller_dev *rcdev,
+				unsigned long id)
+{
+	struct rpi_usb_reset *priv = to_rpi_usb(rcdev);
+	u32 dev_addr;
+	int ret;
+
+	/*
+	 * The pci device address is expected like this:
+	 *
+	 * PCI_BUS << 20 | PCI_SLOT << 15 | PCI_FUNC << 12
+	 *
+	 * But since rpi's PCIe setup is hardwired, we know the address in
+	 * advance.
+	 */
+	dev_addr = 0x100000;
+	ret = rpi_firmware_property(priv->fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET,
+				    &dev_addr, sizeof(dev_addr));
+	if (ret)
+		return ret;
+
+	/* Wait for vl805 to startup */
+	usleep_range(200, 1000);
+
+	return 0;
+}
+
+static const struct reset_control_ops rpi_usb_reset_ops = {
+	.reset	= rpi_usb_reset_reset,
+};
+
+static int rpi_usb_reset_xlate(struct reset_controller_dev *rcdev,
+			       const struct of_phandle_args *reset_spec)
+{
+	/* This is needed if #reset-cells == 0. */
+	return 0;
+}
+
+static int rpi_usb_reset_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *fw_node;
+	struct rpi_usb_reset *priv;
+	struct rpi_firmware *fw;
+
+	fw_node = of_get_parent(dev->of_node);
+	if (!fw_node) {
+		dev_err(dev, "Missing firmware node\n");
+		return -ENOENT;
+	}
+
+	fw = rpi_firmware_get(fw_node);
+	of_node_put(fw_node);
+	if (!fw)
+		return -EPROBE_DEFER;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, priv);
+
+	priv->fw = fw;
+	priv->rcdev.owner = THIS_MODULE;
+	priv->rcdev.nr_resets = 1;
+	priv->rcdev.ops = &rpi_usb_reset_ops;
+	priv->rcdev.of_node = dev->of_node;
+	priv->rcdev.of_xlate = rpi_usb_reset_xlate;
+
+	return devm_reset_controller_register(dev, &priv->rcdev);
+}
+
+static const struct of_device_id rpi_usb_reset_of_match[] = {
+	{ .compatible = "raspberrypi,firmware-usb-reset" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, rpi_usb_reset_of_match);
+
+static struct platform_driver rpi_usb_reset_driver = {
+	.probe	= rpi_usb_reset_probe,
+	.driver	= {
+		.name = "raspberrypi-usb-reset",
+		.of_match_table = rpi_usb_reset_of_match,
+	},
+};
+module_platform_driver(rpi_usb_reset_driver);
+
+MODULE_AUTHOR("Nicolas Saenz Julienne <nsaenzjulienne@suse.de>");
+MODULE_DESCRIPTION("Raspberry Pi 4 USB reset driver");
+MODULE_LICENSE("GPL");
-- 
2.26.2


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

* [PATCH 3/9] ARM: dts: bcm2711: Add firmware usb reset node
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 4/9] ARM: dts: bcm2711: Add reset controller to xHCI node Nicolas Saenz Julienne
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Rob Herring,
	Nicolas Saenz Julienne
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi

Now that the reset driver exposing Raspberry Pi 4's firmware based USB
reset routine is available, let's add the device tree node exposing it.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 arch/arm/boot/dts/bcm2711-rpi-4-b.dts | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/bcm2711-rpi-4-b.dts b/arch/arm/boot/dts/bcm2711-rpi-4-b.dts
index c7f1d97e69bb..47e7c9c14ddf 100644
--- a/arch/arm/boot/dts/bcm2711-rpi-4-b.dts
+++ b/arch/arm/boot/dts/bcm2711-rpi-4-b.dts
@@ -83,6 +83,11 @@ expgpio: gpio {
 				  "";
 		status = "okay";
 	};
+
+	usb_reset: usb-reset {
+		compatible = "raspberrypi,firmware-usb-reset";
+		#reset-cells = <0>;
+	};
 };
 
 &gpio {
-- 
2.26.2


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

* [PATCH 4/9] ARM: dts: bcm2711: Add reset controller to xHCI node
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
                   ` (2 preceding siblings ...)
  2020-06-08 19:26 ` [PATCH 3/9] ARM: dts: bcm2711: Add firmware usb reset node Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 5/9] usb: xhci-pci: Add support for reset controllers Nicolas Saenz Julienne
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Rob Herring,
	Nicolas Saenz Julienne
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi

The chip is hardwired to the board's PCIe bus and needs to be properly
setup trough a firmware routine after a PCI fundamental reset. Pass the
reset controller phandle that takes care of triggering the
initialization to the relevant PCI device.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 arch/arm/boot/dts/bcm2711-rpi-4-b.dts | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/bcm2711-rpi-4-b.dts b/arch/arm/boot/dts/bcm2711-rpi-4-b.dts
index 47e7c9c14ddf..2646c858449f 100644
--- a/arch/arm/boot/dts/bcm2711-rpi-4-b.dts
+++ b/arch/arm/boot/dts/bcm2711-rpi-4-b.dts
@@ -207,6 +207,13 @@ phy1: ethernet-phy@1 {
 	};
 };
 
+&pcie0 {
+	usb@1,0 {
+		reg = <0 0 0 0 0>;
+		resets = <&usb_reset>;
+	};
+};
+
 /* uart0 communicates with the BT module */
 &uart0 {
 	pinctrl-names = "default";
-- 
2.26.2


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

* [PATCH 5/9] usb: xhci-pci: Add support for reset controllers
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
                   ` (3 preceding siblings ...)
  2020-06-08 19:26 ` [PATCH 4/9] ARM: dts: bcm2711: Add reset controller to xHCI node Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 19:43   ` Florian Fainelli
       [not found]   ` <CAHp75VdWq96SSzB1S9pM=H8=3np8-1Cep_9BqGiTCUTtCUt-yw@mail.gmail.com>
  2020-06-08 19:26 ` [PATCH 6/9] Revert "USB: pci-quirks: Add Raspberry Pi 4 quirk" Nicolas Saenz Julienne
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Mathias Nyman, Philipp Zabel
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi,
	Nicolas Saenz Julienne

Some atypical users of xhci-pci might need to manually reset their xHCI
controller before starting the HCD setup. Check if a reset controller
device is available to the PCI bus and trigger a reset.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/usb/host/xhci-pci.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index ef513c2fb843..45f70facdfcd 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/acpi.h>
+#include <linux/reset.h>
 
 #include "xhci.h"
 #include "xhci-trace.h"
@@ -339,6 +340,7 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	struct xhci_hcd *xhci;
 	struct usb_hcd *hcd;
 	struct xhci_driver_data *driver_data;
+	struct reset_control *reset;
 
 	driver_data = (struct xhci_driver_data *)id->driver_data;
 	if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
@@ -347,6 +349,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 			return retval;
 	}
 
+	reset = devm_reset_control_get(&dev->bus->dev, NULL);
+	if (IS_ERR(reset)) {
+		retval = PTR_ERR(reset);
+		return retval;
+	}
+	reset_control_reset(reset);
+
 	/* Prevent runtime suspending between USB-2 and USB-3 initialization */
 	pm_runtime_get_noresume(&dev->dev);
 
-- 
2.26.2


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

* [PATCH 6/9] Revert "USB: pci-quirks: Add Raspberry Pi 4 quirk"
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
                   ` (4 preceding siblings ...)
  2020-06-08 19:26 ` [PATCH 5/9] usb: xhci-pci: Add support for reset controllers Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 19:26 ` [PATCH 7/9] usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4 Nicolas Saenz Julienne
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Mathias Nyman
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi,
	Nicolas Saenz Julienne

This reverts commit c65822fef4adc0ba40c37a47337376ce75f7a7bc.

The initialization of Raspberry Pi 4's USB chip is now handled through a
reset controller. No need to directly call the firmware routine trough a
pci quirk.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/firmware/Kconfig      |  3 +--
 drivers/usb/host/pci-quirks.c | 16 ----------------
 2 files changed, 1 insertion(+), 18 deletions(-)

diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index fbd785dd0513..4843e94713a4 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -178,9 +178,8 @@ config ISCSI_IBFT
 	  Otherwise, say N.
 
 config RASPBERRYPI_FIRMWARE
-	bool "Raspberry Pi Firmware Driver"
+	tristate "Raspberry Pi Firmware Driver"
 	depends on BCM2835_MBOX
-	default USB_PCI
 	help
 	  This option enables support for communicating with the firmware on the
 	  Raspberry Pi.
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 0b949acfa258..92150ecdb036 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -16,9 +16,6 @@
 #include <linux/export.h>
 #include <linux/acpi.h>
 #include <linux/dmi.h>
-
-#include <soc/bcm2835/raspberrypi-firmware.h>
-
 #include "pci-quirks.h"
 #include "xhci-ext-caps.h"
 
@@ -1246,24 +1243,11 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 
 static void quirk_usb_early_handoff(struct pci_dev *pdev)
 {
-	int ret;
-
 	/* Skip Netlogic mips SoC's internal PCI USB controller.
 	 * This device does not need/support EHCI/OHCI handoff
 	 */
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
-
-	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) {
-		ret = rpi_firmware_init_vl805(pdev);
-		if (ret) {
-			/* Firmware might be outdated, or something failed */
-			dev_warn(&pdev->dev,
-				 "Failed to load VL805's firmware: %d. Will continue to attempt to work, but bad things might happen. You should fix this...\n",
-				 ret);
-		}
-	}
-
 	if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
 			pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
 			pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&
-- 
2.26.2


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

* [PATCH 7/9] usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
                   ` (5 preceding siblings ...)
  2020-06-08 19:26 ` [PATCH 6/9] Revert "USB: pci-quirks: Add Raspberry Pi 4 quirk" Nicolas Saenz Julienne
@ 2020-06-08 19:26 ` Nicolas Saenz Julienne
  2020-06-08 19:50   ` Florian Fainelli
  2020-06-08 19:27 ` [PATCH 8/9] Revert "firmware: raspberrypi: Introduce vl805 init routine" Nicolas Saenz Julienne
  2020-06-08 19:27 ` [PATCH 9/9] Revert "PCI: brcmstb: Wait for Raspberry Pi's firmware when present" Nicolas Saenz Julienne
  8 siblings, 1 reply; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:26 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Mathias Nyman
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi,
	Nicolas Saenz Julienne

The board doesn't need the quirks to be run, and takes case of its own
initialization trough a reset controller device. So let's bypass it
quirk.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/usb/host/pci-quirks.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 92150ecdb036..4b3be05d1290 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -16,6 +16,8 @@
 #include <linux/export.h>
 #include <linux/acpi.h>
 #include <linux/dmi.h>
+#include <linux/of.h>
+
 #include "pci-quirks.h"
 #include "xhci-ext-caps.h"
 
@@ -1248,6 +1250,16 @@ static void quirk_usb_early_handoff(struct pci_dev *pdev)
 	 */
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
+
+	/*
+	 * Bypass the Raspberry Pi 4 controller xHCI controller, things are
+	 * taken care by the board's co-processor.
+	 */
+	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483 &&
+	    of_device_is_compatible(of_get_parent(pdev->bus->dev.of_node),
+				    "brcm,bcm2711-pcie"))
+		return;
+
 	if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
 			pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
 			pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&
-- 
2.26.2


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

* [PATCH 8/9] Revert "firmware: raspberrypi: Introduce vl805 init routine"
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
                   ` (6 preceding siblings ...)
  2020-06-08 19:26 ` [PATCH 7/9] usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4 Nicolas Saenz Julienne
@ 2020-06-08 19:27 ` Nicolas Saenz Julienne
  2020-06-08 19:27 ` [PATCH 9/9] Revert "PCI: brcmstb: Wait for Raspberry Pi's firmware when present" Nicolas Saenz Julienne
  8 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:27 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Nicolas Saenz Julienne,
	Ray Jui, Scott Branden
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi

This reverts commit fbbc5ff3f7f9f4cad562e530ae2cf5d8964fe6d3.

The vl805 routine has moved to drivers/reset/reset-raspberrypi-usb.c

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/firmware/raspberrypi.c             | 61 ----------------------
 include/soc/bcm2835/raspberrypi-firmware.h |  7 ---
 2 files changed, 68 deletions(-)

diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index ef8098856a47..a3e85186f8e6 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -12,8 +12,6 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
-#include <linux/pci.h>
-#include <linux/delay.h>
 #include <soc/bcm2835/raspberrypi-firmware.h>
 
 #define MBOX_MSG(chan, data28)		(((data28) & ~0xf) | ((chan) & 0xf))
@@ -21,8 +19,6 @@
 #define MBOX_DATA28(msg)		((msg) & ~0xf)
 #define MBOX_CHAN_PROPERTY		8
 
-#define VL805_PCI_CONFIG_VERSION_OFFSET		0x50
-
 static struct platform_device *rpi_hwmon;
 static struct platform_device *rpi_clk;
 
@@ -284,63 +280,6 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
 }
 EXPORT_SYMBOL_GPL(rpi_firmware_get);
 
-/*
- * The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip that
- * implements xHCI. After a PCI reset, VL805's firmware may either be loaded
- * directly from an EEPROM or, if not present, by the SoC's co-processor,
- * VideoCore. RPi4's VideoCore OS contains both the non public firmware load
- * logic and the VL805 firmware blob. This function triggers the aforementioned
- * process.
- */
-int rpi_firmware_init_vl805(struct pci_dev *pdev)
-{
-	struct device_node *fw_np;
-	struct rpi_firmware *fw;
-	u32 dev_addr, version;
-	int ret;
-
-	fw_np = of_find_compatible_node(NULL, NULL,
-					"raspberrypi,bcm2835-firmware");
-	if (!fw_np)
-		return 0;
-
-	fw = rpi_firmware_get(fw_np);
-	of_node_put(fw_np);
-	if (!fw)
-		return -ENODEV;
-
-	/*
-	 * Make sure we don't trigger a firmware load unnecessarily.
-	 *
-	 * If something went wrong with PCI, this whole exercise would be
-	 * futile as VideoCore expects from us a configured PCI bus. Just take
-	 * the faulty version (likely ~0) and let xHCI's registration fail
-	 * further down the line.
-	 */
-	pci_read_config_dword(pdev, VL805_PCI_CONFIG_VERSION_OFFSET, &version);
-	if (version)
-		goto exit;
-
-	dev_addr = pdev->bus->number << 20 | PCI_SLOT(pdev->devfn) << 15 |
-		   PCI_FUNC(pdev->devfn) << 12;
-
-	ret = rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET,
-				    &dev_addr, sizeof(dev_addr));
-	if (ret)
-		return ret;
-
-	/* Wait for vl805 to startup */
-	usleep_range(200, 1000);
-
-	pci_read_config_dword(pdev, VL805_PCI_CONFIG_VERSION_OFFSET,
-			      &version);
-exit:
-	pci_info(pdev, "VL805 firmware version %08x\n", version);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(rpi_firmware_init_vl805);
-
 static const struct of_device_id rpi_firmware_of_match[] = {
 	{ .compatible = "raspberrypi,bcm2835-firmware", },
 	{},
diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index 3025aca3c358..cc9cdbc66403 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -10,7 +10,6 @@
 #include <linux/of_device.h>
 
 struct rpi_firmware;
-struct pci_dev;
 
 enum rpi_firmware_property_status {
 	RPI_FIRMWARE_STATUS_REQUEST = 0,
@@ -142,7 +141,6 @@ int rpi_firmware_property(struct rpi_firmware *fw,
 int rpi_firmware_property_list(struct rpi_firmware *fw,
 			       void *data, size_t tag_size);
 struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
-int rpi_firmware_init_vl805(struct pci_dev *pdev);
 #else
 static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
 					void *data, size_t len)
@@ -160,11 +158,6 @@ static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware
 {
 	return NULL;
 }
-
-static inline int rpi_firmware_init_vl805(struct pci_dev *pdev)
-{
-	return 0;
-}
 #endif
 
 #endif /* __SOC_RASPBERRY_FIRMWARE_H__ */
-- 
2.26.2


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

* [PATCH 9/9] Revert "PCI: brcmstb: Wait for Raspberry Pi's firmware when present"
  2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
                   ` (7 preceding siblings ...)
  2020-06-08 19:27 ` [PATCH 8/9] Revert "firmware: raspberrypi: Introduce vl805 init routine" Nicolas Saenz Julienne
@ 2020-06-08 19:27 ` Nicolas Saenz Julienne
  8 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-08 19:27 UTC (permalink / raw)
  To: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Nicolas Saenz Julienne,
	Lorenzo Pieralisi
  Cc: linux-kernel, tim.gover, helgaas, Bjorn Helgaas

This reverts commit 44331189f9082c7e659697bbac1747db3def73e7.

Now that the VL805 init routine is run through a reset controller driver
the dependencies are being taken care of by the device core. No need to
do it manually here.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/pci/controller/pcie-brcmstb.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
index 7730ea845ff2..752f5b331579 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -28,8 +28,6 @@
 #include <linux/string.h>
 #include <linux/types.h>
 
-#include <soc/bcm2835/raspberrypi-firmware.h>
-
 #include "../pci.h"
 
 /* BRCM_PCIE_CAP_REGS - Offset for the mandatory capability config regs */
@@ -931,26 +929,11 @@ static int brcm_pcie_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node, *msi_np;
 	struct pci_host_bridge *bridge;
-	struct device_node *fw_np;
 	struct brcm_pcie *pcie;
 	struct pci_bus *child;
 	struct resource *res;
 	int ret;
 
-	/*
-	 * We have to wait for Raspberry Pi's firmware interface to be up as a
-	 * PCI fixup, rpi_firmware_init_vl805(), depends on it. This driver's
-	 * probe can race with the firmware interface's (see
-	 * drivers/firmware/raspberrypi.c) and potentially break the PCI fixup.
-	 */
-	fw_np = of_find_compatible_node(NULL, NULL,
-					"raspberrypi,bcm2835-firmware");
-	if (fw_np && !rpi_firmware_get(fw_np)) {
-		of_node_put(fw_np);
-		return -EPROBE_DEFER;
-	}
-	of_node_put(fw_np);
-
 	bridge = devm_pci_alloc_host_bridge(&pdev->dev, sizeof(*pcie));
 	if (!bridge)
 		return -ENOMEM;
-- 
2.26.2


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

* Re: [PATCH 5/9] usb: xhci-pci: Add support for reset controllers
  2020-06-08 19:26 ` [PATCH 5/9] usb: xhci-pci: Add support for reset controllers Nicolas Saenz Julienne
@ 2020-06-08 19:43   ` Florian Fainelli
  2020-06-09 11:18     ` Nicolas Saenz Julienne
       [not found]   ` <CAHp75VdWq96SSzB1S9pM=H8=3np8-1Cep_9BqGiTCUTtCUt-yw@mail.gmail.com>
  1 sibling, 1 reply; 19+ messages in thread
From: Florian Fainelli @ 2020-06-08 19:43 UTC (permalink / raw)
  To: Nicolas Saenz Julienne, f.fainelli, gregkh, wahrenst, robh,
	mathias.nyman, Eric Anholt, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, devicetree, linux-pci,
	linux-usb, Mathias Nyman, Philipp Zabel
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi



On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> Some atypical users of xhci-pci might need to manually reset their xHCI
> controller before starting the HCD setup. Check if a reset controller
> device is available to the PCI bus and trigger a reset.
> 
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  drivers/usb/host/xhci-pci.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> index ef513c2fb843..45f70facdfcd 100644
> --- a/drivers/usb/host/xhci-pci.c
> +++ b/drivers/usb/host/xhci-pci.c
> @@ -12,6 +12,7 @@
>  #include <linux/slab.h>
>  #include <linux/module.h>
>  #include <linux/acpi.h>
> +#include <linux/reset.h>
>  
>  #include "xhci.h"
>  #include "xhci-trace.h"
> @@ -339,6 +340,7 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
>  	struct xhci_hcd *xhci;
>  	struct usb_hcd *hcd;
>  	struct xhci_driver_data *driver_data;
> +	struct reset_control *reset;
>  
>  	driver_data = (struct xhci_driver_data *)id->driver_data;
>  	if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
> @@ -347,6 +349,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
>  			return retval;
>  	}
>  
> +	reset = devm_reset_control_get(&dev->bus->dev, NULL);

Should not this be devm_reset_control_get_optional()?

> +	if (IS_ERR(reset)) {
> +		retval = PTR_ERR(reset);
> +		return retval;
> +	}
> +	reset_control_reset(reset);
> +
>  	/* Prevent runtime suspending between USB-2 and USB-3 initialization */
>  	pm_runtime_get_noresume(&dev->dev);
>  
> 

-- 
Florian

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

* Re: [PATCH 7/9] usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4
  2020-06-08 19:26 ` [PATCH 7/9] usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4 Nicolas Saenz Julienne
@ 2020-06-08 19:50   ` Florian Fainelli
  0 siblings, 0 replies; 19+ messages in thread
From: Florian Fainelli @ 2020-06-08 19:50 UTC (permalink / raw)
  To: Nicolas Saenz Julienne, f.fainelli, gregkh, wahrenst, robh,
	mathias.nyman, Eric Anholt, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, devicetree, linux-pci,
	linux-usb, Mathias Nyman
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi



On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> The board doesn't need the quirks to be run, and takes case of its own

(if you have to resubmit) takes care

> initialization trough a reset controller device. So let's bypass it

its quirk.

> quirk.
> 
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  drivers/usb/host/pci-quirks.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
> index 92150ecdb036..4b3be05d1290 100644
> --- a/drivers/usb/host/pci-quirks.c
> +++ b/drivers/usb/host/pci-quirks.c
> @@ -16,6 +16,8 @@
>  #include <linux/export.h>
>  #include <linux/acpi.h>
>  #include <linux/dmi.h>
> +#include <linux/of.h>
> +
>  #include "pci-quirks.h"
>  #include "xhci-ext-caps.h"
>  
> @@ -1248,6 +1250,16 @@ static void quirk_usb_early_handoff(struct pci_dev *pdev)
>  	 */
>  	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
>  		return;
> +
> +	/*
> +	 * Bypass the Raspberry Pi 4 controller xHCI controller, things are
> +	 * taken care by the board's co-processor.

taken care of by.

With that:

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

> +	 */
> +	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483 &&
> +	    of_device_is_compatible(of_get_parent(pdev->bus->dev.of_node),
> +				    "brcm,bcm2711-pcie"))
> +		return;
> +
>  	if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
>  			pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
>  			pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&
> 

-- 
Florian

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

* Re: [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset
  2020-06-08 19:26 ` [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset Nicolas Saenz Julienne
@ 2020-06-08 19:58   ` Florian Fainelli
  2020-06-09 11:14     ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 19+ messages in thread
From: Florian Fainelli @ 2020-06-08 19:58 UTC (permalink / raw)
  To: Nicolas Saenz Julienne, f.fainelli, gregkh, wahrenst, robh,
	mathias.nyman, Eric Anholt, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, devicetree, linux-pci,
	linux-usb, Ray Jui, Scott Branden
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi, Rob Herring



On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> The firmware running on the RPi VideoCore can be used to reset and
> initialize the board's xHCI controller. The reset controller is passed
> to the PCI device through the DT, hence this binding.
> 
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  .../arm/bcm/raspberrypi,bcm2835-firmware.yaml | 21 +++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
> index b48ed875eb8e..8f9d0986c28f 100644
> --- a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
> +++ b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
> @@ -39,6 +39,22 @@ properties:
>        - compatible
>        - "#clock-cells"
>  
> +  usb-reset:
> +    type: object
> +
> +    properties:
> +      compatible:
> +        const: raspberrypi,firmware-usb-reset

I would make this less USB centric, even if this is the only consumer of
the reset controller for now, there could, in premise be other blocks
that require a reset (e.g.: V3D) that would involve going to the VPU
firmware because of various requirements (security, register blocking etc.).

> +
> +      "#clock-cells":

Did not you mean #reset-cells here?


> +        const: 0
> +        description: >
> +          There is only one reset line available, so no need for cell decoding.
> +
> +    required:
> +      - compatible
> +      - "#reset-cells"
> +
>      additionalProperties: false
>  
>  required:
> @@ -55,5 +71,10 @@ examples:
>              compatible = "raspberrypi,firmware-clocks";
>              #clock-cells = <1>;
>          };
> +
> +        usb_reset: usb-reset {
> +            compatible = "raspberrypi,firmware-usb-reset";
> +            #reset-cells = <0>;
> +        };
>      };
>  ...
> 

-- 
Florian

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

* Re: [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller
  2020-06-08 19:26 ` [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller Nicolas Saenz Julienne
@ 2020-06-08 20:13   ` Florian Fainelli
  0 siblings, 0 replies; 19+ messages in thread
From: Florian Fainelli @ 2020-06-08 20:13 UTC (permalink / raw)
  To: Nicolas Saenz Julienne, f.fainelli, gregkh, wahrenst, robh,
	mathias.nyman, Eric Anholt, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, devicetree, linux-pci,
	linux-usb, Philipp Zabel
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi



On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip
> that implements the xHCI. After a PCI fundamental reset, VL805's
> firmware may either be loaded directly from an EEPROM or, if not
> present, by the SoC's co-processor, VideoCore. RPi4's VideoCore OS
> contains both the non public firmware load logic and the VL805 firmware
> blob.
> 
> We control this trough a reset controller device that's able to trigger
> the aforementioned process when relevant.
> 
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---

[snip]

> +static int rpi_usb_reset_reset(struct reset_controller_dev *rcdev,
> +				unsigned long id)
> +{
> +	struct rpi_usb_reset *priv = to_rpi_usb(rcdev);
> +	u32 dev_addr;
> +	int ret;
> +
> +	/*
> +	 * The pci device address is expected like this:
> +	 *
> +	 * PCI_BUS << 20 | PCI_SLOT << 15 | PCI_FUNC << 12
> +	 *
> +	 * But since rpi's PCIe setup is hardwired, we know the address in
> +	 * advance.
> +	 */
> +	dev_addr = 0x100000;

You could encode the device address as part of the reset identifier,
such that if we ever have more devices to reset, then we only need to
define new identifiers for them, and internally within your reset
controller provide you can resolve that reset identifier 0 is PCI_BUS <<
20 | PCI_SLOT << 15 | PCI_FUN << 12 for instance.

This would make your reset controller define a "#reset-cells" property
to 1 now, such that no further DT ABI breakage would occur if you were
to extend it later on.
-- 
Florian

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

* Re: [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset
  2020-06-08 19:58   ` Florian Fainelli
@ 2020-06-09 11:14     ` Nicolas Saenz Julienne
  0 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-09 11:14 UTC (permalink / raw)
  To: Florian Fainelli, gregkh, wahrenst, robh, mathias.nyman,
	Eric Anholt, bcm-kernel-feedback-list, linux-rpi-kernel,
	linux-arm-kernel, devicetree, linux-pci, linux-usb, Ray Jui,
	Scott Branden
  Cc: linux-kernel, tim.gover, helgaas, lorenzo.pieralisi, Rob Herring


[-- Attachment #1: Type: text/plain, Size: 1678 bytes --]

On Mon, 2020-06-08 at 12:58 -0700, Florian Fainelli wrote:
> 
> On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> > The firmware running on the RPi VideoCore can be used to reset and
> > initialize the board's xHCI controller. The reset controller is passed
> > to the PCI device through the DT, hence this binding.
> > 
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> >  .../arm/bcm/raspberrypi,bcm2835-firmware.yaml | 21 +++++++++++++++++++
> >  1 file changed, 21 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-
> > firmware.yaml
> > b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-
> > firmware.yaml
> > index b48ed875eb8e..8f9d0986c28f 100644
> > --- a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-
> > firmware.yaml
> > +++ b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-
> > firmware.yaml
> > @@ -39,6 +39,22 @@ properties:
> >        - compatible
> >        - "#clock-cells"
> >  
> > +  usb-reset:
> > +    type: object
> > +
> > +    properties:
> > +      compatible:
> > +        const: raspberrypi,firmware-usb-reset
> 
> I would make this less USB centric, even if this is the only consumer of
> the reset controller for now, there could, in premise be other blocks
> that require a reset (e.g.: V3D) that would involve going to the VPU
> firmware because of various requirements (security, register blocking etc.).

I like the idea, I'll introduce this in v2.

> > +
> > +      "#clock-cells":
> 
> Did not you mean #reset-cells here?
> 

Sorry I missed that.

Regards,
Nicolas


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 5/9] usb: xhci-pci: Add support for reset controllers
  2020-06-08 19:43   ` Florian Fainelli
@ 2020-06-09 11:18     ` Nicolas Saenz Julienne
  2020-06-09 11:59       ` Philipp Zabel
  0 siblings, 1 reply; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-09 11:18 UTC (permalink / raw)
  To: Florian Fainelli, gregkh, wahrenst, robh, mathias.nyman,
	Eric Anholt, bcm-kernel-feedback-list, linux-rpi-kernel,
	linux-arm-kernel, devicetree, linux-pci, linux-usb,
	Mathias Nyman, Philipp Zabel
  Cc: lorenzo.pieralisi, tim.gover, helgaas, linux-kernel


[-- Attachment #1: Type: text/plain, Size: 1934 bytes --]

Hi Florian, thanks for the reviews!

On Mon, 2020-06-08 at 12:43 -0700, Florian Fainelli wrote:
> 
> On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> > Some atypical users of xhci-pci might need to manually reset their xHCI
> > controller before starting the HCD setup. Check if a reset controller
> > device is available to the PCI bus and trigger a reset.
> > 
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> >  drivers/usb/host/xhci-pci.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> > index ef513c2fb843..45f70facdfcd 100644
> > --- a/drivers/usb/host/xhci-pci.c
> > +++ b/drivers/usb/host/xhci-pci.c
> > @@ -12,6 +12,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/module.h>
> >  #include <linux/acpi.h>
> > +#include <linux/reset.h>
> >  
> >  #include "xhci.h"
> >  #include "xhci-trace.h"
> > @@ -339,6 +340,7 @@ static int xhci_pci_probe(struct pci_dev *dev, const
> > struct pci_device_id *id)
> >  	struct xhci_hcd *xhci;
> >  	struct usb_hcd *hcd;
> >  	struct xhci_driver_data *driver_data;
> > +	struct reset_control *reset;
> >  
> >  	driver_data = (struct xhci_driver_data *)id->driver_data;
> >  	if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
> > @@ -347,6 +349,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const
> > struct pci_device_id *id)
> >  			return retval;
> >  	}
> >  
> > +	reset = devm_reset_control_get(&dev->bus->dev, NULL);
> 
> Should not this be devm_reset_control_get_optional()?

Yes, you're right.

Regards,
Nicolas

> > +	if (IS_ERR(reset)) {
> > +		retval = PTR_ERR(reset);
> > +		return retval;
> > +	}
> > +	reset_control_reset(reset);
> > +
> >  	/* Prevent runtime suspending between USB-2 and USB-3 initialization */
> >  	pm_runtime_get_noresume(&dev->dev);
> >  
> > 


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 5/9] usb: xhci-pci: Add support for reset controllers
       [not found]   ` <CAHp75VdWq96SSzB1S9pM=H8=3np8-1Cep_9BqGiTCUTtCUt-yw@mail.gmail.com>
@ 2020-06-09 11:19     ` Nicolas Saenz Julienne
  0 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-09 11:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: f.fainelli, gregkh, wahrenst, robh, mathias.nyman, Eric Anholt,
	bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel,
	devicetree, linux-pci, linux-usb, Mathias Nyman, Philipp Zabel,
	linux-kernel, tim.gover, helgaas, lorenzo.pieralisi


[-- Attachment #1: Type: text/plain, Size: 2090 bytes --]

On Mon, 2020-06-08 at 22:44 +0300, Andy Shevchenko wrote:
> 
> 
> On Monday, June 8, 2020, Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> wrote:
> > Some atypical users of xhci-pci might need to manually reset their xHCI
> > controller before starting the HCD setup. Check if a reset controller
> > device is available to the PCI bus and trigger a reset.
> > 
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> >  drivers/usb/host/xhci-pci.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> > index ef513c2fb843..45f70facdfcd 100644
> > --- a/drivers/usb/host/xhci-pci.c
> > +++ b/drivers/usb/host/xhci-pci.c
> > @@ -12,6 +12,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/module.h>
> >  #include <linux/acpi.h>
> > +#include <linux/reset.h>
> > 
> >  #include "xhci.h"
> >  #include "xhci-trace.h"
> > @@ -339,6 +340,7 @@ static int xhci_pci_probe(struct pci_dev *dev, const
> > struct pci_device_id *id)
> >         struct xhci_hcd *xhci;
> >         struct usb_hcd *hcd;
> >         struct xhci_driver_data *driver_data;
> > +       struct reset_control *reset;
> > 
> >         driver_data = (struct xhci_driver_data *)id->driver_data;
> >         if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
> > @@ -347,6 +349,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const
> > struct pci_device_id *id)
> >                         return retval;
> >         }
> > 
> > +       reset = devm_reset_control_get(&dev->bus->dev, NULL);
> 
>  
> > +       if (IS_ERR(reset)) {
> > +               retval = PTR_ERR(reset);
> > +               return retval;
> > +       }
> 
> These four can be two, we have too many LOCs in the kernel for no reason.

Noted

>  
> > +       reset_control_reset(reset);
> > +
> >         /* Prevent runtime suspending between USB-2 and USB-3 initialization
> > */
> >         pm_runtime_get_noresume(&dev->dev);
> >  
> > -- 
> > 2.26.2
> > 
> > 
> 
> 


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 5/9] usb: xhci-pci: Add support for reset controllers
  2020-06-09 11:18     ` Nicolas Saenz Julienne
@ 2020-06-09 11:59       ` Philipp Zabel
  2020-06-09 13:08         ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 19+ messages in thread
From: Philipp Zabel @ 2020-06-09 11:59 UTC (permalink / raw)
  To: Nicolas Saenz Julienne, Florian Fainelli, gregkh, wahrenst, robh,
	mathias.nyman, Eric Anholt, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, devicetree, linux-pci,
	linux-usb, Mathias Nyman
  Cc: lorenzo.pieralisi, tim.gover, helgaas, linux-kernel

Hi Nicolas,

On Tue, 2020-06-09 at 13:18 +0200, Nicolas Saenz Julienne wrote:
> Hi Florian, thanks for the reviews!
> 
> On Mon, 2020-06-08 at 12:43 -0700, Florian Fainelli wrote:
> > On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> > > Some atypical users of xhci-pci might need to manually reset their xHCI
> > > controller before starting the HCD setup. Check if a reset controller
> > > device is available to the PCI bus and trigger a reset.
> > > 
> > > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > > ---
> > >  drivers/usb/host/xhci-pci.c | 9 +++++++++
> > >  1 file changed, 9 insertions(+)
> > > 
> > > diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> > > index ef513c2fb843..45f70facdfcd 100644
> > > --- a/drivers/usb/host/xhci-pci.c
> > > +++ b/drivers/usb/host/xhci-pci.c
[...]
> > > @@ -347,6 +349,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const
> > > struct pci_device_id *id)
> > >  			return retval;
> > >  	}
> > >  
> > > +	reset = devm_reset_control_get(&dev->bus->dev, NULL);
> > 
> > Should not this be devm_reset_control_get_optional()?
> 
> Yes, you're right.

Please use devm_reset_control_get_optional_exclusive() while you're at
it.

regards
Philipp

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

* Re: [PATCH 5/9] usb: xhci-pci: Add support for reset controllers
  2020-06-09 11:59       ` Philipp Zabel
@ 2020-06-09 13:08         ` Nicolas Saenz Julienne
  0 siblings, 0 replies; 19+ messages in thread
From: Nicolas Saenz Julienne @ 2020-06-09 13:08 UTC (permalink / raw)
  To: Philipp Zabel, Florian Fainelli, gregkh, wahrenst, robh,
	mathias.nyman, Eric Anholt, bcm-kernel-feedback-list,
	linux-rpi-kernel, linux-arm-kernel, devicetree, linux-pci,
	linux-usb, Mathias Nyman
  Cc: lorenzo.pieralisi, tim.gover, helgaas, linux-kernel


[-- Attachment #1: Type: text/plain, Size: 1436 bytes --]

On Tue, 2020-06-09 at 13:59 +0200, Philipp Zabel wrote:
> Hi Nicolas,
> 
> 
> 
> On Tue, 2020-06-09 at 13:18 +0200, Nicolas Saenz Julienne wrote:
> 
> > Hi Florian, thanks for the reviews!
> > On Mon, 2020-06-08 at 12:43 -0700, Florian Fainelli wrote:
> > > On 6/8/2020 12:26 PM, Nicolas Saenz Julienne wrote:
> > > > Some atypical users of xhci-pci might need to manually reset their xHCI
> > > > controller before starting the HCD setup. Check if a reset controller
> > > > device is available to the PCI bus and trigger a reset.
> > > > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > > > ---
> > > >   drivers/usb/host/xhci-pci.c | 9 +++++++++
> > > >   1 file changed, 9 insertions(+)
> > > > diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> > > > index ef513c2fb843..45f70facdfcd 100644
> > > > --- a/drivers/usb/host/xhci-pci.c
> > > > +++ b/drivers/usb/host/xhci-pci.c
> 
> [...]
> 
> > > > @@ -347,6 +349,13 @@ static int xhci_pci_probe(struct pci_dev *dev,
> > > > const
> > > > struct pci_device_id *id)
> > > >                    return retval;
> > > >    }
> > > >   
> > > > + reset = devm_reset_control_get(&dev->bus->dev, NULL);
> > > Should not this be devm_reset_control_get_optional()?
> > Yes, you're right.
> 
> 
> Please use devm_reset_control_get_optional_exclusive() while you're at
> 
> it.
> 

Will do!

Regards,
Nicolas


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, back to index

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08 19:26 [PATCH 0/9] Raspberry Pi 4 USB firmware initialization rework Nicolas Saenz Julienne
2020-06-08 19:26 ` [PATCH 1/9] dt-bindings: reset: Add a binding for the RPi Firmware USB reset Nicolas Saenz Julienne
2020-06-08 19:58   ` Florian Fainelli
2020-06-09 11:14     ` Nicolas Saenz Julienne
2020-06-08 19:26 ` [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller Nicolas Saenz Julienne
2020-06-08 20:13   ` Florian Fainelli
2020-06-08 19:26 ` [PATCH 3/9] ARM: dts: bcm2711: Add firmware usb reset node Nicolas Saenz Julienne
2020-06-08 19:26 ` [PATCH 4/9] ARM: dts: bcm2711: Add reset controller to xHCI node Nicolas Saenz Julienne
2020-06-08 19:26 ` [PATCH 5/9] usb: xhci-pci: Add support for reset controllers Nicolas Saenz Julienne
2020-06-08 19:43   ` Florian Fainelli
2020-06-09 11:18     ` Nicolas Saenz Julienne
2020-06-09 11:59       ` Philipp Zabel
2020-06-09 13:08         ` Nicolas Saenz Julienne
     [not found]   ` <CAHp75VdWq96SSzB1S9pM=H8=3np8-1Cep_9BqGiTCUTtCUt-yw@mail.gmail.com>
2020-06-09 11:19     ` Nicolas Saenz Julienne
2020-06-08 19:26 ` [PATCH 6/9] Revert "USB: pci-quirks: Add Raspberry Pi 4 quirk" Nicolas Saenz Julienne
2020-06-08 19:26 ` [PATCH 7/9] usb: host: pci-quirks: Bypass xHCI quirks for Raspberry Pi 4 Nicolas Saenz Julienne
2020-06-08 19:50   ` Florian Fainelli
2020-06-08 19:27 ` [PATCH 8/9] Revert "firmware: raspberrypi: Introduce vl805 init routine" Nicolas Saenz Julienne
2020-06-08 19:27 ` [PATCH 9/9] Revert "PCI: brcmstb: Wait for Raspberry Pi's firmware when present" Nicolas Saenz Julienne

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git