Skip to contentSkip to conversation

phy: cix: add Sky1 USB/DP combo PHY support

PATCH Superseded Gary Yang 3 participants 7 messages Dec 3 – Dec 4

Subsystems (2)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Gary Yang

author
#0 lore raw

v8 cover phy: cix: add Sky1 USB/DP combo PHY support

This series adds support for the USB/DP combo PHY of the CIX Sky1 SoC. Each PHY instance drives one SuperSpeedPlus USB lane and up to four DisplayPort lanes of a USB Type-C port. The USB and the DP controller get their own PHY through the PHY_TYPE_USB3 and PHY_TYPE_DP cells. Plug orientation and the USB/DP mode decision are taken by the Type-C connector driver; the PHY consumes them through the Type-C switch and mux API.

The USB and the DisplayPort controllers and the Type-C connector are not yet described in the CIX device trees. The graph links and the consumers will be added together with them.

Patch 1 adds the binding and patch 2 the driver. The MAINTAINERS update is part of patch 2, so that patch 2 can be applied without patch 1. The SoC and board nodes are sent separately as a follow-up, since they go through the SoC tree.

Patch 2 builds on Luo Liu's "Add Sky1 DisplayPort PHY support" series:

https://lore.kernel.org/linux-phy/[email protected]

That series creates drivers/phy/cix/ together with the PHY_CIX_DP Kconfig symbol and the CIX SKY1 DISPLAYPORT PHY DRIVER MAINTAINERS entry. This series adds the PHY_CIX_USBDP symbol and the new binding, and renames the entry to CIX SKY1 PHY DRIVERS. It should be applied on top of Luo's series to avoid conflicts in drivers/phy/cix/{Kconfig,Makefile} and MAINTAINERS.

Changes in v8:
- Name the system controller property after the S5 system controller it points to (cix,s5-syscon) instead of cix,usbphy-syscon, which read as if the PHY node referenced a syscon of its own.
- Drop the redundant type of the orientation-switch and mode-switch properties, which the common USB switch binding already defines.
- Limit the voltage programming to the lanes that the programmed register table assigns to DisplayPort while the deferred reprogramming is still pending. The lane count of a new mode was committed before the table switch, so a voltage update arriving in between could write DisplayPort levels onto the lines that still carried the USB3 signals. Track the lane count of the table itself, as the mode tracking does not always match the table, and verify and program the same lane count in that window.

Changes in v7:
- Report the PHY bus width as soon as the mux selects the new mode, instead of waiting for the deferred reprogramming that runs from phy_configure(). The DP controller reads the bus width before configuring the link, so a 2-lane to 4-lane switch trained only two lanes, and a 4-lane to 2-lane switch was rejected before the deferred reprogramming could run.
- Keep the lane count used for the voltage programming unchanged when the mux switches between the DisplayPort modes. The register table still belongs to the previous mode until the deferred reprogramming runs, and its outer PMA lanes may still carry the USB3 signals, so a voltage update arriving in between would write DisplayPort levels to the USB3 lanes.
- Commit the lane count of the requested mode only after the DisplayPort power-on succeeded. A failed power-on leaves the register table in the previous mode, and the lane count of the requested mode would let the voltage programming reach the lanes that still belong to USB3.
- Program the high-speed clock divider of every lane assigned to DisplayPort on a rate change, not only the lanes of the previous configuration, so that a lane count raised in a separate phy_configure() call also gets the new divider.
- Keep the orientation programmed into the PHY separate from the requested one and only update it when the PHY is actually reprogrammed, so that voltage swing updates arriving while the reprogramming is pending no longer address the lanes of the new orientation before the hardware has switched.
- Track whether the caller configured the lane count for the current mode, and fall back to the lanes that the new mode assigns to DisplayPort when the deferred reprogramming follows a mode change. A rate-only update after a 2-lane to 4-lane switch otherwise kept the previous two-lane count and left the outer lanes without voltage levels, while a rate-only update in the same mode still keeps the configured count, clamped to the lanes that the mode assigns to DisplayPort.

Changes in v6:
- Keep the DP lane count, the PHY bus width and the USB mode bit in sync with the requested mode when the deferred reprogramming is applied from the DP configuration path, instead of leaving the values from the previous power-on in place. A rate update that does not repeat set_lanes could otherwise program the USB3 lanes after a 4-lane to 2-lane switch, or skip the lanes that became available after a 2-lane to 4-lane switch. Validate the voltage levels against the same lane count, so that the verification and the programming steps agree.
- Ignore DP configuration requests that arrive after the connector has left the DisplayPort alt mode, so that a stale link-training call cannot reprogram lanes that no longer belong to DisplayPort.
- Complete a DisplayPort power-on that arrives while the mux still reports a USB-only mode when the mux later selects the DisplayPort mode. The PHY core has already taken the power reference, so without remembering the request the DP PHY would stay unpowered for the session and all link configuration would be dropped.
- Only remember that power-on once it succeeded or when it has been deferred until the mux selects the DisplayPort mode. A failed power-on does not give the PHY core a reference to account, so remembering it anyway would let the mux path power the block up without a consumer and never power it down again.
- Drop a pending reprogramming request when the PHY is fully powered down. The next power-on programs the complete register table for the requested mode and orientation, so the request is applied there and must not leak into the next session.

Changes in v5:
- Attempt the USB restore on every mux event whose requested mode contains USB, instead of only on the plain USB state, so that a configuration change or a disconnect after a 4-lane DP session no longer leaves the initialized USB3 controller attached to a powered down PHY.
- Do not run the power-on sequence when the DP PHY releases the lanes:
the PHY is still powered at that point, so restoring the USB mode there would enable the APB clock a second time and leak a prepare/enable reference. Account the USB mode again instead and only apply a deferred reprogramming.
- Drop the USB mode bit and power the PHY down when the mux switches to a DP-only configuration while USB3 is the only user, instead of keeping the PHY powered with a USB bit that the DP-only register table has already disconnected. The DP PHY powers the block up again when it is powered on.
- Apply a deferred mode or plug orientation reprogramming when the DP link parameters are configured, before the link training starts, instead of leaving it pending while the DP PHY is powered. A mode change that arrives after the DP PHY has been powered on with the previous table cannot be applied from the mux notification, and the link would otherwise be trained against the previous lane mapping.

Changes in v4:
- Map the safe and USB states signalled by the DP altmode driver to the USB+DP mode instead of the USB-only mode, so that a DP PHY power-on request that races with the altmode notification no longer leaves the PHY unpowered and silently drops the link training writes. Handle the deprecated pin assignments A and B the same way as C and D instead of mapping them to USB only.
- Apply a deferred mode table or plug orientation reprogramming as soon as the DP PHY stops using the lanes, instead of waiting for a USB3 power-on that is not guaranteed while the PHY stays initialized.
- Drop the USB mode bit when a 4-lane DP configuration takes over all the lanes, so that releasing the DP PHY powers the combo PHY down instead of leaving it and its apb clock enabled. Remember whether the USB3 controller still holds the PHY initialized and power the PHY back up to USB once the last DP user releases the lanes, including when the DP altmode driver switches the sink back to USB before the DP PHY is powered off, so that the controller does not end up driving an unpowered PHY.

Changes in v3:
- Drop the inline keyword from the register access helpers, drop the udphy_write() wrapper and use writel() directly.
- Return the actual clk_prepare_enable() error instead of initialising the return value to -EBUSY, and reflow the retry comment to use the full 80 columns.
- Initialise the PHY mutex with devm_mutex_init().

Changes in v2:
- Replace the hand-written regmap backend over the PHY registers with direct writel()/readl() access.
- Take the DP link rate in Mb/s, as defined by struct phy_configure_opts_dp, and select the register table from the link configuration entry instead of repeating it per case.
- Protect the PHY state with guard(mutex) and drop the goto-based unlock paths.
- Use dev_err_probe() consistently in probe().
- Fix local variable ordering in probe() and sky1_udphy_init(), and drop the unused register read.
- Lowercase hex constants, fix overlong lines, add the missing copyright header and a missing newline before return.
- Move the driver out of ARM/CIX SOC SUPPORT into the CIX SKY1 PHY DRIVERS entry, and drop the commit message claim about the bootloader handing over an initialized port.
- Validate the DP link rate before the PLL is touched, so that an unsupported rate no longer leaves PLL1 disabled.
- Honour set_rate, set_lanes and set_voltages independently, and keep the negotiated lane count in the driver, so that a caller that only updates the voltage swing and pre-emphasis levels, as dw-dp does, works with an uninitialised lanes field. Validate all of the options before any of them is applied.
- Program the TX voltage swing and pre-emphasis levels per lane instead of applying the settings of lane 0 to all lanes.
- Add .init to the USB3 PHY ops and only touch the PHY registers while the PHY is powered.
- Track the active and the requested mode separately and reprogram the PHY on the next power-on only when the alt mode or the plug orientation has changed, instead of enabling the APB clock a second time.
- Reset the PHY when it is reprogrammed, and only reprogram it when the register table actually changes, so that an active USB link is left alone when the mode changes between USB and USB+DisplayPort.
- Handle the deprecated DisplayPort pin assignment F as a USB+DP state, like the other Type-C mux drivers do.
- Report the DisplayPort lane count only after the PHY has been powered on.
- Ignore Type-C mux states of alt modes other than DisplayPort, which used to be mistaken for a DisplayPort state because the state numbers overlap.
- Describe the two PHYs with #phy-cells = <1> instead of child nodes, reference the common USB switch binding, describe the Type-C graph connection, and drop the cix,default-conf property.
- Keep the binding example limited to the PHY node and its graph ports, and drop the stubbed USB and DisplayPort consumers.

Gary Yang (2):
dt-bindings: phy: add CIX Sky1 USB/DP combo PHY
phy: cix: add Sky1 USB/DP combo PHY driver

 .../bindings/phy/cix,sky1-usbdp-phy.yaml      |  148 ++
 MAINTAINERS                                   |    4 +-
 drivers/phy/cix/Kconfig                       |   16 +
 drivers/phy/cix/Makefile                      |    1 +
 drivers/phy/cix/phy-cix-usbdp.c               | 1753 +++++++++++++++++
 drivers/phy/cix/phy-cix-usbdp.h               |  257 +++
 6 files changed, 2178 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
 create mode 100644 drivers/phy/cix/phy-cix-usbdp.c
 create mode 100644 drivers/phy/cix/phy-cix-usbdp.h
Signature · 1 line
2.50.1
author
#1 lore raw

PATCH v8 1/2 dt-bindings: phy: add CIX Sky1 USB/DP combo PHY

Document the USB/DP combo PHY of the CIX Sky1 SoC. One PHY instance provides one SuperSpeedPlus USB lane and up to four DisplayPort lanes of a USB Type-C port; consumers select the part they need with a PHY type cell, using PHY_TYPE_USB3 or PHY_TYPE_DP.

The PHY performs Type-C plug orientation switching and USB/DP lane muxing in hardware and is therefore described with the properties of the common USB switch binding. The plug orientation is switched through the S5 system controller, identified by the "cix,s5-syscon" phandle followed by the PHY instance index.

---
Changes in v8:
- Rename the system controller property to cix,s5-syscon, after the S5 system controller it points to. The previous name read as if the PHY node referenced a syscon of its own.
- Drop the redundant type of the orientation-switch and mode-switch properties, which the common USB switch binding already defines.

---
 .../bindings/phy/cix,sky1-usbdp-phy.yaml      | 148 ++++++++++++++++++
 1 file changed, 148 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +148 -0
new file mode 100644
index 000000000000..0dd518768f33
@@ -0,0 +1,148 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/cix,sky1-usbdp-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CIX Sky1 USB/DP Combo PHY
+
+maintainers:
+  - Gary Yang <[email protected]>
+
+description:
+  The CIX Sky1 USB/DP combo PHY provides one SuperSpeedPlus USB lane and
+  up to four DisplayPort lanes for a USB Type-C port. Which of the two
+  functions is in use depends on the Type-C alt mode and on the plug
+  orientation.
+
+allOf:
+  - $ref: /schemas/usb/usb-switch.yaml#
+
+properties:
+  compatible:
+    const: cix,sky1-usbdp-phy
+
+  reg:
+    maxItems: 1
+
+  "#phy-cells":
+    description: |
+      Cell allows setting the type of the PHY. Possible values are:
+      - PHY_TYPE_USB3
+      - PHY_TYPE_DP
+    const: 1
+
+  clocks:
+    maxItems: 1
+    description: PHY APB clock.
+
+  resets:
+    items:
+      - description: PHY core reset
+      - description: PHY APB preset
+
+  reset-names:
+    items:
+      - const: core
+      - const: apb
+
+  orientation-switch:
+    description:
+      The PHY handles Type-C plug orientation switching.
+
+  mode-switch:
+    description:
+      The PHY handles multiplexing of the USB and DisplayPort lanes.
+
+  cix,s5-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: phandle to the S5 system controller
+          - description: PHY instance index within the system controller
+    description:
+      Phandle to the S5 system controller, which holds the Type-C plug
+      orientation control register, followed by the PHY instance index.
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        description:
+          Output endpoint of the PHY for USB, or for DisplayPort when
+          configured into 4-lane mode, which should point to the
+          SuperSpeed port of a USB Type-C connector.
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Incoming endpoint from the USB controller.
+      port@2:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Incoming endpoint from the DisplayPort controller.
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - "#phy-cells"
+  - clocks
+  - resets
+  - reset-names
+  - cix,s5-syscon
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/cix,sky1.h>
+    #include <dt-bindings/reset/cix,sky1-s5-system-control.h>
+
+    phy@9030000 {
+        compatible = "cix,sky1-usbdp-phy";
+        reg = <0x09030000 0x40000>;
+        #phy-cells = <1>;
+        clocks = <&scmi_clk CLK_TREE_USB3C_DRD_PHY3_GATE>;
+        resets = <&s5_syscon SKY1_USB_DP_PHY0_RST_N>,
+                 <&s5_syscon SKY1_USB_DP_PHY0_PRST_N>;
+        reset-names = "core", "apb";
+        orientation-switch;
+        mode-switch;
+        cix,s5-syscon = <&s5_syscon 0>;
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+
+                endpoint {
+                    remote-endpoint = <&usb_c_connector>;
+                };
+            };
+
+            port@1 {
+                reg = <1>;
+
+                endpoint {
+                    remote-endpoint = <&usb3_controller>;
+                };
+            };
+
+            port@2 {
+                reg = <2>;
+
+                endpoint {
+                    remote-endpoint = <&dp_controller>;
+                };
+            };
+        };
+    };
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH v8 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dt-bindings: phy: cix,sky1-usbdp-phy omits x4 PHY reference clock --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] dt-bindings: phy: cix,sky1-usbdp-phy omits x4 PHY reference clock
--

commit 0e3779bcf0200a489641a559231045c35b6b9e3a
Author: Gary Yang <[email protected]>

dt-bindings: phy: add CIX Sky1 USB/DP combo PHY

This commit adds the Devicetree binding schema for the CIX Sky1 USB/DP combo PHY, describing its registers, clock, resets, Type-C switch properties, S5 syscon reference, and OF graph ports.

Quoted 6 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +0 -0
new file mode 100644
index 0000000000000..0dd518768f339
@@ -0,0 +1,148 @@

[ ... ]

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 37

Quoted 3 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +3 -0
+  clocks:
+    maxItems: 1
+    description: PHY APB clock.

[Severity: Medium]
Should clocks also describe the per-instance x4 PHY reference clock along with clock-names?

include/dt-bindings/clock/cix,sky1.h defines four x4 reference clocks (CLK_TREE_USB3C_DRD_PHY_x4_REF and CLK_TREE_USB3C_H0..H2_PHY_x4_REF) matching the four USB/DP combo PHY instances alongside their CLK_TREE_USB3C_*_PHY3_GATE APB clocks.

Because clocks is capped at maxItems: 1 with no clock-names property and
additionalProperties: false, DTS nodes cannot describe this reference clock. If a driver later needs to control or query the reference clock rate, expanding an unnamed single-clock binding will complicate DT ABI.

If CLK_TREE_USB3C_*_PHY_x4_REF feeds this PHY block, listing both clocks with clock-names now avoids that ABI break; otherwise it would help to document why it is omitted.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw

Re: [PATCH v8 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY

In reply to Gary Yang
Quoted 59 lines · Gary Yang

Document the USB/DP combo PHY of the CIX Sky1 SoC. One PHY instance provides one SuperSpeedPlus USB lane and up to four DisplayPort lanes of a USB Type-C port; consumers select the part they need with a PHY type cell, using PHY_TYPE_USB3 or PHY_TYPE_DP.

The PHY performs Type-C plug orientation switching and USB/DP lane muxing in hardware and is therefore described with the properties of the common USB switch binding. The plug orientation is switched through the S5 system controller, identified by the "cix,s5-syscon" phandle followed by the PHY instance index.

---
Changes in v8:
- Rename the system controller property to cix,s5-syscon, after the S5 system controller it points to. The previous name read as if the PHY node referenced a syscon of its own.
- Drop the redundant type of the orientation-switch and mode-switch properties, which the common USB switch binding already defines.

---
 .../bindings/phy/cix,sky1-usbdp-phy.yaml      | 148 ++++++++++++++++++
 1 file changed, 148 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +27 -0
new file mode 100644
index 000000000000..0dd518768f33
@@ -0,0 +1,148 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/cix,sky1-usbdp-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CIX Sky1 USB/DP Combo PHY
+
+maintainers:
+  - Gary Yang <[email protected]>
+
+description:
+  The CIX Sky1 USB/DP combo PHY provides one SuperSpeedPlus USB lane and
+  up to four DisplayPort lanes for a USB Type-C port. Which of the two
+  functions is in use depends on the Type-C alt mode and on the plug
+  orientation.
+
+allOf:
+  - $ref: /schemas/usb/usb-switch.yaml#
+
+properties:
+  compatible:
+    const: cix,sky1-usbdp-phy
+
+  reg:
+    maxItems: 1
+

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 37

Quoted 10 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +10 -0
+  "#phy-cells":
+    description: |
+      Cell allows setting the type of the PHY. Possible values are:
+      - PHY_TYPE_USB3
+      - PHY_TYPE_DP
+    const: 1
+
+  clocks:
+    maxItems: 1
+    description: PHY APB clock.

Please answer sashiko.

Quoted 35 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +35 -0
+
+  resets:
+    items:
+      - description: PHY core reset
+      - description: PHY APB preset
+
+  reset-names:
+    items:
+      - const: core
+      - const: apb
+
+  orientation-switch:
+    description:
+      The PHY handles Type-C plug orientation switching.
+
+  mode-switch:
+    description:
+      The PHY handles multiplexing of the USB and DisplayPort lanes.
+
+  cix,s5-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: phandle to the S5 system controller
+          - description: PHY instance index within the system controller
+    description:
+      Phandle to the S5 system controller, which holds the Type-C plug
+      orientation control register, followed by the PHY instance index.
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      "#address-cells":
+        const: 1

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 82

Quoted 10 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +10 -0
+
+      "#size-cells":
+        const: 0
+
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        description:
+          Output endpoint of the PHY for USB, or for DisplayPort when
+          configured into 4-lane mode, which should point to the
+          SuperSpeed port of a USB Type-C connector.

blank line

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 85

Quoted 3 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +3 -0
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Incoming endpoint from the USB controller.

blank line

Quoted 66 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +63 -0
+      port@2:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Incoming endpoint from the DisplayPort controller.
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - "#phy-cells"
+  - clocks
+  - resets
+  - reset-names
+  - cix,s5-syscon
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/cix,sky1.h>
+    #include <dt-bindings/reset/cix,sky1-s5-system-control.h>
+
+    phy@9030000 {
+        compatible = "cix,sky1-usbdp-phy";
+        reg = <0x09030000 0x40000>;
+        #phy-cells = <1>;
+        clocks = <&scmi_clk CLK_TREE_USB3C_DRD_PHY3_GATE>;
+        resets = <&s5_syscon SKY1_USB_DP_PHY0_RST_N>,
+                 <&s5_syscon SKY1_USB_DP_PHY0_PRST_N>;
+        reset-names = "core", "apb";
+        orientation-switch;
+        mode-switch;
+        cix,s5-syscon = <&s5_syscon 0>;
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+
+                endpoint {
+                    remote-endpoint = <&usb_c_connector>;
+                };
+            };
+
+            port@1 {
+                reg = <1>;
+
+                endpoint {
+                    remote-endpoint = <&usb3_controller>;
+                };
+            };
+
+            port@2 {
+                reg = <2>;
+
+                endpoint {
+                    remote-endpoint = <&dp_controller>;
+                };
+            };
+        };
+    };
Signature · 1 line
2.50.1
author
#4 lore raw

Re: [PATCH v8 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY

hi Rob:

Thanks for your review and kindly comments!

Quoted 75 lines · Rob Herring

EXTERNAL EMAIL

Quoted 59 lines · Gary Yang

Document the USB/DP combo PHY of the CIX Sky1 SoC. One PHY instance provides one SuperSpeedPlus USB lane and up to four DisplayPort lanes of a USB Type-C port; consumers select the part they need with a PHY type cell, using PHY_TYPE_USB3 or PHY_TYPE_DP.

The PHY performs Type-C plug orientation switching and USB/DP lane muxing in hardware and is therefore described with the properties of the common USB switch binding. The plug orientation is switched through the S5 system controller, identified by the "cix,s5-syscon" phandle followed by the PHY instance index.

---
Changes in v8:
- Rename the system controller property to cix,s5-syscon, after the S5 system controller it points to. The previous name read as if the PHY node referenced a syscon of its own.
- Drop the redundant type of the orientation-switch and mode-switch properties, which the common USB switch binding already defines.

---
 .../bindings/phy/cix,sky1-usbdp-phy.yaml      | 148 ++++++++++++++++++
 1 file changed, 148 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +27 -0
new file mode 100644
index 000000000000..0dd518768f33
@@ -0,0 +1,148 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/cix,sky1-usbdp-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CIX Sky1 USB/DP Combo PHY
+
+maintainers:
+  - Gary Yang <[email protected]>
+
+description:
+  The CIX Sky1 USB/DP combo PHY provides one SuperSpeedPlus USB lane and
+  up to four DisplayPort lanes for a USB Type-C port. Which of the two
+  functions is in use depends on the Type-C alt mode and on the plug
+  orientation.
+
+allOf:
+  - $ref: /schemas/usb/usb-switch.yaml#
+
+properties:
+  compatible:
+    const: cix,sky1-usbdp-phy
+
+  reg:
+    maxItems: 1
+

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 37

Quoted 10 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +10 -0
+  "#phy-cells":
+    description: |
+      Cell allows setting the type of the PHY. Possible values are:
+      - PHY_TYPE_USB3
+      - PHY_TYPE_DP
+    const: 1
+
+  clocks:
+    maxItems: 1
+    description: PHY APB clock.

Please answer sashiko.

Quoted 2 lines

Should clocks also describe the per-instance x4 PHY reference clock along with clock-names?

No. The reference clock of this PHY is a 24MHz crystal, and there is only a gate in clock tree. That gate is enabled by default and is never touched by the OS: neither the driver nor the device trees consume the corresponding clock IDs(CLK_TREE_USB3C_*_PHY_x4_REF / CLK_TREE_USB3C_*_PHY_REF). These IDs are added to match the IDs in the firmware clock tree and don't use them.

If you have any more questions about it, please let us know. Thanks

Quoted 40 lines
Quoted 40 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +39 -0
+
+  resets:
+    items:
+      - description: PHY core reset
+      - description: PHY APB preset
+
+  reset-names:
+    items:
+      - const: core
+      - const: apb
+
+  orientation-switch:
+    description:
+      The PHY handles Type-C plug orientation switching.
+
+  mode-switch:
+    description:
+      The PHY handles multiplexing of the USB and DisplayPort lanes.
+
+  cix,s5-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: phandle to the S5 system controller
+          - description: PHY instance index within the system controller
+    description:
+      Phandle to the S5 system controller, which holds the Type-C plug
+      orientation control register, followed by the PHY instance index.
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
Quoted 8 lines

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 82

Quoted 6 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +6 -0
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        description:
+          Output endpoint of the PHY for USB, or for DisplayPort when
+          configured into 4-lane mode, which should point to the
+          SuperSpeed port of a USB Type-C connector.

blank line

OK, add a blank line in next version.

Quoted 6 lines

Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml line 85

Quoted 4 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +3 -0
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Incoming endpoint from the USB controller.

blank line

the same

Best Regards
Gary

Quoted 67 lines
Quoted 67 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +63 -1
+      port@2:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Incoming endpoint from the DisplayPort controller.
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - "#phy-cells"
+  - clocks
+  - resets
+  - reset-names
+  - cix,s5-syscon
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/cix,sky1.h>
+    #include <dt-bindings/reset/cix,sky1-s5-system-control.h>
+
+    phy@9030000 {
+        compatible = "cix,sky1-usbdp-phy";
+        reg = <0x09030000 0x40000>;
+        #phy-cells = <1>;
+        clocks = <&scmi_clk CLK_TREE_USB3C_DRD_PHY3_GATE>;
+        resets = <&s5_syscon SKY1_USB_DP_PHY0_RST_N>,
+                 <&s5_syscon SKY1_USB_DP_PHY0_PRST_N>;
+        reset-names = "core", "apb";
+        orientation-switch;
+        mode-switch;
+        cix,s5-syscon = <&s5_syscon 0>;
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+
+                endpoint {
+                    remote-endpoint = <&usb_c_connector>;
+                };
+            };
+
+            port@1 {
+                reg = <1>;
+
+                endpoint {
+                    remote-endpoint = <&usb3_controller>;
+                };
+            };
+
+            port@2 {
+                reg = <2>;
+
+                endpoint {
+                    remote-endpoint = <&dp_controller>;
+                };
+            };
+        };
+    };
--

2.50.1

author
#5 lore raw

PATCH v8 2/2 phy: cix: add Sky1 USB/DP combo PHY driver

In reply to Gary Yang

Add a driver for the USB/DP combo PHY found on the CIX Sky1 SoC. A single PHY instance drives one SuperSpeedPlus USB lane and up to four DisplayPort lanes of a USB Type-C port, and exposes them as two PHYs selected by PHY_TYPE_USB3 and PHY_TYPE_DP, so that the USB and DP controllers can bind to them independently.

The PHY supports Type-C plug orientation switching, which is driven through the S5 system controller, and muxing of the PHY lanes between USB and DP, which is programmed in the PHY registers. It registers a Type-C switch and mux with the Type-C class, so the orientation and mode decisions are taken by the connector driver instead of the PHY.

The shared PHY is programmed once per mode combination: the driver tracks the current and requested USB/DP mode as well as the plug orientation, and reprograms the PHY when the mode combination or the orientation changes, but never while the DP lanes are still in use.

---
Changes in v8:
- Look up the system controller through its new cix,s5-syscon property and name the regmap after the S5 system controller it belongs to.
- Limit the voltage programming to the lanes that the programmed register table assigns to DisplayPort while the deferred reprogramming is still pending. The lane count of a new mode was committed before the table switch, so a voltage update arriving in between could write DisplayPort levels onto the lines that still carried the USB3 signals. Track the lane count of the table itself, as the mode tracking does not always match the table, and verify and program the same lane count in that window.

Changes in v7:
- Report the PHY bus width as soon as the mux selects the new mode, instead of waiting for the deferred reprogramming that runs from phy_configure(). The DP controller reads the bus width before configuring the link, so a 2-lane to 4-lane switch trained only two lanes, and a 4-lane to 2-lane switch was rejected before the deferred reprogramming could run.
- Keep the lane count used for the voltage programming unchanged when the mux switches between the DisplayPort modes. The register table still belongs to the previous mode until the deferred reprogramming runs, and its outer PMA lanes may still carry the USB3 signals, so a voltage update arriving in between would write DisplayPort levels to the USB3 lanes.
- Commit the lane count of the requested mode only after the DisplayPort power-on succeeded. A failed power-on leaves the register table in the previous mode, and the lane count of the requested mode would let the voltage programming reach the lanes that still belong to USB3.
- Program the high-speed clock divider of every lane assigned to DisplayPort on a rate change, not only the lanes of the previous configuration, so that a lane count raised in a separate phy_configure() call also gets the new divider.
- Keep the orientation programmed into the PHY separate from the requested one and only update it when the PHY is actually reprogrammed, so that voltage swing updates arriving while the reprogramming is pending no longer address the lanes of the new orientation before the hardware has switched.
- Track whether the caller configured the lane count for the current mode, and fall back to the lanes that the new mode assigns to DisplayPort when the deferred reprogramming follows a mode change. A rate-only update after a 2-lane to 4-lane switch otherwise kept the previous two-lane count and left the outer lanes without voltage levels, while a rate-only update in the same mode still keeps the configured count, clamped to the lanes that the mode assigns to DisplayPort.

Changes in v6:
- Keep the DP lane count, the PHY bus width and the USB mode bit in sync with the requested mode when the deferred reprogramming is applied from the DP configuration path, instead of leaving the values from the previous power-on in place. A rate update that does not repeat set_lanes could otherwise program the USB3 lanes after a 4-lane to 2-lane switch, or skip the lanes that became available after a 2-lane to 4-lane switch. Validate the voltage levels against the same lane count, so that the verification and the programming steps agree.
- Ignore DP configuration requests that arrive after the connector has left the DisplayPort alt mode, so that a stale link-training call cannot reprogram lanes that no longer belong to DisplayPort.
- Complete a DisplayPort power-on that arrives while the mux still reports a USB-only mode when the mux later selects the DisplayPort mode. The PHY core has already taken the power reference, so without remembering the request the DP PHY would stay unpowered for the session and all link configuration would be dropped.
- Only remember that power-on once it succeeded or when it has been deferred until the mux selects the DisplayPort mode. A failed power-on does not give the PHY core a reference to account, so remembering it anyway would let the mux path power the block up without a consumer and never power it down again.
- Drop a pending reprogramming request when the PHY is fully powered down. The next power-on programs the complete register table for the requested mode and orientation, so the request is applied there and must not leak into the next session.

Changes in v5:
- Attempt the USB restore on every mux event whose requested mode contains USB, instead of only on the plain USB state, so that a configuration change or a disconnect after a 4-lane DP session no longer leaves the initialized USB3 controller attached to a powered down PHY.
- Do not run the power-on sequence when the DP PHY releases the lanes:
the PHY is still powered at that point, so restoring the USB mode there would enable the APB clock a second time and leak a prepare/enable reference. Account the USB mode again instead and only apply a deferred reprogramming.
- Drop the USB mode bit and power the PHY down when the mux switches to a DP-only configuration while USB3 is the only user, instead of keeping the PHY powered with a USB bit that the DP-only register table has already disconnected. The DP PHY powers the block up again when it is powered on.
- Apply a deferred mode or plug orientation reprogramming when the DP link parameters are configured, before the link training starts, instead of leaving it pending while the DP PHY is powered. A mode change that arrives after the DP PHY has been powered on with the previous table cannot be applied from the mux notification, and the link would otherwise be trained against the previous lane mapping.

Changes in v4:
- Map the safe and USB states signalled by the DP altmode driver to the USB+DP mode instead of the USB-only mode, so that a DP PHY power-on request that races with the altmode notification no longer leaves the PHY unpowered and silently drops the link training writes. Handle the deprecated pin assignments A and B the same way as C and D instead of mapping them to USB only.
- Apply a deferred mode table or plug orientation reprogramming as soon as the DP PHY stops using the lanes, instead of waiting for a USB3 power-on that is not guaranteed while the PHY stays initialized.
- Drop the USB mode bit when a 4-lane DP configuration takes over all the lanes, so that releasing the DP PHY powers the combo PHY down instead of leaving it and its apb clock enabled. Remember whether the USB3 controller still holds the PHY initialized and power the PHY back up to USB once the last DP user releases the lanes, including when the DP altmode driver switches the sink back to USB before the DP PHY is powered off, so that the controller does not end up driving an unpowered PHY.

---
 MAINTAINERS                     |    4 +-
 drivers/phy/cix/Kconfig         |   16 +
 drivers/phy/cix/Makefile        |    1 +
 drivers/phy/cix/phy-cix-usbdp.c | 1753 +++++++++++++++++++++++++++++++
 drivers/phy/cix/phy-cix-usbdp.h |  257 +++++
 5 files changed, 2030 insertions(+), 1 deletion(-)
 create mode 100644 drivers/phy/cix/phy-cix-usbdp.c
 create mode 100644 drivers/phy/cix/phy-cix-usbdp.h
MAINTAINERS +3 -1
index d05771fe5bb2..f53c2d9de226 100644
@@ -6522,12 +6522,14 @@ M:	Satish Kharat <[email protected]>
 S:	Supported
 F:	drivers/infiniband/hw/usnic/
 
-CIX SKY1 DISPLAYPORT PHY DRIVER
+CIX SKY1 PHY DRIVERS
+M:	Gary Yang <[email protected]>
 M:	Luo Liu <[email protected]>
 R:	CIX Linux Kernel Upstream Group <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/phy/cix,sky1-dp-phy.yaml
+F:	Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
 F:	drivers/phy/cix/
 
 CLANG CONTEXT ANALYSIS
drivers/phy/cix/Kconfig +16 -0
index fd3becae2b23..84853a99f42f 100644
@@ -16,3 +16,19 @@ config PHY_CIX_DP
 
 	  To compile this driver as a module, choose M here. The module will
 	  be called phy-cix-dp.
+
+config PHY_CIX_USBDP
+	tristate "CIX Sky1 USB3/DP combo PHY driver"
+	depends on OF && HAS_IOMEM && COMMON_CLK
+	depends on ARCH_CIX || COMPILE_TEST
+	depends on RESET_CONTROLLER
+	depends on TYPEC
+	select GENERIC_PHY
+	select MFD_SYSCON
+	help
+	  Enable this to support the CIX Sky1 USB3/DP combo PHY, which
+	  provides one SuperSpeedPlus USB lane and up to four DisplayPort
+	  lanes for a USB Type-C port.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called phy-cix-usbdp.
drivers/phy/cix/Makefile +1 -0
index cc56c7586ec5..a1bc2b3d7ea2 100644
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_PHY_CIX_DP) += phy-cix-dp.o
+obj-$(CONFIG_PHY_CIX_USBDP) += phy-cix-usbdp.o
drivers/phy/cix/phy-cix-usbdp.c new file +1753 -0

1,753 lines not on this page · raw message

drivers/phy/cix/phy-cix-usbdp.h new file +257 -0

257 lines not on this page · raw message

Signature · 1 line
2.50.1
#6 lore raw

Re: [PATCH v8 2/2] phy: cix: add Sky1 USB/DP combo PHY driver

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] phy: cix: udphy_dp_phy_set_rate() ignores dp->ssc leaving SSC always enabled - [Medium] phy: cix…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] phy: cix: udphy_dp_phy_set_rate() ignores dp->ssc leaving SSC always enabled
- [Medium] phy: cix: premature PHY provider registration in cix_udphy_probe()
- [Medium] phy: cix: udphy_dp_phy_set_rate() under-waits PLL1 lock and PMA ready
--

commit 29c5fede3844afcbadc8c1146b5c8f3d0bf0f9e2
Author: Gary Yang <[email protected]>

phy: cix: add Sky1 USB/DP combo PHY driver

This commit adds a driver for the CIX Sky1 USB/DP combo PHY, exposing separate USB3 and DisplayPort PHYs and registering a Type-C orientation switch and mode mux.

Quoted 5 lines
drivers/phy/cix/phy-cix-usbdp.c new file +0 -0
new file mode 100644
index 0000000000000..6d655cc0ac076

[ ... ]

Quoted 3 lines
drivers/phy/cix/phy-cix-usbdp.c new file +3 -0
+static int udphy_dp_phy_set_rate(struct cix_udphy *udphy,
+				 struct phy_configure_opts_dp *dp)
+{

[ ... ]

Quoted 12 lines
drivers/phy/cix/phy-cix-usbdp.c new file +12 -0
+	udphy_update_bits(udphy, PHY_PMA_PLL_CTRL, BIT(1), 0x0);
+	usleep_range(10, 20);
+
+	udphy_write_table(udphy, conf->seq, conf->num_seq);
+
+	/*
+	 * Program the divider of every lane assigned to DisplayPort, not just
+	 * the lanes of the previous configuration: the caller may raise the
+	 * lane count in a separate phy_configure() call, without repeating the
+	 * rate update.
+	 */
+	for (i = 0; i < udphy_dplane_get(udphy); i++) {

drivers/phy/cix/phy-cix-usbdp.c line 1345

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+		u32 lane = udphy_dp_lane_to_pma(udphy, i);
+		u32 reg = XCVR_DIAG_HSCLK_DIV_LANE0 + lane * PHY_LANE_STRIDE;
+
+		writel(conf->hsclk_div, udphy->base + reg * 4);
+	}
+
+	writel(conf->pll_intdiv, udphy->base + CMN_PLL1_INTDIV_M0 * 4);
+	writel(conf->pll_fracdivl, udphy->base + CMN_PLL1_FRACDIVL_M0 * 4);
+	writel(conf->pll_high_thr, udphy->base + CMN_PLL1_HIGH_THR_M0 * 4);
+	writel(conf->clk_sel, udphy->base + CMN_PDIAG_PLL1_CLK_SEL_M0 * 4);

[Severity: Medium]
Should udphy_dp_phy_set_rate() also program CMN_PLL1_SS_CTRL1_M0 according to dp->ssc?

All three mode tables unconditionally write 0x0001 to CMN_PLL1_SS_CTRL1_M0, so SSC stays enabled on PLL1 even when a DisplayPort sink does not support downspread (dp->ssc == 0).

struct phy_configure_opts_dp expects set_rate to apply both link_rate and ssc, and driving SSC on a non-SSC sink can break link training. The sibling driver in drivers/phy/cix/phy-cix-dp.c toggles the same offset (0x00d8) between 0x0001 and 0x0000 in cix_dp_phy_set_ssc().

drivers/phy/cix/phy-cix-usbdp.c line 1351

Quoted 6 lines
drivers/phy/cix/phy-cix-usbdp.c new file +6 -0
+
+	udphy_update_bits(udphy, PHY_PMA_PLL_CTRL, BIT(1), BIT(1));
+	usleep_range(10, 20);
+
+	return 0;
+}

[Severity: Medium]
Is usleep_range(10, 20) long enough here, instead of polling the PMA status registers for PLL1 disable and lock?

At the 24 MHz reference clock implied by link_cfg[], the PLL1 startup, VCO calibration, and lock timers programmed in the mode tables sum to at least 61 us for a single calibration iteration. Reprogramming PLL1 before it disables or returning before it locks can break DP link training.

Similarly, after a deferred sky1_udphy_reinit() in udphy_dp_phy_configure(), udphy_dp_phy_set_rate() runs right after deasserting udphy->reset without waiting for PMA common readiness.

Both drivers/phy/cix/phy-cix-dp.c (cix_dp_pll_raw_ctrl_ack()) and drivers/phy/cadence/phy-cadence-torrent.c poll PHY_PMA_CMN_CTRL2 (0xe001) for PLL disable/ready and wait for PMA common readiness after reset.

[ ... ]

Quoted 22 lines
drivers/phy/cix/phy-cix-usbdp.c new file +22 -0
+	phy_provider = devm_of_phy_provider_register(dev, cix_udphy_phy_xlate);
+	if (IS_ERR(phy_provider))
+		return dev_err_probe(dev, PTR_ERR(phy_provider),
+				     "failed to register PHY provider\n");
+
+	/*
+	 * Register with the Type-C class only once the PHYs and the provider
+	 * are in place, so that the switch and mux callbacks cannot run before
+	 * the driver is fully set up.
+	 */
+	if (device_property_present(dev, "orientation-switch")) {
+		ret = udphy_setup_orien_switch(udphy);
+		if (ret)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev,
+					       udphy_orien_switch_unregister,
+					       udphy);
+		if (ret)
+			return ret;
+	}
+

drivers/phy/cix/phy-cix-usbdp.c line 1726

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+	if (device_property_present(dev, "mode-switch")) {
+		ret = udphy_setup_typec_mux(udphy);
+		if (ret)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, udphy_typec_mux_unregister,
+					       udphy);
+		if (ret)
+			return ret;
+	}

[Severity: Medium]
Can registering the PHY provider before the Type-C orientation switch and mux cause a use-after-free if one of those registrations fails?

Because the OF graph ports between this PHY and its USB3/DP consumers form a cycle with the phys links, fw_devlink relaxes them and a consumer can probe as soon as devm_of_phy_provider_register() publishes the provider:

CPU0 CPU1
cix_udphy_probe()
devm_of_phy_provider_register()

                                    consumer probe
                                      phy_get() -> u3_phy
                                      phy_init(u3_phy)
  udphy_setup_typec_mux() fails
  devres_release_all()
    phy_destroy(u3_phy)
    devm_kfree(udphy)
                                      phy_exit(u3_phy)
                                        cix_u3phy_exit()
                                          &udphy->mutex  <-- use-after-free

phy_destroy() calls device_unregister() without revoking active consumer references, so devres frees struct cix_udphy (and puts apb_clk while still enabled) while the consumer still holds u3_phy.

Moving devm_of_phy_provider_register() to the end of cix_udphy_probe(), after the Type-C switch and mux registrations, closes this window since their callbacks only need u3_phy and dp_phy from devm_phy_create().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2