Skip to contentSkip to conversation

usb: typec: tipd: Add sn201202x (ACE3) support

PATCH Superseded Sasha Finkelstein 2 participants 6 messages Aug 1

Subsystems (3)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 cover usb: typec: tipd: Add sn201202x (ACE3) support

Add support for sn201202x (a.k.a ACE3), an Apple-specific tps6598x variant that wraps the tps6598x core register set with a SPMI based regmap-like protocol, first appearing in Apple M3 devices. This series first makes the core parts bus-agnostic, and then adds the new SPMI interface as a custom regmap implementation.

To simplify the merge strategy, the device tree entries will be sent in a future patch series.

---
Changes in v3:
- Restore accidentally deleted static
- Fix building with tracepoints
- Sleep the device on failed probe
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Use a -core module instead of building everything twice
- Fix completion handling
- Make regmaps debugfs-safe
- Link to v1: https://patch.msgid.link/[email protected]

---
Alyssa Milburn (1):
usb: typec: tipd: Factor out i2c specifics

Sasha Finkelstein (2):
dt-bindings: usb: tps6598x: Add sn201202x/ACE3
usb: typec: tipd: Add sn201202x support

 Documentation/devicetree/bindings/usb/apple,sn201202x.yaml |  78 +++++++++++++++++++++++++++++++
 MAINTAINERS                                                |   2 +
 drivers/usb/typec/tipd/Kconfig                             |  20 +++++++-
 drivers/usb/typec/tipd/Makefile                            |  14 ++++--
 drivers/usb/typec/tipd/core.c                              | 241 +++++++++++++++++++++--------------------------------------------------------------------------
 drivers/usb/typec/tipd/i2c.c                               | 104 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tipd/spmi.c                              | 297 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tipd/tps6598x.h                          | 124 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 685 insertions(+), 195 deletions(-)

---
base-commit: 0ce37745d4bfbc493f718169c3974898ffec8ee7
change-id: 20260725-tipd-ace3-090bf570ef59

Best regards,

Signature · 1 line
Sasha Finkelstein <[email protected]>
#1 lore raw

PATCH v3 1/3 dt-bindings: usb: tps6598x: Add sn201202x/ACE3

A variant of tps6598x that is attached to a SPMI bus and is found on Apple devices starting from the M3 series

---
 Documentation/devicetree/bindings/usb/apple,sn201202x.yaml | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS                                                |  1 +
 2 files changed, 79 insertions(+)
Documentation/devicetree/bindings/usb/apple,sn201202x.yaml new file +78 -0
new file mode 100644
index 000000000000..133a71bbedb7
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/apple,sn201202x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments sn201202x Type-C Power Delivery controller
+
+maintainers:
+  - Sasha Finkelstein <[email protected]>
+
+description: |
+  Texas Instruments sn201202x Type-C Power Delivery controller
+
+  A variant of tps6598x controller also known as Apple ACE3
+  present on hardware with Apple SoCs starting from the M3.
+
+properties:
+  compatible:
+    enum:
+      - apple,sn201202x
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: Primary irq used for tps6598x events
+      - description: Logical register selection completed
+      - description: Standby command completed
+      - description: Wakeup command completed
+
+  interrupt-names:
+    items:
+      - const: irq
+      - const: select
+      - const: sleep
+      - const: wake
+
+  connector:
+    $ref: /schemas/connector/usb-connector.yaml#
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/spmi/spmi.h>
+    spmi {
+        #address-cells = <2>;
+        #size-cells = <0>;
+        usb-pd@c {
+            compatible = "apple,sn201202x";
+            reg = <0xc SPMI_USID>;
+            interrupts = <11 IRQ_TYPE_EDGE_RISING>,
+                         <13 IRQ_TYPE_EDGE_RISING>,
+                         <17 IRQ_TYPE_EDGE_RISING>,
+                         <19 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "irq", "select", "sleep", "wake";
+
+            connector {
+                compatible = "usb-c-connector";
+                label = "USB-C";
+
+                port {
+                    typec_ep: endpoint {
+                        remote-endpoint = <&otg_ep>;
+                    };
+                };
+            };
+        };
+    };
MAINTAINERS +1 -0
index ff08a65d942a..b2819ca62e0c 100644
@@ -2610,6 +2610,7 @@ F:	Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
 F:	Documentation/devicetree/bindings/spi/apple,spi.yaml
 F:	Documentation/devicetree/bindings/spmi/apple,spmi.yaml
 F:	Documentation/devicetree/bindings/usb/apple,dwc3.yaml
+F:	Documentation/devicetree/bindings/usb/apple,sn201202x.yaml
 F:	Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
 F:	Documentation/hwmon/macsmc-hwmon.rst
 F:	arch/arm64/boot/dts/apple/
Signature · 1 line
2.55.0
#2 lore raw

PATCH v3 2/3 usb: typec: tipd: Factor out i2c specifics

In reply to Sasha Finkelstein

From: Alyssa Milburn <[email protected]>

Make the core driver more bus-agnostic to prepare for SPMI variants of the tipd chip

---
 drivers/usb/typec/tipd/Kconfig    |   8 ++++--
 drivers/usb/typec/tipd/Makefile   |  11 ++++---
 drivers/usb/typec/tipd/core.c     | 225 ++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------
 drivers/usb/typec/tipd/i2c.c      | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tipd/tps6598x.h | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 266 insertions(+), 197 deletions(-)
drivers/usb/typec/tipd/Kconfig +6 -2
index b82715293072..c87cbe6109ca 100644
@@ -1,9 +1,13 @@
+config TYPEC_TPS6598X_CORE
+	tristate
+	select USB_ROLE_SWITCH
+	select POWER_SUPPLY
+
 config TYPEC_TPS6598X
 	tristate "TI TPS6598x USB Power Delivery controller driver"
 	depends on I2C
-	select POWER_SUPPLY
 	select REGMAP_I2C
-	select USB_ROLE_SWITCH
+	select TYPEC_TPS6598X_CORE
 	help
 	  Say Y or M here if your system has TI TPS65982 or TPS65983 USB Power
 	  Delivery controller.
drivers/usb/typec/tipd/Makefile +7 -4
index aa439f80a889..c741bf44f52f 100644
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
-CFLAGS_trace.o			:= -I$(src)
+CFLAGS_trace.o				:= -I$(src)
 
-obj-$(CONFIG_TYPEC_TPS6598X)	+= tps6598x.o
-tps6598x-y			:= core.o
-tps6598x-$(CONFIG_TRACING)	+= trace.o
+obj-$(CONFIG_TYPEC_TPS6598X_CORE)	+= tps6598x-core.o
+tps6598x-core-y				:= core.o
+tps6598x-core-$(CONFIG_TRACING)		+= trace.o
+
+obj-$(CONFIG_TYPEC_TPS6598X)		+= tps6598x.o
+tps6598x-y				:= i2c.o
drivers/usb/typec/tipd/core.c +34 -191

370 lines not on this page · raw message

drivers/usb/typec/tipd/i2c.c new file +104 -0

104 lines not on this page · raw message

drivers/usb/typec/tipd/tps6598x.h +115 -0

125 lines not on this page · raw message

Signature · 1 line
2.55.0
#3 lore raw

Re: [PATCH v3 2/3] usb: typec: tipd: Factor out i2c specifics

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] The newly extracted core.c retains I2C-specific casts in tps25750_write_firmware(), risking memory corruption for non-I2C buses.

Pre-existing issues:
- [Critical] tipd_suspend() and tipd_resume() unconditionally pass an invalid IRQ 0 to disable_irq() and enable_irq() if configured as a wakeup source but lacking an interrupt.
- [High] tipd_resume() attempts to communicate with the device over I2C before de-asserting its reset GPIO, causing a guaranteed communication failure.
- [High] Delayed works (wq_poll and cd321x->update_work) are queued but not canceled on probe error paths, leading to a Use-After-Free.
- [High] Early returns in tipd_resume() skip enable_irq(), permanently disabling a shared interrupt line.
--

--- Patch [2]: [PATCH v3 2/3] usb: typec: tipd: Factor out i2c specifics --- commit 8d801170f1c1aaccc36ed5f0477a7ac708265867
Author: Alyssa Milburn <[email protected]>

usb: typec: tipd: Factor out i2c specifics

Make the core driver more bus-agnostic to prepare for SPMI variants of the tipd chip.

drivers/usb/typec/tipd/core.c

Quoted 4 lines
drivers/usb/typec/tipd/core.c +0 -0
index d5ee0af9058b9..31098bdce1096 100644

[Severity: High]
Since this commit prepares core.c for non-I2C buses, will the hardcoded I2C casts remaining in tps25750_write_firmware() cause memory corruption if an SPMI variant reaches this path?

For example:

drivers/usb/typec/tipd/core.c:tps25750_write_firmware() {
    struct i2c_client *client = to_i2c_client(tps->dev);
    ...
    client->adapter->timeout = msecs_to_jiffies(5000);
    client->addr = bpms_addr;
}

Could this overwrite memory at the client->adapter->timeout and client->addr offsets for non-I2C devices?

[ ... ]

Quoted 37 lines
drivers/usb/typec/tipd/core.c +7 -8
@@ -1842,14 +1716,14 @@ static int tps6598x_probe(struct i2c_client *client)
 			goto err_unregister_port;
 		ret = tps->data->connect(tps, status);
 		if (ret)
-			dev_err(&client->dev, "failed to register partner\n");
+			dev_err(tps->dev, "failed to register partner\n");
 	}
 
-	if (client->irq) {
-		ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+	if (tps->irq) {
+		ret = devm_request_threaded_irq(tps->dev, tps->irq, NULL,
 						tps->data->irq_handler,
 						IRQF_SHARED | IRQF_ONESHOT,
-						dev_name(&client->dev), tps);
+						dev_name(tps->dev), tps);
 	} else {
 		dev_warn(tps->dev, "Unable to find the interrupt, switching to polling\n");
 		INIT_DELAYED_WORK(&tps->wq_poll, tps6598x_poll_work);
@@ -1860,13 +1734,12 @@ static int tps6598x_probe(struct i2c_client *client)
 	if (ret)
 		goto err_disconnect;
 
-	i2c_set_clientdata(client, tps);
 	fwnode_handle_put(fwnode);
 
 	tps->wakeup = device_property_read_bool(tps->dev, "wakeup-source");
-	if (tps->wakeup && client->irq) {
-		devm_device_init_wakeup(&client->dev);
-		enable_irq_wake(client->irq);
+	if (tps->wakeup && tps->irq) {
+		devm_device_init_wakeup(tps->dev);
+		enable_irq_wake(tps->irq);
 	}
 
 	return 0;

drivers/usb/typec/tipd/core.c static int tps6598x_probe(struct i2c_client *client) · line 1763

Quoted 4 lines
drivers/usb/typec/tipd/core.c +1 -0
@@ -1887,15 +1760,14 @@ static int tps6598x_probe(struct i2c_client *client)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tipd_init);

[Severity: High]
This is a pre-existing issue, but does the error path in tipd_init() leak the delayed works?

If tps->data->connect() succeeds and queues cd321x->update_work, or if the polling mode queues tps->wq_poll, and a subsequent step fails, we take the err_disconnect path.

Does this path exit and drop the device structure without calling cancel_delayed_work_sync(&tps->wq_poll) or tps->data->remove(tps) to cancel pending works, potentially causing a use-after-free when the tps struct is freed?

[ ... ]

drivers/usb/typec/tipd/core.c static void tps6598x_remove(struct i2c_client *client) · line 1791

Quoted 11 lines
drivers/usb/typec/tipd/core.c +3 -6
-static int __maybe_unused tps6598x_suspend(struct device *dev)
+int tipd_suspend(struct tps6598x *tps)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct tps6598x *tps = i2c_get_clientdata(client);
-
 	if (tps->wakeup) {
-		disable_irq(client->irq);
-		enable_irq_wake(client->irq);
+		disable_irq(tps->irq);
+		enable_irq_wake(tps->irq);

[Severity: Critical]
This is a pre-existing issue, but can this pass an invalid IRQ 0 to disable_irq() and enable_irq_wake()?

If the device specifies a wakeup-source in the device tree but has no interrupt configured, tps->wakeup will be true while tps->irq is 0.

Could calling disable_irq(0) inadvertently disable critical system interrupts, such as the primary system timer?

[ ... ]

drivers/usb/typec/tipd/core.c static void tps6598x_remove(struct i2c_client *client) · line 1807

Quoted 8 lines
drivers/usb/typec/tipd/core.c +1 -3
-static int __maybe_unused tps6598x_resume(struct device *dev)
+int tipd_resume(struct tps6598x *tps)
 {
-	struct i2c_client *client = to_i2c_client(dev);
-	struct tps6598x *tps = i2c_get_clientdata(client);
 	int ret;
 
 	ret = tps6598x_check_mode(tps);

[Severity: High]
This is a pre-existing issue, but does tipd_resume() attempt to communicate with the device before it is taken out of reset?

When the device lacks a wakeup source but has a reset GPIO, tipd_suspend() asserts the reset GPIO.

During tipd_resume(), we call tps6598x_check_mode() which tries to read from the device. However, the reset GPIO is not de-asserted until later:

drivers/usb/typec/tipd/core.c:tipd_resume() {
    ...
    } else if (tps->reset) {
        gpiod_set_value_cansleep(tps->reset, 0);
        ...
    }
}

Will this lead to a guaranteed communication failure during resume?

[Severity: High]
This is also a pre-existing issue, but do the early returns from tps6598x_check_mode() and tps->data->init() skip re-enabling the interrupt?

If tipd_resume() encounters an error here, it returns early and skips:

drivers/usb/typec/tipd/core.c:tipd_resume() {
    ...
    if (tps->wakeup) {
        disable_irq_wake(tps->irq);
        enable_irq(tps->irq);
    }
    ...
}

Could this permanently disable a shared interrupt line?

drivers/usb/typec/tipd/core.c static int __maybe_unused tps6598x_resume(struct device *dev) · line 1819

Quoted 8 lines
drivers/usb/typec/tipd/core.c +2 -2
@@ -1946,25 +1815,22 @@ static int __maybe_unused tps6598x_resume(struct device *dev)
 	}
 
 	if (tps->wakeup) {
-		disable_irq_wake(client->irq);
-		enable_irq(client->irq);
+		disable_irq_wake(tps->irq);
+		enable_irq(tps->irq);

[Severity: Critical]
This isn't a bug introduced by this patch, but can this pass an invalid IRQ 0 to disable_irq_wake() and enable_irq()?

As in tipd_suspend(), if the device specifies a wakeup-source in the device tree but has no interrupt configured, tps->wakeup will be true while tps->irq is 0.

Could calling enable_irq(0) corrupt the IRQ state for critical system interrupts?

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

PATCH v3 3/3 usb: typec: tipd: Add sn201202x support

In reply to Sasha Finkelstein

Add support for sn201202x (aka ACE3), a tipd variant that uses a very similar register map, that is exposed over a "logical register" interface on the SPMI bus.

---
 MAINTAINERS                       |   1 +
 drivers/usb/typec/tipd/Kconfig    |  12 ++++++
 drivers/usb/typec/tipd/Makefile   |   3 ++
 drivers/usb/typec/tipd/core.c     |  20 ++++++++++
 drivers/usb/typec/tipd/spmi.c     | 297 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tipd/tps6598x.h |   9 +++++
 6 files changed, 342 insertions(+)
MAINTAINERS +1 -0
index b2819ca62e0c..821932703b60 100644
@@ -2641,6 +2641,7 @@ F:	drivers/soc/apple/*
 F:	drivers/spi/spi-apple.c
 F:	drivers/spmi/spmi-apple-controller.c
 F:	drivers/usb/dwc3/dwc3-apple.c
+F:	drivers/usb/typec/tipd/spmi.c
 F:	drivers/video/backlight/apple_dwi_bl.c
 F:	drivers/watchdog/apple_wdt.c
 F:	include/dt-bindings/interrupt-controller/apple-aic.h
drivers/usb/typec/tipd/Kconfig +12 -0
index c87cbe6109ca..8177f860f89d 100644
@@ -14,3 +14,15 @@ config TYPEC_TPS6598X
 
 	  If you choose to build this driver as a dynamically linked module, the
 	  module will be called tps6598x.ko.
+
+config TYPEC_SN201202X
+	tristate "TI SN201202x USB Power Delivery controller support"
+	depends on SPMI
+	select TYPEC_TPS6598X_CORE
+	help
+	  Say Y here to enable support for SN201202x, a TPS6598x variant
+	  that uses SPMI as a host bus, and is found on Apple devices starting
+	  from the M3 series.
+
+	  If you choose to build this driver as a dynamically linked module, the
+	  module will be called sn201202x.ko.
drivers/usb/typec/tipd/Makefile +3 -0
index c741bf44f52f..6f5ebc1e1a5f 100644
@@ -7,3 +7,6 @@ tps6598x-core-$(CONFIG_TRACING)		+= trace.o
 
 obj-$(CONFIG_TYPEC_TPS6598X)		+= tps6598x.o
 tps6598x-y				:= i2c.o
+
+obj-$(CONFIG_TYPEC_SN201202X)		+= sn201202x.o
+sn201202x-y				:= spmi.o
drivers/usb/typec/tipd/core.c +20 -0
index 31098bdce109..3120055213c8 100644
@@ -1888,6 +1888,26 @@ const struct tipd_data tipd_tps25750_data = {
 };
 EXPORT_SYMBOL_GPL(tipd_tps25750_data);
 
+const struct tipd_data tipd_sn201202x_data = {
+	.irq_handler = cd321x_interrupt,
+	.irq_mask1 = APPLE_CD_REG_INT_POWER_STATUS_UPDATE |
+		     APPLE_CD_REG_INT_DATA_STATUS_UPDATE |
+		     APPLE_CD_REG_INT_PLUG_EVENT,
+	.tps_struct_size = sizeof(struct sn201202x),
+	.remove = cd321x_remove,
+	.register_port = cd321x_register_port,
+	.unregister_port = cd321x_unregister_port,
+	.trace_data_status = trace_cd321x_data_status,
+	.trace_power_status = trace_tps6598x_power_status,
+	.trace_status = trace_tps6598x_status,
+	.init = cd321x_init,
+	.read_data_status = cd321x_read_data_status,
+	.reset = cd321x_reset,
+	.switch_power_state = cd321x_switch_power_state,
+	.connect = cd321x_connect,
+};
+EXPORT_SYMBOL_GPL(tipd_sn201202x_data);
+
 MODULE_AUTHOR("Heikki Krogerus <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("TI TPS6598x USB Power Delivery Controller Core Functions");
drivers/usb/typec/tipd/spmi.c new file +297 -0

297 lines not on this page · raw message

drivers/usb/typec/tipd/tps6598x.h +9 -0
index 2b61963d97c9..ab60aeb0c274 100644
@@ -374,9 +374,18 @@ struct cd321x {
 	struct usb_pd_identity cur_partner_identity;
 };
 
+struct sn201202x {
+	struct cd321x cd;
+	struct completion select_completion;
+	struct completion sleep_completion;
+	struct completion wake_completion;
+	struct spmi_device *sdev;
+};
+
 extern const struct tipd_data tipd_cd321x_data;
 extern const struct tipd_data tipd_tps6598x_data;
 extern const struct tipd_data tipd_tps25750_data;
+extern const struct tipd_data tipd_sn201202x_data;
 extern const struct regmap_config tps6598x_regmap_config;
 
 int tipd_init(struct tps6598x *tps);
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH v3 3/3] usb: typec: tipd: Add sn201202x support

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

New issues:
- [High] sn201202x_suspend fails to wake up the device if the sleep completion times out, leaving the device in an unresponsive state during error recovery.
- [High] Passing NULL as the devname parameter to devm_request_irq causes a kernel panic during procfs directory creation.
- [Medium] Missing reinit_completion() before spmi_command_wakeup() in probe can cause premature timeout completion due to a spurious or pending interrupt.
- [Medium] The busy-wait check val == (reg | 0x80) incorrectly handles register addresses >= 0x80, leading to an infinite polling loop.

Pre-existing issues:
- [High] If wakeup-source is present in DT but irq is missing, tipd_suspend and tipd_resume will erroneously operate on IRQ 0.
- [High] If connect() fails and no IRQ is present, tipd_init leaks the initialized delayed work queue, leading to a Use-After-Free. --

--- Patch [3]: [PATCH v3 3/3] usb: typec: tipd: Add sn201202x support --- commit a0251ef6ede2e8ce60700056a8add92aa7a36382
Author: Sasha Finkelstein <[email protected]>
Subject: usb: typec: tipd: Add sn201202x support

This patch adds support for the sn201202x (ACE3) controller, which is a tipd variant utilizing the SPMI bus. It provides the SPMI regmap implementation along with probe and PM routines.

Quoted 5 lines
drivers/usb/typec/tipd/spmi.c new file +0 -0
new file mode 100644
index 0000000000000..73575a854bde1

[ ... ]

Quoted 2 lines
drivers/usb/typec/tipd/spmi.c new file +2 -0
+static int regmap_sn201202x_select_reg(struct spmi_device *sdev, u8 reg)
+{

[ ... ]

Quoted 10 lines
drivers/usb/typec/tipd/spmi.c new file +10 -0
+	while (--attempts) {
+		err = spmi_register_read(sdev, 0, &val);
+		if (err)
+			return err;
+		if (val == (reg | 0x80)) {
+			if (!warned) {
+				dev_warn(tps->dev,
+					 "Got interrupt but selection not complete?\n");
+				warned = true;
+			}

drivers/usb/typec/tipd/spmi.c line 49

Quoted 10 lines
drivers/usb/typec/tipd/spmi.c new file +10 -0
+			msleep(20);
+			continue;
+		}
+		if (val == reg)
+			return 0;
+		return -EIO;
+	}
+
+	return -EIO;
+}

[Severity: Medium]
Does this logic work correctly for register addresses >= 0x80? If reg is 0x85, for example, then (reg | 0x80) evaluates to just reg. This would make the busy condition val == (reg | 0x80) identical to the success condition val == reg. Since the busy condition is checked first, it will falsely match, trigger the warning, and eventually timeout returning -EIO.

[ ... ]

Quoted 2 lines
drivers/usb/typec/tipd/spmi.c new file +2 -0
+static int sn201202x_probe(struct spmi_device *device)
+{

[ ... ]

Quoted 4 lines
drivers/usb/typec/tipd/spmi.c new file +4 -0
+	init_completion(&sn->select_completion);
+	init_completion(&sn->sleep_completion);
+	init_completion(&sn->wake_completion);
+

drivers/usb/typec/tipd/spmi.c line 210

Quoted 10 lines
drivers/usb/typec/tipd/spmi.c new file +10 -0
+	ret = devm_request_irq(&device->dev, irq_select, sn201202x_irq,
+			       0, NULL, &sn->select_completion);
+	if (ret)
+		return ret;
+	ret = devm_request_irq(&device->dev, irq_sleep, sn201202x_irq,
+			       0, NULL, &sn->sleep_completion);
+	if (ret)
+		return ret;
+	ret = devm_request_irq(&device->dev, irq_wake, sn201202x_irq,
+			       0, NULL, &sn->wake_completion);

[Severity: High]
Can passing NULL as the devname parameter to devm_request_irq() cause a kernel panic during boot? The IRQ subsystem passes the devname to proc_mkdir() to create an entry in /proc/irq/, and calling strlen() on a NULL name will fault.

drivers/usb/typec/tipd/spmi.c line 223

Quoted 13 lines
drivers/usb/typec/tipd/spmi.c new file +13 -0
+	if (ret)
+		return ret;
+
+	spmi_device_set_drvdata(device, tps);
+	tps->regmap = devm_regmap_init_sn201202x(device, &tps6598x_regmap_config);
+	if (IS_ERR(tps->regmap))
+		return PTR_ERR(tps->regmap);
+
+	ret = spmi_command_wakeup(device);
+	if (ret)
+		return ret;
+	if (!wait_for_completion_timeout(&sn->wake_completion, msecs_to_jiffies(100)))
+		return -ETIMEDOUT;

[Severity: Medium]
Should there be a call to reinit_completion(&sn->wake_completion) right before sending the wakeup command? If a pending or spurious interrupt fires immediately after the IRQ is registered above, wait_for_completion_timeout() might consume the stale completion and return immediately without waiting for the actual hardware wakeup sequence to finish.

[ ... ]

Quoted 2 lines
drivers/usb/typec/tipd/spmi.c new file +2 -0
+static int __maybe_unused sn201202x_suspend(struct device *dev)
+{

[ ... ]

drivers/usb/typec/tipd/spmi.c line 277

Quoted 13 lines
drivers/usb/typec/tipd/spmi.c new file +13 -0
+	err = spmi_command_sleep(sn->sdev);
+	if (err)
+		goto out_resume;
+	if (!wait_for_completion_timeout(&sn->sleep_completion, msecs_to_jiffies(100))) {
+		err = -ETIMEDOUT;
+		goto out_resume;
+	}
+	return 0;
+
+out_resume:
+	tipd_resume(tps);
+	return err;
+}

[Severity: High]
Does this error path leave the device in an unresponsive state? If the sleep command succeeds but wait_for_completion_timeout() times out (perhaps due to a lost interrupt), we jump to out_resume and call tipd_resume(). Since the device was commanded to sleep and no spmi_command_wakeup() is issued in this error path, the regmap reads inside tipd_resume() could fail or hang.

I also noticed a couple of pre-existing issues in the core code that might be worth addressing:

[Severity: High]
This is a pre-existing issue, but does tipd_suspend() correctly handle cases where the wakeup-source property is present in the device tree but the irq property is missing?

drivers/usb/typec/tipd/core.c:tipd_suspend() {
    if (tps->wakeup) {
        disable_irq(tps->irq);
        enable_irq_wake(tps->irq);
    } else if (tps->reset) {

...

In tipd_init(), tps->wakeup can be set to true even if tps->irq is 0. If that happens, calling disable_irq() and enable_irq_wake() here will operate on IRQ 0, which might disable a core system interrupt like the timer.

[Severity: High]
This isn't a regression introduced by this patch, but could tipd_init() leak the delayed work queue if connect() fails?

drivers/usb/typec/tipd/core.c:tipd_init() {
...

    if (status & TPS_STATUS_PLUG_PRESENT) {
        ret = -EINVAL;
        ...
        ret = tps->data->connect(tps, status);
        if (ret)
            dev_err(tps->dev, "failed to register partner\n");
    }

    if (tps->irq) {
        ...
    } else {
        ...
        INIT_DELAYED_WORK(&tps->wq_poll, tps6598x_poll_work);
        queue_delayed_work(system_power_efficient_wq, &tps->wq_poll,
                   msecs_to_jiffies(POLL_INTERVAL));
    }

    if (ret)
        goto err_disconnect;

...

If tps->data->connect() fails, ret holds an error code. If the device has no IRQ, we queue the polling work. Since ret isn't cleared, the subsequent if (ret) check triggers a jump to err_disconnect, freeing the tps structure without cancelling the delayed work queue. This could lead to a use-after-free when the timer fires.

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