phy: airoha: add support for AN7583 PCIe PHY driver
Subsystems (2)
v3 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 v3:
- Improve example for Documentation patch
- Deinit G3 PHY on QPHY error
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 | 826 ++++++++++++++++++ 8 files changed, 1294 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
PATCH v3 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
@@ -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 0x1000>, + <0x1fc7e000 0x1000>, + <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
Rob Herring
maintainerRe: [PATCH v3 1/2] dt-bindings: phy: airoha: Document support for AN7583 Gen3 PCIe PHY
Quoted 41 lines · Christian Marangi
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.
Signed-off-by Christian Marangi <[email protected]>--- .../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.yamlDocumentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +25
-0@@ -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 +
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml line 35
Quoted 10 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen3-phy.yaml new file +10
-0+ 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
A phy for the phy... That's kind of odd. It there some reason the gen3 and gen2 phys aren't both linked to the PCIe host and controlled from there? Doesn't look like there is any interleaved or cross initialization needed to handle these in one place.
Rob
PATCH v3 2/2 phy: airoha: add support for AN7583 Gen3 PCIe PHY driver
In reply to Christian MarangiAdd 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 | 826 ++++++++++++++++++++++ 7 files changed, 1229 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +826 -0
826 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/2] phy: airoha: add support for AN7583 Gen3 PCIe PHY driver
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Incorrect teardown order and potential resource leak in an7583_pcie_phy_exit(). - [Medium] Calling…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Incorrect teardown order and potential resource leak in an7583_pcie_phy_exit().
- [Medium] Calling phy_init() and phy_exit() on a child PHY from within the parent's init/exit callbacks triggers a lockdep recursive locking warning.
- [Low] Missing 'select REGMAP_MMIO' causes build failures.
--
commit d7a329b5d2d570ebb31f2d95a8c4c781915cf2bd
Author: Christian Marangi <[email protected]>
phy: airoha: add support for AN7583 Gen3 PCIe PHY driver
This commit adds support for the AN7583 PCIe PHY driver. It introduces the initialization callback for the PCIe Gen3 port present on the Airoha AN7583 SoC, which requires a different calibration process and register setup compared to the EN7581.
Quoted 6 lines
drivers/phy/airoha/Kconfig new file +0
-0@@ -0,0 +1,13 @@
[ ... ]
drivers/phy/airoha/Kconfig line 9
Quoted 5 lines
drivers/phy/airoha/Kconfig new file +5
-0+config PHY_AIROHA_AN7583_PCIE + tristate "Airoha AN7583 PCIe-PHY Driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on OF + select GENERIC_PHY
[Severity: Low]
Since the driver uses devm_regmap_init_mmio(), should this Kconfig entry also select REGMAP_MMIO to prevent build failures? If this driver is built with COMPILE_TEST on architectures that do not select REGMAP_MMIO by default, it will cause an undefined reference link error for __devm_regmap_init_mmio_clk.
Quoted 5 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +5
-0+static int an7583_pcie_phy_init (struct phy *phy) +{ +struct an7583_pcie_phy *pcie_phy =phy_get_drvdata (phy); +u32 val; +int ret;
[ ... ]
drivers/phy/airoha/phy-an7583-pcie.c line 706
Quoted 6 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +6
-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);
[Severity: Medium]
Will calling phy_init() on the child PHY from within the parent's init callback trigger a lockdep recursive locking warning? The PHY core already holds the parent's phy->mutex when executing this callback. Since all PHY mutexes are initialized to the same lock class in phy_create(), acquiring the child's mutex here is seen by lockdep as recursive locking on the same class, which will emit a warning splat and disable lockdep.
Quoted 12 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +12
-0+if (ret) { +an7583_pcie_phy_deinit (pcie_phy); + +return dev_err_probe (pcie_phy->dev, ret,"failed to initialize QP phy\n" ); + } + +/* Wait for the PCIe PHY to complete initialization before returning */ +msleep (PHY_HW_INIT_TIME_MS ); + +return 0 ; +} +
drivers/phy/airoha/phy-an7583-pcie.c line 728
Quoted 10 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +10
-0+static int an7583_pcie_phy_exit (struct phy *phy) +{ +struct an7583_pcie_phy *pcie_phy =phy_get_drvdata (phy); +int ret; + + ret =an7583_pcie_phy_deinit (pcie_phy); +if (ret) +return ret; + +return phy_exit (pcie_phy->qp_phy);
[Severity: High]
Does this teardown order safely handle the child PHY? This sequence shuts down the parent PHY hardware and clocks before calling phy_exit() on the child PHY. If the child PHY attempts to access parent-provided clocks or registers during its exit routine, could this cause a bus hang or system crash?
Additionally, if an7583_pcie_phy_deinit() returns an error, the child PHY resource will be leaked due to the early return. Should phy_exit() be called first to exactly reverse the initialization order?
[Severity: Medium]
Similar to the init path, will calling phy_exit() on the child PHY from within the parent's exit callback trigger a lockdep recursive locking warning on phy->mutex?
Quoted 3 lines
drivers/phy/airoha/phy-an7583-pcie.c new file +3
-0+} + +static const struct phy_ops an7583_pcie_phy_ops = {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2