Skip to contentSkip to conversation

dt-bindings: PCI: mediatek: Add support for optional perstout reset

PATCH In review Christian Marangi 3 participants 5 messages Jul 8 – Jul 16

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

PATCH 1/2 dt-bindings: PCI: mediatek: Add support for optional perstout reset

Airoha AN7583 have a dedicated reset for PCIe PERSTOUT. Add optional support for it in schema.

---
 .../devicetree/bindings/pci/mediatek-pcie.yaml       | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +10 -2
index c009a7a52bc6..cc5400c26185 100644
@@ -43,10 +43,12 @@ properties:
       - enum: [ pipe_ck0, pipe_ck1 ]
 
   resets:
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
 
   reset-names:
-    const: pcie-rst1
+    minItems: 1
+    maxItems: 2
 
   interrupts:
     maxItems: 1
@@ -127,6 +129,12 @@ allOf:
         phy-names:
           const: pcie-phy1
 
+        resets-names:
+          minItems: 1
+          items:
+            - const: pcie-rst1
+            - const: pcie-perstout1
+
         power-domain: false
 
       required:
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 PCI: mediatek: handle optional reset for perstout for AN7583

The Airoha AN7583 provide the perstout via a dedicated reset line as using the PCIe register is not possible as it will cause glitch.

Add support for it via the additional reset name pcie-perstout[slot] and assert/deassert on an7583 specific startup.

---
 drivers/pci/controller/pcie-mediatek.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pci/controller/pcie-mediatek.c +10 -0
index 8b57c3d75b94..3d4de9d69407 100644
@@ -175,6 +175,7 @@ struct mtk_pcie_soc {
  * @phys_base: Physical address of the I/O register base region
  * @list: port list
  * @pcie: pointer to PCIe host info
+ * @perstout_reset: pointer to port perstout reset control
  * @reset: pointer to port reset control
  * @sys_ck: pointer to transaction/data link layer clock
  * @ahb_ck: pointer to AHB slave interface operating clock for CSR access
@@ -198,6 +199,7 @@ struct mtk_pcie_port {
 	struct list_head list;
 	struct mtk_pcie *pcie;
 	struct reset_control *reset;
+	struct reset_control *perstout_reset;
 	struct clk *sys_ck;
 	struct clk *ahb_ck;
 	struct clk *axi_ck;
@@ -865,6 +867,9 @@ static int mtk_pcie_startup_port_an7583(struct mtk_pcie_port *port)
 	size = lower_32_bits(resource_size(entry->res));
 	regmap_write(pbus_regmap, args[1], GENMASK(31, __fls(size)));
 
+	reset_control_assert(port->perstout_reset);
+	reset_control_deassert(port->perstout_reset);
+
 	return mtk_pcie_startup_port_v2(port);
 }
 
@@ -1020,6 +1025,11 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,
 	if (PTR_ERR(port->reset) == -EPROBE_DEFER)
 		return PTR_ERR(port->reset);
 
+	snprintf(name, sizeof(name), "pcie-perstout%d", slot);
+	port->perstout_reset = devm_reset_control_get_optional_exclusive(dev, name);
+	if (PTR_ERR(port->perstout_reset) == -EPROBE_DEFER)
+		return PTR_ERR(port->perstout_reset);
+
 	/* some platforms may use default PHY setting */
 	snprintf(name, sizeof(name), "pcie-phy%d", slot);
 	port->phy = devm_phy_optional_get(dev, name);
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 2/2] PCI: mediatek: handle optional reset for perstout for AN7583

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing T_PERST delay between PCIe PERST# assert and deassert. - [Medium] Fails to handle…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing T_PERST delay between PCIe PERST# assert and deassert.
- [Medium] Fails to handle non-EPROBE_DEFER error pointers from devm_reset_control_get_optional_exclusive(). --

--- Patch [2]: [PATCH 2/2] PCI: mediatek: handle optional reset for perstout for AN7583 --- commit 78554414cf365c230ecb9c4411ea14d8c699dd5c
Author: Christian Marangi <[email protected]>

PCI: mediatek: handle optional reset for perstout for AN7583

The commit adds support for a dedicated perstout reset line for the Airoha AN7583 SoC to avoid glitches. It introduces the pcie-perstout[slot] reset name handling and asserts/deasserts it during AN7583 specific startup.

Quoted 4 lines
drivers/pci/controller/pcie-mediatek.c +0 -0
index 8b57c3d75b942..3d4de9d694071 100644

[ ... ]

drivers/pci/controller/pcie-mediatek.c static int mtk_pcie_startup_port_an7583(struct mtk_pcie_port *port) · line 871

Quoted 6 lines
drivers/pci/controller/pcie-mediatek.c +2 -0
@@ -865,6 +867,9 @@ static int mtk_pcie_startup_port_an7583(struct mtk_pcie_port *port)
 	size = lower_32_bits(resource_size(entry->res));
 	regmap_write(pbus_regmap, args[1], GENMASK(31, __fls(size)));
 
+	reset_control_assert(port->perstout_reset);
+	reset_control_deassert(port->perstout_reset);

[Severity: High]
Is it intentional to omit the 100ms T_PERST delay here?

Without a delay between assert and deassert, the endpoint device will receive a zero-width reset pulse which violates the PCIe CEM specification. Because the AN7583 quirks likely include MTK_PCIE_SKIP_RSTB, the standard 100ms delay in mtk_pcie_startup_port_v2() will be skipped, leaving no delay at all before link training begins.

drivers/pci/controller/pcie-mediatek.c static int mtk_pcie_parse_port(struct mtk_pcie *pcie, · line 1031

Quoted 12 lines
drivers/pci/controller/pcie-mediatek.c +5 -0
+
 	return mtk_pcie_startup_port_v2(port);
 }
 
@@ -1020,6 +1025,11 @@ static int mtk_pcie_parse_port(struct mtk_pcie *pcie,
 	if (PTR_ERR(port->reset) == -EPROBE_DEFER)
 		return PTR_ERR(port->reset);
 
+	snprintf(name, sizeof(name), "pcie-perstout%d", slot);
+	port->perstout_reset = devm_reset_control_get_optional_exclusive(dev, name);
+	if (PTR_ERR(port->perstout_reset) == -EPROBE_DEFER)
+		return PTR_ERR(port->perstout_reset);

[Severity: Medium]
Will this silently leak non-EPROBE_DEFER error pointers (like -EINVAL or -ENOMEM) into port->perstout_reset?

If devm_reset_control_get_optional_exclusive() fails with something other than -EPROBE_DEFER, the error pointer will be stored in port->perstout_reset since IS_ERR() isn't checked first.

When this pointer is later passed to reset_control_assert() in mtk_pcie_startup_port_an7583(), it will trigger a WARN_ON(IS_ERR(rstc)) in the reset core framework.

Quoted 4 lines
drivers/pci/controller/pcie-mediatek.c +1 -0
+
 	/* some platforms may use default PHY setting */
 	snprintf(name, sizeof(name), "pcie-phy%d", slot);
 	port->phy = devm_phy_optional_get(dev, name);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw
In reply to Christian Marangi
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch introduces a typo `resets-names:` instead of `reset-names:` in the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch introduces a typo resets-names: instead of reset-names: in the airoha,an7583-pcie conditional block. --

--- Patch [1]: [PATCH 1/2] dt-bindings: PCI: mediatek: Add support for optional perstout reset --- commit 940c7b8d9eadf01ceca0b3e3526e890e946e92a5
Author: Christian Marangi <[email protected]>

dt-bindings: PCI: mediatek: Add support for optional perstout reset

This commit adds optional schema support for a dedicated PCIe PERSTOUT reset on Airoha AN7583 devices. It bumps the maximum items for resets and reset-names, and adds specific name constraints in the conditional block.

Quoted 3 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +0 -0

[ ... ]

Documentation/devicetree/bindings/pci/mediatek-pcie.yaml allOf: · line 132

Quoted 5 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +1 -0
@@ -127,6 +129,12 @@ allOf:
         phy-names:
           const: pcie-phy1
 
+        resets-names:

[Severity: Medium]
This isn't a runtime bug, but there appears to be a typo in this property name (resets-names instead of reset-names). Will this cause the DT binding schema validation to ignore these constraints and silently allow incorrectly ordered values for the reset-names property?

Quoted 8 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +5 -0
+          minItems: 1
+          items:
+            - const: pcie-rst1
+            - const: pcie-perstout1
+
         power-domain: false
 
       required:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#4 lore raw
In reply to Christian Marangi
Quoted 2 lines · Christian Marangi

Airoha AN7583 have a dedicated reset for PCIe PERSTOUT. Add optional support for it in schema.

This is just the standard PCIe PERST# signal? Then it should be in the device that gets it or at least the RP node if the downstream device is not described. That is how we're handling perst-gpios in anything new.

Rob