Skip to contentSkip to conversation

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

PATCH Superseded Gary Yang 2 participants 4 messages Nov 30

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Gary Yang

author
#0 lore raw

v3 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 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.

Patch 1 is unchanged from v2.

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      |  150 ++
 MAINTAINERS                                   |    4 +-
 drivers/phy/cix/Kconfig                       |   16 +
 drivers/phy/cix/Makefile                      |    1 +
 drivers/phy/cix/phy-cix-usbdp.c               | 1419 +++++++++++++++++
 drivers/phy/cix/phy-cix-usbdp.h               |  257 +++
 6 files changed, 1846 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

--
2.50.1

author
#1 lore raw

PATCH v3 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,usbphy-syscon" phandle followed by the PHY instance index.

---
 .../bindings/phy/cix,sky1-usbdp-phy.yaml      | 150 ++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +150 -0
new file mode 100644
index 000000000000..9bdd01e348b2
@@ -0,0 +1,150 @@
+# 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.
+    type: boolean
+
+  mode-switch:
+    description:
+      The PHY handles multiplexing of the USB and DisplayPort lanes.
+    type: boolean
+
+  cix,usbphy-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 system controller used for Type-C plug orientation
+      control, 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,usbphy-syscon
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/cix,sky1.h>
+    #include <dt-bindings/reset/cix,sky1-s5-system-control.h>
+
+    usbc_phy0: 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";
+        cix,usbphy-syscon = <&s5_syscon 0>;
+        orientation-switch;
+        mode-switch;
+
+        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
#2 lore raw

PATCH v3 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 on the next power-on only when the mode combination or the orientation has changed.

---
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().

 MAINTAINERS                     |    4 +-
 drivers/phy/cix/Kconfig         |   16 +
 drivers/phy/cix/Makefile        |    1 +
 drivers/phy/cix/phy-cix-usbdp.c | 1419 +++++++++++++++++++++++++++++++
 drivers/phy/cix/phy-cix-usbdp.h |  257 ++++++
 5 files changed, 1696 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 +1419 -0

1,419 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
#3 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] phy: cix: stale cur_mode and deferred reinit in cix_usbdp_phy_power_on() - [High] phy: cix…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] phy: cix: stale cur_mode and deferred reinit in cix_usbdp_phy_power_on()
- [High] phy: cix: usbdp_typec_mux_set() drops UDPHY_MODE_DP in default branch
--

commit 65650ff2bab980862db4f825d7173df1ccff3e28
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 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..9a2c8b827ff8c

[ ... ]

Quoted 19 lines
drivers/phy/cix/phy-cix-usbdp.c new file +19 -0
+static int usbdp_typec_mux_set(struct typec_mux_dev *mux,
+			       struct typec_mux_state *state)
+{
+	struct cix_udphy *udphy = typec_mux_get_drvdata(mux);
+	u8 mode;
+
+	/* Ignore mux events not involving USB or DisplayPort */
+	if (!usbdp_typec_is_supported_mode(state)) {
+		dev_dbg(udphy->dev, "ignore mux event with mode=%lu\n",
+			state->mode);
+		return 0;
+	}
+
+	switch (state->mode) {
+	case TYPEC_DP_STATE_C:
+		fallthrough;
+	case TYPEC_DP_STATE_E:
+		mode = UDPHY_MODE_DP;
+		break;

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+	case TYPEC_DP_STATE_D:
+		fallthrough;
+	case TYPEC_DP_STATE_F:
+		mode = UDPHY_MODE_DP_USB;
+		break;
+	default:
+		/* usb only handle as usb+dp mode */
+		mode = UDPHY_MODE_USB;
+		break;
+	}

[Severity: High]
Should the default case set mode to UDPHY_MODE_DP_USB instead of UDPHY_MODE_USB, matching the comment and udphy_set_default_mode()?

When dp_altmode_configure_vdm() places the mux in TYPEC_STATE_SAFE before sending DP_CMD_CONFIGURE, setting udphy->next_mode to UDPHY_MODE_USB drops UDPHY_MODE_DP. If HPD then triggers phy_power_on(udphy->dp_phy) before the DisplayPort alt mode state notification arrives (as in dp_altmode_configured()), udphy_dp_phy_power_on() sees !(udphy->next_mode & UDPHY_MODE_DP) and returns 0 without powering on the PHY or setting UDPHY_MODE_DP in udphy->cur_mode, causing udphy_dp_phy_configure() to silently drop all subsequent link training writes.

[ ... ]

Quoted 78 lines
drivers/phy/cix/phy-cix-usbdp.c new file +78 -0
+static int cix_usbdp_phy_power_on(struct cix_udphy *udphy)
+{
+	int ret;
+
+	if (udphy->cur_mode == udphy->next_mode && !udphy->needs_reinit)
+		return 0;
+
+	if (udphy->cur_mode == UDPHY_MODE_NONE)
+		ret = udphy->cfg->udphy_init(udphy);
+	else if (udphy->needs_reinit)
+		ret = udphy->cfg->udphy_reinit(udphy);
+	else
+		return 0;
+
+	if (ret) {
+		dev_err(udphy->dev, "failed to bring up udphy\n");
+		return ret;
+	}
+
+	udphy->needs_reinit = false;
+
+	return 0;
+}
+
+static int cix_usbdp_phy_power_off(struct cix_udphy *udphy)
+{
+	int ret;
+
+	ret = udphy->cfg->udphy_exit(udphy);
+	if (ret) {
+		dev_err(udphy->dev, "failed to exit udphy\n");
+		return ret;
+	}
+
+	udphy->cur_mode = UDPHY_MODE_NONE;
+
+	return 0;
+}
+
+static int udphy_dp_phy_power_on(struct phy *phy)
+{
+	struct cix_udphy *udphy = phy_get_drvdata(phy);
+	int ret;
+
+	guard(mutex)(&udphy->mutex);
+
+	if (!(udphy->next_mode & UDPHY_MODE_DP))
+		return 0;
+
+	udphy->dp_lanes = udphy_dplane_get(udphy);
+
+	ret = cix_usbdp_phy_power_on(udphy);
+	if (ret)
+		return ret;
+
+	phy_set_bus_width(phy, udphy->dp_lanes);
+	udphy->cur_mode |= UDPHY_MODE_DP;
+
+	return 0;
+}
+
+static int udphy_dp_phy_power_off(struct phy *phy)
+{
+	struct cix_udphy *udphy = phy_get_drvdata(phy);
+
+	guard(mutex)(&udphy->mutex);
+
+	if (!(udphy->cur_mode & UDPHY_MODE_DP))
+		return 0;
+
+	udphy->cur_mode &= ~UDPHY_MODE_DP;
+	phy_set_bus_width(phy, 0);
+
+	if (udphy->cur_mode == UDPHY_MODE_NONE)
+		return cix_usbdp_phy_power_off(udphy);
+
+	return 0;
+}

[ ... ]

Quoted 8 lines
drivers/phy/cix/phy-cix-usbdp.c new file +8 -0
+static int cix_u3phy_init(struct phy *phy)
+{
+	struct cix_udphy *udphy = phy_get_drvdata(phy);
+	int ret;
+
+	guard(mutex)(&udphy->mutex);
+
+	if (!(udphy->next_mode & UDPHY_MODE_USB))

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+		return 0;
+
+	ret = cix_usbdp_phy_power_on(udphy);
+	if (ret)
+		return ret;
+
+	udphy->cur_mode |= UDPHY_MODE_USB;
+
+	return 0;
+}

[Severity: High]
Does transitioning into 4-lane DisplayPort mode (UDPHY_MODE_DP) while u3_phy is already initialized leave UDPHY_MODE_USB stuck in udphy->cur_mode?

When u3_phy is initialized at probe or on initial Type-C attach, cix_u3phy_init() sets UDPHY_MODE_USB in udphy->cur_mode. Entering 4-lane DP alt mode sets udphy->next_mode = UDPHY_MODE_DP and udphy->needs_reinit = true without tearing down u3_phy (and even if cix_u3phy_set_mode() runs, cix_u3phy_init() returns 0 early when !(udphy->next_mode & UDPHY_MODE_USB) without clearing UDPHY_MODE_USB). udphy_dp_phy_power_on() then calls sky1_udphy_reinit() to reprogram the whole PHY into 4-lane DP-only mode and ORs UDPHY_MODE_DP into udphy->cur_mode. When udphy_dp_phy_power_off() later clears UDPHY_MODE_DP, udphy->cur_mode is still UDPHY_MODE_USB rather than UDPHY_MODE_NONE, so cix_usbdp_phy_power_off() is skipped and the PHY and apb_clk stay enabled.

Also, because udphy_orien_sw_set() and usbdp_typec_mux_set() only set udphy->needs_reinit = true and defer sky1_udphy_reinit() to the next cix_usbdp_phy_power_on(), any orientation change or exit from 4-lane DP back to USB while u3_phy is already active will never trigger sky1_udphy_reinit(), leaving the hardware programmed with the stale orientation or 4-lane DP-only register table.

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