Skip to contentSkip to conversation

usb: typec: add CIX Type-C PD controller driver

PATCH Superseded Gary Yang 3 participants 6 messages Nov 10 – Nov 12

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Gary Yang

author
#0 lore raw

v3 cover usb: typec: add CIX Type-C PD controller driver

This series adds a Type-C PD controller driver for CIX platforms.

The first supported controller is the Realtek RTS5453H, a stand-alone port controller: the CC and USB Power Delivery state machines run in its firmware and are configured through vendor registers rather than the TCPC register interface, so it cannot be driven by the tcpm framework. The driver translates the controller status registers into Type-C class notifications and drives the platform PHY's orientation switch and mode mux.

The driver is named after the CIX platform integration rather than the RTS5453H so that further register-compatible PD controllers can be supported without renaming it.

Patch 1 adds the devicetree binding and patch 2 adds the driver and its MAINTAINERS entry. The DTS patches from v1 are sent separately through the SoC tree.

Changes since v2:
- Report the Type-C data role from the controller status for every connection, including DisplayPort-only configurations where no USB data role is available, instead of deriving it from the USB role switch.
- Pass the port alternate mode in the mux state, matching other firmware-driven port drivers.
- Force the USB role switch to be reprogrammed on system resume and check the enable_irq_wake() return value.
- Acknowledge a pending controller interrupt during probe so that a shared interrupt line is not left asserted.
- Do not drop the borrowed fwnode reference when parsing the connector properties fails.
- Treat all fwnode_usb_role_switch_get() errors as fatal; a connector without a role switch link returns NULL, not -ENODEV.
- Drop a redundant include.

Tested on a Radxa Orion O6 (Sky1): attach/detach, USB-only and DP-only alt modes, cable orientation detection and HPD reporting all work.

Gary Yang (2):
dt-bindings: usb: add Realtek RTS5453H Type-C port controller
usb: typec: add CIX Type-C PD controller driver

 .../bindings/usb/realtek,rts5453h.yaml        | 112 +++
 MAINTAINERS                                   |   7 +
 drivers/usb/typec/Kconfig                     |  13 +
 drivers/usb/typec/Makefile                    |   1 +
 drivers/usb/typec/cix_pd.c                    | 701 ++++++++++++++++++
 5 files changed, 834 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml
 create mode 100644 drivers/usb/typec/cix_pd.c

--
2.50.1

author
#1 lore raw

PATCH v3 1/2 dt-bindings: usb: add Realtek RTS5453H Type-C port controller

Document the Realtek RTS5453H stand-alone USB Type-C port controller. The controller is connected over I2C and manages a single USB Type-C connector, described with the generic USB connector binding.

The connector's OF graph links to the Type-C orientation switch and mode mux provided by the platform PHY.

---
 .../bindings/usb/realtek,rts5453h.yaml        | 112 ++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml
Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml new file +112 -0
new file mode 100644
index 000000000000..14bbd563e66a
@@ -0,0 +1,112 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/realtek,rts5453h.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek RTS5453H USB Type-C port controller
+
+description: |
+  The RTS5453H is a stand-alone USB Type-C port controller with USB
+  Power Delivery support. It is controlled over I2C and reports
+  changes of the port state through an interrupt line.
+
+  Orientation switching and USB/DisplayPort lane muxing are performed by
+  the platform PHY. The controller finds the Type-C switch and mux
+  through the OF graph of its connector node.
+
+maintainers:
+  - Gary Yang <[email protected]>
+
+properties:
+  compatible:
+    const: realtek,rts5453h
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  connector:
+    type: object
+    $ref: /schemas/connector/usb-connector.yaml#
+    unevaluatedProperties: false
+    description:
+      The USB Type-C connector managed by this controller.
+
+    required:
+      - data-role
+      - power-role
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - connector
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        typec@30 {
+            compatible = "realtek,rts5453h";
+            reg = <0x30>;
+            interrupt-parent = <&gpio0>;
+            interrupts = <8 IRQ_TYPE_LEVEL_LOW>;
+
+            connector {
+                compatible = "usb-c-connector";
+                data-role = "host";
+                power-role = "source";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+
+                        typec_hs_ep: endpoint {
+                            remote-endpoint = <&usb_hs_ep>;
+                        };
+                    };
+
+                    port@1 {
+                        reg = <1>;
+
+                        typec_ss_ep: endpoint {
+                            remote-endpoint = <&usb_ss_ep>;
+                        };
+                    };
+                };
+            };
+        };
+    };
+
+    usb {
+        usb-role-switch;
+
+        port {
+            usb_hs_ep: endpoint {
+                remote-endpoint = <&typec_hs_ep>;
+            };
+        };
+    };
+
+    usb-mux {
+        orientation-switch;
+        mode-switch;
+
+        port {
+            usb_ss_ep: endpoint {
+                remote-endpoint = <&typec_ss_ep>;
+            };
+        };
+    };
Signature · 1 line
2.50.1
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: usb: add Realtek RTS5453H Type-C port controller

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

Document the Realtek RTS5453H stand-alone USB Type-C port controller. The controller is connected over I2C and manages a single USB Type-C connector, described with the generic USB connector binding.

The connector's OF graph links to the Type-C orientation switch and mode mux provided by the platform PHY.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v3 1/2
#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: usb: add Realtek RTS5453H Type-C port controller

In reply to Gary Yang
Quoted 32 lines · Gary Yang
Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml new file +32 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        typec@30 {
+            compatible = "realtek,rts5453h";
+            reg = <0x30>;
+            interrupt-parent = <&gpio0>;
+            interrupts = <8 IRQ_TYPE_LEVEL_LOW>;
+
+            connector {
+                compatible = "usb-c-connector";
+                data-role = "host";
+                power-role = "source";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+
+                        typec_hs_ep: endpoint {
+                            remote-endpoint = <&usb_hs_ep>;
+                        };
+                    };
+
+                    port@1 {

Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml line 91

Quoted 10 lines
Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml new file +10 -0
+                        reg = <1>;
+
+                        typec_ss_ep: endpoint {
+                            remote-endpoint = <&usb_ss_ep>;
+                        };
+                    };
+                };
+            };
+        };
+    };

Drop all nodes below, not really part of the scope.

With this fixed

Best regards,
Krzysztof

author
#4 lore raw

PATCH v3 2/2 usb: typec: add CIX Type-C PD controller driver

In reply to Gary Yang

Add a driver for the CIX Type-C PD controller, which is connected over I2C and reports power, data and plug orientation changes through a level-triggered interrupt. The Realtek RTS5453H is the first supported device.

The controller runs the Type-C and PD state machines in firmware and exposes the current port status over I2C. The driver translates that into Type-C class notifications, driving the orientation switch and mode mux registered by the platform PHY for the DisplayPort alternate mode. It also drives the platform USB role switch so that the USB controller follows the negotiated data role.

Several controller instances can share a single interrupt line, so each instance registers a handler on it with IRQF_SHARED and only accesses its own registers.

The driver is named after the CIX platform integration rather than the RTS5453H so that further register-compatible PD controllers can be supported without renaming it.

---
 MAINTAINERS                |   7 +
 drivers/usb/typec/Kconfig  |  13 +
 drivers/usb/typec/Makefile |   1 +
 drivers/usb/typec/cix_pd.c | 701 +++++++++++++++++++++++++++++++++++++
 4 files changed, 722 insertions(+)
 create mode 100644 drivers/usb/typec/cix_pd.c
MAINTAINERS +7 -0
index 93abbb315065..bd99313bf91d 100644
@@ -6522,6 +6522,13 @@ M:	Satish Kharat <[email protected]>
 S:	Supported
 F:	drivers/infiniband/hw/usnic/
 
+CIX USB TYPE-C PD CONTROLLER
+M:	Gary Yang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/usb/realtek,rts5453h.yaml
+F:	drivers/usb/typec/cix_pd.c
+
 CLANG CONTEXT ANALYSIS
 M:	Marco Elver <[email protected]>
 R:	Bart Van Assche <[email protected]>
drivers/usb/typec/Kconfig +13 -0
index 2f80c2792dbd..4d62f5deeeba 100644
@@ -110,6 +110,19 @@ config TYPEC_WUSB3801
 	  If you choose to build this driver as a dynamically linked module, the
 	  module will be called wusb3801.ko.
 
+config TYPEC_CIX_PD
+	tristate "CIX Type-C PD controller driver"
+	depends on I2C
+	depends on USB_ROLE_SWITCH
+	depends on ARCH_CIX || COMPILE_TEST
+	select REGMAP_I2C
+	help
+	  Say Y or M here if your system has a CIX Type-C PD controller.
+	  This driver currently supports the Realtek RTS5453H controller.
+
+	  If you choose to build this driver as a dynamically linked module, the
+	  module will be called cix_pd.ko.
+
 source "drivers/usb/typec/mux/Kconfig"
 
 source "drivers/usb/typec/altmodes/Kconfig"
drivers/usb/typec/Makefile +1 -0
index 8a6a1c663eb6..bb3f3139fd7e 100644
@@ -11,4 +11,5 @@ obj-$(CONFIG_TYPEC_HD3SS3220)	+= hd3ss3220.o
 obj-$(CONFIG_TYPEC_STUSB160X) 	+= stusb160x.o
 obj-$(CONFIG_TYPEC_RT1719)	+= rt1719.o
 obj-$(CONFIG_TYPEC_WUSB3801)	+= wusb3801.o
+obj-$(CONFIG_TYPEC_CIX_PD)	+= cix_pd.o
 obj-$(CONFIG_TYPEC)		+= mux/
drivers/usb/typec/cix_pd.c new file +701 -0

701 lines not on this page · raw message

Signature · 1 line
2.50.1
#5 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] usb: typec: cix_pd: missing IRQ disable across system suspend and resume - [Medium] usb: typec…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] usb: typec: cix_pd: missing IRQ disable across system suspend and resume
- [Medium] usb: typec: cix_pd: unserialized mux state changes via partner_altmode()
- [Medium] usb: typec: cix_pd: unconditional IRQ_HANDLED in cix_pd_irq_handle()
--

commit 02feb7b4ab5ba21a4874114738a3f180152e2832
Author: Gary Yang <[email protected]>

usb: typec: add CIX Type-C PD controller driver

This commit adds an I2C driver for the CIX Type-C PD controller (Realtek RTS5453H) to report port status, orientation, USB data role, and DisplayPort alternate mode state to the Type-C framework.

Quoted 5 lines
drivers/usb/typec/cix_pd.c new file +0 -0
new file mode 100644
index 0000000000000..5a7a3efd3ac12

[ ... ]

Quoted 5 lines
drivers/usb/typec/cix_pd.c new file +5 -0
+		if (typec->partner && dp && !typec->partner_altmode) {
+			typec->partner_altmode =
+				typec_partner_register_altmode(typec->partner,
+							       &cix_pd_dp_partner_altmode);
+			if (IS_ERR(typec->partner_altmode)) {

drivers/usb/typec/cix_pd.c line 260

Quoted 10 lines
drivers/usb/typec/cix_pd.c new file +10 -0
+				dev_err(typec->dev,
+					"typec port(%d): failed to register DP altmode: %ld\n",
+					typec->id,
+					PTR_ERR(typec->partner_altmode));
+				typec->partner_altmode = NULL;
+			} else {
+				typec_altmode_update_active(typec->partner_altmode,
+							    true);
+			}
+		}

[Severity: Medium]
Can dp_altmode_driver reconfigure the shared Type-C mux behind cix_pd's back when bound to typec->partner_altmode?

cix_pd_init_ports() registers typec->port_altmode with USB_TYPEC_DP_SID without setting typec_altmode_ops, which gives port_altmode its own handle to the platform Type-C mux. When dp_altmode_driver binds to typec->partner_altmode, writing to sysfs displayport/configuration or unbinding dp_altmode_driver calls typec_altmode_notify() or typec_altmode_set_state(), switching the physical mux to TYPEC_STATE_USB or TYPEC_STATE_SAFE outside rts->lock while leaving typec->mode stale at TYPEC_DP_STATE_D/E.

In addition, calling typec_altmode_update_active(typec->partner_altmode, true) immediately after registration runs before a modular typec_displayport driver finishes binding, so try_module_get() is skipped while the disconnect path still calls module_put() on the bound driver.

[ ... ]

Quoted 19 lines
drivers/usb/typec/cix_pd.c new file +19 -0
+static int cix_pd_event_handler(struct cix_pd *rts, u8 clear_irq, bool force)
+{
+	int ret, err = 0;
+	u8 data_control[3] = {0};
+
+	mutex_lock(&rts->lock);
+	if (clear_irq) {
+		data_control[0] = 2;
+		data_control[1] = I2C_INT_ACK_BIT;
+		data_control[2] = 0;
+
+		ret = cix_pd_block_write(rts, RTS_DATA_CONTROL, data_control, 3);
+		if (ret)
+			goto i2c_err;
+	}
+
+	ret = cix_pd_block_read(rts, RTS_DATA_STATUS, rts->data_status, 6);
+	if (ret)
+		goto i2c_err;

[ ... ]

drivers/usb/typec/cix_pd.c line 493

Quoted 9 lines
drivers/usb/typec/cix_pd.c new file +9 -0
+static irqreturn_t cix_pd_irq_handle(int irq, void *data)
+{
+	struct cix_pd *rts = data;
+
+	if (cix_pd_event_handler(rts, 1, false) == -ESHUTDOWN)
+		return IRQ_NONE;
+
+	return IRQ_HANDLED;
+}

[Severity: Medium]
Does cix_pd_irq_handle() returning IRQ_HANDLED unconditionally prevent the IRQ core from detecting a stuck shared level-triggered interrupt line?

cix_pd_event_handler() acknowledges I2C_INT_ACK_BIT and returns 0 without checking whether this controller instance actually asserted the interrupt. If a sibling controller sharing the line holds the level-triggered IRQ asserted while not yet probed, while probe-deferred in cix_pd_init_ports() (which runs before cix_pd_probe() acknowledges pre-existing interrupts), or while unresponsive over I2C, any healthy bound instance on the same IRQ line still returns IRQ_HANDLED on every pass, causing an unbounded IRQ thread loop and I2C bus storm instead of letting note_interrupt() disable the stuck line.

[ ... ]

Quoted 27 lines
drivers/usb/typec/cix_pd.c new file +27 -0
+static int __maybe_unused cix_pd_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct cix_pd *rts = i2c_get_clientdata(client);
+	int ret;
+
+	if (client->irq > 0 && device_may_wakeup(dev)) {
+		mutex_lock(&rts->irq_lock);
+		if (!rts->wake_enabled) {
+			ret = enable_irq_wake(client->irq);
+			if (ret)
+				dev_err(dev, "failed to enable IRQ wake: %d\n",
+					ret);
+			else
+				rts->wake_enabled = true;
+		}
+		mutex_unlock(&rts->irq_lock);
+	}
+
+	return 0;
+}
+
+static int __maybe_unused cix_pd_resume(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct cix_pd *rts = i2c_get_clientdata(client);
+	int ret;

drivers/usb/typec/cix_pd.c line 667

Quoted 10 lines
drivers/usb/typec/cix_pd.c new file +10 -0
+
+	mutex_lock(&rts->irq_lock);
+	if (rts->wake_enabled) {
+		disable_irq_wake(client->irq);
+		rts->wake_enabled = false;
+	}
+	mutex_unlock(&rts->irq_lock);
+
+	/* Force the USB role to be reprogrammed after system resume. */
+	ret = cix_pd_event_handler(rts, 0, true);

[Severity: Medium]
Can cix_pd_irq_handle() run while the parent I2C adapter is still suspended during system sleep transitions?

cix_pd_suspend() does not call disable_irq(client->irq), so the interrupt remains enabled during dpm_suspend_late() after runtime PM is disabled on the parent I2C controller, and resume_device_irqs() unmasks it at the end of dpm_resume_noirq() before dpm_resume_early() and dpm_resume() resume the I2C controller, USB role switch, and Type-C mux:

dpm_resume_noirq()
resume_device_irqs()
<threaded IRQ>
cix_pd_irq_handle()
cix_pd_event_handler()
cix_pd_block_write() <-- I2C adapter still suspended
dpm_resume_early()
device_resume_early() <-- I2C adapter runtime PM re-enabled here
dpm_resume()
cix_pd_resume()

When the I2C transfer fails, cix_pd_event_handler() returns -ESHUTDOWN without acknowledging the level-triggered interrupt in RTS_DATA_CONTROL, leaving the line asserted so it repeatedly re-fires. In addition, cix_pd_resume() calls cix_pd_event_handler(rts, 0, true), which clears HPD_IRQ via HPD_IRQ_ACK without writing I2C_INT_ACK_BIT.

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