phy: Add support for Airoha AN7583 USB PHY
Subsystems (2)
v5 cover phy: Add support for Airoha AN7583 USB PHY
This small series add support for Airoha USB PHY and Gen2 PCIe PHY.
Changes v5:
- Rebase on top of phy/next
- Add Tested-by tag
Changes v4:
- Fix typo for Documentation patch
- Fix wrong regex for usb subnode for Documentation patch
- Improve register example for Documentation patch
- Address bugs reported by bot (off-by one and xlate function)
Changes v3:
- Fix broken patch for YAML patch
- Split the YAML for USB and PCIe
- Rework driver to direct node for PCIe PHY
Changes v2:
- Add Documentation
- Out of RFC
- Rework to Serdes PHY instead of SCU (following
for consistency AN7581 implementation)
Christian Marangi (3):
dt-bindings: phy: airoha: Document support for AN7583 USB PHY
dt-bindings: phy: airoha: Document support for AN7583 Gen2 PCIe PHY
phy: airoha: Add support for Airoha AN7583 USB PHY
.../phy/airoha,an7583-pcie-gen2-phy.yaml | 63 + .../bindings/phy/airoha,an7583-usb-phy.yaml | 133 ++ drivers/phy/airoha/Kconfig | 11 + drivers/phy/airoha/Makefile | 1 + drivers/phy/airoha/phy-an7583-usb.c | 2023 +++++++++++++++++ 5 files changed, 2231 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml create mode 100644 drivers/phy/airoha/phy-an7583-usb.c
Signature · 1 line
2.55.0
PATCH v5 1/3 dt-bindings: phy: airoha: Document support for AN7583 USB PHY
Add documentation for Airoha AN7583 USB PHY that describe the USB PHY for the USB controller.
Airoha AN7583 SoC support a maximum of 2 USB port. The USB 2.0 mode is always supported. The USB 3.0 mode is optional and depends on the Serdes mode currently configured on the system for the relevant USB port.
To correctly calibrate, the USB 2.0 port require correct value in "airoha,usb2-monitor-clk-sel" property. Both the 2 USB 2.0 port permit selecting one of the 4 monitor clock for calibration (internal clock not exposed to the system) but each port have only one of the 4 actually connected in HW hence the correct value needs to be specified in DT based on board and the physical port. Normally it's monitor clock 1 for USB1 and monitor clock 2 for USB2.
To correctly setup the Serdes mode attached to the USB 3.0 mode, a phys property is required with the phandle pointing to the correct Serdes port provided by the SCU node. Providing the phys property is optional if USB 3.0 is not used.
--- .../bindings/phy/airoha,an7583-usb-phy.yaml | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +133 -0
@@ -0,0 +1,133 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/airoha,an7583-usb-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN7583 SoC USB PHY + +maintainers: + - Christian Marangi <[email protected]> + +description: > + The Airoha AN7583 SoC USB PHY describes the USB PHY for the USB controller.. + + Airoha AN7583 SoC support a maximum of 2 USB port. The USB 2.0 mode is + always supported. The USB 3.0 mode is optional and depends on the Serdes + mode currently configured on the system for the relevant USB port. + + On Airoha AN7583 there is an unified PHY implementation where a single + PHY provide support for both the 2 USB 2.0 port and + optionally one 3.0 USB. + +properties: + compatible: + const: airoha,an7583-usb-phy + + reg: + items: + - description: phy register + - description: ana register + - description: pma register + - description: dig register + + reg-names: + items: + - const: phy + - const: ana + - const: pma + - const: dig + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + usb3-phy: + type: object + + properties: + phys: + items: + - description: phandle to Serdes PHY + + '#phy-cells': + description: The cell contains the mode, PHY_TYPE_USB2 or PHY_TYPE_USB3, + as defined in dt-bindings/phy/phy.h. + const: 1 + + required: + - phys + - '#phy-cells' + + additionalProperties: false + +patternProperties: + '^usb2-phy@[0-9a-f]+$': + type: object + + properties: + reg: + enum: [0x0, 0x1000] + + airoha,usb2-monitor-clk-sel: + description: Describe what oscillator across the available 4 + should be selected for USB 2.0 Slew Rate calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + + '#phy-cells': + description: The cell contains the mode, PHY_TYPE_USB2 or PHY_TYPE_USB3, + as defined in dt-bindings/phy/phy.h. + const: 1 + + required: + - reg + - airoha,usb2-monitor-clk-sel + - '#phy-cells' + + additionalProperties: false + +required: + - compatible + - reg + - reg-names + - '#address-cells' + - '#size-cells' + +unevaluatedProperties: false + +examples: + - | + phy@1fac0000 { + compatible = "airoha,an7583-usb-phy"; + reg = <0x1fac0000 0x1200>, + <0x1fa6f000 0x100>, + <0x1fa6e000 0x400>, + <0x1fa6a000 0x900>; + reg-names = "phy", "ana", "pma", "dig"; + + #address-cells = <1>; + #size-cells = <0>; + + usb2-phy@0 { + reg = <0x0>; + airoha,usb2-monitor-clk-sel = <0>; + + #phy-cells = <1>; + }; + + usb2-phy@1000 { + reg = <0x1000>; + airoha,usb2-monitor-clk-sel = <1>; + + #phy-cells = <1>; + }; + + usb3-phy { + phys = <&serdes_phy>; + + #phy-cells = <1>; + }; + };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 1/3] dt-bindings: phy: airoha: Document support for AN7583 USB PHY
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] dt-bindings: phy: airoha: mixed addressed and unaddressed PHY subnodes - [Low] dt-bindings: phy…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] dt-bindings: phy: airoha: mixed addressed and unaddressed PHY subnodes
- [Low] dt-bindings: phy: airoha: copy-pasted #phy-cells in AN7583 USB subnodes
- [Low] dt-bindings: phy: airoha: AN7583 commit msg describes AN7581 layout
- [Low] dt-bindings: phy: airoha: singular register in reg item descriptions
--
commit 28d6de48d44444f428cdf1e96b4b62c78a9e6bbb
Author: Christian Marangi <[email protected]>
Quoted 17 lines
dt-bindings: phy: airoha: Document support for AN7583 USB PHY
Add documentation for Airoha AN7583 USB PHY that describe the USB PHY for the USB controller.
Airoha AN7583 SoC support a maximum of 2 USB port. The USB 2.0 mode is always supported. The USB 3.0 mode is optional and depends on the Serdes mode currently configured on the system for the relevant USB port.
To correctly calibrate, the USB 2.0 port require correct value in "airoha,usb2-monitor-clk-sel" property. Both the 2 USB 2.0 port permit selecting one of the 4 monitor clock for calibration (internal clock not exposed to the system) but each port have only one of the 4 actually connected in HW hence the correct value needs to be specified in DT based on board and the physical port. Normally it's monitor clock 1 for USB1 and monitor clock 2 for USB2.
Quoted 6 lines
To correctly setup the Serdes mode attached to the USB 3.0 mode, a phys property is required with the phandle pointing to the correct Serdes port provided by the SCU node. Providing the phys property is optional if USB 3.0 is not used.
Signed-off-by Christian Marangi <[email protected]>
[Severity: Low]
This commit message appears to be copied from commit b5e699a21adf ("dt-bindings: phy: Add documentation for Airoha AN7581 USB PHY") and still describes the AN7581 single-node layout rather than this binding. In particular, it states that the phys property is optional if USB 3.0 is not used (whereas here phys is required inside the optional usb3-phy subnode), says monitor clocks 1 and 2 are normally used (while the example uses 0 and 1), and does not mention the unified PHY layout with child nodes.
Quoted 6 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +0
-0@@ -0,0 +1,133 @@
[ ... ]
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml line 32
Quoted 10 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +10
-0+properties: + compatible: + const: airoha,an7583-usb-phy + + reg: + items: + - description: phy register + - description: ana register + - description: pma register + - description: dig register
[Severity: Low]
As reported by Krzysztof Kozlowski on v4 [1], each entry in reg describes a register range rather than a single register, so these descriptions should use the plural "registers".
Quoted 30 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +30
-0+ + reg-names: + items: + - const: phy + - const: ana + - const: pma + - const: dig + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + usb3-phy: + type: object + + properties: + phys: + items: + - description: phandle to Serdes PHY + + '#phy-cells': + description: The cell contains the mode, PHY_TYPE_USB2 or PHY_TYPE_USB3, + as defined in dt-bindings/phy/phy.h. + const: 1 + + required: + - phys + - '#phy-cells'
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml line 72
Quoted 10 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +10
-0+ + additionalProperties: false + +patternProperties: + '^usb2-phy@[0-9a-f]+$': + type: object + + properties: + reg: + enum: [0x0, 0x1000]
[Severity: Medium]
As reported by Krzysztof Kozlowski on v2 [2], this binding mixes addressed MMIO child nodes (usb2-phy@0 and usb2-phy@1000) with an unaddressed child node (usb3-phy) under a parent with #address-cells = <1> and #size-cells = <0>. The 0x0 and 0x1000 offsets are already covered by the parent phy register region (0x1fac0000 0x1200) and the child nodes have no independent resources, so should the child nodes be dropped and folded into the parent node?
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml line 83
Quoted 11 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +11
-0+ + airoha,usb2-monitor-clk-sel: + description: Describe what oscillator across the available 4 + should be selected for USB 2.0 Slew Rate calibration. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + + '#phy-cells': + description: The cell contains the mode, PHY_TYPE_USB2 or PHY_TYPE_USB3, + as defined in dt-bindings/phy/phy.h. + const: 1
[Severity: Low]
Why do both usb3-phy and usb2-phy@[0-9a-f]+ require #phy-cells = <1> to select between PHY_TYPE_USB2 and PHY_TYPE_USB3?
Unlike airoha,an7581-usb-phy.yaml where a single node provides both USB 2.0 and USB 3.0 PHYs, each subnode here represents a single PHY of a fixed type (USB 3.0 for usb3-phy and USB 2.0 for usb2-phy), and the driver's an7583_usb_phy_parse_ports() and an7583_usb_phy_xlate() already determine the PHY type from the subnode itself rather than the phandle cell.
[1] https://lore.kernel.org/r/20260907-auspicious-liberal-raccoon-bd7a81@quoll
[2] https://lore.kernel.org/r/20260813-xanthic-sawfly-of-greatness-47e9bc@quoll
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/3 dt-bindings: phy: airoha: Document support for AN7583 Gen2 PCIe PHY
In reply to Christian MarangiDocument support for AN7583 Gen2 PCIe PHY used to make the Gen2 PCIe port work. Add the required register to configure the PCIe PHY and provide an example for it.
Similar to the USB 3.0 PHY, a dedicated phys property is required to configure the serdes for PCIe or Ethernet usage.
--- .../phy/airoha,an7583-pcie-gen2-phy.yaml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml new file +63 -0
@@ -0,0 +1,63 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/airoha,an7583-pcie-gen2-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN7583 SoC PCIe Gen2 PHY + +maintainers: + - Christian Marangi <[email protected]> + +description: > + The Airoha AN7583 SoC PCIe Gen2 PHY describes the PCIe PHY for the + Gen2 PCIe controller. + + This PCIe PHY makes use of a dedicated USB PHY for PCIe usage and + can also be used for Ethernet usage for SGMII or HSGMII mode. + +properties: + compatible: + const: airoha,an7583-pcie-gen2-phy + + reg: + items: + - description: ana register + - description: pma register + - description: dig register + + reg-names: + items: + - const: ana + - const: pma + - const: dig + + phys: + items: + - description: phandle to Serdes PHY + + '#phy-cells': + const: 0 + +required: + - compatible + - reg + - reg-names + - phys + - '#phy-cells' + +additionalProperties: false + +examples: + - | + phy@1fa5f000 { + compatible = "airoha,an7583-pcie-gen2-phy"; + reg = <0x1fa5f000 0x100>, + <0x1fa5e000 0x400>, + <0x1fa5a000 0x900>; + reg-names = "ana", "pma", "dig"; + + phys = <&serdes_phy>; + + #phy-cells = <0>; + };
Signature · 1 line
2.55.0
PATCH v5 3/3 phy: airoha: Add support for Airoha AN7583 USB PHY
In reply to Christian MarangiAdd support for USB PHY for Airoha AN7583 SoC, this share some U2 init from AN7581 but use a totally different init phase for PLL and calibration for U3. Also on AN7583 there is a single USB PHY that init 2 U2 port and one U3 port. (the USB controller expose 2 hub, one with 2 usb 2.0 port and one with one 3.0 port)
A second USB PHY is used for PCIe Gen2 controller and follow the same calibration and setup logic of USB.
--- drivers/phy/airoha/Kconfig | 11 + drivers/phy/airoha/Makefile | 1 + drivers/phy/airoha/phy-an7583-usb.c | 2023 +++++++++++++++++++++++++++ 3 files changed, 2035 insertions(+) create mode 100644 drivers/phy/airoha/phy-an7583-usb.c
drivers/phy/airoha/Kconfig +11 -0
@@ -22,3 +22,14 @@ config PHY_AIROHA_AN7581_USB Say 'Y' here to add support for Airoha AN7581 USB PHY driver. This driver create the basic PHY instance and provides initialize callback for USB port. + +config PHY_AIROHA_AN7583_USB + tristate "Airoha AN7583 USB PHY Driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on OF + select GENERIC_PHY + select REGMAP_MMIO + help + Say 'Y' here to add support for Airoha AN7583 USB PHY driver. + This driver create the basic PHY instance and provides initialize + callback for USB port.
drivers/phy/airoha/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_PHY_AIROHA_AN7581_PCIE) += phy-an7581-pcie.o obj-$(CONFIG_PHY_AIROHA_AN7581_USB) += phy-an7581-usb.o +obj-$(CONFIG_PHY_AIROHA_AN7583_USB) += phy-an7583-usb.o
drivers/phy/airoha/phy-an7583-usb.c new file +2023 -0
2,023 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 3/3] phy: airoha: Add support for Airoha AN7583 USB PHY
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] phy: airoha: broken 0-cell PCIe xlate and type check in an7583_usb_phy_xlate() - [High] phy: airoha…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] phy: airoha: broken 0-cell PCIe xlate and type check in an7583_usb_phy_xlate()
- [High] phy: airoha: broken USB host mode and SerDes init in an7583_usb_phy_init()
- [Medium] phy: airoha: unshifted AIROHA_USB_ANA_TX_RESERVE_8 write to register 0x28
- [Medium] phy: airoha: write RX_IMP_SEL to INTF_STS_9 in an7583_usb_phy_set_mode_eth()
--
commit 8d0f29ff8d877f4177177940f87f2d0a3776baf6
Author: Christian Marangi <[email protected]>
phy: airoha: Add support for Airoha AN7583 USB PHY
This commit adds a PHY driver for the Airoha AN7583 USB PHY (supporting two USB 2.0 ports and one USB 3.0 port) and the AN7583 PCIe Gen2 PHY.
[Severity: Medium]
In drivers/phy/airoha/phy-an7583-usb.c at lines 225-228 and in an7583_usb_phy_set_mode_eth() at lines 671-675, should AIROHA_USB_PMA_RX_IMP_SEL_SEL and AIROHA_USB_PMA_RX_IMP_SEL_FORCE be written to a PMA interface control register instead of AIROHA_USB_PMA_INTF_STS_9 (0x364)?
All other *_SEL and *_FORCE override pairs live in the INTF_CTRL_5..8 block (0x314..0x320), whereas AIROHA_USB_PMA_INTF_STS_9 (0x364) is the status register read for AIROHA_USB_PMA_ADDR_INTF_STS_PLL_VCOCAL during KBand calibration. Writing the RX impedance override to the status register leaves RX impedance unconfigured in SGMII and 2500Base-X Ethernet modes.
[Severity: Medium]
In drivers/phy/airoha/phy-an7583-usb.c, inside an7583_usb_phy_u3_init() at lines 1092-1093 and an7583_usb_phy_pcie_init() at lines 1378-1379, should AIROHA_USB_ANA_TX_RESERVE_8 be wrapped in FIELD_PREP(AIROHA_USB_QP_TX_RESERVE, ...) when updating AIROHA_USB_ANA_QP_TX_MODE_16B_EN (0x28)?
At lines 157-160, AIROHA_USB_ANA_TX_RESERVE_8 (BIT(8)) is defined relative to AIROHA_USB_QP_TX_RESERVE (GENMASK(31, 16)), and an7583_usb_phy_set_mode_eth() at lines 726-729 shifts it with FIELD_PREP(AIROHA_USB_QP_TX_RESERVE, ...). Passing raw AIROHA_USB_ANA_TX_RESERVE_8 to regmap_set_bits() sets bit 8 in the lower half of register 0x28 instead of bit 24.
[Severity: High]
In drivers/phy/airoha/phy-an7583-usb.c, how are USB host modes and SerDes PHY mode selection expected to work across an7583_usb_phy_init() (lines 1408-1429), an7583_usb_phy_u2_set_mode() (lines 1663-1699), and an7583_usb_phy_u3_set_mode() (lines 1701-1731)?
There are three related issues in these paths:
1. During HCD registration, usb_add_hcd() calls usb_phy_roothub_set_mode(hcd->phy_roothub, PHY_MODE_USB_HOST_SS) and falls back to PHY_MODE_USB_HOST only if that call returns an error. an7583_usb_phy_u3_set_mode() only accepts PHY_MODE_ETHERNET and PHY_MODE_USB_DEVICE_SS, returning -EOPNOTSUPP for both host modes and causing usb_add_hcd() to fail when the USB3 PHY is enabled. Even if host modes were allowed in the switch statement, forwarding PHY_MODE_USB_HOST_SS or PHY_MODE_USB_HOST to phy_set_mode_ext(instance->serdes_phy, mode, submode) will be rejected by en7581_serdes_phy_set_mode() in drivers/clk/clk-en7523.c, which only accepts PHY_MODE_USB_DEVICE and PHY_MODE_USB_DEVICE_SS for USB.
2. In an7583_usb_phy_u2_set_mode() at lines 1678-1690, PHY_MODE_USB_HOST_SS hits the default case and returns 0 without updating AIROHA_USB_PHY_U2PHYDTM1. Because the PHY_MODE_USB_HOST_SS call succeeds on USB2 PHYs, usb_add_hcd() skips the fallback call with PHY_MODE_USB_HOST, leaving AIROHA_USB_PHY_FORCE_IDDIG unset.
3. Unlike an7581_usb_phy_init(), an7583_usb_phy_init() runs an7583_usb_phy_u3_init() and an7583_usb_phy_pcie_init() without configuring instance->serdes_phy. Because usb_add_hcd() calls usb_phy_roothub_init() before usb_phy_roothub_set_mode(), USB3 setup and KBand PLL calibration run before instance->serdes_phy is switched to USB mode; and because mtk_pcie_enable_port() in drivers/pci/controller/pcie-mediatek.c only calls phy_init() and phy_power_on() without calling phy_set_mode(), instance->serdes_phy is never configured to PHY_MODE_PCIE.
[Severity: High]
In drivers/phy/airoha/phy-an7583-usb.c, does an7583_usb_phy_xlate() at lines 1775-1814 break lookups for airoha,an7583-pcie-gen2-phy and skip matching the requested PHY type against instance->type?
an7583_usb_phy_probe() at line 1987 registers an7583_usb_phy_xlate() for both airoha,an7583-usb-phy and airoha,an7583-pcie-gen2-phy. However, the binding in Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml specifies #phy-cells = <0>, so args->args_count is 0 for PCIe and the check at line 1786 (if (args->args_count != 1)) unconditionally fails with ERR_PTR(-EINVAL).
In addition, when args->args_count == 1, lines 1806-1811 only check that args->args[0] is one of PHY_TYPE_USB2, PHY_TYPE_USB3, or PHY_TYPE_PCIE rather than verifying that args->args[0] matches the resolved PHY's instance->type.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3