usb: typec: tipd: Add sn201202x (ACE3) support
Subsystems (3)
v6 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 v6:
- Fix rebase issues
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- Rebase on usb-next
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Unexport variant data
- One more debugfs-safety fix
- Link to v3: https://patch.msgid.link/[email protected]
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/Makefile | 1 + drivers/usb/typec/tipd/Kconfig | 20 +++++++- drivers/usb/typec/tipd/Makefile | 14 ++++-- drivers/usb/typec/tipd/core.c | 247 +++++++++++++++++++++++-------------------------------------------------------------------------- drivers/usb/typec/tipd/i2c.c | 107 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/typec/tipd/spmi.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/typec/tipd/tps6598x.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 705 insertions(+), 196 deletions(-)
---
base-commit: 3d9eeb336131bc5a174367c384fa00c15c8744fd
change-id: 20260725-tipd-ace3-090bf570ef59
Best regards,
Signature · 1 line
Sasha Finkelstein <[email protected]>
PATCH v6 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
@@ -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
@@ -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
PATCH v6 2/3 usb: typec: tipd: Factor out i2c specifics
In reply to Sasha FinkelsteinFrom: 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 | 230 ++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------- drivers/usb/typec/tipd/i2c.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/typec/tipd/tps6598x.h | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 281 insertions(+), 198 deletions(-)
drivers/usb/typec/tipd/Kconfig +6 -2
@@ -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
@@ -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 +38 -192
380 lines not on this page · raw message
drivers/usb/typec/tipd/i2c.c new file +107 -0
107 lines not on this page · raw message
drivers/usb/typec/tipd/tps6598x.h +123 -0
133 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v6 2/3] usb: typec: tipd: Factor out i2c specifics
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] A delayed work item is queued but never cancelled on the probe error path in polling mode, leading to a Use-After-Free.
- [High] Suspend and resume callbacks operate blindly on IRQ 0 if the wakeup-source property is present but no valid IRQ is configured.
- [High] If hardware checks fail during tipd_resume(), early return leaves the system IRQ permanently disabled. --
commit 74c8f85f00d632452859f6773ca966726049ba5e
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.
Quoted 4 lines
drivers/usb/typec/tipd/core.c +0
-0
[ ... ]
Quoted 20 lines
drivers/usb/typec/tipd/core.c +4
-4@@ -1887,14 +1760,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_dbg (tps->dev,"no IRQ specified, using polling mode\n" );INIT_DELAYED_WORK (&tps->wq_poll, tps6598x_poll_work);
drivers/usb/typec/tipd/core.c static int tps6598x_probe(struct i2c_client *client) · line 1779
Quoted 2 lines
drivers/usb/typec/tipd/core.c +0
-0@@ -1905,13 +1778,12 @@ static int tps6598x_probe(struct i2c_client *client)if (ret) goto err_disconnect;
[Severity: High]
This is a pre-existing issue, but can this error path in tipd_init() lead to a use-after-free?
If tps->data->connect() fails in polling mode (where tps->irq == 0), ret will hold the error code. The polling work is then queued in the else branch.
Because ret is non-zero, the "if (ret)" check triggers a jump to err_disconnect. The error handling path misses calling cancel_delayed_work_sync(&tps->wq_poll). When the devres framework frees the tps structure upon probe failure, the scheduled delayed work might execute and access freed memory.
[ ... ]
Quoted 4 lines
drivers/usb/typec/tipd/core.c +1
-2-static int __maybe_unused tps6598x_suspend (struct device *dev) +int tipd_suspend (struct tps6598x *tps) { -struct i2c_client *client =to_i2c_client (dev);
drivers/usb/typec/tipd/core.c static void tps6598x_remove(struct i2c_client *client) · line 1838
Quoted 10 lines
drivers/usb/typec/tipd/core.c +2
-4-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); }else if (tps->reset) {gpiod_set_value_cansleep (tps->reset,1 ); }
[Severity: High]
This isn't a bug introduced by this patch, but does tipd_suspend() blindly operate on IRQ 0?
During probe, tps->wakeup can be set to true if the wakeup-source property is found in the device tree, even if no valid IRQ is configured (tps->irq == 0).
If this happens, tipd_suspend() will pass IRQ 0 to disable_irq() and enable_irq_wake(), which could crash the system or disable critical system timers (such as the PIT on x86).
[ ... ]
drivers/usb/typec/tipd/core.c static void tps6598x_remove(struct i2c_client *client)
Quoted 10 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);if (ret <0 )return ret;
[Severity: High]
This is a pre-existing issue, but could this early return in tipd_resume() leave the system IRQ permanently disabled?
If tps6598x_check_mode(tps) fails on resume, the function returns early before balancing the disable_irq() call from suspend with enable_irq().
This creates an unbalanced IRQ depth, keeping the IRQ line disabled, which will break any other devices sharing the same IRQ.
[ ... ]
drivers/usb/typec/tipd/core.c static int __maybe_unused tps6598x_resume(struct device *dev) · line 1867
Quoted 12 lines
drivers/usb/typec/tipd/core.c +2
-2@@ -1991,25 +1859,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); }else if (tps->reset) {gpiod_set_value_cansleep (tps->reset,0 );msleep (TPS_SETUP_MS ); }
[Severity: High]
This isn't a bug introduced by this patch, but similar to the suspend path, will tipd_resume() pass IRQ 0 to disable_irq_wake() and enable_irq() if no IRQ is configured but the wakeup-source property is present?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v6 3/3 usb: typec: tipd: Add sn201202x support
In reply to Sasha FinkelsteinAdd 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/Makefile | 1 + drivers/usb/typec/tipd/Kconfig | 12 ++++++ drivers/usb/typec/tipd/Makefile | 3 ++ drivers/usb/typec/tipd/core.c | 21 ++++++++++ drivers/usb/typec/tipd/spmi.c | 300 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/typec/tipd/tps6598x.h | 9 +++++ 7 files changed, 347 insertions(+)
MAINTAINERS +1 -0
@@ -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/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_TYPEC) += altmodes/ obj-$(CONFIG_TYPEC_TCPM) += tcpm/ obj-$(CONFIG_TYPEC_UCSI) += ucsi/ obj-$(CONFIG_TYPEC_TPS6598X) += tipd/ +obj-$(CONFIG_TYPEC_SN201202X) += tipd/ obj-$(CONFIG_TYPEC_ANX7411) += anx7411.o obj-$(CONFIG_TYPEC_HD3SS3220) += hd3ss3220.o obj-$(CONFIG_TYPEC_STUSB160X) += stusb160x.o
drivers/usb/typec/tipd/Kconfig +12 -0
@@ -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
@@ -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 +21 -0
@@ -1950,11 +1950,32 @@ static const struct tipd_data tipd_tps25750_data = { .connect = tps6598x_connect, }; +static 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, + .read_power_status = tps6598x_read_power_status, + .reset = cd321x_reset, + .switch_power_state = cd321x_switch_power_state, + .connect = cd321x_connect, +}; +const struct tipd_data *tipd_hw_variants[] = { [TIPD_VARIANT_CD321X ] = &tipd_cd321x_data, [TIPD_VARIANT_TPS6598X ] = &tipd_tps6598x_data, [TIPD_VARIANT_TPS66993 ] = &tipd_tps66993_data, [TIPD_VARIANT_TPS25750 ] = &tipd_tps25750_data, + [TIPD_VARIANT_SN201202X ] = &tipd_sn201202x_data, };EXPORT_SYMBOL_GPL (tipd_hw_variants);
drivers/usb/typec/tipd/spmi.c new file +300 -0
300 lines not on this page · raw message
drivers/usb/typec/tipd/tps6598x.h +9 -0
@@ -283,6 +283,7 @@ enum tipd_hw_variant {TIPD_VARIANT_TPS6598X ,TIPD_VARIANT_TPS66993 ,TIPD_VARIANT_TPS25750 , +TIPD_VARIANT_SN201202X , TIPD_VARIANT_MAX, };
@@ -388,6 +389,14 @@ 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_hw_variants[];extern const struct regmap_config tps6598x_regmap_config;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v6 3/3] usb: typec: tipd: Add sn201202x support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Delayed works (update_work and wq_poll) are not cancelled on the probe error path in tipd_init, leading to a Use-After-Free. --
commit 547c3b2aceecd19f6dae9a6a5703b8abccb6b9fc
Author: Sasha Finkelstein <[email protected]>
usb: typec: tipd: Add sn201202x support
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.
Quoted 4 lines
drivers/usb/typec/tipd/core.c +0
-0
[ ... ]
drivers/usb/typec/tipd/core.c static const struct tipd_data tipd_tps25750_data = { · line 1961
Quoted 13 lines
drivers/usb/typec/tipd/core.c +9
-0@@ -1950,11 +1950,32 @@ static const struct tipd_data tipd_tps25750_data = { .connect = tps6598x_connect, }; +static 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,
[Severity: High]
This is a pre-existing issue, but does cd321x_unregister_port() completely miss cancelling the update_work?
When tipd_init() calls the err_disconnect cleanup path on probe failure, it calls this unregister_port callback:
drivers/usb/typec/tipd/core.c:cd321x_unregister_port() {
...
typec_mux_put(cd321x->mux);
cd321x->mux = NULL;
}Since the delayed work isn't cancelled here or in err_disconnect, the update_work or wq_poll can run 500ms later and try to access the freed cd321x or tps6598x device structure, causing a use-after-free.
Quoted 1 line
drivers/usb/typec/tipd/core.c +1
-0+ .trace_data_status = trace_cd321x_data_status,
[ ... ]
Quoted 5 lines
drivers/usb/typec/tipd/spmi.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/usb/typec/tipd/spmi.c new file +2
-0+static int sn201202x_probe (struct spmi_device *device) +{
[ ... ]
drivers/usb/typec/tipd/spmi.c line 233
Quoted 11 lines
drivers/usb/typec/tipd/spmi.c new file +11
-0+ ret =spmi_command_wakeup (device); +if (ret) +return ret; +if (!wait_for_completion_timeout (&sn->wake_completion,msecs_to_jiffies (100 ))) +return -ETIMEDOUT ; + + ret =tipd_init (tps); +if (ret) +spmi_command_sleep (device); +return ret; +}
[Severity: High]
This isn't a bug introduced by this patch, but could this error path trigger the use-after-free mentioned above?
If tipd_init() fails after the delayed works are scheduled (for instance, if devm_request_threaded_irq returns an error, or if polling mode is used and connect() fails), tipd_init() jumps to err_disconnect:
drivers/usb/typec/tipd/core.c:tipd_init() {
...
if (ret)
goto err_disconnect;
...
}This returns the error code, causing the driver core devres framework to free the memory allocated for the device structure, leaving the delayed work active and accessing freed memory.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Greg Kroah-Hartman
maintainerQuoted 6 lines · Sasha Finkelstein
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.
Quoted 8 lines
To simplify the merge strategy, the device tree entries will be sent in a future patch series.
Signed-off-by Sasha Finkelstein <[email protected]>---
Changes in v6:
- Fix rebase issues
- Link to v5: https://patch.msgid.link/[email protected]
Can you please rebase again against the usb-testing branch? Patch 2/3 doesn't apply :(
thanks,
greg k-h