Skip to contentSkip to conversation

phy: airoha: add support for AN7583 PCIe PHY driver

PATCH Superseded Christian Marangi 3 participants 8 messages Aug 27 – Sep 3

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover phy: airoha: add support for AN7583 PCIe PHY driver

This small series introduce support for Airoha AN7583 Gen3 PCIe PHY.

It's not possible to reuse the EN7581 code as the register changed between the 2 SoC and also the setup method changed (different calibration logic)

Putting the PHY in a dedicated directory is also needed for other series current pending that will add USB PHY support.

Also a dedicated schema is added as the register names is entirely different compared to EN7581.

Changes v2:
- Drop move patch (handled in different series)
- Rework to regmap implementation
- Rename files to more specific name
- Add .exit logic
- Drop QPHY in favor of external PHY handling
- Update schema with new requirement and improve example

Christian Marangi (2):
dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY
phy: airoha: add support for AN7583 Gen3 PCIe PHY driver

 .../phy/airoha,an7583-pcie-gen3-phy.yaml      |  65 ++
 MAINTAINERS                                   |   8 +
 drivers/phy/Kconfig                           |   1 +
 drivers/phy/Makefile                          |   3 +-
 drivers/phy/airoha/Kconfig                    |  13 +
 drivers/phy/airoha/Makefile                   |   2 +
 drivers/phy/airoha/phy-an7583-pcie-regs.h     | 377 ++++++++
 drivers/phy/airoha/phy-an7583-pcie.c          | 815 ++++++++++++++++++
 8 files changed, 1283 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml
 create mode 100644 drivers/phy/airoha/Kconfig
 create mode 100644 drivers/phy/airoha/Makefile
 create mode 100644 drivers/phy/airoha/phy-an7583-pcie-regs.h
 create mode 100644 drivers/phy/airoha/phy-an7583-pcie.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY

Document support for AN7583 PCIe PHY used to make the Gen3 PCIe port work. Add the required register to configure the PCIe PHY and provide an example for it.

---
 .../phy/airoha,an7583-pcie-gen3-phy.yaml      | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +65 -0
new file mode 100644
index 000000000000..07bb20152c0a
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/airoha,an7583-pcie-gen3-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN7583 PCI-Express PHY
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+description:
+  The PCIe PHY supports physical layer functionality for PCIe Gen2/Gen3 port.
+
+properties:
+  compatible:
+    const: airoha,an7583-pcie-gen3-phy
+
+  reg:
+    items:
+      - description: PCIE G3 analog base address
+      - description: PCIE G3 PMA base address
+      - description: PCIE detection time base address
+      - description: PCIE Rx AEQ base address
+
+  reg-names:
+    items:
+      - const: g3-ana
+      - const: g3-pma
+      - const: xr-dtime
+      - const: rx-aeq
+
+  phys:
+    items:
+      - description: phandle to QPHY phy for Gen2 support
+
+  "#phy-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - phys
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+
+    phy@1fc7f000 {
+        compatible = "airoha,an7583-pcie-gen3-phy";
+        reg = <0x1fc7f000 0xfff>,
+              <0x1fc7e000 0xfff>,
+              <0x1fc30044 0x4>,
+              <0x1fc35030 0x4>;
+        reg-names = "g3-ana", "g3-pma",
+                    "xr-dtime", "rx-aeq";
+
+        phys = <&pcie1_phy PHY_TYPE_PCIE>;
+
+        #phy-cells = <0>;
+    };
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Incorrect memory region size in the device tree example (0xfff instead of 0x1000). --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incorrect memory region size in the device tree example (0xfff instead of 0x1000). --

commit 41aa642fd5dfb10ea2b50d62af99f95cc040fb55
Author: Christian Marangi <[email protected]>

dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY

Document support for AN7583 PCIe PHY used to make the Gen3 PCIe port work. Add the required register to configure the PCIe PHY and provide an example for it.

Quoted 5 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +0 -0
new file mode 100644
index 0000000000000..07bb20152c0a7

[ ... ]

Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml line 56

Quoted 8 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +8 -0
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+
+    phy@1fc7f000 {
+        compatible = "airoha,an7583-pcie-gen3-phy";
+        reg = <0x1fc7f000 0xfff>,
+              <0x1fc7e000 0xfff>,

[Severity: Low]
Are these memory region sizes off-by-one?

Since the base addresses (0x1fc7e000 and 0x1fc7f000) are exactly 4KB (0x1000) apart, a size of 0xfff (4095 bytes) mathematically leaves the last byte of the 4KB block unmapped.

While ioremap rounds up to the page size meaning there is likely no functional failure in practice, should this specify 0x1000 instead to prevent propagating off-by-one size errors to consumers of this example?

Quoted 9 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +9 -0
+              <0x1fc30044 0x4>,
+              <0x1fc35030 0x4>;
+        reg-names = "g3-ana", "g3-pma",
+                    "xr-dtime", "rx-aeq";
+
+        phys = <&pcie1_phy PHY_TYPE_PCIE>;
+
+        #phy-cells = <0>;
+    };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY

In reply to Christian Marangi

Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml line 56

Quoted 9 lines · Christian Marangi
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +9 -0
+
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+
+    phy@1fc7f000 {
+        compatible = "airoha,an7583-pcie-gen3-phy";
+        reg = <0x1fc7f000 0xfff>,
+              <0x1fc7e000 0xfff>,

Sashiko has a valid point here.

This should reflect real hardware, not current driver. It is very, very unlikely that hardware designers designed a block of 0xfff size or 0x4

Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml line 58

Quoted 2 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +2 -0
+              <0x1fc30044 0x4>,
+              <0x1fc35030 0x4>;

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY

Quoted 13 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml line 56

Quoted 9 lines · Christian Marangi
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +9 -0
+
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+
+    phy@1fc7f000 {
+        compatible = "airoha,an7583-pcie-gen3-phy";
+        reg = <0x1fc7f000 0xfff>,
+              <0x1fc7e000 0xfff>,

Sashiko has a valid point here.

Quoted 3 lines

This should reflect real hardware, not current driver. It is very, very unlikely that hardware designers designed a block of 0xfff size or 0x4

Hi for 0xfff yes the block is 0x1000 but I was reporting how it was defined in the original DTS. For the 0x4 is for real a single register for that usage. Documentation is scarce for that single block but this also reflect the same implementation used on EN7581. I updated the example to address the strange block of 0xfff.

Quoted 3 lines
Quoted 2 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +2 -0
+              <0x1fc30044 0x4>,
+              <0x1fc35030 0x4>;
Signature · 1 line
	Ansuel
#5 lore raw

Re: [PATCH v2 1/2] dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY

Quoted 14 lines · Christian Marangi
Quoted 13 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml line 56

Quoted 9 lines · Christian Marangi
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +9 -0
+
+examples:
+  - |
+    #include <dt-bindings/phy/phy.h>
+
+    phy@1fc7f000 {
+        compatible = "airoha,an7583-pcie-gen3-phy";
+        reg = <0x1fc7f000 0xfff>,
+              <0x1fc7e000 0xfff>,

Sashiko has a valid point here.

Quoted 6 lines
Quoted 3 lines

This should reflect real hardware, not current driver. It is very, very unlikely that hardware designers designed a block of 0xfff size or 0x4

Hi for 0xfff yes the block is 0x1000 but I was reporting how it was defined in the original DTS. For the 0x4 is for real a single register for that

And the original DTS was likely wrong...

Quoted 3 lines

usage. Documentation is scarce for that single block but this also reflect the same implementation used on EN7581. I updated the example to address the strange block of 0xfff.

Best regards,
Krzysztof

#6 lore raw

PATCH v2 2/2 phy: airoha: add support for AN7583 Gen3 PCIe PHY driver

In reply to Christian Marangi

Add support for AN7583 PCIe PHY driver. This is required to make the Gen3 PCIe port present on the Airoha AN7583 SoC correctly work.

A different setup is needed compared to Airoha EN7581 where the calibration process and the register map greatly changed.

---
 MAINTAINERS                               |   8 +
 drivers/phy/Kconfig                       |   1 +
 drivers/phy/Makefile                      |   3 +-
 drivers/phy/airoha/Kconfig                |  13 +
 drivers/phy/airoha/Makefile               |   2 +
 drivers/phy/airoha/phy-an7583-pcie-regs.h | 377 ++++++++++
 drivers/phy/airoha/phy-an7583-pcie.c      | 815 ++++++++++++++++++++++
 7 files changed, 1218 insertions(+), 1 deletion(-)
 create mode 100644 drivers/phy/airoha/Kconfig
 create mode 100644 drivers/phy/airoha/Makefile
 create mode 100644 drivers/phy/airoha/phy-an7583-pcie-regs.h
 create mode 100644 drivers/phy/airoha/phy-an7583-pcie.c
MAINTAINERS +8 -0
index fe10d29b7657..260261b6a688 100644
@@ -767,6 +767,14 @@ F:	Documentation/devicetree/bindings/phy/airoha,en7581-pcie-phy.yaml
 F:	drivers/phy/phy-airoha-pcie-regs.h
 F:	drivers/phy/phy-airoha-pcie.c
 
+AIROHA AN7583 PCIE PHY DRIVER
+M:	Christian Marangi <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml
+F:	drivers/phy/airoha/phy-an7583-pcie-regs.h
+F:	drivers/phy/airoha/phy-an7583-pcie.c
+
 AIROHA SPI SNFI DRIVER
 M:	Lorenzo Bianconi <[email protected]>
 M:	Ray Liu <[email protected]>
drivers/phy/Kconfig +1 -0
index 19f3b7d12b7d..80b7c50fd768 100644
@@ -168,6 +168,7 @@ config PHY_XGENE
 	help
 	  This option enables support for APM X-Gene SoC multi-purpose PHY.
 
+source "drivers/phy/airoha/Kconfig"
 source "drivers/phy/allwinner/Kconfig"
 source "drivers/phy/amlogic/Kconfig"
 source "drivers/phy/apple/Kconfig"
drivers/phy/Makefile +2 -1
index d7aa516bcc49..0baf0b7fd077 100644
@@ -20,7 +20,8 @@ obj-$(CONFIG_PHY_PISTACHIO_USB)		+= phy-pistachio-usb.o
 obj-$(CONFIG_PHY_SNPS_EUSB2)		+= phy-snps-eusb2.o
 obj-$(CONFIG_PHY_XGENE)			+= phy-xgene.o
 
-obj-$(CONFIG_GENERIC_PHY)		+= allwinner/	\
+obj-$(CONFIG_GENERIC_PHY)		+= airoha/	\
+					   allwinner/	\
 					   amlogic/	\
 					   apple/	\
 					   axiado/	\
drivers/phy/airoha/Kconfig new file +13 -0
new file mode 100644
index 000000000000..55fd20f29da6
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Phy drivers for Airoha platforms
+#
+config PHY_AIROHA_AN7583_PCIE
+	tristate "Airoha AN7583 PCIe-PHY Driver"
+	depends on ARCH_AIROHA || COMPILE_TEST
+	depends on OF
+	select GENERIC_PHY
+	help
+	  Say Y here to add support for Airoha AN7583 PCIe PHY driver.
+	  This driver create the basic PHY instance and provides initialize
+	  callback for PCIe GEN3 port.
drivers/phy/airoha/Makefile new file +2 -0
new file mode 100644
index 000000000000..ca0fe9cffc96
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_PHY_AIROHA_AN7583_PCIE)	+= phy-an7583-pcie.o
drivers/phy/airoha/phy-an7583-pcie-regs.h new file +377 -0

377 lines not on this page · raw message

drivers/phy/airoha/phy-an7583-pcie.c new file +815 -0

815 lines not on this page · raw message

Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH v2 2/2] phy: airoha: add support for AN7583 Gen3 PCIe PHY driver

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing hardware state cleanup on error path in `an7583_pcie_phy_init()`. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing hardware state cleanup on error path in an7583_pcie_phy_init(). --

commit 62d7cb2950076a9ff89670b2868f00bd58e5c43e
Author: Christian Marangi <[email protected]>

phy: airoha: add support for AN7583 Gen3 PCIe PHY driver

Add support for AN7583 PCIe PHY driver. This is required to make the Gen3 PCIe port present on the Airoha AN7583 SoC correctly work.

Quoted 5 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +0 -0
new file mode 100644
index 0000000000000..61b5f1dd64c07

[ ... ]

Quoted 13 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +13 -0
+static int an7583_pcie_phy_init(struct phy *phy)
+{
+	struct an7583_pcie_phy *pcie_phy = phy_get_drvdata(phy);
+	u32 val;
+	int ret;
+
+	/* Setup Tx-Rx detection time */
+	val = FIELD_PREP(PCIE_XTP_RXDET_VCM_OFF_STB_T_SEL, 0x33) |
+	      FIELD_PREP(PCIE_XTP_RXDET_EN_STB_T_SEL, 0x1) |
+	      FIELD_PREP(PCIE_XTP_RXDET_FINISH_STB_T_SEL, 0x2) |
+	      FIELD_PREP(PCIE_XTP_TXPD_TX_DATA_EN_DLY, 0x3) |
+	      FIELD_PREP(PCIE_XTP_RXDET_LATCH_STB_T_SEL, 0x1);
+	regmap_write(pcie_phy->xr_dtime, REG_PCIE_PEXTP_DIG_GLB44, val);

[ ... ]

drivers/phy/airoha/phy-an7583-pcie.c line 670

Quoted 9 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +9 -0
+	regmap_set_bits(pcie_phy->g3_pma, REG_SS_DA_XPON_PWDB_0,
+			G3_PMA_DA_XPON_CDR_PR_PWDB);
+
+	usleep_range(100, 200);
+
+	ret = phy_init(pcie_phy->qp_phy);
+	if (ret) {
+		dev_err(pcie_phy->dev, "failed to initialize QP phy\n");
+		return ret;

[Severity: Medium]
Does this error path need to unwind the hardware state changes made earlier in an7583_pcie_phy_init()?

If phy_init() fails, the PHY framework won't call the .exit callback because init_count hasn't been incremented. This could leave hardware resources like PLLs, LDOs, and clocks fully enabled and un-reset. Should there be a cleanup sequence here or a call to a teardown helper?

Quoted 7 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +7 -0
+	}
+
+	/* Wait for the PCIe PHY to complete initialization before returning */
+	msleep(PHY_HW_INIT_TIME_MS);
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2