phy: Add support for Airoha AN7583 USB PHY
Subsystems (2)
v3 cover phy: Add support for Airoha AN7583 USB PHY
This small series add support for Airoha USB PHY and Gen2 PCIe PHY.
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/Kconfig | 1 + drivers/phy/Makefile | 3 +- drivers/phy/airoha/Kconfig | 11 + drivers/phy/airoha/Makefile | 3 + drivers/phy/airoha/phy-an7583-usb.c | 2016 +++++++++++++++++ 7 files changed, 2229 insertions(+), 1 deletion(-) 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/Kconfig create mode 100644 drivers/phy/airoha/Makefile create mode 100644 drivers/phy/airoha/phy-an7583-usb.c
Signature · 1 line
2.53.0
PATCH v3 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 AN7581 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-9-a-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 0x11ff>, + <0x1fa6f000 0xff>, + <0x1fa6e000 0x3ff>, + <0x1fa6a000 0x8ff>; + 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.53.0
[email protected]
AI reviewRe: [PATCH v3 1/3] dt-bindings: phy: airoha: Document support for AN7583 USB PHY
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Malformed character range in patternProperties regex allows invalid unit addresses. - [Low] Typo…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Malformed character range in patternProperties regex allows invalid unit addresses.
- [Low] Typo in the binding title and grammatical errors in the description.
--
commit 4a5fe874f5d1686d215561949399a35ae4b5a15b
Author: Christian Marangi <[email protected]>
dt-bindings: phy: airoha: Document support for AN7583 USB PHY
Adds documentation for the Airoha AN7583 USB PHY for the USB controller. The binding details support for up to two USB 2.0 ports, optional USB 3.0 modes via Serdes configuration, and monitor clock calibration.
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml line 7
Quoted 13 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +7
-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 AN7581 SoC USB PHY
[Severity: Low]
This isn't a bug, but is the title targeting the correct SoC variant? The compatible string and filename target AN7583, but the title mistakenly says AN7581.
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml line 13
Quoted 6 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +6
-0+ +maintainers: + - Christian Marangi <[email protected]> + +description: > + The Airoha AN7583 SoC USB PHY describes the USB PHY for the USB controller..
[Severity: Low]
This isn't a bug, but there is a typo here with the double period at the end of the sentence.
[ ... ]
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml line 67
Quoted 2 lines
Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yaml new file +2
-0+patternProperties: + '^usb2-phy@[0-9-a-f]+$':
[Severity: Medium]
Does this regex correctly restrict unit addresses?
The regex [0-9-a-f] contains a hyphen after a completed range (0-9), causing the hyphen to be treated as a literal character rather than part of a valid hex range. This incorrectly validates malformed device tree node names containing hyphens in the unit address (e.g., usb2-phy@0-a).
Should this pattern be updated to [0-9a-f]+ to enforce proper hex unit addresses?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v3 1/3] dt-bindings: phy: airoha: Document support for AN7583 USB PHY
In reply to Christian MarangiQuoted 15 lines · Christian Marangi
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]>
Sashiko comments look valid, also same discussion as in PCI phy.
Best regards,
Krzysztof
PATCH v3 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 AN7581 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-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-phy"; + reg = <0x1fa5f000 0xff>, + <0x1fa5e000 0x3ff>, + <0x1fa5a000 0x8ff>; + reg-names = "ana", "pma", "dig"; + + phys = <&serdes_phy>; + + #phy-cells = <0>; + };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/3] dt-bindings: phy: airoha: Document support for AN7583 Gen2 PCIe PHY
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Low] The binding title incorrectly refers to 'AN7581' instead of 'AN7583'. - [Low] The register sizes in…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] The binding title incorrectly refers to 'AN7581' instead of 'AN7583'.
- [Low] The register sizes in the example are off-by-one, incorrectly using the maximum offset instead of the byte count.
- [Low] The binding filename 'airoha,an7583-pcie-gen2-phy.yaml' does not match the compatible string 'airoha,an7583-pcie-phy'. --
commit a30f9e597cd1c12059c1c3ca3b0550d5e5800f4d
Author: Christian Marangi <[email protected]>
Subject: dt-bindings: phy: airoha: Document support for AN7583 Gen2 PCIe PHY
This commit documents support for the AN7583 Gen2 PCIe PHY, which is used to make the Gen2 PCIe port work. It adds the required registers to configure the PCIe PHY and provides a usage example.
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml line 4
Quoted 10 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml new file +4
-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#
[Severity: Low]
Should the filename (and consequently the $id path) match the defined compatible string airoha,an7583-pcie-phy? The extraneous 'gen2-' in the filename causes it to diverge from the compatible string, which typically triggers a schema validation warning when running dt_binding_check.
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml line 7
Quoted 3 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml new file +3
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN7581 SoC PCIe Gen2 PHY
[Severity: Low]
Does this title incorrectly refer to AN7581 instead of the intended target AN7583?
[ ... ]
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml line 57
Quoted 7 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml new file +7
-0+examples: + - | + phy@1fa5f000 { + compatible = "airoha,an7583-pcie-phy"; + reg = <0x1fa5f000 0xff>, + <0x1fa5e000 0x3ff>, + <0x1fa5a000 0x8ff>;
[Severity: Low]
Are these register sizes in the example off-by-one? The sizes 0xff, 0x3ff, and 0x8ff (255, 1023, and 2303 bytes) are not multiples of 4, meaning the final byte of the last 32-bit register is excluded from the memory region.
A developer copying this example verbatim might create an invalid device tree that could cause out-of-bounds accesses when the driver reads the final register.
Quoted 6 lines
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yaml new file +6
-0+ reg-names = "ana", "pma", "dig"; + + phys = <&serdes_phy>; + + #phy-cells = <0>; + };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v3 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/Kconfig | 1 + drivers/phy/Makefile | 3 +- drivers/phy/airoha/Kconfig | 11 + drivers/phy/airoha/Makefile | 3 + drivers/phy/airoha/phy-an7583-usb.c | 2016 +++++++++++++++++++++++++++ 5 files changed, 2033 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-usb.c
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 +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config PHY_AIROHA_AN7583_USB + tristate "Airoha AN7583 USB PHY Driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on OF + select GENERIC_PHY + 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 new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_PHY_AIROHA_AN7583_USB) += phy-an7583-usb.o
drivers/phy/airoha/phy-an7583-usb.c new file +2016 -0
2,016 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 3/3] phy: airoha: Add support for Airoha AN7583 USB PHY
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider: - [High] Off-by-one error in array bounds check allows out-of-bounds array write. - [High] Incorrect device…
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [High] Off-by-one error in array bounds check allows out-of-bounds array write.
- [High] Incorrect device node is used to fetch the per-port serdes PHY.
- [High] Missing per-port register offset in an7583_usb_phy_u2_set_mode causes cross-instance state corruption.
- [Medium] Uninitialized variable ret is used as an error return code in an7583_usb_phy_parse_ports.
- [Medium] fm_out may be evaluated uninitialized if the regmap polling macro fails.
- [Medium] The PHY initialization error codes for USB3 and PCIe are silently ignored.
- [Medium] Nested acquisition of same-class PHY mutex triggers lockdep warning.
- [Medium] Excessive busy-waiting using mdelay() in PHY initialization loops.
- [Low] Missing fallthrough; annotation in switch statements triggers implicit fallthrough warnings. --
commit e08eb2476fb864bd66e0895961c95bf0fbc89352
Author: Christian Marangi <[email protected]>
phy: airoha: Add support for Airoha AN7583 USB PHY
Adds support for USB PHY on Airoha AN7583 SoC, supporting two U2 ports and one U3 port via a single USB PHY instance, plus a second instance for PCIe Gen2.
Quoted 24 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -280,18 +280,18 @@ static int an7583_usb_phy_u2_slew_rate_calibration(struct phy *phy)/* Timeout can happen and we will apply workaround at the end */ regmap_read_poll_timeout (priv->regs[AIROHA_USB_PHY_PHY ],AIROHA_USB_PHY_FMMONR0 + offset, fm_out, fm_out,AIROHA_USB_PHY_FREQDET_SLEEP ,AIROHA_USB_PHY_FREQDET_TIMEOUT );/* Disable Frequency meter */ regmap_clear_bits (priv->regs[AIROHA_USB_PHY_PHY ],AIROHA_USB_PHY_FMCR0 + offset,AIROHA_USB_PHY_FREQDET_EN );/* Disable Free run clock */ regmap_clear_bits (priv->regs[AIROHA_USB_PHY_PHY ],AIROHA_USB_PHY_FMMONR1 + offset,AIROHA_USB_PHY_FRCK_EN );/* Disable HS TX SR calibration */ regmap_clear_bits(priv->regs[AIROHA_USB_PHY_PHY],
drivers/phy/airoha/phy-an7583-usb.c
Quoted 7 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0AIROHA_USB_PHY_USBPHYACR5 + offset, AIROHA_USB_PHY_USB20_HSTX_SRCAL_EN);usleep_range (1000 ,1500 );/* Frequency was not detected, use default SR calibration value */ if (!fm_out) {
[Severity: Medium]
If the regmap read returns an error here in an7583_usb_phy_u2_slew_rate_calibration(), regmap_read_poll_timeout() will terminate early without initializing fm_out.
Will this cause the subsequent check if (!fm_out) to evaluate garbage data?
[ ... ]
drivers/phy/airoha/phy-an7583-usb.c static bool an7583_usb_phy_u3_kband_is_calibrated(struct an7583_usb_phy_priv *pr · line 345
Quoted 7 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -340,11 +340,11 @@ static bool an7583_usb_phy_u3_kband_is_calibrated(struct an7583_usb_phy_priv *pr/* Read KBand */ regmap_clear_bits (priv->regs[AIROHA_USB_PHY_ANA ],AIROHA_USB_ANA_TDC_FT_CK_EN ,AIROHA_USB_ANA_PLL_DEBUG_SEL );mdelay (5 );
[Severity: Medium]
Can this delay in an7583_usb_phy_u3_kband_is_calibrated() cause excessive CPU stalling?
It uses mdelay(5) twice per loop, and is called up to 50 times in an7583_usb_phy_u3_init(). Because mdelay spins the CPU instead of sleeping, this could freeze the CPU for up to 500ms during hardware initialization failures.
Should this be using usleep_range() or msleep() instead?
[ ... ]
Quoted 17 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -1020,16 +1020,16 @@ static int an7583_usb_phy_init(struct phy *phy)struct an7583_usb_phy_instance *instance =phy_get_drvdata (phy);switch (instance->type) {case PHY_TYPE_USB2 :an7583_usb_phy_u2_init (phy);break ;case PHY_TYPE_USB3 :if (phy_get_mode (phy) ==PHY_MODE_ETHERNET )return 0 ;an7583_usb_phy_u3_init (phy);break ;case PHY_TYPE_PCIE :if (phy_get_mode (phy) ==PHY_MODE_ETHERNET )return 0 ;
Quoted 1 line
an7583_usb_phy_pcie_init(phy);
[Severity: Medium]
Both an7583_usb_phy_u3_init() and an7583_usb_phy_pcie_init() return an error code (-EINVAL) when calibration fails, but those values are ignored here.
Does this falsely notify the PHY framework of a successful initialization?
Quoted 4 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0break ;default :return -EINVAL ; }
[ ... ]
Quoted 11 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -1176,8 +1176,8 @@ static int an7583_usb_phy_u2_set_mode(struct phy *phy, enum phy_mode mode)case PHY_MODE_USB_HOST : val |=AIROHA_USB_PHY_FORCE_IDDIG ;break ;case PHY_MODE_USB_OTG :break ;default :return 0 ; }regmap_update_bits(priv->regs[AIROHA_USB_PHY_PHY],
AIROHA_USB_PHY_U2PHYDTM1,
[Severity: High]
Does this code in an7583_usb_phy_u2_set_mode() write to the base register space of port 0 instead of the correct port?
Unlike other functions (e.g., power_on or init), this directly accesses AIROHA_USB_PHY_U2PHYDTM1 without adding instance->offset. If mode configuration is applied to a secondary port, it seems like this will corrupt port 0's state.
Quoted 2 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0AIROHA_USB_PHY_FORCE_IDDIG | AIROHA_USB_PHY_IDDIG, val);
[ ... ]
drivers/phy/airoha/phy-an7583-usb.c static int an7583_usb_phy_u3_set_mode(struct phy *phy, enum phy_mode mode, · line 1204
Quoted 13 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -1193,12 +1193,12 @@ static int an7583_usb_phy_u3_set_mode(struct phy *phy, enum phy_mode mode, int submode) {struct an7583_usb_phy_instance *instance =phy_get_drvdata (phy);int ret;switch (mode) {case PHY_MODE_ETHERNET :if (submode !=PHY_INTERFACE_MODE_SGMII && submode !=PHY_INTERFACE_MODE_1000BASEX && submode !=PHY_INTERFACE_MODE_2500BASEX )return -EOPNOTSUPP ;case PHY_MODE_USB_DEVICE_SS :
[Severity: Low]
Is this an intentional fallthrough?
If so, this switch block needs a fallthrough annotation to prevent compiler warnings.
drivers/phy/airoha/phy-an7583-usb.c
Quoted 6 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0break ;default :return -EOPNOTSUPP ; } ret =phy_set_mode_ext (instance->serdes_phy, mode, submode);
[Severity: Medium]
Will this nested call to phy_set_mode_ext() in an7583_usb_phy_u3_set_mode() trigger a lockdep warning?
The core PHY framework invokes the driver's set_mode callback with the primary phy->mutex held. Calling phy_set_mode_ext() on the secondary PHY attempts to acquire the secondary PHY's mutex, which belongs to the same lock class.
[ ... ]
drivers/phy/airoha/phy-an7583-usb.c static int an7583_usb_phy_pcie_set_mode(struct phy *phy, enum phy_mode mode, · line 1226
Quoted 13 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -1215,12 +1215,12 @@ static int an7583_usb_phy_pcie_set_mode(struct phy *phy, enum phy_mode mode, int submode) {struct an7583_usb_phy_instance *instance =phy_get_drvdata (phy);int ret;switch (mode) {case PHY_MODE_ETHERNET :if (submode !=PHY_INTERFACE_MODE_SGMII && submode !=PHY_INTERFACE_MODE_1000BASEX && submode !=PHY_INTERFACE_MODE_2500BASEX )return -EOPNOTSUPP ;case PHY_MODE_PCIE :
[Severity: Low]
Is this an intentional fallthrough?
If so, this switch block needs a fallthrough annotation to prevent compiler warnings.
drivers/phy/airoha/phy-an7583-usb.c
Quoted 6 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0break ;default :return -EOPNOTSUPP ; } ret =phy_set_mode_ext (instance->serdes_phy, mode, submode);
[Severity: Medium]
Will this nested call to phy_set_mode_ext() in an7583_usb_phy_pcie_set_mode() trigger a lockdep warning?
The core PHY framework invokes the driver's set_mode callback with the primary phy->mutex held. Calling phy_set_mode_ext() on the secondary PHY attempts to acquire the secondary PHY's mutex, which belongs to the same lock class.
[ ... ]
drivers/phy/airoha/phy-an7583-usb.c static int an7583_usb_phy_parse_ports(struct device *dev, · line 1307
Quoted 12 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -1297,29 +1297,29 @@ static int an7583_usb_phy_parse_ports(struct device *dev,struct an7583_usb_phy_priv *priv, int index, struct device_node *subnode) { const struct an7583_usb_phy_match_data *data;struct an7583_usb_phy_instance *instance;struct phy *phy;int ret; data =of_device_get_match_data (dev);if (index > data->max_instance)
[Severity: High]
Should this bounds check use >= instead of > in an7583_usb_phy_parse_ports()?
The max_instance is the size of the array (3 for USB), so allowing index to equal max_instance will cause an out-of-bounds write when priv->phys[index] is assigned later.
drivers/phy/airoha/phy-an7583-usb.c static int an7583_usb_phy_parse_ports(struct device *dev, · line 1317
Quoted 10 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0return -EINVAL ;if (!of_device_is_available (subnode))return 0 ; instance =devm_kzalloc (dev,sizeof (*instance),GFP_KERNEL );if (!instance)return -ENOMEM ; instance->serdes_phy =devm_phy_optional_get (dev,NULL );
[Severity: High]
Does devm_phy_optional_get() fetch the per-port serdes PHY from the parent device node rather than the specific port subnode?
Because it uses dev and not subnode, it appears all subnodes will resolve to the exact same PHY instance, which would misclassify every port as PHY_TYPE_USB3 and break USB2 port initialization.
Should this use devm_of_phy_optional_get(dev, subnode, NULL)?
drivers/phy/airoha/phy-an7583-usb.c static int an7583_usb_phy_parse_ports(struct device *dev, · line 1323
Quoted 6 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0if (IS_ERR (instance->serdes_phy))return dev_err_probe (dev,PTR_ERR (instance->serdes_phy),"error on serdes phy for USB 3.0\n" );if (!instance->serdes_phy && !of_property_present (subnode,"airoha,usb2-monitor-clk-sel" ))return dev_err_probe (dev, ret,"monitor clock selection or serdes PHY is mandatory for USB PHY\n" );
[Severity: Medium]
If the subnode lacks both the serdes_phy and the airoha,usb2-monitor-clk-sel properties, the error path returns the uninitialized ret variable.
Can this return a garbage error code (or 0) leading to silent initialization failures?
Quoted 22 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0if (instance->serdes_phy) { instance->type =PHY_TYPE_USB3 ;drivers/phy/airoha/phy-an7583-usb.c new file +0
-0}else { ret =of_property_read_u32 (subnode,"airoha,usb2-monitor-clk-sel" , &instance->monclk_sel);if (ret)return dev_err_probe (dev, ret,"failed to parse Monitor clock selection\n" ); ret =of_property_read_u32 (subnode,"reg" , &instance->offset);if (ret)return dev_err_probe (dev, ret,"missing reg for U2 PHY\n" ); instance->type =PHY_TYPE_USB2 ; } phy =devm_phy_create (dev, subnode, &airoha_phy);if (IS_ERR (phy))return dev_err_probe (dev,PTR_ERR (phy),"failed to create phy\n" ); priv->phys[index] = phy;
[ ... ]
drivers/phy/airoha/phy-an7583-usb.c static int airoha_pcie_phy_parse_ports(struct device *dev, · line 1350
Quoted 11 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0@@ -1341,12 +1341,12 @@ static int airoha_pcie_phy_parse_ports(struct device *dev,struct an7583_usb_phy_priv *priv, int index, struct device_node *subnode) { const struct an7583_usb_phy_match_data *data;struct an7583_usb_phy_instance *instance;struct phy *phy; data =of_device_get_match_data (dev);if (index > data->max_instance)
[Severity: High]
Should this bounds check use >= instead of > in airoha_pcie_phy_parse_ports()?
The max_instance is the size of the array (1 for PCIe), so allowing index to equal max_instance will cause an out-of-bounds write when priv->phys[index] is assigned later.
Quoted 4 lines
drivers/phy/airoha/phy-an7583-usb.c new file +0
-0return -EINVAL ;drivers/phy/airoha/phy-an7583-usb.c new file +0
-0if (!of_device_is_available (subnode))return 0 ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Quoted 2 lines
This small series add support for Airoha USB PHY and Gen2 PCIe PHY.
Quoted 32 lines
Changes v3:
- Fix broken patch for YAML patch
- Split the YAML for USB and PCIe
- Rework driver to direct node for PCIe PHYChanges 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/Kconfig | 1 + drivers/phy/Makefile | 3 +- drivers/phy/airoha/Kconfig | 11 + drivers/phy/airoha/Makefile | 3 + drivers/phy/airoha/phy-an7583-usb.c | 2016 +++++++++++++++++ 7 files changed, 2229 insertions(+), 1 deletion(-)create mode 100644
Documentation/devicetree/bindings/phy/airoha,an7583-pcie-gen2-phy.yamlcreate mode 100644Documentation/devicetree/bindings/phy/airoha,an7583-usb-phy.yamlcreate mode 100644drivers/phy/airoha/Kconfig
create mode 100644drivers/phy/airoha/Makefile
create mode 100644drivers/phy/airoha/phy-an7583-usb.c