[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250819-pci-pwrctrl-perst-v1-6-4b74978d2007@oss.qualcomm.com>
Date: Tue, 19 Aug 2025 12:44:55 +0530
From: Manivannan Sadhasivam via B4 Relay <devnull+manivannan.sadhasivam.oss.qualcomm.com@...nel.org>
To: Manivannan Sadhasivam <mani@...nel.org>,
Lorenzo Pieralisi <lpieralisi@...nel.org>,
Krzysztof WilczyĆski <kwilczynski@...nel.org>,
Rob Herring <robh@...nel.org>, Bjorn Helgaas <bhelgaas@...gle.com>,
Bartosz Golaszewski <brgl@...ev.pl>, Saravana Kannan <saravanak@...gle.com>
Cc: linux-pci@...r.kernel.org, linux-arm-msm@...r.kernel.org,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
Krishna Chaitanya Chundru <krishna.chundru@....qualcomm.com>,
Brian Norris <briannorris@...omium.org>,
Manivannan Sadhasivam <manivannan.sadhasivam@....qualcomm.com>
Subject: [PATCH 6/6] PCI: qcom: Allow pwrctrl core to toggle PERST# for new
DT binding
From: Manivannan Sadhasivam <manivannan.sadhasivam@....qualcomm.com>
If the platform is using the new DT binding, let the pwrctrl core toggle
PERST# for the device. This is achieved by populating the
'pci_host_bridge::toggle_perst' callback with qcom_pcie_toggle_perst().
qcom_pcie_toggle_perst() will find the PERST# GPIO descriptor associated
with the supplied 'device_node' and toggle PERST#. If PERST# is not found
in the supplied node, the function will look for PERST# in the parent node
as a fallback. This is needed since PERST# won't be available in the
endpoint node as per the DT binding.
Note that the driver still asserts PERST# during the controller
initialization as it is needed as per the hardware documentation. Apart
from that, the driver wouldn't touch PERST# for the new binding.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@....qualcomm.com>
---
drivers/pci/controller/dwc/pcie-qcom.c | 70 +++++++++++++++++++++++++++++-----
1 file changed, 61 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
index 5d73c46095af3219687ff77e5922f08bb41e43a9..fd07cd493f9fb974acfc924778c7a5e980630ae6 100644
--- a/drivers/pci/controller/dwc/pcie-qcom.c
+++ b/drivers/pci/controller/dwc/pcie-qcom.c
@@ -294,12 +294,44 @@ struct qcom_pcie {
#define to_qcom_pcie(x) dev_get_drvdata((x)->dev)
-static void qcom_perst_assert(struct qcom_pcie *pcie, bool assert)
+static void qcom_toggle_perst_per_device(struct qcom_pcie *pcie,
+ struct device_node *np, int val)
+{
+ struct gpio_desc *perst;
+ int bdf;
+
+ bdf = of_pci_get_bdf(np);
+ if (bdf < 0)
+ return;
+
+ perst = idr_find(&pcie->perst, bdf);
+ if (perst)
+ goto toggle_perst;
+
+ /*
+ * If PERST# is not available in the current node, try the parent. This
+ * fallback is needed if the current node belongs to an endpoint.
+ */
+ bdf = of_pci_get_bdf(np->parent);
+ if (bdf < 0)
+ return;
+
+ perst = idr_find(&pcie->perst, bdf);
+toggle_perst:
+ /* gpiod* APIs handle NULL gpio_desc gracefully. So no need to check. */
+ gpiod_set_value_cansleep(perst, val);
+}
+
+static void qcom_perst_assert(struct qcom_pcie *pcie, struct device_node *np,
+ bool assert)
{
int val = assert ? 1 : 0;
struct gpio_desc *perst;
int bdf;
+ if (np)
+ return qcom_toggle_perst_per_device(pcie, np, val);
+
if (idr_is_empty(&pcie->perst))
gpiod_set_value_cansleep(pcie->reset, val);
@@ -307,22 +339,34 @@ static void qcom_perst_assert(struct qcom_pcie *pcie, bool assert)
gpiod_set_value_cansleep(perst, val);
}
-static void qcom_ep_reset_assert(struct qcom_pcie *pcie)
+static void qcom_ep_reset_assert(struct qcom_pcie *pcie, struct device_node *np)
{
- qcom_perst_assert(pcie, true);
+ qcom_perst_assert(pcie, np, true);
usleep_range(PERST_DELAY_US, PERST_DELAY_US + 500);
}
-static void qcom_ep_reset_deassert(struct qcom_pcie *pcie)
+static void qcom_ep_reset_deassert(struct qcom_pcie *pcie,
+ struct device_node *np)
{
struct dw_pcie_rp *pp = &pcie->pci->pp;
msleep(PCIE_T_PVPERL_MS);
- qcom_perst_assert(pcie, false);
+ qcom_perst_assert(pcie, np, false);
if (!pp->use_linkup_irq)
msleep(PCIE_RESET_CONFIG_WAIT_MS);
}
+static void qcom_pcie_toggle_perst(struct pci_host_bridge *bridge,
+ struct device_node *np, bool assert)
+{
+ struct qcom_pcie *pcie = dev_get_drvdata(bridge->dev.parent);
+
+ if (assert)
+ qcom_ep_reset_assert(pcie, np);
+ else
+ qcom_ep_reset_deassert(pcie, np);
+}
+
static int qcom_pcie_start_link(struct dw_pcie *pci)
{
struct qcom_pcie *pcie = to_qcom_pcie(pci);
@@ -1317,7 +1361,7 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)
struct qcom_pcie *pcie = to_qcom_pcie(pci);
int ret;
- qcom_ep_reset_assert(pcie);
+ qcom_ep_reset_assert(pcie, NULL);
ret = pcie->cfg->ops->init(pcie);
if (ret)
@@ -1333,7 +1377,13 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)
goto err_disable_phy;
}
- qcom_ep_reset_deassert(pcie);
+ /*
+ * Only deassert PERST# for all devices here if legacy binding is used.
+ * For the new binding, pwrctrl driver is expected to toggle PERST# for
+ * individual devices.
+ */
+ if (idr_is_empty(&pcie->perst))
+ qcom_ep_reset_deassert(pcie, NULL);
if (pcie->cfg->ops->config_sid) {
ret = pcie->cfg->ops->config_sid(pcie);
@@ -1341,10 +1391,12 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)
goto err_assert_reset;
}
+ pci->pp.bridge->toggle_perst = qcom_pcie_toggle_perst;
+
return 0;
err_assert_reset:
- qcom_ep_reset_assert(pcie);
+ qcom_ep_reset_assert(pcie, NULL);
err_disable_phy:
qcom_pcie_phy_power_off(pcie);
err_deinit:
@@ -1358,7 +1410,7 @@ static void qcom_pcie_host_deinit(struct dw_pcie_rp *pp)
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
struct qcom_pcie *pcie = to_qcom_pcie(pci);
- qcom_ep_reset_assert(pcie);
+ qcom_ep_reset_assert(pcie, NULL);
qcom_pcie_phy_power_off(pcie);
pcie->cfg->ops->deinit(pcie);
}
--
2.45.2
Powered by blists - more mailing lists