Skip to contentSkip to conversation

PCI: brcmstb: Use "num-lanes" DT property if present

PATCH In review Jim Quinlan 3 participants 7 messages May 9, 2025 – May 16, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover PCI: brcmstb: Use "num-lanes" DT property if present

If present, grok the "num-lanes" DT property for Broadcom STB chips and configure accordingly.

Jim Quinlan (2):
dt-bindings: PCI: brcm,stb-pcie: Add num-lanes property
PCI: brcmstb: Use "num-lanes" DT property if present

 .../bindings/pci/brcm,stb-pcie.yaml           |  2 ++
 drivers/pci/controller/pcie-brcmstb.c         | 26 ++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

base-commit: 01f95500a162fca88cefab9ed64ceded5afabc12

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 dt-bindings: PCI: brcm,stb-pcie: Add num-lanes property

Add optional num-lanes property Broadcom STB PCIe host controllers.

---
 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +2 -0
index 29f0e1eb5096..f31d654ac3a0 100644
@@ -107,6 +107,8 @@ properties:
       - const: bridge
       - const: swinit
 
+  num-lanes: true
+
 required:
   - compatible
   - reg
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH 1/2] dt-bindings: PCI: brcm,stb-pcie: Add num-lanes property

In reply to Jim Quinlan
Quoted 13 lines · Jim Quinlan

Add optional num-lanes property Broadcom STB PCIe host controllers.

---
 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +0 -0
index 29f0e1eb5096..f31d654ac3a0 100644

Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml properties: · line 110

Quoted 4 lines
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +1 -0
@@ -107,6 +107,8 @@ properties:
       - const: bridge
       - const: swinit
 
+  num-lanes: true

Why do you need this? It is already allowed by the referenced schemas. Though maybe you don't support 16 lanes and need to limit this to something less? I would also set 'default' if you do that.

Rob

#4 lore raw

Re: [PATCH 1/2] dt-bindings: PCI: brcm,stb-pcie: Add num-lanes property

Quoted 18 lines · Rob Herring
Quoted 16 lines · Jim Quinlan

Add optional num-lanes property Broadcom STB PCIe host controllers.

---
 Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +0 -0
index 29f0e1eb5096..f31d654ac3a0 100644
@@ -107,6 +107,8 @@ properties:
       - const: bridge
       - const: swinit
 
Quoted 5 lines

Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml properties: · line 110

Quoted 1 line
Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +1 -0
+  num-lanes: true

Why do you need this? It is already allowed by the referenced schemas. Though maybe you don't support 16 lanes and need to limit this to something less? I would also set 'default' if you do that.

I just thought that if our driver actually did something with "num-lanes" -- most drivers do not -- then it should be mentioned in the YAML, even if "num-lanes" is pre-defined.

At any rate we cannot handle 16 lanes so I will add a "default" and "maximum".

Regards,
Jim Quinlan
Broadcom STB

Quoted 3 lines

Rob

#5 lore raw

PATCH 2/2 PCI: brcmstb: Use "num-lanes" DT property if present

In reply to Jim Quinlan

By default, we use automatic HW negotiation to ascertain the number of lanes of the PCIe connection. If the "num-lanes" DT property is present, assume that the chip's built-in capability information is incorrect or undesired, and use the specified value instead.

---
 drivers/pci/controller/pcie-brcmstb.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-brcmstb.c +25 -1
index e19628e13898..76fd4f515898 100644
@@ -46,6 +46,7 @@
 #define  PCIE_RC_CFG_PRIV1_ID_VAL3_CLASS_CODE_MASK	0xffffff
 
 #define PCIE_RC_CFG_PRIV1_LINK_CAPABILITY			0x04dc
+#define  PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_MAX_LINK_WIDTH_MASK	0x1f0
 #define  PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_ASPM_SUPPORT_MASK	0xc00
 
 #define PCIE_RC_CFG_PRIV1_ROOT_CAP			0x4f8
@@ -55,6 +56,9 @@
 #define PCIE_RC_DL_MDIO_WR_DATA				0x1104
 #define PCIE_RC_DL_MDIO_RD_DATA				0x1108
 
+#define PCIE_RC_PL_REG_PHY_CTL_1			0x1804
+#define  PCIE_RC_PL_REG_PHY_CTL_1_REG_P2_POWERDOWN_ENA_NOSYNC_MASK	0x8
+
 #define PCIE_RC_PL_PHY_CTL_15				0x184c
 #define  PCIE_RC_PL_PHY_CTL_15_DIS_PLL_PD_MASK		0x400000
 #define  PCIE_RC_PL_PHY_CTL_15_PM_CLK_PERIOD_MASK	0xff
@@ -1072,7 +1076,7 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie)
 	void __iomem *base = pcie->base;
 	struct pci_host_bridge *bridge;
 	struct resource_entry *entry;
-	u32 tmp, burst, aspm_support;
+	u32 tmp, burst, aspm_support, num_lanes, num_lanes_cap;
 	u8 num_out_wins = 0;
 	int num_inbound_wins = 0;
 	int memc, ret;
@@ -1180,6 +1184,26 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie)
 		PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_ASPM_SUPPORT_MASK);
 	writel(tmp, base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY);
 
+	/* 'tmp' still holds the contents of PRIV1_LINK_CAPABILITY */
+	num_lanes_cap = u32_get_bits(tmp, PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_MAX_LINK_WIDTH_MASK);
+	num_lanes = 0;
+	/*
+	 * Use automatic num-lanes HW negotiation by default.  If the
+	 * "num-lanes" DT property is present, assume that the chip's
+	 * built-in link width capability information is
+	 * incorrect/undesired and use the specified value instead.
+	 */
+	if (!of_property_read_u32(pcie->np, "num-lanes", &num_lanes) &&
+	    num_lanes && num_lanes_cap != num_lanes) {
+		u32p_replace_bits(&tmp, num_lanes,
+			PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_MAX_LINK_WIDTH_MASK);
+		writel(tmp, base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY);
+		tmp = readl(base + PCIE_RC_PL_REG_PHY_CTL_1);
+		u32p_replace_bits(&tmp, 1,
+			PCIE_RC_PL_REG_PHY_CTL_1_REG_P2_POWERDOWN_ENA_NOSYNC_MASK);
+		writel(tmp, base + PCIE_RC_PL_REG_PHY_CTL_1);
+	}
+
 	/*
 	 * For config space accesses on the RC, show the right class for
 	 * a PCIe-PCIe bridge (the default setting is to be EP mode).
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 2/2
#6 lore raw
Quoted 6 lines · Jim Quinlan

By default, we use automatic HW negotiation to ascertain the number of lanes of the PCIe connection. If the "num-lanes" DT property is present, assume that the chip's built-in capability information is incorrect or undesired, and use the specified value instead.

Signature · 1 line
Florian