All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] PCI: apple: Follow the PCIe specifications when resetting the port
@ 2021-11-22 10:41 ` Marc Zyngier
  0 siblings, 0 replies; 22+ messages in thread
From: Marc Zyngier @ 2021-11-22 10:41 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-pci
  Cc: kernel-team, Alyssa Rosenzweig, Lorenzo Pieralisi, Bjorn Helgaas,
	Pali Rohár

While the Apple PCIe driver works correctly when directly booted
from the firmware, it fails to initialise when the kernel is booted
from a bootloader using PCIe such as u-boot.

That's beacuse we're missing a proper reset of the port (we only
clear the reset, but never assert it).

The PCIe spec requirements are two-fold:

- #PERST must be asserted before setting up the clocks, and
  stay asserted for at least 100us (Tperst-clk).

- Once #PERST is deasserted, the OS must wait for at least 100ms
  "from the end of a Conventional Reset" before we can start talking
  to the devices

Implementing this results in a booting system.

Fixes: 1e33888fbe44 ("PCI: apple: Add initial hardware bring-up")
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Pali Rohár <pali@kernel.org>
---
 drivers/pci/controller/pcie-apple.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index 1bf4d75b61be..957960a733c4 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -539,13 +539,23 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 
 	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
 
+	/* Engage #PERST before setting up the clock */
+	gpiod_set_value(reset, 0);
+
 	ret = apple_pcie_setup_refclk(pcie, port);
 	if (ret < 0)
 		return ret;
 
+	/* The minimal Tperst-clk value is 100us (PCIe CMS r2.0, 2.6.2) */
+	usleep_range(100, 200);
+
+	/* Deassert #PERST */
 	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
 	gpiod_set_value(reset, 1);
 
+	/* Wait for 100ms after #PERST deassertion (PCIe r2.0, 6.6.1) */
+	msleep(100);
+
 	ret = readl_relaxed_poll_timeout(port->base + PORT_STATUS, stat,
 					 stat & PORT_STATUS_READY, 100, 250000);
 	if (ret < 0) {
-- 
2.30.2


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

end of thread, other threads:[~2021-11-23 13:21 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 10:41 [PATCH v2] PCI: apple: Follow the PCIe specifications when resetting the port Marc Zyngier
2021-11-22 10:41 ` Marc Zyngier
2021-11-22 12:03 ` Pali Rohár
2021-11-22 12:03   ` Pali Rohár
2021-11-22 14:43   ` Marc Zyngier
2021-11-22 14:43     ` Marc Zyngier
2021-11-22 21:32     ` Luca Ceresoli
2021-11-22 21:32       ` Luca Ceresoli
2021-11-23  8:48       ` Marc Zyngier
2021-11-23  8:48         ` Marc Zyngier
2021-11-23 12:27         ` Mark Kettenis
2021-11-23 12:27           ` Mark Kettenis
2021-11-22 21:50     ` Mark Kettenis
2021-11-22 21:50       ` Mark Kettenis
2021-11-23 12:24       ` Marc Zyngier
2021-11-23 12:24         ` Marc Zyngier
2021-11-23 12:27         ` Pali Rohár
2021-11-23 12:27           ` Pali Rohár
2021-11-23 13:09           ` Marc Zyngier
2021-11-23 13:09             ` Marc Zyngier
2021-11-23 12:49         ` Mark Kettenis
2021-11-23 12:49           ` Mark Kettenis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.