linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: f.fainelli@gmail.com, gregkh@linuxfoundation.org,
	wahrenst@gmx.net, robh@kernel.org, mathias.nyman@linux.intel.com,
	Eric Anholt <eric@anholt.net>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-usb@vger.kernel.org,
	Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-kernel@vger.kernel.org, tim.gover@raspberrypi.org,
	helgaas@kernel.org, lorenzo.pieralisi@arm.com,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller
Date: Mon,  8 Jun 2020 21:26:54 +0200	[thread overview]
Message-ID: <20200608192701.18355-3-nsaenzjulienne@suse.de> (raw)
In-Reply-To: <20200608192701.18355-1-nsaenzjulienne@suse.de>

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


  parent reply	other threads:[~2020-06-08 19:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Nicolas Saenz Julienne [this message]
2020-06-08 20:13   ` [PATCH 2/9] reset: Add Raspberry Pi 4 firmware USB reset controller 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200608192701.18355-3-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=helgaas@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mathias.nyman@linux.intel.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=tim.gover@raspberrypi.org \
    --cc=wahrenst@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).