[PATCH v2 2/3] PCI: cadence: Add cdns_pcie_get_pcie_cap() helper and cache capability offset

From: Hans Zhang

Date: Sat May 09 2026 - 09:08:23 EST


Add a helper cdns_pcie_get_pcie_cap() that finds and caches the
PCIe Capability offset in struct cdns_pcie::pcie_cap. This avoids
repeated searches and follows the pattern used in other PCIe drivers.

The helper uses cdns_pcie_find_capability() to locate PCI_CAP_ID_EXP
and stores the result for later use.

This is a preparatory step for removing the hardcoded capability
offset from host driver code.

Signed-off-by: Hans Zhang <18255117159@xxxxxxx>
---
drivers/pci/controller/cadence/pcie-cadence.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h
index c057f4b393e6..bbd275193bc1 100644
--- a/drivers/pci/controller/cadence/pcie-cadence.h
+++ b/drivers/pci/controller/cadence/pcie-cadence.h
@@ -219,6 +219,7 @@ struct cdns_plat_pcie_of_data {
* wrapper
* @cdns_pcie_reg_offsets: Register bank offsets for different SoC
* @debug_dir: debugfs node
+ * @pcie_cap: PCIe capability offset
*/
struct cdns_pcie {
void __iomem *reg_base;
@@ -233,6 +234,7 @@ struct cdns_pcie {
const struct cdns_pcie_ops *ops;
const struct cdns_plat_pcie_of_data *cdns_pcie_reg_offsets;
struct dentry *debug_dir;
+ u8 pcie_cap;
};

/**
@@ -651,6 +653,22 @@ static inline int cdns_pcie_hpa_ep_setup(struct cdns_pcie_ep *ep)

u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap);
u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap);
+
+/**
+ * cdns_pcie_get_pcie_cap() - Return cached PCIe Capability offset
+ * @pcie: Cadence PCIe instance
+ *
+ * Finds and caches the offset of PCI_CAP_ID_EXP on first call.
+ * Returns 0 if the capability is not present.
+ */
+static inline u8 cdns_pcie_get_pcie_cap(struct cdns_pcie *pcie)
+{
+ if (!pcie->pcie_cap)
+ pcie->pcie_cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_EXP);
+
+ return pcie->pcie_cap;
+}
+
bool cdns_pcie_linkup(struct cdns_pcie *pcie);

void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie);
--
2.34.1