Skip to contentSkip to conversation

phy: cix: add Sky1 USB/DP combo PHY

PATCH New Gary Yang 2 participants 7 messages Nov 2

Subsystems (3)
lore
Share & tools
lore

Gary Yang

author maintainer
#0 lore raw

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

This series adds support for the USB/DP combo PHY found on the CIX Sky1 SoC. Each PHY instance provides one SuperSpeedPlus USB lane and one DisplayPort lane of a USB Type-C port, with plug orientation and USB/DP lane muxing handled through the S5 system controller.

The PHY registers a Type-C switch and mux so that the connector driver owns orientation and mode decisions, and exposes the USB and DP lanes as separate child PHYs so that the USB and DP controllers can bind to them independently.

Patch 1 documents the binding, patch 2 adds the driver, and patch 3 adds the SoC nodes and enables them on the Radxa Orion O6.

The driver has been built for arm64 with the PHY enabled both built-in and as a module. dt_binding_check, dtbs_check and checkpatch --strict pass.

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

 .../bindings/phy/cix,sky1-usbdp-phy.yaml      |  150 ++
 MAINTAINERS                                   |    2 +
 arch/arm64/boot/dts/cix/sky1-orion-o6.dts     |   28 +
 arch/arm64/boot/dts/cix/sky1.dtsi             |   96 ++
 drivers/phy/Kconfig                           |    1 +
 drivers/phy/Makefile                          |    1 +
 drivers/phy/cix/Kconfig                       |   22 +
 drivers/phy/cix/Makefile                      |    2 +
 drivers/phy/cix/phy-cix-usbdp.c               | 1477 +++++++++++++++++
 drivers/phy/cix/phy-cix-usbdp.h               |  265 +++
 10 files changed, 2044 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
 create mode 100644 drivers/phy/cix/Kconfig
 create mode 100644 drivers/phy/cix/Makefile
 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 maintainer
#1 lore raw

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

Document the USB/DP combo PHY of the CIX Sky1 SoC. Each PHY instance exposes one SuperSpeedPlus USB lane and one DisplayPort lane as child nodes, so that the USB and DP consumers can each reference the lane they use.

The PHY performs Type-C plug orientation switching and USB/DP lane muxing in hardware and is therefore described with the "orientation-switch" and "mode-switch" properties. Lane muxing is programmed 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 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 151 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..a5b6943f84eb
@@ -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 one DisplayPort lane for a USB3C Type-C port. The USB and DP
+  lanes are represented as child nodes of the PHY controller.
+
+properties:
+  compatible:
+    const: cix,sky1-usbdp-phy
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  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 lane muxing and
+      Type-C orientation control, followed by the PHY instance index.
+
+  cix,default-conf:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    enum: [0, 1, 2, 3]
+    default: 3
+    description: |
+      Lane mode the PHY is put in until a consumer changes it through the
+      Type-C mux. The value is a bit mask: 0 = none, 1 = USB, 2 = DP,
+      3 = USB and DP.
+
+patternProperties:
+  "^usb-port@[0-9a-f]+$":
+    type: object
+    description:
+      The USB lane of the combo PHY.
+
+    properties:
+      reg:
+        maxItems: 1
+
+      "#phy-cells":
+        const: 0
+
+    required:
+      - reg
+      - "#phy-cells"
+
+    additionalProperties: false
+
+  "^dp-port@[0-9a-f]+$":
+    type: object
+    description:
+      The DisplayPort lane of the combo PHY.
+
+    properties:
+      reg:
+        maxItems: 1
+
+      "#phy-cells":
+        const: 0
+
+    required:
+      - reg
+      - "#phy-cells"
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-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: usb-phy@9030000 {
+        compatible = "cix,sky1-usbdp-phy";
+        reg = <0x09030000 0x40000>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+        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>;
+        cix,default-conf = /bits/ 8 <0x03>;
+        orientation-switch;
+        mode-switch;
+
+        usb-port@0 {
+            reg = <0>;
+            #phy-cells = <0>;
+        };
+
+        dp-port@1 {
+            reg = <1>;
+            #phy-cells = <0>;
+        };
+    };
MAINTAINERS +1 -0
index 93abbb315065..8fb940a3ea3b 100644
@@ -2903,6 +2903,7 @@ S:	Maintained
 T:	git https://github.com/cixtech/linux-mainline.git
 F:	Documentation/devicetree/bindings/arm/cix.yaml
 F:	Documentation/devicetree/bindings/mailbox/cix,sky1-mbox.yaml
+F:	Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
 F:	arch/arm64/boot/dts/cix/
 F:	drivers/mailbox/cix-mailbox.c
 K:	\bcix\b
Signature · 1 line
2.50.1
#2 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] dt-bindings: phy: cix,sky1-usbdp-phy: missing OF graph port/ports for Type-C - [Low]…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] dt-bindings: phy: cix,sky1-usbdp-phy: missing OF graph port/ports for Type-C
- [Low] dt-bindings: phy: cix,sky1-usbdp-phy: dummy child nodes and policy property --

commit 861d429c69ca8c486ffb6fda39bbf7f07f828ee7
Author: Gary Yang <[email protected]>

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

This commit adds the Device Tree binding schema for the CIX Sky1 SoC USB/DP combo PHY, describing its clocks, resets, system controller phandle, Type-C switch properties, and child nodes for the USB and DisplayPort lanes.

Quoted 5 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +0 -0
new file mode 100644
index 0000000000000..a5b6943f84ebd

[ ... ]

Quoted 9 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +9 -0
+  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

[ ... ]

Quoted 35 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +35 -0
+  cix,default-conf:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    enum: [0, 1, 2, 3]
+    default: 3
+    description: |
+      Lane mode the PHY is put in until a consumer changes it through the
+      Type-C mux. The value is a bit mask: 0 = none, 1 = USB, 2 = DP,
+      3 = USB and DP.
+
+patternProperties:
+  "^usb-port@[0-9a-f]+$":
+    type: object
+    description:
+      The USB lane of the combo PHY.
+
+    properties:
+      reg:
+        maxItems: 1
+
+      "#phy-cells":
+        const: 0
+
+    required:
+      - reg
+      - "#phy-cells"
+
+    additionalProperties: false
+
+  "^dp-port@[0-9a-f]+$":
+    type: object
+    description:
+      The DisplayPort lane of the combo PHY.
+
+    properties:
+      reg:

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

Quoted 10 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +10 -0
+        maxItems: 1
+
+      "#phy-cells":
+        const: 0
+
+    required:
+      - reg
+      - "#phy-cells"
+
+    additionalProperties: false

[Severity: Low]
Why are child nodes and cix,default-conf needed in the binding here?

The usb-port and dp-port child nodes only contain reg and #phy-cells = <0> with no per-lane hardware resources (such as separate clocks, resets, regulators, or OF graph ports), and the driver in cix_udphy_probe() does not read the child reg property at all. When combo PHY sub-lanes have no independent DT resources, could the parent PHY node expose both lanes directly using #phy-cells = <1> (for example taking PHY_TYPE_USB3 and PHY_TYPE_DP) instead of requiring #address-cells, #size-cells, and dummy child nodes with arbitrary unit addresses?

Similarly, cix,default-conf describes the initial software lane mode prior to Type-C mux updates rather than a hardware property of the PHY, and both the binding and driver already default to 3. Could cix,default-conf be dropped from the binding so the driver initializes its default state directly?

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

Quoted 12 lines
Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml new file +12 -0
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - clocks
+  - resets
+  - reset-names
+  - cix,usbphy-syscon
+
+additionalProperties: false

[Severity: Medium]
How can a Type-C connector or controller link to this PHY when orientation-switch and mode-switch are used?

In the Type-C mux and switch core (fwnode_typec_switch_get() -> fwnode_connection_find_matches() -> fwnode_graph_devcon_matches() -> typec_switch_match() and fwnode_typec_mux_get() -> typec_mux_match() in drivers/usb/typec/mux.c), the boolean orientation-switch and mode-switch properties on a provider node are matched by traversing OF graph endpoints (port or ports) from the Type-C connector node to the provider node:

drivers/usb/typec/mux.c:typec_switch_match() {
	if (id && !fwnode_property_present(fwnode, id))
		return NULL;
	...
}

However, Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml defines orientation-switch and mode-switch inline and sets
additionalProperties: false without defining port or ports properties or referencing /schemas/usb/usb-switch.yaml# and /schemas/usb/usb-switch-ports.yaml#.

As a result, any board Device Tree that connects a Type-C connector to this PHY via OF graph will fail dtbs_check validation, while omitting the OF graph links prevents fwnode_typec_switch_get() and fwnode_typec_mux_get() from discovering the PHY's switch and mux at runtime. Should this schema reference usb-switch.yaml and define the required OF graph port/ports nodes?

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

PATCH 2/3 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 one DisplayPort lane of a USB Type-C port, and exposes the two lanes as separate child PHYs so that the USB and DP controllers can bind to them independently.

The PHY supports Type-C plug orientation switching and lane muxing between USB and DP, both driven through the S5 system controller. 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 bootloader may hand over the port already initialized; in that case the first power_on calls skip the re-initialization.

---
 MAINTAINERS                     |    1 +
 drivers/phy/Kconfig             |    1 +
 drivers/phy/Makefile            |    1 +
 drivers/phy/cix/Kconfig         |   22 +
 drivers/phy/cix/Makefile        |    2 +
 drivers/phy/cix/phy-cix-usbdp.c | 1477 +++++++++++++++++++++++++++++++
 drivers/phy/cix/phy-cix-usbdp.h |  265 ++++++
 7 files changed, 1769 insertions(+)
 create mode 100644 drivers/phy/cix/Kconfig
 create mode 100644 drivers/phy/cix/Makefile
 create mode 100644 drivers/phy/cix/phy-cix-usbdp.c
 create mode 100644 drivers/phy/cix/phy-cix-usbdp.h
MAINTAINERS +1 -0
index 8fb940a3ea3b..ed595861174b 100644
@@ -2906,6 +2906,7 @@ F:	Documentation/devicetree/bindings/mailbox/cix,sky1-mbox.yaml
 F:	Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml
 F:	arch/arm64/boot/dts/cix/
 F:	drivers/mailbox/cix-mailbox.c
+F:	drivers/phy/cix/
 K:	\bcix\b
 
 ARM/CLKDEV SUPPORT
drivers/phy/Kconfig +1 -0
index 105fbe408aa2..876e5857634c 100644
@@ -176,6 +176,7 @@ source "drivers/phy/axiado/Kconfig"
 source "drivers/phy/broadcom/Kconfig"
 source "drivers/phy/cadence/Kconfig"
 source "drivers/phy/canaan/Kconfig"
+source "drivers/phy/cix/Kconfig"
 source "drivers/phy/eswin/Kconfig"
 source "drivers/phy/freescale/Kconfig"
 source "drivers/phy/hisilicon/Kconfig"
drivers/phy/Makefile +1 -0
index c6dd02003bbe..5a31c5df1746 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_GENERIC_PHY)		+= allwinner/	\
 					   broadcom/	\
 					   cadence/	\
 					   canaan/	\
+					   cix/		\
 					   eswin/	\
 					   freescale/	\
 					   hisilicon/	\
drivers/phy/cix/Kconfig new file +22 -0
new file mode 100644
index 000000000000..769ec302657c
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Phy drivers for CIX platforms
+#
+
+config PHY_CIX_USBDP
+	tristate "CIX USB3/DP combo PHY driver"
+	depends on ARCH_CIX || COMPILE_TEST
+	depends on OF
+	depends on HAS_IOMEM
+	depends on RESET_CONTROLLER
+	depends on TYPEC
+	select GENERIC_PHY
+	select MFD_SYSCON
+	select REGMAP
+	help
+	  Enable this to support the CIX USB3/DP combo PHY, which provides
+	  one SuperSpeedPlus USB lane and one DisplayPort lane 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 new file +2 -0
new file mode 100644
index 000000000000..68b5d7a029a8
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_PHY_CIX_USBDP)		+= phy-cix-usbdp.o
drivers/phy/cix/phy-cix-usbdp.c new file +1477 -0

1,477 lines not on this page · raw message

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

265 lines not on this page · raw message

Signature · 1 line
2.50.1
#4 lore raw

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

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] phy: cix: wrong link_rate units and early PLL disable in udphy_dp_phy_set_rate() - [High] phy…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] phy: cix: wrong link_rate units and early PLL disable in udphy_dp_phy_set_rate()
- [High] phy: cix: lane 0 voltage and pre-emphasis applied to all lanes in udphy_dp_phy_set_voltages()
- [High] phy: cix: missing .init callback in cix_u3phy_ops alongside .exit
- [High] phy: cix: clock enable leak and broken mode/orientation state in cix_usbdp_phy_power_on()
- [High] phy: cix: unclocked MMIO access and missing lane bound in udphy_dp_phy_configure()
- [Medium] phy: cix: missing SVID check for DisplayPort states in usbdp_typec_mux_set()
- [Medium] phy: cix: probe resets PHY despite bootloader handover claim and dead macros --

commit ba3650ed160ebad8a4d82ef366b4d21f8c1a0ce7
Author: Gary Yang <[email protected]>

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

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

Quoted 37 lines
drivers/phy/cix/phy-cix-usbdp.c new file +31 -0
new file mode 100644
index 0000000000000..d596e89c74f76
@@ -0,0 +1,1477 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * phy driver for cdn_sd0804_t7g_typec
+ */
+
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/usb/typec_dp.h>
+#include <linux/usb/typec_mux.h>
+
+#include "phy-cix-usbdp.h"
+
+enum {
+	UDPHY_MODE_NONE		= 0,
+	UDPHY_MODE_USB		= BIT(0),
+	UDPHY_MODE_DP		= BIT(1),
+	UDPHY_MODE_DP_USB	= BIT(1) | BIT(0),
+};
+
+#define PHY_LANE_MUX_USB			0
+#define PHY_LANE_MUX_DP				1

[ ... ]

Quoted 31 lines
drivers/phy/cix/phy-cix-usbdp.c new file +31 -0
+static int sky1_udphy_exit(struct cix_udphy *udphy)
+{
+	reset_control_assert(udphy->reset);
+	reset_control_assert(udphy->preset);
+	clk_disable_unprepare(udphy->apb_clk);
+	return 0;
+}
+
+static int sky1_udphy_init(struct cix_udphy *udphy)
+{
+	int ret;
+	u32 value;
+	const struct cix_udphy_con_dir *con_dir = &udphy->cfg->con_dir[udphy->id];
+
+	regmap_update_bits(udphy->usbphy_syscon, con_dir->offset,
+			   GENMASK(con_dir->bit, con_dir->bit),
+			   udphy->flip << con_dir->bit);
+
+	usleep_range(10, 20);
+
+	regmap_read(udphy->usbphy_syscon, con_dir->offset, &value);
+
+	/* usb rcsu reset is default deassert */
+	reset_control_assert(udphy->reset);
+	reset_control_assert(udphy->preset);
+
+	ret = sky1_udphy_clk_enable(udphy->apb_clk);
+	if (ret) {
+		dev_err(udphy->dev, "Failed to prepare_enable udphy apb clock\n");
+		return ret;
+	}

[ ... ]

Quoted 16 lines
drivers/phy/cix/phy-cix-usbdp.c new file +16 -0
+static int udphy_orien_sw_set(struct typec_switch_dev *sw,
+			      enum typec_orientation orien)
+{
+	struct cix_udphy *udphy = typec_switch_get_drvdata(sw);
+
+	mutex_lock(&udphy->mutex);
+
+	if (orien == TYPEC_ORIENTATION_NONE)
+		goto unlock_ret;
+
+	udphy->flip = (orien == TYPEC_ORIENTATION_REVERSE) ? true : false;
+
+unlock_ret:
+	mutex_unlock(&udphy->mutex);
+	return 0;
+}

[ ... ]

Quoted 20 lines
drivers/phy/cix/phy-cix-usbdp.c new file +20 -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);
+
+	mutex_lock(&udphy->mutex);
+
+	switch (state->mode) {
+	case TYPEC_DP_STATE_C:
+		fallthrough;
+	case TYPEC_DP_STATE_E:
+		udphy->next_mode = UDPHY_MODE_DP;
+		break;
+	case TYPEC_DP_STATE_D:
+		udphy->next_mode = UDPHY_MODE_DP_USB;
+		break;
+	case TYPEC_STATE_SAFE:
+		udphy->next_mode = UDPHY_MODE_USB;
+		break;
+	default:

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+		/* usb only handle as usb+dp mode */
+		udphy->next_mode = UDPHY_MODE_USB;
+		break;
+	}
+
+	/* TODO: check whether the HPD state needs software */
+	mutex_unlock(&udphy->mutex);
+
+	return 0;
+}

[Severity: Medium]
In drivers/phy/cix/phy-cix-usbdp.c, usbdp_typec_mux_set() switches directly on state->mode without checking state->alt.

In include/linux/usb/typec_altmode.h and include/linux/usb/typec_dp.h, both connector modal states (TYPEC_MODE_USB2 = 2, TYPEC_MODE_USB3 = 3, TYPEC_MODE_USB4 = 4, TYPEC_MODE_AUDIO = 5, TYPEC_MODE_DEBUG = 6) and DisplayPort pin assignment states (TYPEC_DP_STATE_A = 2 through TYPEC_DP_STATE_F = 7) start at TYPEC_STATE_MODAL.

If the Type-C mux is called with a non-DisplayPort modal state such as TYPEC_MODE_USB4, TYPEC_MODE_AUDIO, TYPEC_MODE_DEBUG, or another alternate mode SVID, won't usbdp_typec_mux_set() match TYPEC_DP_STATE_C, TYPEC_DP_STATE_D, or TYPEC_DP_STATE_E and misconfigure udphy->next_mode for DisplayPort unless it first verifies state->alt && state->alt->svid == USB_TYPEC_DP_SID?

[ ... ]

Quoted 53 lines
drivers/phy/cix/phy-cix-usbdp.c new file +53 -0
+static int cix_usbdp_phy_power_on(struct cix_udphy *udphy)
+{
+	const struct cix_udphy_cfg *phy_cfgs = udphy->cfg;
+	int ret;
+
+	if (udphy->cur_mode == udphy->next_mode)
+		return 0;
+
+	if ((udphy->cur_mode == UDPHY_MODE_USB || udphy->cur_mode == UDPHY_MODE_DP) &&
+	    udphy->next_mode == UDPHY_MODE_DP_USB)
+		return 0;
+
+	if (phy_cfgs->udphy_init) {
+		ret = phy_cfgs->udphy_init(udphy);
+		if (ret) {
+			dev_err(udphy->dev, "failed to init udphy\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int cix_usbdp_phy_power_off(struct cix_udphy *udphy)
+{
+	const struct cix_udphy_cfg *phy_cfgs = udphy->cfg;
+	int ret;
+
+	if (phy_cfgs->udphy_exit) {
+		ret = phy_cfgs->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 = 0;
+
+	mutex_lock(&udphy->mutex);
+	if (!(udphy->next_mode & UDPHY_MODE_DP))
+		goto unlock;
+
+	ret = cix_usbdp_phy_power_on(udphy);
+	if (ret)
+		goto unlock;
+

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+	phy_set_bus_width(phy, udphy_dplane_get(udphy));
+	if (udphy->next_mode == UDPHY_MODE_DP)
+		udphy->cur_mode = UDPHY_MODE_DP;
+	else
+		udphy->cur_mode |= UDPHY_MODE_DP;
+
+unlock:
+	mutex_unlock(&udphy->mutex);
+	return ret;
+}

[Severity: High]
How does udphy->cur_mode track both the active sub-PHYs and the programmed hardware configuration in drivers/phy/cix/phy-cix-usbdp.c?

First, sky1_udphy_init() unconditionally calls sky1_udphy_clk_enable(udphy->apb_clk), which calls clk_prepare_enable(), while sky1_udphy_exit() calls clk_disable_unprepare(udphy->apb_clk) only once when udphy->cur_mode reaches UDPHY_MODE_NONE. If one child PHY is already active (for example, cix_u3phy_init() set udphy->cur_mode = UDPHY_MODE_USB) and the mux switches to udphy->next_mode = UDPHY_MODE_DP before udphy_dp_phy_power_on() runs, cix_usbdp_phy_power_on() calls sky1_udphy_init() a second time and leaks an enable reference on udphy->apb_clk. In that same path, udphy_dp_phy_power_on() then assigns udphy->cur_mode = UDPHY_MODE_DP, clearing UDPHY_MODE_USB so that a later cix_u3phy_exit() becomes a no-op.

Second, if udphy_dp_phy_power_on() initializes the PHY with udphy->next_mode == UDPHY_MODE_DP, sky1_udphy_init() programs sky1_udphy_dp_conf (4-lane DP-only mode) and sets udphy->cur_mode = UDPHY_MODE_DP. If the mux later switches udphy->next_mode to UDPHY_MODE_DP_USB and cix_u3phy_init() calls cix_usbdp_phy_power_on(), the check:

	if ((udphy->cur_mode == UDPHY_MODE_USB || udphy->cur_mode == UDPHY_MODE_DP) &&
	    udphy->next_mode == UDPHY_MODE_DP_USB)
		return 0;

returns early without calling sky1_udphy_init(), leaving the hardware in 4-lane DP-only mode with the USB3 lanes unconfigured.

Third, udphy_orien_sw_set() updates udphy->flip without marking the PHY as needing re-initialization. If udphy->flip changes after one sub-PHY has already initialized in UDPHY_MODE_DP_USB, won't cix_usbdp_phy_power_on() skip sky1_udphy_init(), leaving the syscon orientation bit and lane configuration tables in the old orientation while udphy_dp_phy_set_rate() and udphy_dp_phy_set_voltages() program the flipped PMA lanes?

[ ... ]

Quoted 60 lines
drivers/phy/cix/phy-cix-usbdp.c new file +60 -0
+static int udphy_dp_phy_verify_config(struct cix_udphy *udphy,
+				      struct phy_configure_opts_dp *dp)
+{
+	int i;
+
+	switch (dp->lanes) {
+	case 1:
+	case 2:
+	case 4:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*
+	 * If changing voltages is required, check swing and pre-emphasis
+	 * levels, per-lane.
+	 */
+	if (dp->set_voltages) {
+		for (i = 0; i < dp->lanes; i++) {
+			if (dp->voltage[i] > 3 || dp->pre[i] > 3)
+				return -EINVAL;
+
+			/*
+			 * Sum of voltage swing and pre-emphasis levels cannot
+			 * exceed 3.
+			 */
+			if (dp->voltage[i] + dp->pre[i] > 3)
+				return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int udphy_dp_phy_set_rate(struct cix_udphy *udphy,
+				 struct phy_configure_opts_dp *dp)
+{
+	int ret;
+	const struct phy_link_cfg *conf = NULL;
+
+	dev_dbg(udphy->dev, "lane %d, rate %x\n", dp->lanes, dp->link_rate);
+
+	regmap_update_bits(udphy->phy_regmap, PHY_PMA_PLL_CTRL, BIT(1), 0x0);
+	usleep_range(10, 20);
+
+	switch (dp->link_rate) {
+	case 0x6:
+		conf = &link_cfg[0];
+		ret = regmap_multi_reg_write(udphy->phy_regmap, sky1_udphy_dp_partial_conf,
+					     ARRAY_SIZE(sky1_udphy_dp_partial_conf));
+		break;
+	case 0xa:
+		conf = &link_cfg[1];
+		ret = regmap_multi_reg_write(udphy->phy_regmap, sky1_udphy_dp_partial_conf,
+					     ARRAY_SIZE(sky1_udphy_dp_partial_conf));
+		break;
+	case 0x14:
+		conf = &link_cfg[2];
+		ret = regmap_multi_reg_write(udphy->phy_regmap, sky1_udphy_dp_partial_conf,

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+					     ARRAY_SIZE(sky1_udphy_dp_partial_conf));
+		break;
+	case 0x1e:
+		conf = &link_cfg[3];
+		ret = regmap_multi_reg_write(udphy->phy_regmap, sky1_udphy_dp_8p1_conf,
+					     ARRAY_SIZE(sky1_udphy_dp_8p1_conf));
+		break;
+	default:
+		return -EINVAL;
+	}

[Severity: High]
In drivers/phy/cix/phy-cix-usbdp.c, udphy_dp_phy_set_rate() switches on dp->link_rate using DPCD bandwidth code values (0x6, 0xa, 0x14, 0x1e).

According to include/linux/phy/phy-dp.h, struct phy_configure_opts_dp defines link_rate in Mb/s (1620, 2700, 5400, 8100). When a standard DisplayPort bridge or controller driver calls phy_configure() -> udphy_dp_phy_configure() -> udphy_dp_phy_set_rate() with dp->set_rate = 1 and dp->link_rate in Mb/s, won't it always hit the default case and fail with -EINVAL?

Also, because udphy_dp_phy_verify_config() does not validate dp->link_rate and udphy_dp_phy_set_rate() clears BIT(1) of PHY_PMA_PLL_CTRL before the switch statement, returning -EINVAL on an unsupported rate leaves PLL1 disabled.

[ ... ]

Quoted 14 lines
drivers/phy/cix/phy-cix-usbdp.c new file +14 -0
+static int udphy_dp_phy_set_voltages(struct cix_udphy *udphy,
+				     struct phy_configure_opts_dp *dp)
+{
+	u32 index = dp->voltage[0] * 4 + dp->pre[0];
+	const struct phy_voltage_conf *cfg = volt_cfg;
+
+	dev_dbg(udphy->dev, "lane %d, vs %d, pe %d\n", dp->lanes, dp->voltage[0],
+		dp->pre[0]);
+
+	switch (dp->lanes) {
+	case 1:
+		if (!udphy->flip) { /* lane 2 */
+			regmap_update_bits(udphy->phy_regmap, TX_DIAG_ACYA_LANE2,
+					   BIT(0), 0x1);

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+			regmap_write(udphy->phy_regmap, TX_TXCC_CTRL_LANE2,
+				     cfg[index].tx_txcc_ctrl);
+			regmap_write(udphy->phy_regmap, DRV_DIAG_TX_DRV_LANE2,
+				     cfg[index].drv_diag_tx_drv);
+			regmap_write(udphy->phy_regmap, TX_TXCC_MGNFS_MULT_000_LANE2,
+				     cfg[index].tx_txcc_mgnfc_mult_000);
+			regmap_write(udphy->phy_regmap, TX_TXCC_CPOST_MULT_00_LANE2,
+				     cfg[index].tx_txcc_cpost_mult_00);
+			regmap_update_bits(udphy->phy_regmap, TX_DIAG_ACYA_LANE2,
+					   BIT(0), 0x0);

[Severity: High]
In drivers/phy/cix/phy-cix-usbdp.c, udphy_dp_phy_verify_config() validates dp->voltage[i] and dp->pre[i] for each lane up to dp->lanes, but udphy_dp_phy_set_voltages() computes index solely from dp->voltage[0] and dp->pre[0] and writes cfg[index] to all active lanes in the 2-lane and 4-lane cases.

During DisplayPort link training on a 2-lane or 4-lane link, if the sink requests different voltage swing or pre-emphasis levels across lanes, won't lanes 1..3 be programmed with lane 0's settings instead of dp->voltage[i] and dp->pre[i]?

Could this also use a per-lane helper instead of duplicating the 6-register programming sequence across all branches?

[ ... ]

Quoted 23 lines
drivers/phy/cix/phy-cix-usbdp.c new file +23 -0
+static int udphy_dp_phy_configure(struct phy *phy,
+				  union phy_configure_opts *opts)
+{
+	struct cix_udphy *udphy = phy_get_drvdata(phy);
+	int ret;
+
+	mutex_lock(&udphy->mutex);
+	ret = udphy_dp_phy_verify_config(udphy, &opts->dp);
+	if (ret)
+		goto unlock;
+
+	if (opts->dp.set_rate) {
+		ret = udphy_dp_phy_set_rate(udphy, &opts->dp);
+		if (ret) {
+			dev_err(udphy->dev, "failed to set DP link rate\n");
+			goto unlock;
+		}
+	}
+
+	if (opts->dp.set_voltages) {
+		ret = udphy_dp_phy_set_voltages(udphy, &opts->dp);
+		if (ret) {
+			dev_err(udphy->dev, "dp_phy_set_voltages failed\n");

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

Quoted 10 lines
drivers/phy/cix/phy-cix-usbdp.c new file +10 -0
+			goto unlock;
+		}
+	}
+	mutex_unlock(&udphy->mutex);
+	return 0;
+
+unlock:
+	mutex_unlock(&udphy->mutex);
+	return ret;
+}

[Severity: High]
What happens if udphy_dp_phy_configure() in drivers/phy/cix/phy-cix-usbdp.c is called before udphy_dp_phy_power_on(), or after udphy_dp_phy_power_on() returned 0 early because !(udphy->next_mode & UDPHY_MODE_DP)?

In both cases, udphy->apb_clk is disabled and udphy->preset is asserted (from cix_udphy_probe() or sky1_udphy_exit()), yet udphy_dp_phy_configure() proceeds to call udphy_dp_phy_set_rate() and udphy_dp_phy_set_voltages(), performing MMIO reads and writes on udphy->base without checking (udphy->cur_mode & UDPHY_MODE_DP). Won't accessing those registers with the APB clock gated and reset asserted cause a bus abort or hang?

Additionally, udphy_dp_phy_verify_config() allows dp->lanes == 4 even when udphy->next_mode is UDPHY_MODE_DP_USB (where udphy_dplane_get(udphy) is 2), which causes udphy_dp_phy_set_rate() and udphy_dp_phy_set_voltages() to overwrite the PMA registers of the active USB3 lanes.

[ ... ]

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

Quoted 13 lines
drivers/phy/cix/phy-cix-usbdp.c new file +13 -0
+static int cix_u3phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
+{
+	if (mode == PHY_MODE_INVALID)
+		return cix_u3phy_exit(phy);
+
+	return cix_u3phy_init(phy);
+}
+
+static const struct phy_ops cix_u3phy_ops = {
+	.set_mode       = cix_u3phy_set_mode,
+	.exit		= cix_u3phy_exit,
+	.owner		= THIS_MODULE,
+};

[Severity: High]
In drivers/phy/cix/phy-cix-usbdp.c, cix_u3phy_ops defines .exit = cix_u3phy_exit, but omits .init = cix_u3phy_init and only invokes cix_u3phy_init() from cix_u3phy_set_mode().

When a USB controller driver calls phy_init() during probe before phy_set_mode(), or calls phy_exit() followed by phy_init() across suspend and resume without calling phy_set_mode(), won't phy_init() be a no-op that leaves the USB3 PHY uninitialized and in reset?

[ ... ]

Quoted 13 lines
drivers/phy/cix/phy-cix-usbdp.c new file +13 -0
+static void udphy_set_default_mode(struct cix_udphy *udphy)
+{
+	udphy->cur_mode = UDPHY_MODE_NONE;
+}
+
+static int cix_udphy_probe(struct platform_device *pdev)
+{
+	struct cix_udphy *udphy;
+	struct device *dev = &pdev->dev;
+	struct phy_provider *phy_provider;
+	struct device_node *np = dev->of_node;
+	u32 id;
+	int ret = 0;

[ ... ]

Quoted 6 lines
drivers/phy/cix/phy-cix-usbdp.c new file +6 -0
+	ret = device_property_read_u8(dev, "cix,default-conf", &udphy->next_mode);
+	if (ret)
+		udphy->next_mode = UDPHY_MODE_DP_USB;
+
+	reset_control_assert(udphy->reset);
+	reset_control_assert(udphy->preset);

[ ... ]

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

Quoted 1 line
drivers/phy/cix/phy-cix-usbdp.c new file +1 -0
+	udphy_set_default_mode(udphy);

[Severity: Medium]
The commit message states:

The bootloader may hand over the port already initialized; in that case the first power_on calls skip the re-initialization.

However, in drivers/phy/cix/phy-cix-usbdp.c, cix_udphy_probe() unconditionally calls reset_control_assert() on udphy->reset and udphy->preset, and udphy_set_default_mode() unconditionally sets udphy->cur_mode = UDPHY_MODE_NONE. As a result, any bootloader initialization is wiped out in probe and the first power_on call never skips re-initialization. Should cix_udphy_probe() and udphy_set_default_mode() be updated to match the commit description, or should the commit message be updated to match the code?

Also, PHY_LANE_MUX_USB and PHY_LANE_MUX_DP at the top of drivers/phy/cix/phy-cix-usbdp.c are unused and can be removed.

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

PATCH 3/3 arm64: dts: cix: add Sky1 USB/DP combo PHY

In reply to Gary Yang

Add the four USB/DP combo PHY nodes to the Sky1 SoC device tree and enable them on the Radxa Orion O6.

Each PHY node describes its USB and DisplayPort lanes as child nodes, points at the S5 system controller instance that controls lane muxing and plug orientation, and is disabled by default so that boards that do not route the port stay unaffected.

---
 arch/arm64/boot/dts/cix/sky1-orion-o6.dts | 28 +++++++
 arch/arm64/boot/dts/cix/sky1.dtsi         | 96 +++++++++++++++++++++++
 2 files changed, 124 insertions(+)
arch/arm64/boot/dts/cix/sky1-orion-o6.dts +28 -0
index e39c87774c12..76f75185b6a8 100644
@@ -117,3 +117,31 @@ &s5_gpio2 {
 &uart2 {
 	status = "okay";
 };
+
+&usbc_phy0 {
+	orientation-switch;
+	mode-switch;
+	cix,default-conf = /bits/ 8 <0x03>;
+	status = "okay";
+};
+
+&usbc_phy1 {
+	orientation-switch;
+	mode-switch;
+	cix,default-conf = /bits/ 8 <0x03>;
+	status = "okay";
+};
+
+&usbc_phy2 {
+	orientation-switch;
+	mode-switch;
+	cix,default-conf = /bits/ 8 <0x03>;
+	status = "okay";
+};
+
+&usbc_phy3 {
+	orientation-switch;
+	mode-switch;
+	cix,default-conf = /bits/ 8 <0x03>;
+	status = "okay";
+};
arch/arm64/boot/dts/cix/sky1.dtsi +96 -0

102 lines not on this page · raw message

Signature · 1 line
2.50.1
#6 lore raw

Re: [PATCH 3/3] arm64: dts: cix: add Sky1 USB/DP combo PHY

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] arm64: dts: cix: enabling usbc_phy0..3 asserts PHY resets at boot - [High] phy: cix: broken mode…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] arm64: dts: cix: enabling usbc_phy0..3 asserts PHY resets at boot
- [High] phy: cix: broken mode transitions, clock leak, and phy_ops in cix_udphy
- [Medium] arm64: dts: cix: missing OF graph ports for usbc_phy Type-C switches --

commit d16228024f6482f816de21fc474d6f5027baff41
Author: Gary Yang <[email protected]>

arm64: dts: cix: add Sky1 USB/DP combo PHY

This commit adds the four USB/DP combo PHY device tree nodes to the CIX Sky1 SoC dtsi and enables them with Type-C orientation-switch and mode-switch properties on the Radxa Orion O6 board.

arch/arm64/boot/dts/cix/sky1-orion-o6.dts &s5_gpio2 { · line 123

Quoted 12 lines
arch/arm64/boot/dts/cix/sky1-orion-o6.dts +4 -0
index e39c87774c128..76f75185b6a8e 100644
@@ -117,3 +117,31 @@ &s5_gpio2 {
 &uart2 {
 	status = "okay";
 };
+
+&usbc_phy0 {
+	orientation-switch;
+	mode-switch;

[Severity: Medium]
How are Type-C connector nodes expected to link to the orientation-switch and mode-switch registered by usbc_phy0 through usbc_phy3?

In drivers/phy/cix/phy-cix-usbdp.c, cix_udphy_probe() checks for these boolean properties and registers a Type-C switch and mux on the PHY device fwnode via udphy_setup_orien_switch() and udphy_setup_typec_mux():

drivers/phy/cix/phy-cix-usbdp.c:cix_udphy_probe() {
	...
	if (device_property_present(dev, "orientation-switch")) {
		ret = udphy_setup_orien_switch(udphy);
		...
	}

	if (device_property_present(dev, "mode-switch")) {
		ret = udphy_setup_typec_mux(udphy);
		...
	}
}

When a Type-C connector driver looks up its switch or mux through fwnode_typec_switch_get() or fwnode_typec_mux_get(), fwnode_connection_find_matches() -> fwnode_graph_devcon_matches() resolves boolean orientation-switch and mode-switch providers by walking OF graph endpoints (port or ports with remote-endpoint) from the connector node to the provider node.

However, neither sky1.dtsi nor sky1-orion-o6.dts defines any port or ports nodes on usbc_phy0..3, and Documentation/devicetree/bindings/phy/cix,sky1-usbdp-phy.yaml sets
additionalProperties: false while only allowing usb-port@[0-9a-f]+ and dp-port@[0-9a-f]+ child nodes:

patternProperties:

    "^usb-port@[0-9a-f]+$":
      ...
    "^dp-port@[0-9a-f]+$":
      ...

additionalProperties: false

Without OF graph port definitions in the binding and device tree nodes, won't any usb-c-connector node be unable to bind to these switches or fail DT schema validation?

arch/arm64/boot/dts/cix/sky1-orion-o6.dts &s5_gpio2 { · line 126

Quoted 3 lines
arch/arm64/boot/dts/cix/sky1-orion-o6.dts +3 -0
+	cix,default-conf = /bits/ 8 <0x03>;
+	status = "okay";
+};

[Severity: High]
Does enabling usbc_phy0 through usbc_phy3 here before any USB or DisplayPort consumer nodes are present in the device tree break bootloader-initialized USB or DisplayPort connections at boot?

Neither arch/arm64/boot/dts/cix/sky1.dtsi nor arch/arm64/boot/dts/cix/sky1-orion-o6.dts currently has any consumer nodes referencing usb3_phy0..3 or usbc0..3_dp_phy. When cix_udphy_probe() runs for each enabled PHY node, it unconditionally asserts both the core and APB resets and sets cur_mode to UDPHY_MODE_NONE:

drivers/phy/cix/phy-cix-usbdp.c:cix_udphy_probe() {
	...
	reset_control_assert(udphy->reset);
	reset_control_assert(udphy->preset);
	...
	udphy_set_default_mode(udphy);
}
drivers/phy/cix/phy-cix-usbdp.c:udphy_set_default_mode() {
	udphy->cur_mode = UDPHY_MODE_NONE;
}

Although commit ba3650ed160e ("phy: cix: add USB/DP combo PHY driver for Sky1") states that the bootloader may hand over the port already initialized, asserting reset and preset in cix_udphy_probe() while no consumers exist to power the PHYs back on leaves all four PHYs permanently held in reset after probe. Wouldn't this tear down any active bootloader-initialized DisplayPort (such as an EFI framebuffer output) or USB link on Radxa Orion O6?

[ ... ]

Quoted 21 lines
arch/arm64/boot/dts/cix/sky1.dtsi +13 -0
index 0a820f45feb96..672aade42d6f8 100644
@@ -606,6 +606,102 @@ mbox_ap2sfh: mailbox@80a0000 {
 			cix,mbox-dir = "tx";
 		};
 
+		usbc_phy0: usb-phy@9030000 {
+			compatible = "cix,sky1-usbdp-phy";
+			reg = <0x00 0x9030000 0x00 0x40000>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			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>;
+
+			status = "disabled";
+

arch/arm64/boot/dts/cix/sky1.dtsi mbox_ap2sfh: mailbox@80a0000 { · line 631

Quoted 10 lines
arch/arm64/boot/dts/cix/sky1.dtsi +10 -0
+			usb3_phy0: usb-port@0 {
+				reg = <0x0>;
+				#phy-cells = <0>;
+			};
+
+			usbc0_dp_phy: dp-port@1 {
+				reg = <0x1>;
+				#phy-cells = <0>;
+			};
+		};

[Severity: High]
When these PHY nodes are enabled on Radxa Orion O6, can the cix,sky1-usbdp-phy driver handle USB3 PHY initialization and Type-C mode transitions without skipping lane reconfiguration or leaking udphy->apb_clk enable references?

First, in drivers/phy/cix/phy-cix-usbdp.c, cix_usbdp_phy_power_on() checks udphy->cur_mode against udphy->next_mode:

drivers/phy/cix/phy-cix-usbdp.c:cix_usbdp_phy_power_on() {
	if (udphy->cur_mode == udphy->next_mode)
		return 0;

	if ((udphy->cur_mode == UDPHY_MODE_USB || udphy->cur_mode == UDPHY_MODE_DP) &&
	    udphy->next_mode == UDPHY_MODE_DP_USB)
		return 0;

	if (phy_cfgs->udphy_init) {
		ret = phy_cfgs->udphy_init(udphy);
		...
	}
}

If the PHY is brought up in 4-lane DP-only mode (udphy->cur_mode == UDPHY_MODE_DP, which programs sky1_udphy_dp_conf in sky1_udphy_init()) and usbdp_typec_mux_set() later switches udphy->next_mode to UDPHY_MODE_DP_USB, a subsequent call to cix_u3phy_init() -> cix_usbdp_phy_power_on() hits the early return above and skips sky1_udphy_init(). Doesn't that leave the hardware in 4-lane DP-only configuration with USB3 non-functional?

Second, if USB is active (udphy->cur_mode == UDPHY_MODE_USB, with udphy->apb_clk already enabled by sky1_udphy_init()) and udphy->next_mode changes to UDPHY_MODE_DP, udphy_dp_phy_power_on() calls cix_usbdp_phy_power_on() -> sky1_udphy_init(), which calls sky1_udphy_clk_enable() -> clk_prepare_enable(udphy->apb_clk) a second time without a preceding disable, and then overwrites udphy->cur_mode:

drivers/phy/cix/phy-cix-usbdp.c:udphy_dp_phy_power_on() {
	...
	ret = cix_usbdp_phy_power_on(udphy);
	if (ret)
		goto unlock;

	phy_set_bus_width(phy, udphy_dplane_get(udphy));
	if (udphy->next_mode == UDPHY_MODE_DP)
		udphy->cur_mode = UDPHY_MODE_DP;
	else
		udphy->cur_mode |= UDPHY_MODE_DP;
}

Because overwriting udphy->cur_mode clears the UDPHY_MODE_USB bit, cix_u3phy_exit() becomes a no-op and cix_usbdp_phy_power_off() -> sky1_udphy_exit() only calls clk_disable_unprepare(udphy->apb_clk) once. Does this leak a prepare/enable reference on udphy->apb_clk?

Third, cix_u3phy_ops only wires up .set_mode and .exit, omitting .init and .power_on:

drivers/phy/cix/phy-cix-usbdp.c:cix_u3phy_ops {
	.set_mode       = cix_u3phy_set_mode,
	.exit		= cix_u3phy_exit,
	.owner		= THIS_MODULE,
};

Won't standard USB controller drivers that call phy_init() and phy_power_on() before accessing controller registers or before calling phy_set_mode() operate while usb3_phy0..3 are still held in reset?

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