Devicetree
 help / color / mirror / Atom feed
* [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support
@ 2026-11-23 18:43 Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

Add PCIe support for the Cortina Systems CS7542, with the shared global
controls, Snow Bush SerDes and DesignWare host glue in separate drivers.
Each controller consumes a clock gate, reset line and generic PHY rather
than modifying the global registers directly.

This series depends on the CS7542 global clock/pinctrl v1 series:
https://lore.kernel.org/all/20261123-cs7542-syscon-v1-0-49858e631449@gmail.com/
Both series are based on Linux v7.4-rc4. Board DTS enablement is kept in
the integration test branch and is not part of these eight driver patches.

The host protects the hardware's 512-byte root configuration limit for
both PCI config operations and direct DBI callbacks, while preserving
access to the private DesignWare register bank and separate iATU base.
It reads live link/LTSSM state from the application wrapper and owns the
combined INTx/MSI interrupt lifecycle.
Clock rates for the controller gates are not inferred; only the SerDes
reference is required to be 24 MHz. SATA mode, hotplug and suspend/resume
are outside the support described by this first version.

Validation:
- Full ARM GCC 14.2 vmlinux+modules for all three new drivers built-in and
  as modules, COMPILE_TEST=n, without the Cortina platform series.
- DT schema/examples, strict source checkpatch, and 49298 UBSan cases
  executing actual config/DBI/link callbacks, including fatal-link guards.
- Almond+ RAM Linux 7.4-rc4: 73 checks / 0 failures; all three endpoints enumerate; xHCI No-op
  commands complete through real MSI-X and INTx interrupts. Module removal,
  injected CMU timeout on every lane, cleanup and subsequent recovery pass.
- With unused SATA gates disabled, the shared PHY status still works.
  Link loss blocks DBI/config until controller reprobe, which restores it;
  a held-reset endpoint safely leaves a root-only bus.
- Shared global register bits are preserved. The RAM program has no MTD
  support and performs no flash I/O. The installed firmware remains intact.

---
Fil Dunsky (8):
      PCI: dwc: Export the multiplexed MSI interrupt handler
      dt-bindings: clock: Describe CS7542 PCIe gates and resets
      clk: Add CS7542 PCIe gates and resets
      dt-bindings: phy: Describe CS7542 PCIe SerDes
      phy: Add CS7542 PCIe SerDes support
      dt-bindings: PCI: Describe the CS7542 host controller
      PCI: cs7542: Add CS7542 PCIe host support
      MAINTAINERS: Add CS7542 PCIe support

 .../clock/cortina,cs7542-pcie-control.yaml         |  47 ++
 .../bindings/pci/cortina,cs7542-pcie.yaml          | 127 ++++++
 .../bindings/phy/cortina,cs7542-pcie-phy.yaml      |  67 +++
 .../soc/cortina/cortina,cs7542-syscon.yaml         |   4 +
 MAINTAINERS                                        |   8 +-
 drivers/clk/Kconfig                                |  11 +
 drivers/clk/Makefile                               |   2 +
 drivers/clk/clk-cs7542-pcie.c                      | 168 +++++++
 drivers/pci/controller/dwc/Kconfig                 |  12 +
 drivers/pci/controller/dwc/Makefile                |   2 +
 drivers/pci/controller/dwc/pcie-cs7542.c           | 508 +++++++++++++++++++++
 drivers/pci/controller/dwc/pcie-designware-host.c  |   1 +
 drivers/phy/Kconfig                                |  11 +
 drivers/phy/Makefile                               |   2 +
 drivers/phy/phy-cs7542-pcie.c                      | 232 ++++++++++
 15 files changed, 1201 insertions(+), 1 deletion(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261123-b4-cs7542-pcie-224e359c8698
prerequisite-message-id: 20261123-cs7542-syscon-v1-0-49858e631449@gmail.com
prerequisite-patch-id: 4b568d742095f1a61312c911d2b6e81c8e754312
prerequisite-patch-id: a4bba26a3aac57e4e4229a727fdf94677373493a
prerequisite-patch-id: f8a2ba71717f71ca2bedda986f8b861995cdc586
prerequisite-patch-id: 7a2275c69dcde437fc8badf2bba06d451943a66f
prerequisite-patch-id: 25220835f5d2506a01ba652d86f9b9ac3ad5121a

Best regards,
--  
Fil Dunsky <filipp.dunsky@gmail.com>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 18:52   ` sashiko-bot
  2026-11-23 18:43 ` [PATCH 2/8] dt-bindings: clock: Describe CS7542 PCIe gates and resets Fil Dunsky via B4 Relay
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Allow modular host glue with a combined application interrupt to dispatch
the internal MSI receiver without installing a second chained handler.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index bbb02458a..1d076bb62 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -85,6 +85,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)
 			generic_handle_demux_domain_irq(pp->msi_irq_domain, irq_off + pos);
 	}
 }
+EXPORT_SYMBOL_GPL(dw_handle_msi_irq);
 
 /* Chained MSI interrupt service routine */
 static void dw_chained_msi_isr(struct irq_desc *desc)

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/8] dt-bindings: clock: Describe CS7542 PCIe gates and resets
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 18:49   ` sashiko-bot
  2026-11-23 18:43 ` [PATCH 3/8] clk: Add " Fil Dunsky via B4 Relay
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Describe the global-syscon child providing three PCIe controller gates
and reset lines. Port indices are shared by clock and reset specifiers.
The gate-only clocks do not claim a source frequency.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 .../clock/cortina,cs7542-pcie-control.yaml         | 47 ++++++++++++++++++++++
 .../soc/cortina/cortina,cs7542-syscon.yaml         |  4 ++
 2 files changed, 51 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml b/Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml
new file mode 100644
index 000000000..08e0214d2
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/cortina,cs7542-pcie-control.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 PCIe gates and resets
+
+maintainers:
+  - Fil Dunsky <filipp.dunsky@gmail.com>
+
+description: |
+  Child of the CS7542 global control syscon. Clock and reset specifiers
+  select controller 0, 1 or 2. These clocks describe only the controller
+  enable gates; their source frequency and rate control are not described.
+  SerDes reference clocks and lane reset controls are separate.
+
+properties:
+  compatible:
+    const: cortina,cs7542-pcie-control
+
+  "#clock-cells":
+    const: 1
+
+  "#reset-cells":
+    const: 1
+
+required:
+  - compatible
+  - "#clock-cells"
+  - "#reset-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    syscon@f0000000 {
+        compatible = "cortina,cs7542-syscon", "syscon", "simple-mfd";
+        reg = <0xf0000000 0x100>;
+        #clock-cells = <1>;
+
+        pcie-control {
+            compatible = "cortina,cs7542-pcie-control";
+            #clock-cells = <1>;
+            #reset-cells = <1>;
+        };
+    };
diff --git a/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml b/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml
index fb074de87..52597c4e8 100644
--- a/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml
+++ b/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml
@@ -29,6 +29,10 @@ properties:
   "#clock-cells":
     const: 1
 
+  pcie-control:
+    type: object
+    $ref: /schemas/clock/cortina,cs7542-pcie-control.yaml#
+
   pinctrl:
     type: object
     $ref: /schemas/pinctrl/cortina,cs7542-pinctrl.yaml#

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/8] clk: Add CS7542 PCIe gates and resets
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 2/8] dt-bindings: clock: Describe CS7542 PCIe gates and resets Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 4/8] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Use the shared global regmap for controller gates at bits 10, 12 and 14
and block resets at bits 6 through 8. Keep the AXI reset-disable bit and
SATA gates intact. Expose independent gate-only clocks and exclusive
reset controls with the vendor reset pulse timing.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/clk/Kconfig           |  11 +++
 drivers/clk/Makefile          |   2 +
 drivers/clk/clk-cs7542-pcie.c | 168 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 181 insertions(+)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 47b5265fe..4abd81260 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -605,4 +605,15 @@ config CLK_DIVIDER_KUNIT_TEST
 	help
 	  Kunit test for the clk-divider type.
 
+config COMMON_CLK_CS7542_PCIE
+	tristate "Cortina Systems CS7542 PCIe control"
+	depends on OF && HAS_IOMEM
+	select MFD_SYSCON
+	select RESET_CONTROLLER
+	help
+	  Enable the three PCIe clock gates and controller resets in the
+	  CS7542 global control block. Shared registers use the parent syscon.
+	  The clocks provide gating only, without a source frequency.
+	  The module is called clk-cs7542-pcie.
+
 endif
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 16b1168c8..8ebb794d0 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -187,3 +187,5 @@ obj-y					+= xilinx/
 obj-$(CONFIG_COMMON_CLK_ZTE)		+= zte/
 obj-$(CONFIG_ARCH_ZYNQ)			+= zynq/
 obj-$(CONFIG_COMMON_CLK_ZYNQMP)         += zynqmp/
+
+obj-$(CONFIG_COMMON_CLK_CS7542_PCIE) += clk-cs7542-pcie.o
diff --git a/drivers/clk/clk-cs7542-pcie.c b/drivers/clk/clk-cs7542-pcie.c
new file mode 100644
index 000000000..c39977a25
--- /dev/null
+++ b/drivers/clk/clk-cs7542-pcie.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Cortina Systems CS7542 PCIe clock gates and controller resets. */
+#include <linux/clk-provider.h>
+#include <linux/delay.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+
+#define CS7542_PORTS	3
+#define GLOBAL_RESET	0x04
+#define GLOBAL_CONFIG	0x10
+
+struct cs7542_gate {
+	struct clk_hw hw;
+	struct regmap *map;
+	u32 mask;
+};
+
+struct cs7542_control {
+	struct reset_controller_dev rcdev;
+	struct regmap *map;
+	struct cs7542_gate gates[CS7542_PORTS];
+	struct clk_hw_onecell_data *clks;
+};
+
+static int cs7542_gate_prepare(struct clk_hw *hw)
+{
+	struct cs7542_gate *gate = container_of(hw, struct cs7542_gate, hw);
+
+	return regmap_update_bits(gate->map, GLOBAL_CONFIG, gate->mask, gate->mask);
+}
+
+static void cs7542_gate_unprepare(struct clk_hw *hw)
+{
+	struct cs7542_gate *gate = container_of(hw, struct cs7542_gate, hw);
+
+	regmap_update_bits(gate->map, GLOBAL_CONFIG, gate->mask, 0);
+}
+
+static int cs7542_gate_is_prepared(struct clk_hw *hw)
+{
+	struct cs7542_gate *gate = container_of(hw, struct cs7542_gate, hw);
+	unsigned int value;
+	int ret;
+
+	ret = regmap_read(gate->map, GLOBAL_CONFIG, &value);
+	return ret ? ret : !!(value & gate->mask);
+}
+
+static const struct clk_ops cs7542_gate_ops = {
+	.prepare = cs7542_gate_prepare,
+	.unprepare = cs7542_gate_unprepare,
+	.is_prepared = cs7542_gate_is_prepared,
+};
+
+static int cs7542_reset_update(struct reset_controller_dev *rcdev,
+			       unsigned long id, bool assert)
+{
+	struct cs7542_control *ctl = container_of(rcdev, struct cs7542_control, rcdev);
+	u32 mask = BIT(6 + id);
+
+	return regmap_update_bits(ctl->map, GLOBAL_RESET, mask, assert ? mask : 0);
+}
+
+static int cs7542_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	return cs7542_reset_update(rcdev, id, true);
+}
+
+static int cs7542_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	return cs7542_reset_update(rcdev, id, false);
+}
+
+static int cs7542_reset_status(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	struct cs7542_control *ctl = container_of(rcdev, struct cs7542_control, rcdev);
+	unsigned int value;
+	int ret;
+
+	ret = regmap_read(ctl->map, GLOBAL_RESET, &value);
+	return ret ? ret : !!(value & BIT(6 + id));
+}
+
+static int cs7542_reset_pulse(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	int ret;
+
+	ret = cs7542_reset_assert(rcdev, id);
+	if (ret)
+		return ret;
+	usleep_range(10000, 12000);
+	ret = cs7542_reset_deassert(rcdev, id);
+	if (ret)
+		return ret;
+	usleep_range(10000, 12000);
+	return 0;
+}
+
+static const struct reset_control_ops cs7542_reset_ops = {
+	.assert = cs7542_reset_assert,
+	.deassert = cs7542_reset_deassert,
+	.status = cs7542_reset_status,
+	.reset = cs7542_reset_pulse,
+};
+
+static int cs7542_control_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct cs7542_control *ctl;
+	int ret, i;
+
+	ctl = devm_kzalloc(dev, sizeof(*ctl), GFP_KERNEL);
+	if (!ctl)
+		return -ENOMEM;
+	ctl->map = syscon_node_to_regmap(dev->of_node->parent);
+	if (IS_ERR(ctl->map))
+		return dev_err_probe(dev, PTR_ERR(ctl->map), "global register map\n");
+	ctl->clks = devm_kzalloc(dev, struct_size(ctl->clks, hws, CS7542_PORTS), GFP_KERNEL);
+	if (!ctl->clks)
+		return -ENOMEM;
+	ctl->clks->num = CS7542_PORTS;
+	for (i = 0; i < CS7542_PORTS; i++) {
+		struct cs7542_gate *gate = &ctl->gates[i];
+		struct clk_init_data init = { .ops = &cs7542_gate_ops };
+
+		init.name = devm_kasprintf(dev, GFP_KERNEL, "%s.pcie%d", dev_name(dev), i);
+		if (!init.name)
+			return -ENOMEM;
+		/* Gate-only controls: no source frequency is described or assumed. */
+		gate->map = ctl->map;
+		gate->mask = BIT(10 + 2 * i);
+		gate->hw.init = &init;
+		ret = devm_clk_hw_register(dev, &gate->hw);
+		if (ret)
+			return dev_err_probe(dev, ret, "clock gate %d\n", i);
+		ctl->clks->hws[i] = &gate->hw;
+	}
+	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, ctl->clks);
+	if (ret)
+		return ret;
+	ctl->rcdev.owner = THIS_MODULE;
+	ctl->rcdev.ops = &cs7542_reset_ops;
+	ctl->rcdev.of_node = dev->of_node;
+	ctl->rcdev.nr_resets = CS7542_PORTS;
+	return devm_reset_controller_register(dev, &ctl->rcdev);
+}
+
+static const struct of_device_id cs7542_control_match[] = {
+	{ .compatible = "cortina,cs7542-pcie-control" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, cs7542_control_match);
+
+static struct platform_driver cs7542_control_driver = {
+	.probe = cs7542_control_probe,
+	.driver = {
+		.name = "cs7542-pcie-control",
+		.of_match_table = cs7542_control_match,
+	},
+};
+module_platform_driver(cs7542_control_driver);
+
+MODULE_DESCRIPTION("Cortina Systems CS7542 PCIe clock gates and resets");
+MODULE_LICENSE("GPL");

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/8] dt-bindings: phy: Describe CS7542 PCIe SerDes
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-23 18:43 ` [PATCH 3/8] clk: Add " Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 5/8] phy: Add CS7542 PCIe SerDes support Fil Dunsky via B4 Relay
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Describe three Snow Bush lanes, their shared status bank, global reset
controls and 24 MHz reference. PCIe is the only supported operating mode.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 .../bindings/phy/cortina,cs7542-pcie-phy.yaml      | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
new file mode 100644
index 000000000..9ccde6e05
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/cortina,cs7542-pcie-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 PCIe SerDes
+
+maintainers:
+  - Fil Dunsky <filipp.dunsky@gmail.com>
+
+description: |
+  Three Snow Bush SerDes lanes shared by PCIe and SATA. Only PCIe mode
+  with a 24 MHz reference is described. The PHY specifier is the lane
+  number, 0 through 2. The status resource contains the shared PHY
+  status registers, with a stride of 0x80 bytes per lane.
+
+properties:
+  compatible:
+    const: cortina,cs7542-pcie-phy
+
+  reg:
+    items:
+      - description: Lane 0 programming registers
+      - description: Lane 1 programming registers
+      - description: Lane 2 programming registers
+      - description: Shared PHY status registers
+
+  reg-names:
+    items:
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: status
+
+  clocks:
+    maxItems: 1
+    description: 24 MHz SerDes reference clock
+
+  cortina,global-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: Global control syscon providing lane reset and mode selection
+
+  "#phy-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - clocks
+  - cortina,global-syscon
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    phy@f00a1000 {
+        compatible = "cortina,cs7542-pcie-phy";
+        reg = <0xf00a1000 0x400>, <0xf00a5000 0x400>,
+              <0xf00a9000 0x400>, <0xf00a0e00 0x180>;
+        reg-names = "phy0", "phy1", "phy2", "status";
+        clocks = <&ref24>;
+        cortina,global-syscon = <&global>;
+        #phy-cells = <1>;
+    };

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/8] phy: Add CS7542 PCIe SerDes support
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
                   ` (3 preceding siblings ...)
  2026-11-23 18:43 ` [PATCH 4/8] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 6/8] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Provide per-lane generic PHYs using the vendor 24 MHz programming table
and revision-dependent value. Sequence power and reset through the shared
global regmap and fail on CMU lock timeout with balanced power cleanup.
Use the shared PHY status bank without overlapping PCIe wrapper resources.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/phy/Kconfig           |  11 ++
 drivers/phy/Makefile          |   2 +
 drivers/phy/phy-cs7542-pcie.c | 232 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 245 insertions(+)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 105fbe408..77cff94fe 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -204,4 +204,15 @@ source "drivers/phy/tegra/Kconfig"
 source "drivers/phy/ti/Kconfig"
 source "drivers/phy/xilinx/Kconfig"
 
+config PHY_CS7542_PCIE
+	tristate "Cortina Systems CS7542 PCIe SerDes"
+	depends on OF && HAS_IOMEM && COMMON_CLK
+	select GENERIC_PHY
+	select MFD_SYSCON
+	help
+	  Support the three CS7542 Snow Bush SerDes lanes in PCIe mode
+	  with a 24 MHz reference clock. Lane resets share the global syscon.
+	  SATA mode and other reference frequencies are not supported.
+	  The module is called phy-cs7542-pcie.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index c6dd02003..54df29e74 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -55,3 +55,5 @@ obj-$(CONFIG_GENERIC_PHY)		+= allwinner/	\
 					   tegra/	\
 					   ti/		\
 					   xilinx/
+
+obj-$(CONFIG_PHY_CS7542_PCIE) += phy-cs7542-pcie.o
diff --git a/drivers/phy/phy-cs7542-pcie.c b/drivers/phy/phy-cs7542-pcie.c
new file mode 100644
index 000000000..d027baa93
--- /dev/null
+++ b/drivers/phy/phy-cs7542-pcie.c
@@ -0,0 +1,232 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* CS7542 Snow Bush SerDes, PCIe mode with a 24 MHz reference clock. */
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#define GLOBAL_JTAG_ID	0x00
+#define GLOBAL_PHY_CONTROL 0x14
+#define PHY_REFCLK_MASK(p) (3U << ((p) * 2))
+#define PHY_REFCLK_24MHZ(p) (2U << ((p) * 2))
+#define PHY_PD(p)	BIT(8 + (p))
+#define PHY_CMU_RESETN(p) BIT(16 + (p) * 4)
+#define PHY_LN0_RESETN(p) BIT(17 + (p) * 4)
+#define PHY_POR_N(p)	BIT(19 + (p) * 4)
+#define PHY_CMU_OK	BIT(18)
+#define PHY_STATUS_STRIDE 0x80
+#define SNOW_COM_REG0	0x00
+#define SNOW_REG0_CFG	0x00090006
+#define SNOW_REG0_AHB_RESETN BIT(0)
+#define SNOW_REV_REG	96
+#define SNOW_REV_REG_A0	0x5e082e00
+#define SNOW_REV_REG_A1	0x5e080600
+#define SNOW_COM_LANE_REG0 0xc8
+#define SNOW_LANE_REG0_CFG 0x400290c0
+#define SNOW_LANE_REG0_MASTER_RESETN BIT(1)
+#define CS7542_PORTS	3
+
+struct cs7542_serdes;
+struct cs7542_lane {
+	struct cs7542_serdes *serdes;
+	void __iomem *base;
+	struct phy *phy;
+	unsigned int id;
+};
+
+struct cs7542_serdes {
+	struct device *dev;
+	struct regmap *global;
+	void __iomem *status;
+	struct clk *ref;
+	struct cs7542_lane lanes[CS7542_PORTS];
+	u32 revision_value;
+};
+
+struct snow_reg {
+	u16 off;
+	u32 val;
+};
+
+static const struct snow_reg snow_phy_24mhz[] = {
+	{ 0,   SNOW_REG0_CFG }, { 4,   0x000e0960 }, { 32,  0x68a00000 },
+	{ 44,  0x50040000 }, { 48,  0x40250270 }, { 52,  0x00004001 },
+	{ 100, 0xf0914200 }, { 104, 0x4c0c9048 }, { 108, 0x00000373 },
+	{ 124, 0x04841000 }, { 128, 0x000000e0 }, { 132, 0x04000023 },
+	{ 136, 0x68001038 }, { 140, 0x0d181ea2 }, { 144, 0x0000000c },
+	{ 196, 0x0f600000 }, { 200, SNOW_LANE_REG0_CFG }, { 204, 0x0000003c },
+	{ 208, 0xc68b8300 }, { 212, 0x98280301 }, { 216, 0xe1782819 },
+	{ 220, 0x00f410f0 }, { 232, 0xa0a0a000 }, { 236, 0xa0a0a0a0 },
+	{ 240, 0x9fc00068 }, { 244, 0x00000001 }, { 248, 0x00000000 },
+	{ 252, 0xd07e4130 }, { 256, 0x935285cc }, { 260, 0xb0dd49e0 },
+	{ 264, 0x0000020b }, { 300, 0xd8000000 }, { 304, 0x0001ff1a },
+	{ 308, 0xf0000000 }, { 312, 0xffffffff }, { 316, 0x3fc3c21c },
+	{ 320, 0x0000000a }, { 324, 0x00f80000 },
+};
+
+static int cs7542_phy_power_off(struct phy *phy)
+{
+	struct cs7542_lane *lane = phy_get_drvdata(phy);
+	unsigned int p = lane->id;
+	u32 mask = PHY_PD(p) | PHY_CMU_RESETN(p) | PHY_LN0_RESETN(p) | PHY_POR_N(p);
+	int ret;
+
+	ret = regmap_update_bits(lane->serdes->global, GLOBAL_PHY_CONTROL, mask, PHY_PD(p));
+	clk_disable_unprepare(lane->serdes->ref);
+	return ret;
+}
+
+static int cs7542_phy_power_on(struct phy *phy)
+{
+	struct cs7542_lane *lane = phy_get_drvdata(phy);
+	struct cs7542_serdes *sd = lane->serdes;
+	unsigned int p = lane->id;
+	u32 mask, value;
+	int ret, i;
+
+	ret = clk_prepare_enable(sd->ref);
+	if (ret)
+		return ret;
+	mask = PHY_PD(p) | PHY_CMU_RESETN(p) | PHY_LN0_RESETN(p) | PHY_POR_N(p) |
+	       PHY_REFCLK_MASK(p);
+	ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, mask,
+				 PHY_PD(p) | PHY_REFCLK_24MHZ(p));
+	if (ret)
+		goto power_off;
+	msleep(100);
+	ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, PHY_PD(p) | PHY_POR_N(p),
+				 PHY_POR_N(p));
+	if (ret)
+		goto power_off;
+	usleep_range(10, 20);
+	for (i = 0; i < ARRAY_SIZE(snow_phy_24mhz); i++) {
+		if (snow_phy_24mhz[i].off == SNOW_REV_REG + 4)
+			writel(sd->revision_value, lane->base + SNOW_REV_REG);
+		writel(snow_phy_24mhz[i].val, lane->base + snow_phy_24mhz[i].off);
+	}
+	writel(SNOW_REG0_CFG | SNOW_REG0_AHB_RESETN, lane->base + SNOW_COM_REG0);
+	ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, PHY_CMU_RESETN(p),
+				 PHY_CMU_RESETN(p));
+	if (ret)
+		goto power_off;
+	ret = readl_poll_timeout(sd->status + p * PHY_STATUS_STRIDE, value,
+				 value & PHY_CMU_OK, 100, 100000);
+	if (ret) {
+		dev_err(sd->dev, "lane %u CMU did not lock\n", p);
+		goto power_off;
+	}
+	writel(SNOW_LANE_REG0_CFG | SNOW_LANE_REG0_MASTER_RESETN,
+	       lane->base + SNOW_COM_LANE_REG0);
+	ret = regmap_update_bits(sd->global, GLOBAL_PHY_CONTROL, PHY_LN0_RESETN(p),
+				 PHY_LN0_RESETN(p));
+	if (ret)
+		goto power_off;
+	msleep(100);
+	return 0;
+
+power_off:
+	cs7542_phy_power_off(phy);
+	return ret;
+}
+
+static int cs7542_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
+{
+	return mode == PHY_MODE_PCIE && !submode ? 0 : -EINVAL;
+}
+
+static const struct phy_ops cs7542_phy_ops = {
+	.power_on = cs7542_phy_power_on,
+	.power_off = cs7542_phy_power_off,
+	.set_mode = cs7542_phy_set_mode,
+	.owner = THIS_MODULE,
+};
+
+static struct phy *cs7542_phy_xlate(struct device *dev, const struct of_phandle_args *args)
+{
+	struct cs7542_serdes *sd = dev_get_drvdata(dev);
+
+	if (args->args_count != 1 || args->args[0] >= CS7542_PORTS)
+		return ERR_PTR(-EINVAL);
+	return sd->lanes[args->args[0]].phy;
+}
+
+static int cs7542_phy_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct phy_provider *provider;
+	struct cs7542_serdes *sd;
+	unsigned int id;
+	int ret, i;
+
+	sd = devm_kzalloc(dev, sizeof(*sd), GFP_KERNEL);
+	if (!sd)
+		return -ENOMEM;
+	sd->dev = dev;
+	sd->global = syscon_regmap_lookup_by_phandle(dev->of_node, "cortina,global-syscon");
+	if (IS_ERR(sd->global))
+		return dev_err_probe(dev, PTR_ERR(sd->global), "global register map\n");
+	sd->ref = devm_clk_get(dev, NULL);
+	if (IS_ERR(sd->ref))
+		return dev_err_probe(dev, PTR_ERR(sd->ref), "reference clock\n");
+	if (clk_get_rate(sd->ref) != 24000000)
+		return dev_err_probe(dev, -EINVAL, "only 24 MHz reference supported\n");
+	ret = regmap_read(sd->global, GLOBAL_JTAG_ID, &id);
+	if (ret)
+		return ret;
+	switch (FIELD_GET(GENMASK(15, 12), id)) {
+	case 0:
+	case 1:
+		sd->revision_value = SNOW_REV_REG_A0;
+		break;
+	case 8:
+	case 9:
+		sd->revision_value = SNOW_REV_REG_A1;
+		break;
+	default:
+		return dev_err_probe(dev, -ENODEV, "unsupported silicon revision %#x\n", id);
+	}
+	sd->status = devm_platform_ioremap_resource(pdev, CS7542_PORTS);
+	if (IS_ERR(sd->status))
+		return PTR_ERR(sd->status);
+	for (i = 0; i < CS7542_PORTS; i++) {
+		struct cs7542_lane *lane = &sd->lanes[i];
+
+		lane->id = i;
+		lane->serdes = sd;
+		lane->base = devm_platform_ioremap_resource(pdev, i);
+		if (IS_ERR(lane->base))
+			return PTR_ERR(lane->base);
+		lane->phy = devm_phy_create(dev, NULL, &cs7542_phy_ops);
+		if (IS_ERR(lane->phy))
+			return PTR_ERR(lane->phy);
+		phy_set_drvdata(lane->phy, lane);
+	}
+	platform_set_drvdata(pdev, sd);
+	provider = devm_of_phy_provider_register(dev, cs7542_phy_xlate);
+	return PTR_ERR_OR_ZERO(provider);
+}
+
+static const struct of_device_id cs7542_phy_match[] = {
+	{ .compatible = "cortina,cs7542-pcie-phy" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, cs7542_phy_match);
+
+static struct platform_driver cs7542_phy_driver = {
+	.probe = cs7542_phy_probe,
+	.driver = {
+		.name = "cs7542-pcie-phy",
+		.of_match_table = cs7542_phy_match,
+	},
+};
+module_platform_driver(cs7542_phy_driver);
+
+MODULE_DESCRIPTION("Cortina Systems CS7542 PCIe SerDes");
+MODULE_LICENSE("GPL");

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/8] dt-bindings: PCI: Describe the CS7542 host controller
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
                   ` (4 preceding siblings ...)
  2026-11-23 18:43 ` [PATCH 5/8] phy: Add CS7542 PCIe SerDes support Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 18:48   ` sashiko-bot
  2026-11-23 18:43 ` [PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
  2026-11-23 18:43 ` [PATCH 8/8] MAINTAINERS: Add CS7542 PCIe support Fil Dunsky via B4 Relay
  7 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Describe the DesignWare host wrapper, clock/reset/PHY consumers, combined
interrupt and INTx domain. Document the root configuration access limit.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 .../bindings/pci/cortina,cs7542-pcie.yaml          | 127 +++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
new file mode 100644
index 000000000..8883b8d09
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/cortina,cs7542-pcie.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 PCIe host controller
+
+maintainers:
+  - Fil Dunsky <filipp.dunsky@gmail.com>
+
+description: |
+  DesignWare host with a Cortina application wrapper. A single interrupt
+  multiplexes four INTx lines, the internal MSI receiver and link errors.
+  Root-port configuration is accessible only below offset 0x200; the
+  DesignWare private register bank starts at offset 0x700.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: cortina,cs7542-pcie
+
+  reg:
+    items:
+      - description: DBI registers including the viewport iATU
+      - description: Downstream configuration window
+      - description: Application wrapper registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: config
+      - const: app
+
+  interrupts:
+    maxItems: 1
+
+  interrupt-names:
+    const: msi
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  phys:
+    maxItems: 1
+
+  phy-names:
+    const: pcie
+
+  num-lanes:
+    const: 1
+
+  reset-gpios:
+    maxItems: 1
+    description: Optional active-low endpoint PERST#
+
+  interrupt-controller:
+    type: object
+    additionalProperties: false
+    properties:
+      "#address-cells":
+        const: 0
+      "#interrupt-cells":
+        const: 1
+      interrupt-controller: true
+    required:
+      - "#address-cells"
+      - "#interrupt-cells"
+      - interrupt-controller
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-names
+  - clocks
+  - resets
+  - phys
+  - phy-names
+  - num-lanes
+  - interrupt-controller
+  - interrupt-map
+  - interrupt-map-mask
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    pcie@80000000 {
+        compatible = "cortina,cs7542-pcie";
+        reg = <0x80000000 0x1000>, <0x80001000 0x1000>,
+              <0xf00a0000 0x100>;
+        reg-names = "dbi", "config", "app";
+        #address-cells = <3>;
+        #size-cells = <2>;
+        device_type = "pci";
+        bus-range = <0 0xff>;
+        num-lanes = <1>;
+        ranges = <0x82000000 0 0x80200000 0x80200000 0 0x1fe00000>;
+        interrupt-parent = <&gic>;
+        interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "msi";
+        clocks = <&pcie_control 0>;
+        resets = <&pcie_control 0>;
+        phys = <&serdes 0>;
+        phy-names = "pcie";
+        #interrupt-cells = <1>;
+        interrupt-map-mask = <0 0 0 7>;
+        interrupt-map = <0 0 0 1 &pcie_intc 1>,
+                        <0 0 0 2 &pcie_intc 2>,
+                        <0 0 0 3 &pcie_intc 3>,
+                        <0 0 0 4 &pcie_intc 4>;
+
+        pcie_intc: interrupt-controller {
+            #address-cells = <0>;
+            #interrupt-cells = <1>;
+            interrupt-controller;
+        };
+    };

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
                   ` (5 preceding siblings ...)
  2026-11-23 18:43 ` [PATCH 6/8] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  2026-11-23 19:11   ` sashiko-bot
  2026-11-23 18:43 ` [PATCH 8/8] MAINTAINERS: Add CS7542 PCIe support Fil Dunsky via B4 Relay
  7 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Add DesignWare host glue consuming separate clock, reset and PHY
providers. Use live link status and stop previous training before
enumeration. Finish endpoint teardown before draining the shared IRQ and
freeing MSI domains. Dispatch enabled INTx/MSI sources through one
application interrupt and use its MSI target window.

Prevent root configuration accesses at and above 0x200, including direct
DesignWare DBI reads, while preserving the private CSR bank and separate
iATU callback base. Unwind power and IRQ domains on failure and removal.

Read live link/LTSSM state through the application wrapper. After link
loss, block configuration and DBI accesses until controller reset and
reprobe.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/pci/controller/dwc/Kconfig       |  12 +
 drivers/pci/controller/dwc/Makefile      |   2 +
 drivers/pci/controller/dwc/pcie-cs7542.c | 508 +++++++++++++++++++++++++++++++
 3 files changed, 522 insertions(+)

diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
index 0a0d56fcf..88415954e 100644
--- a/drivers/pci/controller/dwc/Kconfig
+++ b/drivers/pci/controller/dwc/Kconfig
@@ -577,4 +577,16 @@ config PCIE_ULTRARISC
 	  By default, this symbol is enabled when ARCH_ULTRARISC is active,
 	  requiring no further configuration on that platform.
 
+config PCIE_CS7542
+	tristate "Cortina Systems CS7542 PCIe controller"
+	depends on OF && HAS_IOMEM && PCI_MSI && COMMON_CLK
+	select PCIE_DW_HOST
+	select GENERIC_PHY
+	select RESET_CONTROLLER
+	help
+	  Enable the DesignWare PCIe host controllers on Cortina CS7542.
+	  Separate clock, reset and generic PHY providers are required.
+	  The application interrupt handles both legacy INTx and MSI.
+	  The module is called pcie-cs7542.
+
 endmenu
diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile
index d4f88cfc6..4a6ae9037 100644
--- a/drivers/pci/controller/dwc/Makefile
+++ b/drivers/pci/controller/dwc/Makefile
@@ -61,3 +61,5 @@ obj-$(CONFIG_ARM64) += pcie-hisi.o
 obj-$(CONFIG_ARM64) += pcie-tegra194-acpi.o
 endif
 endif
+
+obj-$(CONFIG_PCIE_CS7542) += pcie-cs7542.o
diff --git a/drivers/pci/controller/dwc/pcie-cs7542.c b/drivers/pci/controller/dwc/pcie-cs7542.c
new file mode 100644
index 000000000..19225e9a2
--- /dev/null
+++ b/drivers/pci/controller/dwc/pcie-cs7542.c
@@ -0,0 +1,508 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/iopoll.h>
+#include <linux/phy/phy.h>
+#include <linux/reset.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/resource.h>
+
+#include "pcie-designware.h"
+
+#define APP_INT_STATUS		0x00
+#define APP_INT_ENABLE		0x04
+#define APP_CORE_CONFIG		0x1c
+#define APP_PM_STATUS		0x20
+#define APP_LINK_ACTIVE		BIT(18)
+#define APP_LTSSM_STATE		GENMASK(9, 4)
+#define APP_CFG_START		0x80
+#define APP_CFG_END		0x84
+
+#define INT_INTX_ASSERT(x)	BIT((x) * 2)
+#define INT_INTX_ASSERT_MASK	(BIT(0) | BIT(2) | BIT(4) | BIT(6))
+#define INT_MSI			BIT(8)
+#define INT_LINK_UP		BIT(9)
+#define INT_RADM_NONFATAL_ERR	BIT(12)
+#define INT_RADM_FATAL_ERR	BIT(13)
+#define INT_GM_COMPOSER_ERR	BIT(16)
+#define INT_RADMX_COMPOSER_ERR	BIT(17)
+#define INT_ELASTIC_OVF		BIT(18)
+#define INT_ELASTIC_UNF		BIT(19)
+#define INT_LINK_DOWN		BIT(22)
+#define INT_ERR_MASK		(INT_RADM_NONFATAL_ERR | INT_RADM_FATAL_ERR | \
+				 INT_GM_COMPOSER_ERR | INT_RADMX_COMPOSER_ERR | \
+				 INT_ELASTIC_OVF | INT_ELASTIC_UNF | INT_LINK_DOWN)
+
+#define CORE_CFG_LTSSM_EN	BIT(0)
+#define CORE_CFG_AXI_UR_MASK	BIT(5)
+
+#define APP_PORT_STRIDE		0x400
+#define APP_PHYS_BASE		0xF00A0000
+#define APP_CFG_WINDOW_LEN	0x1000
+#define APP_MSI_TARGET		0xC0
+#define RC_CFG_LIMIT		0x200
+
+struct cortina_pcie {
+	struct dw_pcie		pci;
+	void __iomem		*app;
+	struct clk		*clk;
+	struct phy		*phy;
+	struct reset_control	*reset;
+	struct gpio_desc	*perst;
+	int			irq;
+	bool			msi_ready;
+	bool			link_lost;
+	struct irq_domain	*intx_domain;
+	raw_spinlock_t		lock;
+	resource_size_t		dbi_phys;
+	resource_size_t		app_phys;
+	int			port;
+};
+
+#define to_cortina_pcie(x)	container_of((x), struct cortina_pcie, pci)
+
+static int cortina_pcie_port_init(struct cortina_pcie *cp)
+{
+	u32 value;
+	int ret;
+
+	writel(cp->dbi_phys, cp->app + APP_CFG_START);
+	writel(cp->dbi_phys + APP_CFG_WINDOW_LEN - 1, cp->app + APP_CFG_END);
+	ret = readl_poll_timeout(cp->app + APP_CFG_END, value,
+				 value == cp->dbi_phys + APP_CFG_WINDOW_LEN - 1, 10, 10000);
+	if (ret)
+		return ret;
+	writel(0, cp->app + APP_INT_ENABLE);
+	writel(readl(cp->app + APP_INT_STATUS), cp->app + APP_INT_STATUS);
+	return 0;
+}
+
+/* APP remains accessible after link loss, unlike the DBI port debug bank. */
+static bool cortina_pcie_link_up(struct dw_pcie *pci)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(pci);
+
+	return !READ_ONCE(cp->link_lost) &&
+	       !!(readl(cp->app + APP_PM_STATUS) & APP_LINK_ACTIVE);
+}
+
+static enum dw_pcie_ltssm cortina_pcie_get_ltssm(struct dw_pcie *pci)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(pci);
+
+	return FIELD_GET(APP_LTSSM_STATE, readl(cp->app + APP_PM_STATUS));
+}
+
+static int cortina_pcie_start_link(struct dw_pcie *pci)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(pci);
+	u32 v;
+
+	v = readl(cp->app + APP_CORE_CONFIG);
+	v |= CORE_CFG_LTSSM_EN | CORE_CFG_AXI_UR_MASK;
+	writel(v, cp->app + APP_CORE_CONFIG);
+	return 0;
+}
+
+static void cortina_pcie_stop_link(struct dw_pcie *pci)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(pci);
+	u32 value = readl(cp->app + APP_CORE_CONFIG);
+
+	writel(value & ~CORE_CFG_LTSSM_EN, cp->app + APP_CORE_CONFIG);
+}
+
+static void cortina_pcie_irq_handler(struct irq_desc *desc)
+{
+	struct cortina_pcie *cp = irq_desc_get_handler_data(desc);
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	u32 status, clear;
+	int i;
+
+	chained_irq_enter(chip, desc);
+
+	status = readl(cp->app + APP_INT_STATUS);
+	status &= readl(cp->app + APP_INT_ENABLE);
+	clear = status & ~INT_LINK_UP;
+	if (status & INT_LINK_DOWN)
+		clear |= INT_LINK_UP;
+	writel(clear, cp->app + APP_INT_STATUS);
+
+	if (status & INT_LINK_DOWN) {
+		/* The DBI interface needs a controller reset after link loss. */
+		raw_spin_lock(&cp->lock);
+		WRITE_ONCE(cp->link_lost, true);
+		writel(0, cp->app + APP_INT_ENABLE);
+		raw_spin_unlock(&cp->lock);
+		dev_warn_ratelimited(cp->pci.dev, "link lost; controller reprobe required\n");
+		goto out;
+	}
+
+	if (status & INT_ERR_MASK)
+		dev_err_ratelimited(cp->pci.dev, "port %d: PCIe error, status %#x\n",
+				    cp->port, status);
+
+	for (i = 0; i < PCI_NUM_INTX; i++)
+		if (status & INT_INTX_ASSERT(i))
+			generic_handle_domain_irq(cp->intx_domain, i);
+	if ((status & INT_MSI) && cp->msi_ready)
+		dw_handle_msi_irq(&cp->pci.pp);
+
+out:
+	chained_irq_exit(chip, desc);
+}
+
+static void cortina_intx_mask(struct irq_data *d)
+{
+	struct cortina_pcie *cp = irq_data_get_irq_chip_data(d);
+	u32 bit = INT_INTX_ASSERT(d->hwirq);
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&cp->lock, flags);
+	writel(readl(cp->app + APP_INT_ENABLE) & ~bit, cp->app + APP_INT_ENABLE);
+	raw_spin_unlock_irqrestore(&cp->lock, flags);
+}
+
+static void cortina_intx_unmask(struct irq_data *d)
+{
+	struct cortina_pcie *cp = irq_data_get_irq_chip_data(d);
+	u32 bit = INT_INTX_ASSERT(d->hwirq);
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&cp->lock, flags);
+	if (!READ_ONCE(cp->link_lost))
+		writel(readl(cp->app + APP_INT_ENABLE) | bit, cp->app + APP_INT_ENABLE);
+	raw_spin_unlock_irqrestore(&cp->lock, flags);
+}
+
+static struct irq_chip cortina_intx_chip = {
+	.name		= "cortina-INTx",
+	.irq_mask	= cortina_intx_mask,
+	.irq_unmask	= cortina_intx_unmask,
+};
+
+static int cortina_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
+				 irq_hw_number_t hwirq)
+{
+	irq_set_chip_and_handler(irq, &cortina_intx_chip, handle_simple_irq);
+	irq_set_chip_data(irq, domain->host_data);
+	return 0;
+}
+
+static const struct irq_domain_ops cortina_intx_domain_ops = {
+	.map = cortina_pcie_intx_map,
+	.xlate = pci_irqd_intx_xlate,
+};
+
+static int cortina_pcie_init_irq_domain(struct cortina_pcie *cp)
+{
+	struct device *dev = cp->pci.dev;
+	struct device_node *intc;
+
+	intc = of_get_child_by_name(dev->of_node, "interrupt-controller");
+	if (!intc)
+		return dev_err_probe(dev, -ENODEV, "no interrupt-controller child\n");
+
+	cp->intx_domain = irq_domain_create_linear(of_fwnode_handle(intc), PCI_NUM_INTX,
+						   &cortina_intx_domain_ops, cp);
+	of_node_put(intc);
+	if (!cp->intx_domain)
+		return dev_err_probe(dev, -ENOMEM, "cannot create INTx domain\n");
+	return 0;
+}
+
+static int cortina_pcie_rd_own_conf(struct pci_bus *bus, unsigned int devfn,
+				    int where, int size, u32 *val)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(bus->sysdata));
+
+	*val = ~0U;
+	if (where < 0 || (size != 1 && size != 2 && size != 4) ||
+	    (where & (size - 1)))
+		return PCIBIOS_BAD_REGISTER_NUMBER;
+	if (READ_ONCE(cp->link_lost))
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) {
+		*val = 0;
+		return PCIBIOS_SUCCESSFUL;
+	}
+	return pci_generic_config_read(bus, devfn, where, size, val);
+}
+
+static int cortina_pcie_wr_own_conf(struct pci_bus *bus, unsigned int devfn,
+				    int where, int size, u32 val)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(bus->sysdata));
+
+	if (where < 0 || (size != 1 && size != 2 && size != 4) ||
+	    (where & (size - 1)))
+		return PCIBIOS_BAD_REGISTER_NUMBER;
+	if (READ_ONCE(cp->link_lost))
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	if (where >= RC_CFG_LIMIT || size > RC_CFG_LIMIT - where) {
+		dev_dbg(bus->dev.parent, "ignoring RC config write at %#x\n", where);
+		return PCIBIOS_SUCCESSFUL;
+	}
+	return pci_generic_config_write(bus, devfn, where, size, val);
+}
+
+static struct pci_ops cortina_own_pci_ops = {
+	.map_bus	= dw_pcie_own_conf_map_bus,
+	.read		= cortina_pcie_rd_own_conf,
+	.write		= cortina_pcie_wr_own_conf,
+};
+
+static int cortina_pcie_host_init(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	u8 cap = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI);
+	u16 flags;
+
+	pp->bridge->ops = &cortina_own_pci_ops;
+	pp->keep_rp_msi_en = true;
+	if (cap) {
+		flags = dw_pcie_readw_dbi(pci, cap + PCI_MSI_FLAGS);
+		dw_pcie_writew_dbi(pci, cap + PCI_MSI_FLAGS, flags | PCI_MSI_FLAGS_ENABLE);
+	}
+	return 0;
+}
+
+static int cortina_pcie_msi_init(struct dw_pcie_rp *pp)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(pp));
+	u32 ctrl;
+	int ret;
+
+	/* The application IRQ multiplexes MSI and INTx, so do not chain it twice. */
+	pp->msi_irq[0] = -ENODEV;
+	ret = dw_pcie_msi_host_init(pp);
+	if (ret)
+		return ret;
+	/* CS7542 routes endpoint MSI writes through its application target. */
+	pp->msi_data = cp->app_phys + APP_MSI_TARGET;
+	/* A custom MSI hook owns setup and teardown of the multiplexed receiver. */
+	for (ctrl = 0; ctrl < pp->num_vectors / MAX_MSI_IRQS_PER_CTRL; ctrl++) {
+		dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_INTR0_MASK + ctrl * MSI_REG_CTRL_BLOCK_SIZE,
+				   pp->irq_mask[ctrl]);
+		dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_INTR0_ENABLE + ctrl * MSI_REG_CTRL_BLOCK_SIZE,
+				   ~0);
+	}
+	dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_ADDR_LO, lower_32_bits(pp->msi_data));
+	dw_pcie_writel_dbi(&cp->pci, PCIE_MSI_ADDR_HI, upper_32_bits(pp->msi_data));
+	cp->msi_ready = true;
+	return 0;
+}
+
+static void cortina_pcie_host_deinit(struct dw_pcie_rp *pp)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(to_dw_pcie_from_pp(pp));
+
+	/* Endpoints have stopped; now drain the shared IRQ before freeing domains. */
+	writel(0, cp->app + APP_INT_ENABLE);
+	readl(cp->app + APP_INT_ENABLE);
+	synchronize_irq(cp->irq);
+	if (cp->msi_ready) {
+		cp->msi_ready = false;
+		dw_pcie_free_msi(pp);
+		pp->msi_irq_domain = NULL;
+	}
+}
+
+static const struct dw_pcie_host_ops cortina_pcie_host_ops = {
+	.init		= cortina_pcie_host_init,
+	.deinit		= cortina_pcie_host_deinit,
+	.msi_init	= cortina_pcie_msi_init,
+};
+
+/* Standard RC configuration above 512 bytes wedges the CS7542 bus.
+ * The DesignWare private register bank at 0x700 and above remains accessible.
+ */
+static u32 cortina_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base,
+				 u32 reg, size_t size)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(pci);
+	u32 value = 0;
+
+	if (READ_ONCE(cp->link_lost))
+		return ~0U;
+	if (base == pci->dbi_base && reg < 0x700 && reg + size > RC_CFG_LIMIT)
+		return 0;
+	dw_pcie_read(base + reg, size, &value);
+	return value;
+}
+
+static void cortina_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base,
+				   u32 reg, size_t size, u32 value)
+{
+	struct cortina_pcie *cp = to_cortina_pcie(pci);
+
+	if (READ_ONCE(cp->link_lost))
+		return;
+	if (base == pci->dbi_base && reg < 0x700 && reg + size > RC_CFG_LIMIT)
+		return;
+	dw_pcie_write(base + reg, size, value);
+}
+
+static const struct dw_pcie_ops cortina_dw_pcie_ops = {
+	.read_dbi = cortina_pcie_read_dbi,
+	.write_dbi = cortina_pcie_write_dbi,
+	.link_up = cortina_pcie_link_up,
+	.get_ltssm = cortina_pcie_get_ltssm,
+	.start_link = cortina_pcie_start_link,
+	.stop_link = cortina_pcie_stop_link,
+};
+
+static void cortina_pcie_power_off(struct cortina_pcie *cp)
+{
+	gpiod_set_value_cansleep(cp->perst, 1);
+	reset_control_assert(cp->reset);
+	phy_power_off(cp->phy);
+	phy_exit(cp->phy);
+	clk_disable_unprepare(cp->clk);
+}
+
+static int cortina_pcie_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct cortina_pcie *cp;
+	struct dw_pcie *pci;
+	struct resource *res;
+	int ret;
+
+	cp = devm_kzalloc(dev, sizeof(*cp), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+	pci = &cp->pci;
+	pci->dev = dev;
+	pci->ops = &cortina_dw_pcie_ops;
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
+	if (!res)
+		return -EINVAL;
+	cp->dbi_phys = res->start;
+	cp->app = devm_platform_ioremap_resource_byname(pdev, "app");
+	if (IS_ERR(cp->app))
+		return PTR_ERR(cp->app);
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "app");
+	cp->app_phys = res->start;
+	if (res->start < APP_PHYS_BASE ||
+	    (res->start - APP_PHYS_BASE) % APP_PORT_STRIDE ||
+	    (res->start - APP_PHYS_BASE) / APP_PORT_STRIDE >= 3)
+		return -EINVAL;
+	cp->port = (res->start - APP_PHYS_BASE) / APP_PORT_STRIDE;
+	raw_spin_lock_init(&cp->lock);
+	cp->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(cp->clk))
+		return dev_err_probe(dev, PTR_ERR(cp->clk), "controller clock\n");
+	cp->reset = devm_reset_control_get_exclusive(dev, NULL);
+	if (IS_ERR(cp->reset))
+		return dev_err_probe(dev, PTR_ERR(cp->reset), "controller reset\n");
+	cp->phy = devm_phy_get(dev, "pcie");
+	if (IS_ERR(cp->phy))
+		return dev_err_probe(dev, PTR_ERR(cp->phy), "SerDes\n");
+	cp->perst = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(cp->perst))
+		return dev_err_probe(dev, PTR_ERR(cp->perst), "PERST# GPIO\n");
+	cp->irq = platform_get_irq(pdev, 0);
+	if (cp->irq < 0)
+		return cp->irq;
+
+	ret = clk_prepare_enable(cp->clk);
+	if (ret)
+		return ret;
+	ret = phy_init(cp->phy);
+	if (ret)
+		goto disable_clk;
+	ret = phy_set_mode(cp->phy, PHY_MODE_PCIE);
+	if (ret)
+		goto exit_phy;
+	ret = phy_power_on(cp->phy);
+	if (ret)
+		goto exit_phy;
+	ret = reset_control_reset(cp->reset);
+	if (ret)
+		goto power_off;
+	writel(0, cp->app + APP_INT_ENABLE);
+	cortina_pcie_stop_link(pci);
+	writel(readl(cp->app + APP_INT_STATUS), cp->app + APP_INT_STATUS);
+	gpiod_set_value_cansleep(cp->perst, 0);
+	msleep(100);
+	ret = cortina_pcie_port_init(cp);
+	if (ret)
+		goto power_off;
+	ret = cortina_pcie_init_irq_domain(cp);
+	if (ret)
+		goto power_off;
+	irq_set_chained_handler_and_data(cp->irq, cortina_pcie_irq_handler, cp);
+	writel(INT_MSI | INT_ERR_MASK, cp->app + APP_INT_ENABLE);
+	pci->pp.ops = &cortina_pcie_host_ops;
+	ret = dw_pcie_host_init(&pci->pp);
+	if (ret) {
+		writel(0, cp->app + APP_INT_ENABLE);
+		irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
+		irq_domain_remove(cp->intx_domain);
+		goto power_off;
+	}
+	platform_set_drvdata(pdev, cp);
+	return 0;
+
+power_off:
+	gpiod_set_value_cansleep(cp->perst, 1);
+	reset_control_assert(cp->reset);
+	phy_power_off(cp->phy);
+exit_phy:
+	phy_exit(cp->phy);
+disable_clk:
+	reset_control_assert(cp->reset);
+	clk_disable_unprepare(cp->clk);
+	return dev_err_probe(dev, ret, "host initialization\n");
+}
+
+static void cortina_pcie_remove(struct platform_device *pdev)
+{
+	struct cortina_pcie *cp = platform_get_drvdata(pdev);
+
+	dw_pcie_host_deinit(&cp->pci.pp);
+	irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
+	irq_domain_remove(cp->intx_domain);
+	cortina_pcie_power_off(cp);
+}
+
+static void cortina_pcie_shutdown(struct platform_device *pdev)
+{
+	struct cortina_pcie *cp = platform_get_drvdata(pdev);
+
+	writel(0, cp->app + APP_INT_ENABLE);
+	cortina_pcie_stop_link(&cp->pci);
+	gpiod_set_value_cansleep(cp->perst, 1);
+	reset_control_assert(cp->reset);
+}
+
+static const struct of_device_id cortina_pcie_of_match[] = {
+	{ .compatible = "cortina,cs7542-pcie" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, cortina_pcie_of_match);
+
+static struct platform_driver cortina_pcie_driver = {
+	.probe = cortina_pcie_probe,
+	.remove = cortina_pcie_remove,
+	.shutdown = cortina_pcie_shutdown,
+	.driver = {
+		.name = "cs7542-pcie",
+		.of_match_table = cortina_pcie_of_match,
+	},
+};
+module_platform_driver(cortina_pcie_driver);
+
+MODULE_DESCRIPTION("Cortina Systems CS7542 PCIe host controller");
+MODULE_LICENSE("GPL");

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 8/8] MAINTAINERS: Add CS7542 PCIe support
  2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
                   ` (6 preceding siblings ...)
  2026-11-23 18:43 ` [PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
@ 2026-11-23 18:43 ` Fil Dunsky via B4 Relay
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-23 18:43 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Stephen Boyd, Vinod Koul
  Cc: Jingoo Han, Lorenzo Pieralisi, Krzysztof Wilczynski, Rob Herring,
	Bjorn Helgaas, Brian Masney, Jerome Brunet, Neil Armstrong,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel, linux-pci,
	linux-arm-kernel, linux-clk, linux-phy, devicetree, linux-kernel

From: Fil Dunsky <filipp.dunsky@gmail.com>

Cover the new PCIe control, SerDes and host drivers and their bindings
under the existing CS7542 entry.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 MAINTAINERS | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index d8835aeca..d4cada9f8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2949,13 +2949,19 @@ F:	tools/perf/tests/shell/coresight/*
 F:	tools/perf/util/cs-etm-decoder/*
 F:	tools/perf/util/cs-etm.*
 
-ARM/CORTINA SYSTEMS CS7542 GLOBAL CONTROL
+ARM/CORTINA SYSTEMS CS7542 GLOBAL CONTROL AND PCIE
 M:	Fil Dunsky <filipp.dunsky@gmail.com>
 L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 S:	Maintained
+F:	Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml
+F:	Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
+F:	Documentation/devicetree/bindings/phy/cortina,cs7542-pcie-phy.yaml
 F:	Documentation/devicetree/bindings/pinctrl/cortina,cs7542-pinctrl.yaml
 F:	Documentation/devicetree/bindings/soc/cortina/
+F:	drivers/clk/clk-cs7542-pcie.c
 F:	drivers/clk/clk-cs7542.c
+F:	drivers/pci/controller/dwc/pcie-cs7542.c
+F:	drivers/phy/phy-cs7542-pcie.c
 F:	drivers/pinctrl/pinctrl-cs7542.c
 F:	include/dt-bindings/clock/cortina,cs7542-clock.h
 

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/8] dt-bindings: PCI: Describe the CS7542 host controller
  2026-11-23 18:43 ` [PATCH 6/8] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
@ 2026-11-23 18:48   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-23 18:48 UTC (permalink / raw)
  To: Fil Dunsky
  Cc: linux-pci, linux-clk, linux-phy, devicetree, robh, conor+dt,
	vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: PCI: interrupts listed before clocks in
  cortina,cs7542-pcie.yaml
--

commit 7f66a931d3a9682495c9ee6049f36df0d2615a1f
Author: Fil Dunsky <filipp.dunsky@gmail.com>

dt-bindings: PCI: Describe the CS7542 host controller

This commit adds the Device Tree binding schema for the Cortina Systems
CS7542 PCIe host controller.

> diff --git a/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
> new file mode 100644
> index 0000000000000..8883b8d091398
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pci/cortina,cs7542-pcie.yaml
> @@ -0,0 +1,127 @@

[ ... ]

> +properties:
> +  compatible:
> +    const: cortina,cs7542-pcie
> +
> +  reg:
> +    items:
> +      - description: DBI registers including the viewport iATU
> +      - description: Downstream configuration window
> +      - description: Application wrapper registers
> +
> +  reg-names:
> +    items:
> +      - const: dbi
> +      - const: config
> +      - const: app
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  interrupt-names:
> +    const: msi
> +
> +  clocks:
> +    maxItems: 1

[ ... ]

> +required:
> +  - compatible
> +  - reg
> +  - reg-names
> +  - interrupts
> +  - interrupt-names
> +  - clocks

[ ... ]

> +        interrupt-parent = <&gic>;
> +        interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
> +        interrupt-names = "msi";
> +        clocks = <&pcie_control 0>;

[Severity: Low]
This isn't a bug, but DT binding schemas and example nodes place clocks
before interrupts and interrupt-names following the canonical property
order (compatible, reg, reg-names, clocks, interrupts, interrupt-names) in
properties, required, and examples.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-pcie-v1-0-4cde5201d404@gmail.com?part=6

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/8] dt-bindings: clock: Describe CS7542 PCIe gates and resets
  2026-11-23 18:43 ` [PATCH 2/8] dt-bindings: clock: Describe CS7542 PCIe gates and resets Fil Dunsky via B4 Relay
@ 2026-11-23 18:49   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-23 18:49 UTC (permalink / raw)
  To: Fil Dunsky
  Cc: linux-pci, linux-clk, linux-phy, devicetree, robh, conor+dt,
	vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dt-bindings: clock: virtual child node for parent syscon
  clocks and resets
--

commit 9d52d2650fe35dd9a422c99bb705a36a99c1ed9f
Author: Fil Dunsky <filipp.dunsky@gmail.com>

dt-bindings: clock: Describe CS7542 PCIe gates and resets

This commit adds a Devicetree binding for the Cortina Systems CS7542 PCIe
clock gates and resets as a child node of the global control syscon.

> diff --git a/Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml b/Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml
> new file mode 100644
> index 0000000000000..08e0214d2bb22
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/clock/cortina,cs7542-pcie-control.yaml
> @@ -0,0 +1,47 @@
[ ... ]
> +properties:
> +  compatible:
> +    const: cortina,cs7542-pcie-control
> +
> +  "#clock-cells":
> +    const: 1
> +
> +  "#reset-cells":
> +    const: 1
[ ... ]
> diff --git a/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml b/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml
> index fb074de870bd4..52597c4e84d20 100644
> --- a/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml
> +++ b/Documentation/devicetree/bindings/soc/cortina/cortina,cs7542-syscon.yaml
> @@ -29,6 +29,10 @@ properties:
>    "#clock-cells":
>      const: 1
>  
> +  pcie-control:
> +    type: object
> +    $ref: /schemas/clock/cortina,cs7542-pcie-control.yaml#

[Severity: Medium]
Should the PCIe gate clocks and controller resets be provided directly by
the parent cortina,cs7542-syscon node instead of a resource-less
pcie-control child node?

The parent node already maps the 0x100-byte global control register block
and acts as a clock provider with #clock-cells = <1>.  Creating a child
node with no reg property or Devicetree resources of its own puts a
driver split into the Devicetree ABI, contrary to
Documentation/devicetree/bindings/writing-bindings.rst.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-pcie-v1-0-4cde5201d404@gmail.com?part=2

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler
  2026-11-23 18:43 ` [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
@ 2026-11-23 18:52   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-23 18:52 UTC (permalink / raw)
  To: Fil Dunsky
  Cc: linux-pci, linux-clk, linux-phy, devicetree, robh, conor+dt,
	vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] PCI: dwc: use-after-free in dw_pcie_free_msi() [1]
--

commit 73ef750c2f801a3eaf7bfcf95e0a5bd88aebd4c3
Author: Fil Dunsky <filipp.dunsky@gmail.com>

PCI: dwc: Export the multiplexed MSI interrupt handler

This commit exports dw_handle_msi_irq() so that modular DesignWare PCIe host
glue drivers can dispatch the internal MSI receiver directly from a combined
application interrupt handler.

> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index bbb02458af58f..1d076bb62783c 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -85,6 +85,7 @@ void dw_handle_msi_irq(struct dw_pcie_rp *pp)
>  			generic_handle_demux_domain_irq(pp->msi_irq_domain, irq_off + pos);
>  	}
>  }
> +EXPORT_SYMBOL_GPL(dw_handle_msi_irq);
>  
>  /* Chained MSI interrupt service routine */
>  static void dw_chained_msi_isr(struct irq_desc *desc)

[Severity: Critical]
This problem wasn't introduced by this patch, but can dw_handle_msi_irq() hit
a use-after-free on pp->msi_irq_domain when racing with dw_pcie_free_msi()
[1]?

During device unbind or module removal, dw_pcie_free_msi() clears the chained
MSI handlers with irq_set_chained_handler_and_data() and immediately removes
pp->msi_irq_domain without waiting for in-flight interrupts on other CPUs:

drivers/pci/controller/dwc/pcie-designware-host.c:dw_pcie_free_msi() {
	for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++) {
		if (pp->msi_irq[ctrl] > 0)
			irq_set_chained_handler_and_data(pp->msi_irq[ctrl],
							 NULL, NULL);
	}

	irq_domain_remove(pp->msi_irq_domain);
}

If dw_chained_msi_isr() is already running on another CPU when teardown
starts, dw_handle_msi_irq() will pass the freed pp->msi_irq_domain to
generic_handle_demux_domain_irq():

CPU0                                    CPU1
dw_pcie_free_msi()                      dw_chained_msi_isr()
  irq_set_chained_handler_and_data()
  irq_domain_remove(pp->msi_irq_domain)
                                          dw_handle_msi_irq(pp)
                                            generic_handle_demux_domain_irq(
                                              pp->msi_irq_domain, ...)
                                              <-- use-after-free

Calling synchronize_irq() for each active pp->msi_irq[ctrl] before
irq_domain_remove() would ensure no chained handler is still running.

[1] https://sashiko.dev/#/bug/linux-a392f803-d749-417f-bb89-17e283cf6476

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-pcie-v1-0-4cde5201d404@gmail.com?part=1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support
  2026-11-23 18:43 ` [PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
@ 2026-11-23 19:11   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-11-23 19:11 UTC (permalink / raw)
  To: Fil Dunsky
  Cc: linux-pci, linux-clk, linux-phy, devicetree, robh, conor+dt,
	vkoul, neil.armstrong, olteanv

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] PCI: cs7542: PCI_MSI_FLAGS_ENABLE in cortina_pcie_host_init()
  cleared on probe
- [High] PCI: cs7542: undisposed INTx virq mappings before
  irq_domain_remove()
- [Medium] PCI: cs7542: cortina_pcie_read_dbi() ~0U return masks iATU
  failure on link loss
- [Medium] PCI: cs7542: missing link_lost and IRQ sync in
  cortina_pcie_shutdown()
--

commit cd2c931b6a3541fd8734c17e2a7332622247b319
Author: Fil Dunsky <filipp.dunsky@gmail.com>

PCI: cs7542: Add CS7542 PCIe host support

This commit adds a DesignWare PCIe host controller driver for Cortina
Systems CS7542 SoCs, handling clock/reset/PHY setup, multiplexed INTx and
MSI interrupts, root configuration filtering, and link-loss blocking.

> diff --git a/drivers/pci/controller/dwc/pcie-cs7542.c b/drivers/pci/controller/dwc/pcie-cs7542.c
> new file mode 100644
> index 0000000000000..19225e9a292ef
> --- /dev/null
> +++ b/drivers/pci/controller/dwc/pcie-cs7542.c
[ ... ]
> +static int cortina_pcie_host_init(struct dw_pcie_rp *pp)
> +{
> +	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> +	u8 cap = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI);
> +	u16 flags;
> +
> +	pp->bridge->ops = &cortina_own_pci_ops;
> +	pp->keep_rp_msi_en = true;
> +	if (cap) {
> +		flags = dw_pcie_readw_dbi(pci, cap + PCI_MSI_FLAGS);
> +		dw_pcie_writew_dbi(pci, cap + PCI_MSI_FLAGS, flags | PCI_MSI_FLAGS_ENABLE);
> +	}
> +	return 0;
> +}

[Severity: High]
Will pci_host_probe() clear PCI_MSI_FLAGS_ENABLE right after
cortina_pcie_host_init() sets it?

dw_pcie_host_init() runs pp->ops->init(pp) before calling
pci_host_probe(bridge).  Because pp->keep_rp_msi_en keeps PCI_CAP_ID_MSI
visible on the Root Port, enumerating the Root Port calls
pci_init_capabilities() -> pci_msi_init(), which clears
PCI_MSI_FLAGS_ENABLE via cortina_pcie_wr_own_conf() and leaves the Root
Port MSI receiver disabled.  Setting PCI_MSI_FLAGS_ENABLE in
pp->ops->post_init (or after dw_pcie_host_init() returns) would avoid
this.

[ ... ]

> +/* Standard RC configuration above 512 bytes wedges the CS7542 bus.
> + * The DesignWare private register bank at 0x700 and above remains accessible.
> + */
> +static u32 cortina_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base,
> +				 u32 reg, size_t size)
> +{
> +	struct cortina_pcie *cp = to_cortina_pcie(pci);
> +	u32 value = 0;
> +
> +	if (READ_ONCE(cp->link_lost))
> +		return ~0U;
> +	if (base == pci->dbi_base && reg < 0x700 && reg + size > RC_CFG_LIMIT)
> +		return 0;
> +	dw_pcie_read(base + reg, size, &value);
> +	return value;
> +}

[Severity: Medium]
Can returning ~0U from cortina_pcie_read_dbi() when cp->link_lost is set
trick dw_pcie_prog_outbound_atu() into reporting success?

CPU0                                    CPU1
dw_pcie_other_conf_map_bus()
  dw_pcie_link_up() -> true
                                        cortina_pcie_irq_handler()
                                          cp->link_lost = true
  dw_pcie_prog_outbound_atu()
    dw_pcie_writel_atu_ob() (dropped)
    dw_pcie_readl_atu_ob(..., ATU_REGION_CTRL2)
      cortina_pcie_read_dbi() -> ~0U
    val & ATU_ENABLE -> true
    return 0
  return pp->va_cfg0_base + where       <-- accesses downstream cfg window

Because ATU_ENABLE is BIT(31), ~0U satisfies the poll in
dw_pcie_prog_outbound_atu() even though cortina_pcie_write_dbi() dropped
the iATU writes, allowing downstream config accesses to proceed after link
loss.

[ ... ]

> +	ret = dw_pcie_host_init(&pci->pp);
> +	if (ret) {
> +		writel(0, cp->app + APP_INT_ENABLE);
> +		irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
> +		irq_domain_remove(cp->intx_domain);
> +		goto power_off;
> +	}
> +	platform_set_drvdata(pdev, cp);
> +	return 0;
> +
> +power_off:
> +	gpiod_set_value_cansleep(cp->perst, 1);
> +	reset_control_assert(cp->reset);
> +	phy_power_off(cp->phy);
> +exit_phy:
> +	phy_exit(cp->phy);
> +disable_clk:
> +	reset_control_assert(cp->reset);
> +	clk_disable_unprepare(cp->clk);
> +	return dev_err_probe(dev, ret, "host initialization\n");
> +}
> +
> +static void cortina_pcie_remove(struct platform_device *pdev)
> +{
> +	struct cortina_pcie *cp = platform_get_drvdata(pdev);
> +
> +	dw_pcie_host_deinit(&cp->pci.pp);
> +	irq_set_chained_handler_and_data(cp->irq, NULL, NULL);
> +	irq_domain_remove(cp->intx_domain);
> +	cortina_pcie_power_off(cp);
> +}

[Severity: High]
Does removing cp->intx_domain without disposing of its mapped virtual IRQs
leak IRQ descriptors and leave dangling pointers to cp and
cortina_intx_chip?

During pci_host_probe(), pci_assign_irq() maps INTx interrupts in
cp->intx_domain (including for the Root Port itself, where
dw_pcie_setup_rc() sets PCI_INTERRUPT_PIN = 1), and the PCI core does not
unmap shared INTx lines on bus removal.  Both cortina_pcie_remove() and
the dw_pcie_host_init() error path call irq_domain_remove(cp->intx_domain)
without first calling irq_dispose_mapping(irq_find_mapping(cp->intx_domain, i))
for each INTx line, leaving allocated irq_desc entries referencing the
freed domain and driver state.

> +static void cortina_pcie_shutdown(struct platform_device *pdev)
> +{
> +	struct cortina_pcie *cp = platform_get_drvdata(pdev);
> +
> +	writel(0, cp->app + APP_INT_ENABLE);
> +	cortina_pcie_stop_link(&cp->pci);
> +	gpiod_set_value_cansleep(cp->perst, 1);
> +	reset_control_assert(cp->reset);
> +}

[Severity: Medium]
Can cortina_pcie_shutdown() race with in-flight interrupts or subsequent
DBI accesses while asserting controller reset?

CPU0                                    CPU1
cortina_pcie_shutdown()
  writel(0, cp->app + APP_INT_ENABLE)
                                        cortina_pcie_irq_handler()
                                          dw_handle_msi_irq()
  cortina_pcie_stop_link()
  reset_control_assert(cp->reset)
                                            dw_pcie_readl_dbi()  <-- DBI access in reset

cortina_pcie_shutdown() does not take cp->lock, set cp->link_lost = true,
or call synchronize_irq(cp->irq).  An in-flight IRQ handler or a
concurrent config/DBI access (which checks cp->link_lost) can access DBI
after the link is stopped and cp->reset is asserted, and a concurrent
cortina_intx_unmask() can also re-enable bits in APP_INT_ENABLE.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-b4-cs7542-pcie-v1-0-4cde5201d404@gmail.com?part=7

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-11-23 19:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 18:43 [PATCH 0/8] soc: cortina: Add CS7542 PCIe control, SerDes and host support Fil Dunsky via B4 Relay
2026-11-23 18:43 ` [PATCH 1/8] PCI: dwc: Export the multiplexed MSI interrupt handler Fil Dunsky via B4 Relay
2026-11-23 18:52   ` sashiko-bot
2026-11-23 18:43 ` [PATCH 2/8] dt-bindings: clock: Describe CS7542 PCIe gates and resets Fil Dunsky via B4 Relay
2026-11-23 18:49   ` sashiko-bot
2026-11-23 18:43 ` [PATCH 3/8] clk: Add " Fil Dunsky via B4 Relay
2026-11-23 18:43 ` [PATCH 4/8] dt-bindings: phy: Describe CS7542 PCIe SerDes Fil Dunsky via B4 Relay
2026-11-23 18:43 ` [PATCH 5/8] phy: Add CS7542 PCIe SerDes support Fil Dunsky via B4 Relay
2026-11-23 18:43 ` [PATCH 6/8] dt-bindings: PCI: Describe the CS7542 host controller Fil Dunsky via B4 Relay
2026-11-23 18:48   ` sashiko-bot
2026-11-23 18:43 ` [PATCH 7/8] PCI: cs7542: Add CS7542 PCIe host support Fil Dunsky via B4 Relay
2026-11-23 19:11   ` sashiko-bot
2026-11-23 18:43 ` [PATCH 8/8] MAINTAINERS: Add CS7542 PCIe support Fil Dunsky via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox