From 3bb25a5e655084dc3c4973ed2a4c80f177dd758c Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Thu, 26 Nov 2026 12:23:09 -0500 Subject: [PATCH 1/5] arm64: dts: apple: t6050-j716c: wire HPM SPMI interrupts and SMC power sensors Add the SPMI controller interrupt lines (AIC 761/763) and fault-queue windows on nub_spmi_a0 and nub_spmi_a1, wire event/sleep/wake interrupts on hpm0/1/2/5 so sn201202x uses interrupt-driven handling and idle sleep instead of 500 ms polling, and expose PSTR/PHPC/PDTR/SBAV SMC hwmon sensors. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 67 ++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index 36575c200d534..d73d4eaf08cd6 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -120,7 +120,7 @@ }; }; -/* ATC1, ATC3 and the PD controller buses nub-spmi-a0 and -a2: not yet described for this board */ +/* ATC1, ATC3 and the PD controller bus nub-spmi-a2: not yet described for this board */ &nub_spmi_a0 { status = "disabled"; }; @@ -205,6 +205,26 @@ apple,fan-mode = "F1md"; apple,fan-manual-control; }; + + power-PSTR { + apple,key-id = "PSTR"; + label = "Total System Power"; + }; + + power-PHPC { + apple,key-id = "PHPC"; + label = "Heatpipe Power"; + }; + + power-PDTR { + apple,key-id = "PDTR"; + label = "AC Input Power"; + }; + + voltage-SBAV { + apple,key-id = "SBAV"; + label = "Battery Voltage"; + }; }; /* @@ -334,19 +354,62 @@ */ #include "t6050-j714s-ane.dtsi" -/* The port controllers follow the sleep's command rules (tipd: woken first, read at intervals) */ +/* + * Wire SPMI controller interrupts (with fault queue windows) and per-port + * event/sleep/wake IRQs on the four USB-PD controllers so tipd uses + * interrupt-driven handling and idle sleep instead of 500 ms polling. + */ +&nub_spmi_a0 { + reg = <0x2 0x8a188000 0x0 0x4000>, + <0x2 0x8a184000 0x0 0x4000>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = ; +}; + +&nub_spmi_a1 { + reg = <0x2 0x8a1a8000 0x0 0x4000>, + <0x2 0x8a1a4000 0x0 0x4000>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = ; +}; + +/* The port controllers follow the sleep's command rules and use SPMI event/sleep/wake IRQs. */ &hpm0 { + compatible = "apple,t8132-sn201202x", "apple,sn201202x"; + interrupts = <11 IRQ_TYPE_EDGE_RISING>, + <17 IRQ_TYPE_EDGE_RISING>, + <19 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; apple,sleep-ssps-rules; }; &hpm1 { + compatible = "apple,t8132-sn201202x", "apple,sn201202x"; + interrupts = <37 IRQ_TYPE_EDGE_RISING>, + <43 IRQ_TYPE_EDGE_RISING>, + <45 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; apple,sleep-ssps-rules; }; &hpm2 { + compatible = "apple,t8132-sn201202x", "apple,sn201202x"; + interrupts = <11 IRQ_TYPE_EDGE_RISING>, + <17 IRQ_TYPE_EDGE_RISING>, + <19 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; apple,sleep-ssps-rules; }; &hpm5 { + compatible = "apple,t8132-sn201202x", "apple,sn201202x"; + interrupts = <63 IRQ_TYPE_EDGE_RISING>, + <69 IRQ_TYPE_EDGE_RISING>, + <71 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; apple,sleep-ssps-rules; }; From b3e5081e5ba96a10ea02d4da169b2526fb86f4c4 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Fri, 27 Nov 2026 18:44:13 -0500 Subject: [PATCH 2/5] dt-bindings: usb: apple,sn201202x: select 3-IRQ layout when select IRQ is absent Key the three-interrupt layout (irq, sleep, wake) in apple,sn201202x.yaml on the absence of the "select" interrupt name instead of requiring the apple,t8132-sn201202x compatible string, so generic apple,sn201202x nodes that omit the register-selection interrupt validate cleanly. Keep apple,t8132-sn201202x and apple,t8152-sn201202x valid in compatible for existing device trees. Signed-off-by: Erik Bourget --- .../bindings/usb/apple,sn201202x.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml index 84ae1f7bf0880..87ad7f95a3159 100644 --- a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml +++ b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml @@ -17,10 +17,11 @@ description: | The controller can be polled when interrupt resources are not supplied. - T8132 omits the register-selection interrupt, so selection is polled while - event, standby and wakeup notifications use interrupts. The T8152 - controllers work as the T8132 ones do: no register-selection interrupt, and - the payload length of a selected register in register 0x1f. + Controllers that omit the register-selection interrupt poll register + selection and read the payload length of a selected register from register + 0x1f, while event, standby and wakeup notifications use interrupts. Legacy + device trees also carry `apple,t8132-sn201202x` or `apple,t8152-sn201202x` + compatibles for those controllers. properties: compatible: @@ -129,20 +130,24 @@ required: allOf: - if: + required: + - interrupt-names properties: - compatible: + interrupt-names: contains: - const: apple,t8132-sn201202x + const: select then: properties: 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 else: @@ -150,13 +155,11 @@ allOf: 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 From e3b8967905e3f434f5701a9591d7c1757f144fb5 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Fri, 27 Nov 2026 18:44:14 -0500 Subject: [PATCH 3/5] usb: typec: tipd: sn201202x: key select polling on absent select IRQ When "irq", "sleep", and "wake" interrupts are present without a "select" entry in "interrupt-names", enable select_polled directly instead of gating it on "apple,t8132-sn201202x", and key the register 0x1f payload-length check in __regmap_sn201202x_read() on sn->select_polled. Check "interrupt-names" presence separately via of_property_match_string() in sn201202x_select_irq_get() so lookup errors (-EINVAL, -EOVERFLOW, -EPROBE_DEFER, etc.) propagate whenever "select" is declared instead of silently falling back to polling. Update sn201202x-transport.py and add sn201202x-pm KUnit coverage for absent vs declared-but-invalid/deferred "select" IRQ handling. Signed-off-by: Erik Bourget --- drivers/usb/typec/tipd/sn201202x-pm-test.c | 146 ++++++++++++++++++ drivers/usb/typec/tipd/spmi.c | 55 +++++-- drivers/usb/typec/tipd/tps6598x.h | 2 + .../drivers/apple/sn201202x-transport.py | 10 +- 4 files changed, 194 insertions(+), 19 deletions(-) diff --git a/drivers/usb/typec/tipd/sn201202x-pm-test.c b/drivers/usb/typec/tipd/sn201202x-pm-test.c index 82bd1d8df528a..a4d35bd549ff4 100644 --- a/drivers/usb/typec/tipd/sn201202x-pm-test.c +++ b/drivers/usb/typec/tipd/sn201202x-pm-test.c @@ -4,11 +4,14 @@ */ #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -1032,6 +1035,148 @@ static void sn201202x_ldcm_stop_requeue_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, delayed_work_pending(&t->sn.ldcm_work)); } +#ifdef CONFIG_OF_DYNAMIC +static void sn201202x_test_changeset_cleanup(void *data) +{ + struct of_changeset *cs = data; + + of_changeset_revert(cs); + of_changeset_destroy(cs); +} + +static void sn201202x_test_irq_domain_remove(void *data) +{ + irq_domain_remove(data); +} +#endif + +static void sn201202x_select_irq_test(struct kunit *test) +{ +#ifndef CONFIG_OF_DYNAMIC + kunit_skip(test, "requires CONFIG_OF_DYNAMIC"); +#else + static const char * const names_3irq[] = { "irq", "sleep", "wake" }; + static const char * const names_4irq[] = { "irq", "select", "sleep", "wake" }; + static const u32 irqs_3irq[] = { 1, 0, 2, 0, 3, 0 }; + static const u32 irqs_4irq[] = { 1, 0, 2, 0, 3, 0, 4, 0 }; + static const u32 irqs_bad_phandle[] = { + 0xffffffff, 0, 0xffffffff, 1, 0xffffffff, 2, 0xffffffff, 3, + }; + static const u32 irqs_trunc[] = { 1, 0 }; + struct device_node *ic, *polled_3irq, *bad_spec, *trunc_spec, *valid_4irq; + struct of_changeset *cs; + struct irq_domain *domain; + bool select_polled; + int ret; + + if (!of_root) + kunit_skip(test, "requires a device tree"); + + cs = kunit_kzalloc(test, sizeof(*cs), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, cs); + of_changeset_init(cs); + + ic = of_changeset_create_node(cs, of_root, "sn201202x-irq-test"); + KUNIT_ASSERT_NOT_NULL(test, ic); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_bool(cs, ic, "interrupt-controller"), 0); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32(cs, ic, "#interrupt-cells", 2), 0); + + polled_3irq = of_changeset_create_node(cs, ic, "polled-select"); + KUNIT_ASSERT_NOT_NULL(test, polled_3irq); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, polled_3irq, + "interrupt-names", + names_3irq, + ARRAY_SIZE(names_3irq)), 0); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, polled_3irq, + "interrupts", + irqs_3irq, + ARRAY_SIZE(irqs_3irq)), 0); + + bad_spec = of_changeset_create_node(cs, ic, "bad-select-spec"); + KUNIT_ASSERT_NOT_NULL(test, bad_spec); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, bad_spec, + "interrupt-names", + names_4irq, + ARRAY_SIZE(names_4irq)), 0); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, bad_spec, + "interrupts-extended", + irqs_bad_phandle, + ARRAY_SIZE(irqs_bad_phandle)), 0); + + trunc_spec = of_changeset_create_node(cs, ic, "trunc-select-spec"); + KUNIT_ASSERT_NOT_NULL(test, trunc_spec); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, trunc_spec, + "interrupt-names", + names_4irq, + ARRAY_SIZE(names_4irq)), 0); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, trunc_spec, + "interrupts", + irqs_trunc, + ARRAY_SIZE(irqs_trunc)), 0); + + valid_4irq = of_changeset_create_node(cs, ic, "valid-4irq"); + KUNIT_ASSERT_NOT_NULL(test, valid_4irq); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, valid_4irq, + "interrupt-names", + names_4irq, + ARRAY_SIZE(names_4irq)), 0); + KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, valid_4irq, + "interrupts", + irqs_4irq, + ARRAY_SIZE(irqs_4irq)), 0); + + ret = of_changeset_apply(cs); + if (ret) { + of_node_put(valid_4irq); + of_node_put(trunc_spec); + of_node_put(bad_spec); + of_node_put(polled_3irq); + of_node_put(ic); + of_changeset_destroy(cs); + KUNIT_ASSERT_EQ(test, ret, 0); + } + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, sn201202x_test_changeset_cleanup, + cs), 0); + of_node_put_kunit(test, ic); + of_node_put_kunit(test, polled_3irq); + of_node_put_kunit(test, bad_spec); + of_node_put_kunit(test, trunc_spec); + of_node_put_kunit(test, valid_4irq); + + /* Absent "select" IRQ falls back to select-polled. */ + select_polled = false; + KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(polled_3irq, &select_polled), 0); + KUNIT_EXPECT_TRUE(test, select_polled); + + /* Declared "select" IRQ with unparseable specifier propagates -EINVAL. */ + select_polled = true; + KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(bad_spec, &select_polled), -EINVAL); + KUNIT_EXPECT_FALSE(test, select_polled); + + /* Declared "select" IRQ missing from interrupts array propagates -EOVERFLOW. */ + select_polled = true; + KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(trunc_spec, &select_polled), -EOVERFLOW); + KUNIT_EXPECT_FALSE(test, select_polled); + + /* Declared "select" IRQ without a registered domain propagates -EPROBE_DEFER. */ + select_polled = true; + KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(valid_4irq, &select_polled), -EPROBE_DEFER); + KUNIT_EXPECT_FALSE(test, select_polled); + + /* Declared "select" IRQ with a registered domain maps cleanly and disables polling. */ + domain = irq_domain_create_linear(of_fwnode_handle(ic), 8, &irq_domain_simple_ops, NULL); + KUNIT_ASSERT_NOT_NULL(test, domain); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, sn201202x_test_irq_domain_remove, + domain), 0); + select_polled = true; + ret = sn201202x_select_irq_get(valid_4irq, &select_polled); + KUNIT_EXPECT_GT(test, ret, 0); + KUNIT_EXPECT_FALSE(test, select_polled); + if (ret > 0) + irq_dispose_mapping(ret); +#endif +} + static struct kunit_case sn201202x_pm_cases[] = { KUNIT_CASE(sn201202x_sleep_cycle_test), KUNIT_CASE(sn201202x_failed_wakeup_test), @@ -1069,6 +1214,7 @@ static struct kunit_case sn201202x_pm_cases[] = { KUNIT_CASE(sn201202x_sleep_from_idle_test), KUNIT_CASE(sn201202x_sleep_from_idle_failed_wakeup_test), KUNIT_CASE(sn201202x_watched_sleep_from_idle_test), + KUNIT_CASE(sn201202x_select_irq_test), {} }; diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c index 44e574400b6ec..9983179acfee0 100644 --- a/drivers/usb/typec/tipd/spmi.c +++ b/drivers/usb/typec/tipd/spmi.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -113,6 +114,8 @@ static int __regmap_sn201202x_read(void *context, void *val, size_t val_size) { struct spmi_device *sdev = context; + struct tps6598x *tps = spmi_device_get_drvdata(sdev); + struct sn201202x *sn = tps_to_sn(tps); int err; unsigned int offset = 0x20; size_t len; @@ -133,7 +136,7 @@ static int __regmap_sn201202x_read(void *context, if (err) return err; - if (of_device_is_compatible(sdev->dev.of_node, "apple,t8132-sn201202x")) { + if (sn->select_polled) { u8 size; /* Selection completion does not establish the payload's length. */ @@ -919,6 +922,40 @@ static int sn201202x_init(struct sn201202x *sn) static int sn201202x_usbw_notify(struct notifier_block *nb, unsigned long usb_asleep, void *unused); +VISIBLE_IF_KUNIT int sn201202x_select_irq_get(struct device_node *np, + bool *select_polled) +{ + int index, ret; + + if (!np) { + *select_polled = false; + return -EINVAL; + } + + index = of_property_match_string(np, "interrupt-names", "select"); + if (index < 0) { + /* + * Some controllers omit the select notification, retaining + * event/sleep/wake IRQs; poll register selection there. + */ + if (index == -EINVAL || index == -ENODATA) { + *select_polled = true; + return 0; + } + *select_polled = false; + return index; + } + + *select_polled = false; + ret = of_irq_get(np, index); + if (ret < 0) + return ret; + if (!ret) + return -EINVAL; + return ret; +} +EXPORT_SYMBOL_IF_KUNIT(sn201202x_select_irq_get); + static int sn201202x_probe(struct spmi_device *device) { const struct of_device_id *match; @@ -975,16 +1012,10 @@ static int sn201202x_probe(struct spmi_device *device) tps->irq = of_irq_get_byname(device->dev.of_node, "irq"); if (tps->irq < 0) return tps->irq; - irq_select = of_irq_get_byname(device->dev.of_node, "select"); - /* T8132 has no select notification, but retains event/sleep/wake IRQs. */ - if (irq_select == -EINVAL || irq_select == -ENODATA) { - if (!of_device_is_compatible(device->dev.of_node, - "apple,t8132-sn201202x")) - return irq_select; - sn->select_polled = true; - } else if (irq_select < 0) { + irq_select = sn201202x_select_irq_get(device->dev.of_node, + &sn->select_polled); + if (irq_select < 0) return irq_select; - } irq_sleep = of_irq_get_byname(device->dev.of_node, "sleep"); if (irq_sleep < 0) return irq_sleep; @@ -1016,8 +1047,8 @@ static int sn201202x_probe(struct spmi_device *device) tps->sleep_event = sn201202x_sleep_event; /* * Idle sleep needs only the event interrupt to stay live while the - * controller sleeps. T8132's select-polled controllers have that, as - * the system sleep filter above relies on; elsewhere the DT says so + * controller sleeps. Select-polled controllers have that, as the + * system sleep filter above relies on; elsewhere the DT says so * (apple,event-irq-in-sleep). A register access then wakes the * controller through runtime PM, select notification or not. Those * controllers keep their own system sleep path (a wake IRQ). diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index eb77f76379ca4..5997f2c3e539b 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -611,6 +611,8 @@ static inline void tipd_debugfs_exit(void) { } #endif #if IS_ENABLED(CONFIG_KUNIT) +struct device_node; +int sn201202x_select_irq_get(struct device_node *np, bool *select_polled); void cd321x_mux_failed(struct cd321x *cd321x, const char *what, int ret, bool held); void cd321x_mux_gave_up(struct cd321x *cd321x, unsigned int retries, unsigned int held_ms); void cd321x_init_work(struct cd321x *cd321x); diff --git a/tools/testing/selftests/drivers/apple/sn201202x-transport.py b/tools/testing/selftests/drivers/apple/sn201202x-transport.py index 0caa42c354143..31d9cb0510631 100755 --- a/tools/testing/selftests/drivers/apple/sn201202x-transport.py +++ b/tools/testing/selftests/drivers/apple/sn201202x-transport.py @@ -56,8 +56,6 @@ def main(): static bool wait_for_completion_timeout(struct completion *c,unsigned n) { (void)c; (void)n; return false; } static void msleep(unsigned n) { (void)n; } -static bool of_device_is_compatible(void *node,const char *name) -{ assert(!strcmp(name,"apple,t8132-sn201202x")); return node != NULL; } static int spmi_register_zero_write(struct spmi_device *s,u8 reg) { (void)s; selected=reg; writes++; return select_error; } static int spmi_register_read(struct spmi_device *s,u8 reg,u8 *value) @@ -77,7 +75,7 @@ def main(): static int spmi_ext_register_read(struct spmi_device *s,unsigned off,void *val,size_t len) { assert(completed); - if(s->dev.of_node) assert(length_checked); + if(sn.select_polled) assert(length_checked); assert(len>0 && len<=16 && off==0x20+bytes && off+len<=0x60); payload_reads++; if(payload_error) return payload_error; @@ -152,16 +150,14 @@ def main(): reg=0x80; assert(regmap_sn201202x_read(&s,®,1,out,4)==-EINVAL && !writes); puts("ok 4 - transport errors and invalid transfer bounds propagate"); - clean(&s); s.dev.of_node=NULL; reg=0x5f; advertised=0; + clean(&s); sn.polled=true; sn.select_polled=false; reg=0x5f; advertised=0; assert(!regmap_sn201202x_read(&s,®,1,out,4) && !length_reads && bytes==4); puts("ok 5 - older SN201202x transport behavior preserved"); return 0; } ''' busy = program.replace("err || val == reg", "err || (val & 0x7f) == reg") - unchecked = program.replace( - 'if (of_device_is_compatible(sdev->dev.of_node, "apple,t8132-sn201202x"))', - 'if (false)', 1) + unchecked = program.replace("if (sn->select_polled)", "if (false && sn->select_polled)", 1) oversized = program.replace("size > TPS_MAX_LEN", "false", 1) assert all(text != program for text in [busy, unchecked, oversized]) resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) From e0bd1a6d676aa8bde01877d199100728e64c1388 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Fri, 27 Nov 2026 18:44:14 -0500 Subject: [PATCH 4/5] arm64: dts: apple: t6050: move SPMI IRQs to SoC dtsi and drop t8132 fallback Move the T6050 nub_spmi_a0/nub_spmi_a1 fault-queue windows, interrupt-controller properties, and AIC 761/763 interrupts from t6050-j716c.dts into the shared T6050 SoC dtsis (t6050-die0.dtsi, t6050-max.dtsi, t6050-peripherals.dtsi) and t6050-j716s.dts so all T6050 boards inherit interrupt-driven SPMI. Drop the "apple,t8132-sn201202x" fallback from hpm0/1/2/5 in t6050-j716c.dts now that the driver and binding key select-polled handling on the absence of the "select" interrupt. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-die0.dtsi | 11 +++++--- arch/arm64/boot/dts/apple/t6050-j716c.dts | 27 ------------------- arch/arm64/boot/dts/apple/t6050-j716s.dts | 13 ++++++--- arch/arm64/boot/dts/apple/t6050-max.dtsi | 11 +++++--- .../boot/dts/apple/t6050-peripherals.dtsi | 3 +++ 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-die0.dtsi b/arch/arm64/boot/dts/apple/t6050-die0.dtsi index 6643e2d66215e..a168ae97515f0 100644 --- a/arch/arm64/boot/dts/apple/t6050-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-die0.dtsi @@ -363,12 +363,17 @@ }; /* - * /arm-io/nub-spmi-a0: reg[0] 0x8a188000, generation 4, a bus of the USB-C PD controllers - * (HPMs, the board's). They are polled (no interrupts), so the bus needs none either. + * /arm-io/nub-spmi-a0: reg[0] 0x8a188000, reg[1] 0x8a184000 (fault queue), generation 4, + * interrupt 761, a bus of the USB-C PD controllers (HPMs, the board's). */ nub_spmi_a0: spmi@28a188000 { compatible = "apple,t6050-spmi", "apple,t8142-spmi"; - reg = <0x2 0x8a188000 0x0 0x4000>; + reg = <0x2 0x8a188000 0x0 0x4000>, + <0x2 0x8a184000 0x0 0x4000>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = ; #address-cells = <2>; #size-cells = <0>; }; diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index d73d4eaf08cd6..77a44045dcb94 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -354,32 +354,8 @@ */ #include "t6050-j714s-ane.dtsi" -/* - * Wire SPMI controller interrupts (with fault queue windows) and per-port - * event/sleep/wake IRQs on the four USB-PD controllers so tipd uses - * interrupt-driven handling and idle sleep instead of 500 ms polling. - */ -&nub_spmi_a0 { - reg = <0x2 0x8a188000 0x0 0x4000>, - <0x2 0x8a184000 0x0 0x4000>; - interrupt-controller; - #interrupt-cells = <2>; - interrupt-parent = <&aic>; - interrupts = ; -}; - -&nub_spmi_a1 { - reg = <0x2 0x8a1a8000 0x0 0x4000>, - <0x2 0x8a1a4000 0x0 0x4000>; - interrupt-controller; - #interrupt-cells = <2>; - interrupt-parent = <&aic>; - interrupts = ; -}; - /* The port controllers follow the sleep's command rules and use SPMI event/sleep/wake IRQs. */ &hpm0 { - compatible = "apple,t8132-sn201202x", "apple,sn201202x"; interrupts = <11 IRQ_TYPE_EDGE_RISING>, <17 IRQ_TYPE_EDGE_RISING>, <19 IRQ_TYPE_EDGE_RISING>; @@ -388,7 +364,6 @@ }; &hpm1 { - compatible = "apple,t8132-sn201202x", "apple,sn201202x"; interrupts = <37 IRQ_TYPE_EDGE_RISING>, <43 IRQ_TYPE_EDGE_RISING>, <45 IRQ_TYPE_EDGE_RISING>; @@ -397,7 +372,6 @@ }; &hpm2 { - compatible = "apple,t8132-sn201202x", "apple,sn201202x"; interrupts = <11 IRQ_TYPE_EDGE_RISING>, <17 IRQ_TYPE_EDGE_RISING>, <19 IRQ_TYPE_EDGE_RISING>; @@ -406,7 +380,6 @@ }; &hpm5 { - compatible = "apple,t8132-sn201202x", "apple,sn201202x"; interrupts = <63 IRQ_TYPE_EDGE_RISING>, <69 IRQ_TYPE_EDGE_RISING>, <71 IRQ_TYPE_EDGE_RISING>; diff --git a/arch/arm64/boot/dts/apple/t6050-j716s.dts b/arch/arm64/boot/dts/apple/t6050-j716s.dts index 7eb3a3415d8dd..f92ef60d0c79d 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716s.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716s.dts @@ -70,13 +70,18 @@ /* A block t6050-die0.dtsi does not describe yet: the third HPM bus */ &die0 { /* - * ADT nub-spmi-a1, the right-hand port's HPM bus (hpm2). Polled like a0: - * the generation 4 driver takes no interrupt. pmgr NUB_SPMI_A1 is - * critical, as NUB_SPMI_A0, so no power-domains. + * ADT nub-spmi-a1, the right-hand port's HPM bus (hpm2), with its fault-queue + * window and AIC 763 interrupt. pmgr NUB_SPMI_A1 is critical, as NUB_SPMI_A0, so + * no power-domains. */ nub_spmi_a1: spmi@28a1a8000 { compatible = "apple,t6050-spmi", "apple,t8142-spmi"; - reg = <0x2 0x8a1a8000 0x0 0x4000>; + reg = <0x2 0x8a1a8000 0x0 0x4000>, + <0x2 0x8a1a4000 0x0 0x4000>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = ; #address-cells = <2>; #size-cells = <0>; }; diff --git a/arch/arm64/boot/dts/apple/t6050-max.dtsi b/arch/arm64/boot/dts/apple/t6050-max.dtsi index 922b83b01d057..2b301dce57a60 100644 --- a/arch/arm64/boot/dts/apple/t6050-max.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-max.dtsi @@ -207,12 +207,17 @@ #if defined(T6050_J714C) || defined(T6050_J716C) /* - * /arm-io/nub-spmi-a1: reg[0] 0x8a1a8000, generation 4, a bus of USB-C PD controllers (the - * board's). They are polled, as on nub-spmi-a0, so the bus takes no interrupt. + * /arm-io/nub-spmi-a1: reg[0] 0x8a1a8000, reg[1] 0x8a1a4000 (fault queue), generation 4, + * interrupt 763, a bus of USB-C PD controllers (the board's). */ nub_spmi_a1: spmi@28a1a8000 { compatible = "apple,t6050-spmi", "apple,t8142-spmi"; - reg = <0x2 0x8a1a8000 0x0 0x4000>; + reg = <0x2 0x8a1a8000 0x0 0x4000>, + <0x2 0x8a1a4000 0x0 0x4000>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = ; #address-cells = <2>; #size-cells = <0>; }; diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index c7a6178d27371..f013e031e0c84 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -1468,6 +1468,9 @@ reg = <0x2 0x8a1a8000 0x0 0x4000>, <0x2 0x8a1a4000 0x0 0x4000>, <0x2 0x8a1a0000 0x0 0x4000>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; interrupts = ; #address-cells = <2>; #size-cells = <0>; From c7b2476fe4204978bb0023e936a8ea58e7b6c1a4 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sat, 28 Nov 2026 13:20:38 -0500 Subject: [PATCH 5/5] usb: typec: tipd: sn201202x: preserve 0x1f length read for polled T8132 Legacy T8132/T8152 device trees without interrupt resources set sn->polled and skip sn201202x_select_irq_get(), leaving sn->select_polled false. Preserve the register 0x1f payload-length validation in __regmap_sn201202x_read() for that fully polled "apple,t8132-sn201202x" path while keeping IRQ-backed select admission and length checking strictly resource-driven via sn->select_polled. Cover fully polled T8132 reads (valid, short, and oversized responses), NULL of_node handling, IRQ-backed select with "apple,t8132-sn201202x" compatible, and the corresponding negative controls in sn201202x-transport.py. Signed-off-by: Erik Bourget --- drivers/usb/typec/tipd/spmi.c | 5 ++- .../drivers/apple/sn201202x-transport.py | 42 ++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c index 9983179acfee0..553efeb4e1a13 100644 --- a/drivers/usb/typec/tipd/spmi.c +++ b/drivers/usb/typec/tipd/spmi.c @@ -136,7 +136,10 @@ static int __regmap_sn201202x_read(void *context, if (err) return err; - if (sn->select_polled) { + if (sn->select_polled || + (sn->polled && + of_device_is_compatible(sdev->dev.of_node, + "apple,t8132-sn201202x"))) { u8 size; /* Selection completion does not establish the payload's length. */ diff --git a/tools/testing/selftests/drivers/apple/sn201202x-transport.py b/tools/testing/selftests/drivers/apple/sn201202x-transport.py index 31d9cb0510631..481e58e959600 100755 --- a/tools/testing/selftests/drivers/apple/sn201202x-transport.py +++ b/tools/testing/selftests/drivers/apple/sn201202x-transport.py @@ -49,13 +49,15 @@ def main(): static u8 selected, advertised; static unsigned polls, busy_cycles, writes, length_reads, payload_reads, bytes; static int select_error, status_error, length_error, payload_error; -static bool wrong, forever, completed, length_checked; +static bool wrong, forever, completed, length_checked, select_irq_done, t8132_compat; static struct tps6598x *spmi_device_get_drvdata(struct spmi_device *s) { return &s->tps; } static struct sn201202x *tps_to_sn(struct tps6598x *t) { (void)t; return &sn; } static void reinit_completion(struct completion *c) { (void)c; } static bool wait_for_completion_timeout(struct completion *c,unsigned n) -{ (void)c; (void)n; return false; } +{ (void)c; (void)n; return select_irq_done; } static void msleep(unsigned n) { (void)n; } +static bool of_device_is_compatible(void *node,const char *name) +{ assert(!strcmp(name,"apple,t8132-sn201202x")); return node != NULL && t8132_compat; } static int spmi_register_zero_write(struct spmi_device *s,u8 reg) { (void)s; selected=reg; writes++; return select_error; } static int spmi_register_read(struct spmi_device *s,u8 reg,u8 *value) @@ -75,7 +77,8 @@ def main(): static int spmi_ext_register_read(struct spmi_device *s,unsigned off,void *val,size_t len) { assert(completed); - if(sn.select_polled) assert(length_checked); + if(sn.select_polled || (sn.polled && s->dev.of_node && t8132_compat)) + assert(length_checked); assert(len>0 && len<=16 && off==0x20+bytes && off+len<=0x60); payload_reads++; if(payload_error) return payload_error; @@ -103,7 +106,7 @@ def main(): selected=0; advertised=4; busy_cycles=2; polls=writes=length_reads=payload_reads=bytes=0; select_error=status_error=length_error=payload_error=0; - wrong=forever=completed=length_checked=false; + wrong=forever=completed=length_checked=select_irq_done=t8132_compat=false; } int main(void) { @@ -152,20 +155,39 @@ def main(): puts("ok 4 - transport errors and invalid transfer bounds propagate"); clean(&s); sn.polled=true; sn.select_polled=false; reg=0x5f; advertised=0; assert(!regmap_sn201202x_read(&s,®,1,out,4) && !length_reads && bytes==4); - puts("ok 5 - older SN201202x transport behavior preserved"); + clean(&s); sn.polled=true; sn.select_polled=false; s.dev.of_node=NULL; t8132_compat=true; + reg=0x5f; advertised=0; + assert(!regmap_sn201202x_read(&s,®,1,out,4) && !length_reads && bytes==4); + clean(&s); sn.polled=false; sn.select_polled=false; select_irq_done=true; + busy_cycles=0; t8132_compat=true; reg=0x5f; advertised=0; + assert(!regmap_sn201202x_read(&s,®,1,out,4) && !length_reads && bytes==4); + puts("ok 5 - older SN201202x and IRQ-backed select transport behavior preserved"); + clean(&s); sn.polled=true; sn.select_polled=false; t8132_compat=true; reg=0x5f; advertised=4; + memset(out,0xa5,sizeof(out)); + assert(!regmap_sn201202x_read(&s,®,1,out,4) && length_reads==1 && length_checked && bytes==4); + clean(&s); sn.polled=true; sn.select_polled=false; t8132_compat=true; reg=0x5f; advertised=3; + assert(regmap_sn201202x_read(&s,®,1,out,4)==-EIO && length_reads==1 && !payload_reads); + clean(&s); sn.polled=true; sn.select_polled=false; t8132_compat=true; reg=0x5f; advertised=65; + assert(regmap_sn201202x_read(&s,®,1,out,4)==-EIO && length_reads==1 && !payload_reads); + puts("ok 6 - legacy fully polled T8132 payload-length check preserved"); return 0; } ''' busy = program.replace("err || val == reg", "err || (val & 0x7f) == reg") - unchecked = program.replace("if (sn->select_polled)", "if (false && sn->select_polled)", 1) + unchecked = program.replace("sn->select_polled ||", "false &&", 1) + polled_t8132_unchecked = program.replace("sn->polled &&", "false &&", 1) + irq_select_compat = program.replace("sn->polled &&", "true &&", 1) oversized = program.replace("size > TPS_MAX_LEN", "false", 1) - assert all(text != program for text in [busy, unchecked, oversized]) + assert all(text != program for text in [busy, unchecked, polled_t8132_unchecked, irq_select_compat, oversized]) resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) - print("TAP version 13\n1..6", flush=True) + print("TAP version 13\n1..7", flush=True) with tempfile.TemporaryDirectory(prefix="sn201202x-transport-") as directory: tmp = Path(directory) for name, text in [("production", program), ("busy", busy), - ("unchecked", unchecked), ("oversized", oversized)]: + ("unchecked", unchecked), + ("polled_t8132_unchecked", polled_t8132_unchecked), + ("irq_select_compat", irq_select_compat), + ("oversized", oversized)]: c, binary = tmp / (name + ".c"), tmp / name c.write_text(text) options = [] if name == "production" else ["-Wno-unused-function"] @@ -176,7 +198,7 @@ def main(): result.check_returncode() elif result.returncode == 0: raise RuntimeError(f"negative control passed: {name}") - print("ok 6 - busy, missing-length and oversize negative controls rejected") + print("ok 7 - busy, missing-length, polled-T8132, IRQ-compat and oversize negative controls rejected") return 0