From: Sean Anderson <sean.anderson@linux.dev>
To: "Manivannan Sadhasivam" <mani@kernel.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Bartosz Golaszewski" <brgl@kernel.org>
Cc: linux-pci@vger.kernel.org, Chen-Yu Tsai <wenst@chromium.org>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
Brian Norris <briannorris@chromium.org>,
Niklas Cassel <cassel@kernel.org>, Chen-Yu Tsai <wens@kernel.org>,
Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>,
Alex Elder <elder@riscstar.com>,
Sean Anderson <sean.anderson@linux.dev>
Subject: [PATCH 3/3] PCI/pwrctrl: Support PERST GPIO in slot driver
Date: Fri, 19 Dec 2025 12:22:22 -0500 [thread overview]
Message-ID: <20251219172222.2808195-3-sean.anderson@linux.dev> (raw)
In-Reply-To: <20251219172222.2808195-1-sean.anderson@linux.dev>
On many embedded platforms PERST is controlled by a GPIO. This was
traditionally handled by the host bridge. However, PERST may be released
before slot resources are initialized if there is a pwrctrl device. To
ensure we follow the power sequence, add support for controlling PERST
to the slot driver.
The host bridge could have already grabbed the GPIO. If this happens the
power sequence might be violated but there's really nothing we can do so
we just ignore the GPIO.
PERST must be asserted for at least T_PERST, such as when
entering/exiting S3/S4. As an optimization, we skip this delay when
PERST was already asserted, which may be the case when booting (such as
if the system has a pull-down on the line).
If the link is already up (e.g. the bootloader configured the power
supplies, clocks, and PERST) we will reset the link anyway. I don't
really know how to avoid this. I think we're OK because the root port
will be probed before we probe the endpoint so we shouldn't reset the
link while we're reading the configuration space.
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---
drivers/pci/pwrctrl/slot.c | 52 +++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pwrctrl/slot.c b/drivers/pci/pwrctrl/slot.c
index 1c56fcd49f2b..59dc92c4bc04 100644
--- a/drivers/pci/pwrctrl/slot.c
+++ b/drivers/pci/pwrctrl/slot.c
@@ -7,6 +7,7 @@
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/device.h>
+#include <linux/gpio/consumer.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/pci-pwrctrl.h>
@@ -18,6 +19,7 @@ struct pci_pwrctrl_slot_data {
struct pci_pwrctrl ctx;
struct regulator_bulk_data *supplies;
int num_supplies;
+ struct gpio_desc *perst;
};
static void devm_pci_pwrctrl_slot_power_off(void *data)
@@ -28,6 +30,13 @@ static void devm_pci_pwrctrl_slot_power_off(void *data)
regulator_bulk_free(slot->num_supplies, slot->supplies);
}
+static void devm_pci_pwrctrl_slot_assert_perst(void *data)
+{
+ struct pci_pwrctrl_slot_data *slot = data;
+
+ gpiod_set_value_cansleep(slot->perst, 1);
+}
+
static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
{
struct pci_pwrctrl_slot_data *slot;
@@ -66,6 +75,14 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
"Failed to enable slot clock\n");
}
+ slot->perst = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
+ if (IS_ERR(slot->perst)) {
+ /* The PCIe host bridge may have already grabbed the reset */
+ if (PTR_ERR(slot->perst) != -EBUSY)
+ return dev_err_probe(dev, ret, "failed to get PERST\n");
+ slot->perst = NULL;
+ }
+
if (slot->num_supplies)
/*
* Delay for T_PVPERL. This could be reduced to 1 ms/50 ms
@@ -76,7 +93,40 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
/* Delay for T_PERST-CLK (100 us for all slot types) */
delay = 100;
- fsleep(delay)
+ if (slot->perst) {
+ /*
+ * If PERST is inactive, the following call to
+ * gpiod_direction_output will be the first time we assert it
+ * and we will need to delay for T_PERST.
+ */
+ if (gpiod_get_value_cansleep(slot->perst) != 1)
+ delay = 100000;
+
+ ret = gpiod_direction_output(slot->perst, 1);
+ if (ret) {
+ dev_err(dev, "failed to assert PERST\n");
+ return ret;
+ }
+ }
+
+ fsleep(delay);
+ if (slot->perst) {
+ gpiod_set_value(slot->perst, 0);
+ ret = devm_add_action_or_reset(dev,
+ devm_pci_pwrctrl_slot_assert_perst,
+ slot);
+ if (ret)
+ return ret;
+
+ /*
+ * PCIe section 6.6.1:
+ * > ... software must wait a minimum of 100 ms before sending a
+ * > Configuration Request to the device immediately below that
+ * > Port.
+ */
+ msleep(100);
+ }
+
pci_pwrctrl_init(&slot->ctx, dev);
ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->ctx);
--
2.35.1.1320.gc452695387.dirty
next prev parent reply other threads:[~2025-12-19 17:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 12:51 [PATCH v2 0/5] PCI/pwrctrl: Major rework to integrate pwrctrl devices with controller drivers Manivannan Sadhasivam
2025-12-16 12:51 ` [PATCH v2 1/5] PCI: qcom: Parse PERST# from all PCIe bridge nodes Manivannan Sadhasivam
2025-12-26 23:24 ` Bjorn Helgaas
2025-12-27 4:42 ` Manivannan Sadhasivam
2025-12-16 12:51 ` [PATCH v2 2/5] PCI/pwrctrl: Add 'struct pci_pwrctrl::power_{on/off}' callbacks Manivannan Sadhasivam
2025-12-16 12:51 ` [PATCH v2 3/5] PCI/pwrctrl: Add APIs for explicitly creating and destroying pwrctrl devices Manivannan Sadhasivam
2025-12-16 12:51 ` [PATCH v2 4/5] PCI/pwrctrl: Add APIs to power on/off the " Manivannan Sadhasivam
2025-12-16 12:51 ` [PATCH v2 5/5] PCI/pwrctrl: Switch to the new pwrctrl APIs Manivannan Sadhasivam
2025-12-19 18:35 ` Sean Anderson
2025-12-23 14:11 ` Manivannan Sadhasivam
2025-12-26 23:07 ` Bjorn Helgaas
2025-12-27 4:44 ` Manivannan Sadhasivam
2025-12-18 6:13 ` (subset) [PATCH v2 0/5] PCI/pwrctrl: Major rework to integrate pwrctrl devices with controller drivers Manivannan Sadhasivam
2025-12-19 17:19 ` Sean Anderson
2025-12-19 17:22 ` [PATCH 1/3] PCI/pwrctrl: Bind a pwrctrl device if clocks are present Sean Anderson
2025-12-19 17:22 ` [PATCH 2/3] PCI/pwrctrl: Add appropriate delays for slot power/clocks Sean Anderson
2025-12-19 17:22 ` Sean Anderson [this message]
2026-01-02 9:52 ` [PATCH 1/3] PCI/pwrctrl: Bind a pwrctrl device if clocks are present Bartosz Golaszewski
2025-12-23 14:05 ` [PATCH v2 0/5] PCI/pwrctrl: Major rework to integrate pwrctrl devices with controller drivers Manivannan Sadhasivam
2026-01-05 15:01 ` Sean Anderson
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=20251219172222.2808195-3-sean.anderson@linux.dev \
--to=sean.anderson@linux.dev \
--cc=bartosz.golaszewski@linaro.org \
--cc=bhelgaas@google.com \
--cc=brgl@kernel.org \
--cc=briannorris@chromium.org \
--cc=cassel@kernel.org \
--cc=elder@riscstar.com \
--cc=krishna.chundru@oss.qualcomm.com \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=manivannan.sadhasivam@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=wens@kernel.org \
--cc=wenst@chromium.org \
/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