airoha: an7581: USB support
Subsystems (3)
v7 cover airoha: an7581: USB support
This is a major rework of the old v2 series.
The SoC always support USB 2.0 but for USB 3.0 it needs additional configuration for the Serdes port. Such port can be either configured for USB usage or for PCIe lines or HSGMII and these are configured in the SCU space.
The previous implementation of a dedicated SSR driver was too complex and fragile for the simple task of configuring a register hence it was dropped and the handling is entirely in the PHY driver.
Everything was reducted to the dt-bindings to describe the Serdes line.
Also the property for the PHY are renamed to a more suitable name and everything is now mandatory to simplify the implementation. (the PHY are always present and active on the SoC)
Also other unrelated patch are dropped from this series.
Changes v7:
- Rework to double PHY implementation
(suggested by Rob)
Now the clk driver expose a PHY for Serdes port
USB PHY driver selects it
- Rebase on top of linux-next
Changes v6:
- Fix kernel test robot (sparse warning)
Changes v5:
- Add Ack and Review tag from Connor
- Implement Ethernet support in the USB driver (testing support for this Serdes on a special reference board)
- Use an7581 prefix for USB PHY driver
Changes v4:
- Rename PCIe and USB PHY to AN7581
- Drop airoha,scu (handled directly in driver)
- Drop dt-bindings for monitor clock in favor of raw values
- Better describe the usage of airoha,usb3-serdes
- Simplify values of dt-bindings SSR SERDES
Changes v3:
- Drop clk changes
- Drop SSR driver
- Rename property in Documentation
- Simplify PHY handling
- Move SSR handling inside the PHY driver
Changes v2:
- Drop changes for simple-mfd
- Rework PHY node structure to single node
- Drop port-id property in favor of serdes-port and usb2-monitor-clock-sel
- Make the SSR driver probe from the clock driver
Christian Marangi (6):
dt-bindings: soc: Add bindings for Airoha SCU Serdes lines
dt-bindings: clock: airoha: Add PHY binding for Serdes port
dt-bindings: phy: Add documentation for Airoha AN7581 USB PHY
clk: en7523: Add support for selecting the Serdes port in SCU
phy: move and rename Airoha PCIe PHY driver to dedicated directory
phy: airoha: Add support for Airoha AN7581 USB PHY
.../bindings/clock/airoha,en7523-scu.yaml | 9 + .../bindings/phy/airoha,an7581-usb-phy.yaml | 62 + MAINTAINERS | 11 +- drivers/clk/Kconfig | 1 + drivers/clk/clk-en7523.c | 207 ++- drivers/phy/Kconfig | 11 +- drivers/phy/Makefile | 4 +- drivers/phy/airoha/Kconfig | 23 + drivers/phy/airoha/Makefile | 4 + drivers/phy/airoha/phy-an7581-pcie-regs.h | 494 +++++++ drivers/phy/airoha/phy-an7581-pcie.c | 1290 +++++++++++++++++ drivers/phy/airoha/phy-an7581-usb.c | 562 +++++++ include/dt-bindings/soc/airoha,scu-ssr.h | 11 + 13 files changed, 2672 insertions(+), 17 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml create mode 100644 drivers/phy/airoha/Kconfig create mode 100644 drivers/phy/airoha/Makefile create mode 100644 drivers/phy/airoha/phy-an7581-pcie-regs.h create mode 100644 drivers/phy/airoha/phy-an7581-pcie.c create mode 100644 drivers/phy/airoha/phy-an7581-usb.c create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.h
Signature · 1 line
2.53.0
PATCH v7 1/6 dt-bindings: soc: Add bindings for Airoha SCU Serdes lines
The Airoha AN7581 SoC can configure the SCU serdes lines for multiple purpose. For example the Serdes for the USB1 port can be both used for USB 3.0 operation or for Ethernet. Or the USB2 serdes can both used for USB 3.0 operation or for PCIe.
The PCIe Serdes can be both used for PCIe operation or Ethernet.
Add bindings to permit correct reference of the different ports in DT, mostly to differentiate the different supported modes internally to the drivers.
Values are just symbolic and enumerates the Serdes port with a specific number for precise reference.
--- include/dt-bindings/soc/airoha,scu-ssr.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.h
include/dt-bindings/soc/airoha,scu-ssr.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef __DT_BINDINGS_AIROHA_SCU_SSR_H +#define __DT_BINDINGS_AIROHA_SCU_SSR_H + +#define AIROHA_SCU_SERDES_PCIE1 0 +#define AIROHA_SCU_SERDES_PCIE2 1 +#define AIROHA_SCU_SERDES_USB1 2 +#define AIROHA_SCU_SERDES_USB2 3 + +#endif /* __DT_BINDINGS_AIROHA_SCU_SSR_H */
Signature · 1 line
2.53.0
PATCH v7 2/6 dt-bindings: clock: airoha: Add PHY binding for Serdes port
In reply to Christian MarangiAdd PHY cell property for Serdes port selection. Currently supported only for Airoha AN7581 SoC, that support up to 4 Serdes port.
The Serdes port can support both PCIe, USB3 or Ethernet mode.
The available Serdes port can be selected following the dt-binding header in [2].
[2] <include/dt-bindings/soc/airoha,scu-ssr.h>
--- .../devicetree/bindings/clock/airoha,en7523-scu.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +9 -0
@@ -23,6 +23,7 @@ description: | All these identifiers can be found in: [1]: <include/dt-bindings/clock/en7523-clk.h>. + [2]: <include/dt-bindings/soc/airoha,scu-ssr.h>. The clocks are provided inside a system controller node.
@@ -50,6 +51,12 @@ properties: description: ID of the controller reset line const: 1 + '#phy-cells': + description: + The first cell indicates the serdes phy number, see [2] for the + available serdes port. + const: 1 + required: - compatible - reg
@@ -65,6 +72,8 @@ allOf: reg: minItems: 2 + '#phy-cells': false + - if: properties: compatible:
Signature · 1 line
2.53.0
PATCH v7 3/6 dt-bindings: phy: Add documentation for Airoha AN7581 USB PHY
In reply to Christian MarangiAdd documentation for Airoha AN7581 USB PHY that describe the USB PHY for the USB controller.
Airoha AN7581 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.
--- .../bindings/phy/airoha,an7581-usb-phy.yaml | 62 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml
Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml new file +62 -0
@@ -0,0 +1,62 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/airoha,an7581-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 AN7581 SoC USB PHY describes the USB PHY for the USB controller. + + Airoha AN7581 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. + +properties: + compatible: + const: airoha,an7581-usb-phy + + reg: + maxItems: 1 + + 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] + + 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: + - compatible + - reg + - airoha,usb2-monitor-clk-sel + - '#phy-cells' + +additionalProperties: false + +examples: + - | + #include <dt-bindings/soc/airoha,scu-ssr.h> + + phy@1fac0000 { + compatible = "airoha,an7581-usb-phy"; + reg = <0x1fac0000 0x10000>; + + airoha,usb2-monitor-clk-sel = <1>; + phys = <&scu AIROHA_SCU_SERDES_USB1>; + + #phy-cells = <1>; + }; +
MAINTAINERS +6 -0
@@ -771,6 +771,12 @@ S: Maintained F: Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml F: drivers/spi/spi-airoha-snfi.c +AIROHA USB PHY DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml + AIRSPY MEDIA DRIVER L: [email protected] S: Orphan
Signature · 1 line
2.53.0
PATCH v7 4/6 clk: en7523: Add support for selecting the Serdes port in SCU
In reply to Christian MarangiIn the SCU register for clock and reset, there are also some register to select the Serdes port mode. The Airoha AN7581 SoC have 4 different Serdes that can switch between PCIe, USB or Ethernet mode.
Add a simple PHY provider that expose the .set_mode OP to toggle the requested mode for the Serdes port.
--- drivers/clk/Kconfig | 1 + drivers/clk/clk-en7523.c | 207 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 205 insertions(+), 3 deletions(-)
drivers/clk/Kconfig +1 -0
@@ -221,6 +221,7 @@ config COMMON_CLK_EN7523 bool "Clock driver for Airoha/EcoNet SoC system clocks" depends on OF depends on ARCH_AIROHA || ECONET || COMPILE_TEST + select GENERIC_PHY default ARCH_AIROHA help This driver provides the fixed clocks and gates present on Airoha
drivers/clk/clk-en7523.c +204 -3
280 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 5/6 phy: move and rename Airoha PCIe PHY driver to dedicated directory
In reply to Christian MarangiTo keep the generic PHY directory tidy, move the PCIe PHY driver for Airoha AN7581 SoC to a dedicated directory.
Also rename the driver and add the relevant SoC name to the .c and .h file in preparation for support of PCIe and USB PHY driver for Airoha AN7583 SoC that use a completely different implementation and calibration for PHYs and will have their own dedicated drivers.
The rename permits to better identify the specific usage of the driver in the future once the airoha PHY directory will have multiple driver for multiple SoC.
The config is changed from PHY_AIROHA_PCIE to PHY_AIROHA_AN7581_PCIE.
--- MAINTAINERS | 4 +- drivers/phy/Kconfig | 11 +- drivers/phy/Makefile | 4 +- drivers/phy/airoha/Kconfig | 13 + drivers/phy/airoha/Makefile | 3 + drivers/phy/airoha/phy-an7581-pcie-regs.h | 494 ++++++++ drivers/phy/airoha/phy-an7581-pcie.c | 1290 +++++++++++++++++++++ 7 files changed, 1805 insertions(+), 14 deletions(-) create mode 100644 drivers/phy/airoha/Kconfig create mode 100644 drivers/phy/airoha/Makefile create mode 100644 drivers/phy/airoha/phy-an7581-pcie-regs.h create mode 100644 drivers/phy/airoha/phy-an7581-pcie.c
MAINTAINERS +2 -2
@@ -759,8 +759,8 @@ M: Lorenzo Bianconi <[email protected]> L: [email protected] (moderated for non-subscribers) S: Maintained 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 +F: drivers/phy/airoha/phy-an7581-pcie-regs.h +F: drivers/phy/airoha/phy-an7581-pcie.c AIROHA SPI SNFI DRIVER M: Lorenzo Bianconi <[email protected]>
drivers/phy/Kconfig +1 -10
@@ -46,16 +46,6 @@ config GENERIC_PHY_MIPI_DPHY Provides a number of helpers a core functions for MIPI D-PHY drivers to us. -config PHY_AIROHA_PCIE - tristate "Airoha PCIe-PHY Driver" - depends on ARCH_AIROHA || COMPILE_TEST - depends on OF - select GENERIC_PHY - help - Say Y here to add support for Airoha PCIe PHY driver. - This driver create the basic PHY instance and provides initialize - callback for PCIe GEN3 port. - config PHY_CAN_TRANSCEIVER tristate "CAN transceiver PHY" select GENERIC_PHY
@@ -133,6 +123,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 -2
@@ -7,7 +7,6 @@ obj-$(CONFIG_PHY_COMMON_PROPS) += phy-common-props.o obj-$(CONFIG_PHY_COMMON_PROPS_TEST) += phy-common-props-test.o obj-$(CONFIG_GENERIC_PHY) += phy-core.o obj-$(CONFIG_GENERIC_PHY_MIPI_DPHY) += phy-core-mipi-dphy.o -obj-$(CONFIG_PHY_AIROHA_PCIE) += phy-airoha-pcie.o obj-$(CONFIG_PHY_CAN_TRANSCEIVER) += phy-can-transceiver.o obj-$(CONFIG_PHY_GOOGLE_USB) += phy-google-usb.o obj-$(CONFIG_USB_LGM_PHY) += phy-lgm-usb.o
@@ -17,7 +16,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/ \ broadcom/ \
drivers/phy/airoha/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Phy drivers for Airoha devices +# +config PHY_AIROHA_AN7581_PCIE + tristate "Airoha AN7581 PCIe-PHY Driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on OF + select GENERIC_PHY + help + Say Y here to add support for Airoha AN7581 PCIe PHY driver. + This driver create the basic PHY instance and provides initialize + callback for PCIe GEN3 port.
drivers/phy/airoha/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_PHY_AIROHA_AN7581_PCIE) += phy-an7581-pcie.o
drivers/phy/airoha/phy-an7581-pcie-regs.h new file +494 -0
494 lines not on this page · raw message
drivers/phy/airoha/phy-an7581-pcie.c new file +1290 -0
1,290 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 6/6 phy: airoha: Add support for Airoha AN7581 USB PHY
In reply to Christian MarangiAdd support for Airoha AN7581 USB PHY driver. AN7581 supports up to 2 USB port with USB 2.0 mode always supported and USB 3.0 mode available only if the Serdes port is correctly configured for USB 3.0.
If the USB 3.0 mode is not configured, the modes needs to be also disabled in the xHCI node or the driver will report unsable clock and fail probe.
For USB 2.0 Slew Rate calibration, airoha,usb2-monitor-clk-sel is mandatory and is used to select the monitor clock for calibration.
Normally it's 1 for USB port 1 and 2 for USB port 2.
--- MAINTAINERS | 1 + drivers/phy/airoha/Kconfig | 10 + drivers/phy/airoha/Makefile | 1 + drivers/phy/airoha/phy-an7581-usb.c | 562 ++++++++++++++++++++++++++++ 4 files changed, 574 insertions(+) create mode 100644 drivers/phy/airoha/phy-an7581-usb.c
MAINTAINERS +1 -0
@@ -776,6 +776,7 @@ M: Christian Marangi <[email protected]> L: [email protected] (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/phy/airoha,an7581-usb-phy.yaml +F: drivers/phy/airoha/phy-an7581-usb.c AIRSPY MEDIA DRIVER L: [email protected]
drivers/phy/airoha/Kconfig +10 -0
@@ -11,3 +11,13 @@ config PHY_AIROHA_AN7581_PCIE Say Y here to add support for Airoha AN7581 PCIe PHY driver. This driver create the basic PHY instance and provides initialize callback for PCIe GEN3 port. + +config PHY_AIROHA_AN7581_USB + tristate "Airoha AN7581 USB PHY Driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on OF + select GENERIC_PHY + help + 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.
drivers/phy/airoha/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_PHY_AIROHA_AN7581_PCIE) += phy-an7581-pcie.o +obj-$(CONFIG_PHY_AIROHA_AN7581_USB) += phy-an7581-usb.o
drivers/phy/airoha/phy-an7581-usb.c new file +562 -0
562 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 2/6] dt-bindings: clock: airoha: Add PHY binding for Serdes port
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The `#phy-cells` property is inadvertently permitted for the `econet,en751221-scu` compatible…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The #phy-cells property is inadvertently permitted for the econet,en751221-scu compatible string, contradicting the commit message. --
commit 36e079ebecab2b854b57826ce9314e34246cb7e4
Author: Christian Marangi <[email protected]>
dt-bindings: clock: airoha: Add PHY binding for Serdes port
This commit adds a #phy-cells property for Serdes port selection. The port selection is intended to only be supported for the Airoha AN7581 SoC.
Quoted 3 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +0
-0
[ ... ]
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml allOf: · line 76
Quoted 6 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +2
-0@@ -65,6 +72,8 @@ allOf: reg: minItems: 2 + '#phy-cells': false +
[Severity: Medium]
The commit message explicitly states that the Serdes port selection is currently supported only for the Airoha AN7581 SoC.
Since #phy-cells is defined in the top-level properties block, it is permitted for all compatible strings matching the schema unless explicitly restricted. This block correctly restricts it for airoha,en7523-scu, but should there also be a restriction for econet,en751221-scu?
Since econet,en751221-scu shares a conditional validation block with airoha,en7581-scu further down in the file, it appears it implicitly inherits the permission to use #phy-cells unless a new, separate if-then block explicitly sets '#phy-cells': false for it.
Does this allow invalid configurations to pass validation?
Quoted 3 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +0
-0- if: properties: compatible:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v7 4/6] clk: en7523: Add support for selecting the Serdes port in SCU
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] The `reg` and `mask` variables are left uninitialized when processing the…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] The reg and mask variables are left uninitialized when processing the AIROHA_SCU_SERDES_PCIE2 case, leading to arbitrary memory/hardware corruption.
- [High] Concurrent read-modify-write operations on shared hardware registers lack spinlock protection, leading to race conditions and potential lost updates.
- [High] USB PHY instances unconditionally reject PHY_MODE_USB_HOST and PHY_MODE_USB_OTG, breaking USB host functionality.
--
commit 714fd2f968cbdacf2f17f7ead8459ffad971d307
Author: Christian Marangi <[email protected]>
Subject: clk: en7523: Add support for selecting the Serdes port in SCU
This commit adds support for selecting the Serdes port in the SCU register for clock and reset. It implements a simple PHY provider with a set_mode operation to toggle the requested mode (PCIe, USB, or Ethernet) for the Airoha AN7581 SoC Serdes ports.
Quoted 4 lines
drivers/clk/clk-en7523.c +0
-0
[ ... ]
Quoted 12 lines
drivers/clk/clk-en7523.c +11
-0@@ -830,12 +858,173 @@ static int en7581_reset_register(struct device *dev, void __iomem *base, +static int en7581_serdes_phy_set_mode (struct phy *phy,enum phy_mode mode, +int submode) +{ +struct en_serdes_phy_instance *instance =phy_get_drvdata (phy); +struct en_clk_priv *priv =dev_get_drvdata (phy->dev.parent); +u32 reg, mask, sel, val; + +switch (instance->serdes_port) { +case AIROHA_SCU_SERDES_PCIE1 : + reg =REG_NP_SCU_SSTR ; + mask =REG_PCIE_XSI0_SEL_MASK ;
[ ... ]
drivers/clk/clk-en7523.c static int en7581_reset_register(struct device *dev, void __iomem *base, · line 895
Quoted 6 lines
drivers/clk/clk-en7523.c +6
-0+ }else { + sel =REG_PCIE_XSI0_SEL_PCIE ; + } + +break ; +case AIROHA_SCU_SERDES_PCIE2 :
[Severity: Critical]
Could this cause random memory or hardware corruption?
It looks like reg and mask are not initialized for AIROHA_SCU_SERDES_PCIE2 here. When the switch statement finishes, the function uses these uninitialized stack variables for the readl and writel operations.
Quoted 2 lines
drivers/clk/clk-en7523.c +2
-0+if (mode !=PHY_MODE_ETHERNET && mode !=PHY_MODE_PCIE ) +return -EINVAL ;
[ ... ]
drivers/clk/clk-en7523.c static int en7581_reset_register(struct device *dev, void __iomem *base, · line 924
Quoted 12 lines
drivers/clk/clk-en7523.c +12
-0+ }else { + sel =REG_PCIE_XSI1_SEL_PCIE ; + } + +break ; +case AIROHA_SCU_SERDES_USB1 : + reg =REG_NP_SCU_SSR3 ; + mask =REG_SSUSB_HSGMII_SEL_MASK ; + +if (mode !=PHY_MODE_ETHERNET && mode !=PHY_MODE_USB_DEVICE && + mode !=PHY_MODE_USB_DEVICE_SS ) +return -EINVAL ;
[Severity: High]
Will this break USB host or dual-role functionality?
USB controllers operating in host or OTG modes often request PHY_MODE_USB_HOST or PHY_MODE_USB_OTG. Since this PHY only acts as a multiplexer, should it accept all valid USB modes when routing lines to the USB controller?
Quoted 10 lines
drivers/clk/clk-en7523.c +10
-0+ +if (mode ==PHY_MODE_ETHERNET ) + sel =REG_SSUSB_HSGMII_SEL_HSGMII ; +else + sel =REG_SSUSB_HSGMII_SEL_USB ; + +break ; +case AIROHA_SCU_SERDES_USB2 : + reg =REG_NP_SCU_SSTR ; + mask =REG_USB_PCIE_SEL_MASK ;
[ ... ]
Quoted 4 lines
drivers/clk/clk-en7523.c +4
-0+if (mode ==PHY_MODE_PCIE ) + sel =REG_USB_PCIE_SEL_PCIE ; +else + sel =REG_USB_PCIE_SEL_USB ;
drivers/clk/clk-en7523.c static int en7581_reset_register(struct device *dev, void __iomem *base, · line 953
Quoted 10 lines
drivers/clk/clk-en7523.c +10
-0+ +break ; +default : +return -EINVAL ; + } + + val =readl (priv->base + reg); + val &= ~mask; + val |= sel; +writel (val, priv->base + reg);
[Severity: High]
Can this read-modify-write sequence race if multiple Serdes ports are configured concurrently?
The PHY subsystem uses a per-PHY instance mutex, so the set_mode callbacks for different Serdes ports could execute in parallel (for example, during asynchronous probing). Because they share hardware registers like REG_NP_SCU_SSTR, concurrent operations could lead to lost updates and route the Serdes to the wrong subsystem.
Would it be safer to protect these accesses with a spinlock added to struct en_clk_priv?
Quoted 3 lines
drivers/clk/clk-en7523.c +3
-0+ +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v7 5/6] phy: move and rename Airoha PCIe PHY driver to dedicated directory
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The commit claims to move and rename the Airoha PCIe PHY driver to a dedicated directory, but fails…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The commit claims to move and rename the Airoha PCIe PHY driver to a dedicated directory, but fails to delete the original source files, leaving them as dead code in the tree.
- [Low] The newly added header file uses the same include guard as the old file.
--
commit 86b6424c6ba53c67472bea2d3d41f8d654e1cb31
Author: Christian Marangi <[email protected]>
phy: move and rename Airoha PCIe PHY driver to dedicated directory
This commit moves the Airoha AN7581 PCIe PHY driver into a dedicated directory and renames the files and config symbols. This change is in preparation for adding other Airoha PHY drivers in the future.
[ ... ]
drivers/phy/Makefile obj-$(CONFIG_PHY_COMMON_PROPS) += phy-common-props.o · line 10
Quoted 9 lines
drivers/phy/Makefile +0
-1@@ -7,7 +7,6 @@ obj-$(CONFIG_PHY_COMMON_PROPS) += phy-common-props.o obj-$(CONFIG_PHY_COMMON_PROPS_TEST) += phy-common-props-test.o obj-$(CONFIG_GENERIC_PHY) += phy-core.o obj-$(CONFIG_GENERIC_PHY_MIPI_DPHY) += phy-core-mipi-dphy.o -obj-$(CONFIG_PHY_AIROHA_PCIE) += phy-airoha-pcie.o
[Severity: Low]
The commit message states the driver is being moved, but the diff only shows adding the new files in the airoha directory. It doesn't remove the original drivers/phy/phy-airoha-pcie.c and drivers/phy/phy-airoha-pcie-regs.h files. Should these old files be deleted in this patch to avoid leaving uncompiled dead code in the tree?
[ ... ]
drivers/phy/airoha/phy-an7581-pcie-regs.h line 7
Quoted 13 lines
drivers/phy/airoha/phy-an7581-pcie-regs.h new file +7
-0@@ -0,0 +1,494 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2024 AIROHA Inc +* Author: Lorenzo Bianconi <[email protected]> +*/ + +#ifndef _PHY_AIROHA_PCIE_H
[Severity: Low]
Since the file is being renamed to phy-an7581-pcie-regs.h, should this include guard be updated to match the new filename? Reusing the old guard might cause conflicts, particularly since the old header file was not deleted.
Quoted 4 lines
drivers/phy/airoha/phy-an7581-pcie-regs.h new file +4
-0+#define _PHY_AIROHA_PCIE_H + +/* CSR_2L */ +#define REG_CSR_2L_CMN 0x0000
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v7 6/6] phy: airoha: Add support for Airoha AN7581 USB PHY
In reply to Christian MarangiThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] `dev_err_probe` is called with `IS_ERR()` instead of `PTR_ERR()`, breaking error propagation and…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] dev_err_probe is called with IS_ERR() instead of PTR_ERR(), breaking error propagation and probe deferral.
- [High] Incorrect configuration of FORCE_IDDIG in PHY_MODE_USB_DEVICE due to a missing flag.
- [Medium] fm_out may be used uninitialized if regmap_read_poll_timeout fails.
- [Medium] Missing select REGMAP_MMIO dependency in Kconfig.
- [Low] Dead code in an7581_usb_phy_power_on checking the USB PHY's mode instead of the SerDes PHY's mode.
- [Low] Assigning generic PHY_TYPE_USB2 values to a variable typed as a local internal enum.
--
commit a54da44fe952522b06761e81fb643efff0dad77a
Author: Christian Marangi <[email protected]>
phy: airoha: Add support for Airoha AN7581 USB PHY
Add support for Airoha AN7581 USB PHY driver. AN7581 supports up to 2 USB port with USB 2.0 mode always supported and USB 3.0 mode available only if the Serdes port is correctly configured for USB 3.0.
Quoted 4 lines
drivers/phy/airoha/Kconfig +0
-0
[ ... ]
drivers/phy/airoha/Kconfig config PHY_AIROHA_AN7581_PCIE · line 19
Quoted 10 lines
drivers/phy/airoha/Kconfig +6
-0@@ -11,3 +11,13 @@ config PHY_AIROHA_AN7581_PCIE Say Y here to add support for Airoha AN7581 PCIe PHY driver. This driver create the basic PHY instance and provides initialize callback for PCIe GEN3 port. + +config PHY_AIROHA_AN7581_USB + tristate "Airoha AN7581 USB PHY Driver" + depends on ARCH_AIROHA || COMPILE_TEST + depends on OF + select GENERIC_PHY
[Severity: Medium]
Will this fail to link under COMPILE_TEST on architectures without REGMAP_MMIO? The driver relies on devm_regmap_init_mmio(), so it might need to explicitly select REGMAP_MMIO.
Quoted 9 lines
drivers/phy/airoha/Kconfig +4
-0+ help + 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.drivers/phy/airoha/phy-an7581-usb.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/phy/airoha/phy-an7581-usb.c new file +4
-0+static void an7581_usb_phy_u2_slew_rate_calibration (struct an7581_usb_phy_priv *priv) +{ +u32 fm_out; +u32 srctrl;
[ ... ]
Quoted 11 lines
drivers/phy/airoha/phy-an7581-usb.c new file +11
-0+/* Timeout can happen and we will apply workaround at the end */ +regmap_read_poll_timeout (priv->regmap,AIROHA_USB_PHY_FMMONR0 , fm_out, + fm_out,AIROHA_USB_PHY_FREQDET_SLEEP , +AIROHA_USB_PHY_FREQDET_TIMEOUT ); + +/* Disable Frequency meter */ +regmap_clear_bits (priv->regmap,AIROHA_USB_PHY_FMCR0 , +AIROHA_USB_PHY_FREQDET_EN ); + +/* Disable Free run clock */ + regmap_clear_bits(priv->regmap, AIROHA_USB_PHY_FMMONR1,
drivers/phy/airoha/phy-an7581-usb.c line 194
Quoted 10 lines
drivers/phy/airoha/phy-an7581-usb.c new file +10
-0+ AIROHA_USB_PHY_FRCK_EN); + +/* Disable HS TX SR calibration */ +regmap_clear_bits (priv->regmap,AIROHA_USB_PHY_USBPHYACR5 , +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 underlying regmap_read() fails immediately (e.g., due to an I/O error), does fm_out remain uninitialized?
Since the return value of regmap_read_poll_timeout() isn't checked, an uninitialized stack value could bypass this check and cause unpredictable behavior during the subsequent division.
Quoted 9 lines
drivers/phy/airoha/phy-an7581-usb.c new file +9
-0+ srctrl =AIROHA_USB_PHY_DEFAULT_SR_CALIBRATION ; +dev_err (priv->dev,"Frequency not detected, using default SR calibration.\n" ); + }else { +/* (1024 / FM_OUT) * REF_CK * U2_SR_COEF (round to the nearest digits) */ + srctrl =AIROHA_USB_PHY_REF_CK *AIROHA_USB_PHY_U2_SR_COEF ; + srctrl = (srctrl *AIROHA_USB_PHY_U2_FM_DET_CYCLE_CNT ) / fm_out; + srctrl =DIV_ROUND_CLOSEST (srctrl,AIROHA_USB_PHY_U2_SR_COEF_DIVISOR ); +dev_dbg (priv->dev,"SR calibration applied: %x\n" , srctrl); + }
[ ... ]
drivers/phy/airoha/phy-an7581-usb.c line 326
Quoted 13 lines
drivers/phy/airoha/phy-an7581-usb.c new file +13
-0+static int an7581_usb_phy_power_on (struct phy *phy) +{ +struct an7581_usb_phy_instance *instance =phy_get_drvdata (phy); +struct an7581_usb_phy_priv *priv =dev_get_drvdata (phy->dev.parent); + +switch (instance->type) { +case PHY_TYPE_USB2 : +an7581_usb_phy_u2_power_on (priv); +break ; +case PHY_TYPE_USB3 : +if (phy_get_mode (phy) ==PHY_MODE_PCIE || +phy_get_mode (phy) ==PHY_MODE_ETHERNET ) +return 0 ;
[Severity: Low]
Is this check examining the wrong phy object?
It seems to be checking the USB PHY's mode instead of the shared SerDes combo PHY (priv->serdes_phy). Since the USB PHY's mode will presumably never be PCIe or Ethernet, will this condition ever evaluate to true?
Quoted 9 lines
drivers/phy/airoha/phy-an7581-usb.c new file +9
-0+ +an7581_usb_phy_u3_power_on (priv); +break ; +default : +return -EINVAL ; + } + +return 0 ; +}
[ ... ]
drivers/phy/airoha/phy-an7581-usb.c line 370
Quoted 13 lines
drivers/phy/airoha/phy-an7581-usb.c new file +13
-0+static int an7581_usb_phy_power_off (struct phy *phy) +{ +struct an7581_usb_phy_instance *instance =phy_get_drvdata (phy); +struct an7581_usb_phy_priv *priv =dev_get_drvdata (phy->dev.parent); + +switch (instance->type) { +case PHY_TYPE_USB2 : +an7581_usb_phy_u2_power_off (priv); +break ; +case PHY_TYPE_USB3 : +if (phy_get_mode (phy) ==PHY_MODE_PCIE || +phy_get_mode (phy) ==PHY_MODE_ETHERNET ) +return 0 ;
[Severity: Low]
Similar to the an7581_usb_phy_power_on() check above, does this check the wrong phy object?
Quoted 13 lines
drivers/phy/airoha/phy-an7581-usb.c new file +13
-0+ +an7581_usb_phy_u3_power_off (priv); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int an7581_usb_phy_u2_set_mode (struct an7581_usb_phy_priv *priv, +enum phy_mode mode) +{
drivers/phy/airoha/phy-an7581-usb.c line 393
Quoted 10 lines
drivers/phy/airoha/phy-an7581-usb.c new file +10
-0+u32 val; + +/* +* For Device and Host mode, enable force IDDIG. +* For Device set IDDIG, for Host clear IDDIG. +* For OTG disable force and clear IDDIG bit while at it. +*/ +switch (mode) { +case PHY_MODE_USB_DEVICE : + val =AIROHA_USB_PHY_IDDIG ;
[Severity: High]
The comment mentions enabling force IDDIG for Device mode, but val is only assigned AIROHA_USB_PHY_IDDIG here. Should AIROHA_USB_PHY_FORCE_IDDIG be included as well?
drivers/phy/airoha/phy-an7581-usb.c line 397
Quoted 4 lines
drivers/phy/airoha/phy-an7581-usb.c new file +4
-0+break ; +case PHY_MODE_USB_HOST : + val =AIROHA_USB_PHY_FORCE_IDDIG | +AIROHA_USB_PHY_FORCE_IDDIG ;
[Severity: Low]
This isn't a bug, but the AIROHA_USB_PHY_FORCE_IDDIG flag is duplicated here.
Quoted 14 lines
drivers/phy/airoha/phy-an7581-usb.c new file +14
-0+break ; +case PHY_MODE_USB_OTG : + val =0 ; +break ; +default : +return 0 ; + } + +regmap_update_bits (priv->regmap,AIROHA_USB_PHY_U2PHYDTM1 , +AIROHA_USB_PHY_FORCE_IDDIG | +AIROHA_USB_PHY_IDDIG , val); + +return 0 ; +}
[ ... ]
Quoted 8 lines
drivers/phy/airoha/phy-an7581-usb.c new file +8
-0+static int an7581_usb_phy_probe (struct platform_device *pdev) +{ +struct phy_provider *phy_provider; +struct an7581_usb_phy_priv *priv; +struct device *dev = &pdev->dev; +unsigned int index; +void __iomem *base; +int ret;
[ ... ]
drivers/phy/airoha/phy-an7581-usb.c line 517
Quoted 12 lines
drivers/phy/airoha/phy-an7581-usb.c new file +12
-0+for (index =0 ; index <AIROHA_PHY_USB_MAX ; index++) { +enum an7581_usb_phy_instance_type phy_type; +struct an7581_usb_phy_instance *instance; + +switch (index) { +case AIROHA_PHY_USB2 : + phy_type =PHY_TYPE_USB2 ; +break ; +case AIROHA_PHY_USB3 : + phy_type =PHY_TYPE_USB3 ; +break ; + }
[Severity: Low]
Should phy_type be declared as an integer or u32?
The generic PHY_TYPE_USB2 macro evaluates to 3, but phy_type is typed as enum an7581_usb_phy_instance_type which only defines values 0 to 2.
drivers/phy/airoha/phy-an7581-usb.c line 522
Quoted 5 lines
drivers/phy/airoha/phy-an7581-usb.c new file +5
-0+ +if (phy_type ==PHY_TYPE_USB3 ) { + priv->serdes_phy =devm_phy_get (dev,NULL ); +if (IS_ERR (priv->serdes_phy)) +return dev_err_probe (dev,IS_ERR (priv->serdes_phy),"missing serdes phy for USB 3.0\n" );
[Severity: High]
Does this inadvertently return 1 instead of a proper negative error code?
Since IS_ERR() returns a boolean, returning it breaks error propagation and probe deferral (e.g. -EPROBE_DEFER). Should this be PTR_ERR() instead?
Quoted 5 lines
drivers/phy/airoha/phy-an7581-usb.c new file +5
-0+ } + + instance =devm_kzalloc (dev,sizeof (*instance),GFP_KERNEL ); +if (!instance) +return -ENOMEM ;
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v7 5/6] phy: move and rename Airoha PCIe PHY driver to dedicated directory
In reply to Christian MarangiHi Christian,
Quoted 15 lines · Christian Marangi
To keep the generic PHY directory tidy, move the PCIe PHY driver for Airoha AN7581 SoC to a dedicated directory.
Also rename the driver and add the relevant SoC name to the .c and .h file in preparation for support of PCIe and USB PHY driver for Airoha AN7583 SoC that use a completely different implementation and calibration for PHYs and will have their own dedicated drivers.
The rename permits to better identify the specific usage of the driver in the future once the airoha PHY directory will have multiple driver for multiple SoC.
The config is changed from
PHY_AIROHA_PCIEtoPHY_AIROHA_AN7581_PCIE.Signed-off-by Christian Marangi <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 4 +- drivers/phy/Kconfig | 11 +- drivers/phy/Makefile | 4 +- drivers/phy/airoha/Kconfig | 13 + drivers/phy/airoha/Makefile | 3 + drivers/phy/airoha/phy-an7581-pcie-regs.h | 494 ++++++++ drivers/phy/airoha/phy-an7581-pcie.c | 1290 +++++++++++++++++++++
This patch creates a .c file under drivers/phy/airoha/, but doesn't remove the existing file under drivers/phy/.
baruch
Signature · 3 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.52.368.4656, http://www.tkos.co.il -Re: [PATCH v7 2/6] dt-bindings: clock: airoha: Add PHY binding for Serdes port
In reply to Christian MarangiQuoted 5 lines · Christian Marangi
Add PHY cell property for Serdes port selection. Currently supported only for Airoha AN7581 SoC, that support up to 4 Serdes port.
The Serdes port can support both PCIe, USB3 or Ethernet mode.
Quoted 8 lines
The available Serdes port can be selected following the dt-binding header in [2].
[2] <
include/dt-bindings/soc/airoha,scu-ssr.h>Signed-off-by Christian Marangi <[email protected]>--- .../devicetree/bindings/clock/airoha,en7523-scu.yaml | 9 +++++++++
The bindings header should be squashed here as I asked previously.
Best regards,
Krzysztof