From f2aaec48fc757f27f65da9dbbfb4a4bc37e6c1fe Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:09:54 -0600 Subject: [PATCH 1/5] spmi: apple: take interrupts on generation 4 controllers Generation 4 (t8142, t6050) had its interrupt refused at probe. macOS's trace (reported by Dj on the Aurora M5 Pro thread) acks peripheral sources 0..255 per bit in words from +0x600, with the controller fault source 263 at +0x620 bit 7. On K114c the PMIC RTC alarm sets +0x600 bit 2 (read-only probe, alarm armed 20 s out). Take the mask and ack bank offsets from the hw table (gen1 unchanged, shared with a host check in spmi-apple-irq.h). Generation 4 has no mask bank we could find (no word in 0x20..0x7f or 0x500..0x6ff toggles), so sources are masked in the cache only. Commands stay polled: the RX notification is not wired for gen 4. Tested: host check of the register math; compile only, not booted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 63 +++++++++++++++---------- drivers/spmi/spmi-apple-irq-host-test.c | 42 +++++++++++++++++ drivers/spmi/spmi-apple-irq.h | 37 +++++++++++++++ 3 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 drivers/spmi/spmi-apple-irq-host-test.c create mode 100644 drivers/spmi/spmi-apple-irq.h diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index ea0b6fe76b34a..76a0f33281a6d 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -30,14 +30,14 @@ #include #include +#include "spmi-apple-irq.h" + /* SPMI Controller Registers */ #define SPMI_STATUS_REG 0 #define SPMI_CMD_REG 0x4 #define SPMI_RSP_REG 0x8 #define SPMI_ACT_REG 0xa4 -#define SPMI_IRQ_MASK_BASE 0x20 -#define SPMI_IRQ_ACK_BASE 0x60 /* * Peripheral interrupts come first. The RX FIFO notification sits right * after them, followed by the controller's own fault interrupts, so the @@ -59,8 +59,6 @@ * reply FIFO. macOS acks the controller's fault interrupt (source 263, after the 256 * peripheral sources; ack words from 0x600) and empties the queue when the controller starts. */ -#define SPMI_GEN4_IRQ_ACK_BASE 0x600 -#define SPMI_GEN4_FAULT_IRQ (SPMI_MAX_PERIPHERAL_IRQS + 7) #define SPMI_FAULT_QUEUE_MAX 64 #define REG_POLL_INTERVAL_US 10000 @@ -73,6 +71,8 @@ struct apple_spmi_hw { u32 rx_empty; bool legacy_irqs; u32 num_irqs; + u32 irq_mask; + u32 irq_ack; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -82,6 +82,8 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; /* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ @@ -92,6 +94,8 @@ static const struct apple_spmi_hw apple_spmi_t6000 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 192, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; static const struct apple_spmi_hw apple_spmi_gen4 = { @@ -99,6 +103,9 @@ static const struct apple_spmi_hw apple_spmi_gen4 = { .command = 0x210, .reply = 0x220, .rx_empty = BIT(30), + .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN4_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN4_IRQ_ACK, }; struct apple_spmi { @@ -121,23 +128,26 @@ struct apple_spmi { static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_ACK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_ack + (irq / 32) * 4; writel(BIT(irq % 32), reg); } static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - writel(readl(reg) & ~BIT(irq % 32), reg); + /* Generation 4 has no mask bank found: sources are masked in irq_mask_cache only. */ + if (spmi->hw->irq_mask) + writel(readl(reg) & ~BIT(irq % 32), reg); } static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - writel(readl(reg) | BIT(irq % 32), reg); + if (spmi->hw->irq_mask) + writel(readl(reg) | BIT(irq % 32), reg); } static void apple_spmi_irq_ack(struct irq_data *d) @@ -177,8 +187,8 @@ static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 param) /* Ack the fault interrupt, then pop and log every queued fault record */ static void apple_spmi_drain_faults(struct device *dev, struct apple_spmi *spmi) { - void __iomem *ack = spmi->regs + SPMI_GEN4_IRQ_ACK_BASE + (SPMI_GEN4_FAULT_IRQ / 32) * 4; - u32 bit = BIT(SPMI_GEN4_FAULT_IRQ % 32), fault; + void __iomem *ack = spmi->regs + APPLE_SPMI_GEN4_IRQ_ACK + (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * 4; + u32 bit = BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32), fault; int i; if (!spmi->faults) @@ -470,7 +480,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) unsigned long val, offset, bit; chained_irq_enter(chip, desc); - val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + val = readl(spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); raw_pending |= !!val; if (val & BIT(notify % 32)) { apple_spmi_irq_ack_raw(spmi, notify); @@ -479,14 +489,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) } /* Other queues' responses, such as the sleep's own commands at the debug link's cut. */ if (val & ~BIT(notify % 32)) { - writel(val & ~BIT(notify % 32), spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + writel(val & ~BIT(notify % 32), spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); handled = true; } for (offset = 0; offset < notify / 8; offset += sizeof(val)) { unsigned long stray; - val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset); + val = readq(spmi->regs + spmi->hw->irq_ack + offset); raw_pending |= !!val; /* * After a real sleep, sources no driver uses come up pending (on the Neo the @@ -497,8 +507,8 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; if (stray) { - writel(lower_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset); - writel(upper_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset + 4); + writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); + writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); handled = true; } if (val & spmi->irq_used[offset / sizeof(val)] & @@ -528,7 +538,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * unmasked, or it fires again for what was just cleared. */ if (handled) - readl(spmi->regs + SPMI_IRQ_ACK_BASE); + readl(spmi->regs + spmi->hw->irq_ack); chained_irq_exit(chip, desc); } @@ -537,7 +547,8 @@ static void apple_spmi_teardown_irq(void *data) struct apple_spmi *spmi = data; for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); + if (spmi->hw->irq_mask) + writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); @@ -557,8 +568,9 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); - writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset); + if (spmi->hw->irq_mask) + writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info); @@ -570,8 +582,10 @@ static int apple_spmi_init_irq(struct platform_device *pdev, return ret; irq_set_chained_handler_and_data(spmi->irq, apple_spmi_irq_handler, spmi); - apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); - spmi->notify_irq = true; + if (spmi->hw->legacy_irqs) { + apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); + spmi->notify_irq = true; + } return 0; } @@ -619,7 +633,7 @@ static int apple_spmi_resume_noirq(struct device *dev) if (pm_resume_via_firmware()) { bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); for (i = 0; i < spmi->hw->num_irqs / 32; i++) - writel(words[i], spmi->regs + SPMI_IRQ_MASK_BASE + i * 4); + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); } apple_spmi_irq_ack_raw(spmi, spmi->hw->num_irqs); apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); @@ -672,9 +686,6 @@ static int apple_spmi_probe(struct platform_device *pdev) if (spmi->irq < 0 && spmi->irq != -ENXIO) return spmi->irq; if (spmi->irq >= 0) { - if (!spmi->hw->legacy_irqs) - return dev_err_probe(&pdev->dev, -EOPNOTSUPP, - "Generation 4 interrupt layout is not supported\n"); ret = apple_spmi_init_irq(pdev, spmi, spmi->irq); if (ret) return ret; diff --git a/drivers/spmi/spmi-apple-irq-host-test.c b/drivers/spmi/spmi-apple-irq-host-test.c new file mode 100644 index 0000000000000..89dbbacfedfb2 --- /dev/null +++ b/drivers/spmi/spmi-apple-irq-host-test.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Host check for the Apple SPMI interrupt register layout (not built by kbuild): + * cc -Wall -Werror -o /tmp/spmi-irq-test drivers/spmi/spmi-apple-irq-host-test.c && /tmp/spmi-irq-test + * + * The expected values are the layouts measured on hardware or traced from macOS: + * generation 1 (T8103/T6000): mask words from 0x20, ack/pending words from 0x60; + * generation 4 (T8142/T6050): ack/pending words from 0x600, source n in bit n % 32 + * of word n / 32, the controller's fault source 263 acked at 0x620 bit 7. + */ +#include +#include +#include + +typedef uint32_t u32; +#define BIT(n) (1U << (n)) + +#include "spmi-apple-irq.h" + +int main(void) +{ + /* generation 1 */ + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_MASK, 3) == 0x20); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 3) == 0x60); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 40) == 0x64); + assert(apple_spmi_irq_bit(40) == BIT(8)); + + /* generation 4: the PMU alarm source seen on K114c, the hpm2 wake bit macOS acks, the fault source */ + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 2) == 0x600); + assert(apple_spmi_irq_bit(2) == BIT(2)); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 19) == 0x600); + assert(apple_spmi_irq_bit(19) == BIT(19)); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, APPLE_SPMI_GEN4_FAULT_IRQ) == 0x620); + assert(apple_spmi_irq_bit(APPLE_SPMI_GEN4_FAULT_IRQ) == BIT(7)); + /* no hardware mask bank for gen 4 */ + assert(APPLE_SPMI_GEN4_IRQ_MASK == 0); + /* the last peripheral source is in word 7 */ + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 255) == 0x61c); + + puts("spmi-apple-irq host check: ok"); + return 0; +} diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h new file mode 100644 index 0000000000000..dce85d2d65ae2 --- /dev/null +++ b/drivers/spmi/spmi-apple-irq.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Apple SPMI controller interrupt register layout, shared with the host check + * (spmi-apple-irq-host-test.c). + * + * Peripheral sources 0..255 come first, then the RX FIFO notification (256) and + * the controller's own fault sources. Source n sits in bit n % 32 of word n / 32 + * of both the mask bank and the ack/pending bank. + */ +#ifndef _SPMI_APPLE_IRQ_H +#define _SPMI_APPLE_IRQ_H + +/* Generation 1 (T8103, T6000) */ +#define APPLE_SPMI_GEN1_IRQ_MASK 0x20 +#define APPLE_SPMI_GEN1_IRQ_ACK 0x60 + +/* + * Generation 4 (T8142, T6050): ack and pending words from 0x600, the fault source + * 263 acked at 0x620 bit 7 (traced from macOS under the hypervisor). The mask bank + * is not found; see APPLE_SPMI_GEN4_IRQ_MASK. + */ +#define APPLE_SPMI_GEN4_IRQ_ACK 0x600 +#define APPLE_SPMI_GEN4_FAULT_IRQ (256 + 7) +/* No mask bank found by toggling every word in 0x20..0x7f and 0x500..0x6ff (K114c): 0 = soft mask only */ +#define APPLE_SPMI_GEN4_IRQ_MASK 0 + +static inline u32 apple_spmi_irq_reg(u32 base, u32 irq) +{ + return base + (irq / 32) * 4; +} + +static inline u32 apple_spmi_irq_bit(u32 irq) +{ + return BIT(irq % 32); +} + +#endif /* _SPMI_APPLE_IRQ_H */ From d18d765c60c034f71deb253100fe878dbdefb8d5 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:23:27 +0000 Subject: [PATCH 2/5] spmi: apple: use the generation 4 mask bank at +0x400 Probe on K114c: +0x400..0x41c toggle and restore (8 words), +0x420 does not, matching the +0x600 ack bank 0x200 above (Dj, seq 713, from write offsets in a macOS trace). The alarm latches +0x600 bit 2 once the PMIC alarm mask byte 0x200e is 0 (as rtc-macsmc writes it) and a write of 4 to +0x600 clears it (measured). Whether the +0x400 bit gates the AIC line is not measured. Drop the cache-only masking for gen 4. On a firmware resume re-apply the runtime mask, since a firmware sleep entry writes the mask bank itself. Host check extended; compile only, not booted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 24 ++++++++++++++---------- drivers/spmi/spmi-apple-irq-host-test.c | 7 +++++-- drivers/spmi/spmi-apple-irq.h | 6 +++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 76a0f33281a6d..178f8ddbae5b9 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -137,17 +137,14 @@ static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq) { u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - /* Generation 4 has no mask bank found: sources are masked in irq_mask_cache only. */ - if (spmi->hw->irq_mask) - writel(readl(reg) & ~BIT(irq % 32), reg); + writel(readl(reg) & ~BIT(irq % 32), reg); } static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq) { u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - if (spmi->hw->irq_mask) - writel(readl(reg) | BIT(irq % 32), reg); + writel(readl(reg) | BIT(irq % 32), reg); } static void apple_spmi_irq_ack(struct irq_data *d) @@ -547,8 +544,7 @@ static void apple_spmi_teardown_irq(void *data) struct apple_spmi *spmi = data; for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) - if (spmi->hw->irq_mask) - writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); @@ -568,8 +564,7 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { - if (spmi->hw->irq_mask) - writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(0, spmi->regs + spmi->hw->irq_mask + offset); writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } @@ -624,8 +619,17 @@ static int apple_spmi_resume_noirq(struct device *dev) unsigned long flags; size_t i; - if (!spmi->notify_parked) + if (!spmi->notify_parked) { + /* Gen 4 never parks the notification, but a firmware sleep entry writes the mask bank itself. */ + if (spmi->hw->legacy_irqs || !spmi->irqd || !pm_resume_via_firmware()) + return 0; + raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); + bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); + for (i = 0; i < spmi->hw->num_irqs / 32; i++) + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); + raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags); return 0; + } guard(mutex)(&spmi->fifo_lock); raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); diff --git a/drivers/spmi/spmi-apple-irq-host-test.c b/drivers/spmi/spmi-apple-irq-host-test.c index 89dbbacfedfb2..5ab780d73bc05 100644 --- a/drivers/spmi/spmi-apple-irq-host-test.c +++ b/drivers/spmi/spmi-apple-irq-host-test.c @@ -32,8 +32,11 @@ int main(void) assert(apple_spmi_irq_bit(19) == BIT(19)); assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, APPLE_SPMI_GEN4_FAULT_IRQ) == 0x620); assert(apple_spmi_irq_bit(APPLE_SPMI_GEN4_FAULT_IRQ) == BIT(7)); - /* no hardware mask bank for gen 4 */ - assert(APPLE_SPMI_GEN4_IRQ_MASK == 0); + /* gen 4 mask bank (measured on K114c, Dj's HV trace writes +0x420), mirrors the ack bank */ + assert(APPLE_SPMI_GEN4_IRQ_MASK == 0x400); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 2) == 0x400); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 263) == 0x420); + assert(APPLE_SPMI_GEN4_IRQ_ACK - APPLE_SPMI_GEN4_IRQ_MASK == 0x200); /* the last peripheral source is in word 7 */ assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 255) == 0x61c); diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h index dce85d2d65ae2..d43dfa1c606cb 100644 --- a/drivers/spmi/spmi-apple-irq.h +++ b/drivers/spmi/spmi-apple-irq.h @@ -17,12 +17,12 @@ /* * Generation 4 (T8142, T6050): ack and pending words from 0x600, the fault source * 263 acked at 0x620 bit 7 (traced from macOS under the hypervisor). The mask bank - * is not found; see APPLE_SPMI_GEN4_IRQ_MASK. + * is at 0x400 (see APPLE_SPMI_GEN4_IRQ_MASK). */ #define APPLE_SPMI_GEN4_IRQ_ACK 0x600 #define APPLE_SPMI_GEN4_FAULT_IRQ (256 + 7) -/* No mask bank found by toggling every word in 0x20..0x7f and 0x500..0x6ff (K114c): 0 = soft mask only */ -#define APPLE_SPMI_GEN4_IRQ_MASK 0 +/* Mask bank mirrors the ack bank 0x200 below; +0x400..0x41c toggle on K114c, +0x420 does not. */ +#define APPLE_SPMI_GEN4_IRQ_MASK 0x400 static inline u32 apple_spmi_irq_reg(u32 base, u32 irq) { From 7ae43cd62b3eb7c83aef0347e33656776e7f8bb7 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 19 Nov 2026 12:07:56 -0600 Subject: [PATCH 3/5] spmi: apple: read the fault queue before the shared ack, limit gen4 mask writes Both open code points from review: The controller's fault source (263, word 0x620 bit 7 on gen4) shares its ack word with the notification word the handler reads first, and the stray-source path acked it directly: queued fault records were lost. Drain the queue before the bit is acked, in both the notification-word path and the readq stray path. gen4 has no notification source, and the word at +0x420 does not behave as a mask bank, so the init and teardown loops now write only the num_irqs / 32 mask words on gen4 (the legacy controllers keep the extra notification word). The host-test file is dropped: kbuild never built it and it checked constants against themselves. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 27 +++++++++++++-- drivers/spmi/spmi-apple-irq-host-test.c | 45 ------------------------- drivers/spmi/spmi-apple-irq.h | 3 +- 3 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 drivers/spmi/spmi-apple-irq-host-test.c diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 178f8ddbae5b9..b3a1864d142a7 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -112,6 +112,7 @@ struct apple_spmi { void __iomem *regs; void __iomem *faults; unsigned int nfaults; + struct device *dev; const struct apple_spmi_hw *hw; struct mutex fifo_lock; struct completion fifo_rx; @@ -478,6 +479,17 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) chained_irq_enter(chip, desc); val = readl(spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); + /* + * On gen4 the controller's own fault source shares this last ack word + * (0x620, bit 7). Its queued records must be read before the source is + * acked, or drain_faults() never sees them. + */ + if (!spmi->hw->legacy_irqs && spmi->faults && + (val & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { + apple_spmi_drain_faults(spmi->dev, spmi); + val &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); + handled = true; + } raw_pending |= !!val; if (val & BIT(notify % 32)) { apple_spmi_irq_ack_raw(spmi, notify); @@ -503,6 +515,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * pending for its unmask: it isn't a bad interrupt either. */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; + if (stray && !spmi->hw->legacy_irqs && spmi->faults && + offset == (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * sizeof(val) && + (stray & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { + /* Same rule as above: read the queued records first. */ + apple_spmi_drain_faults(spmi->dev, spmi); + stray &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); + handled = true; + } if (stray) { writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); @@ -543,7 +563,8 @@ static void apple_spmi_teardown_irq(void *data) { struct apple_spmi *spmi = data; - for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) + for (size_t offset = 0; offset < spmi->hw->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); + offset += 4) writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); @@ -563,7 +584,8 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); - for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { + for (size_t offset = 0; offset < spmi->hw->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); + offset += 4) { writel(0, spmi->regs + spmi->hw->irq_mask + offset); writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } @@ -662,6 +684,7 @@ static int apple_spmi_probe(struct platform_device *pdev) return -ENOMEM; spmi = spmi_controller_get_drvdata(ctrl); + spmi->dev = &pdev->dev; spmi->hw = device_get_match_data(&pdev->dev); if (!spmi->hw) return -EINVAL; diff --git a/drivers/spmi/spmi-apple-irq-host-test.c b/drivers/spmi/spmi-apple-irq-host-test.c deleted file mode 100644 index 5ab780d73bc05..0000000000000 --- a/drivers/spmi/spmi-apple-irq-host-test.c +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Host check for the Apple SPMI interrupt register layout (not built by kbuild): - * cc -Wall -Werror -o /tmp/spmi-irq-test drivers/spmi/spmi-apple-irq-host-test.c && /tmp/spmi-irq-test - * - * The expected values are the layouts measured on hardware or traced from macOS: - * generation 1 (T8103/T6000): mask words from 0x20, ack/pending words from 0x60; - * generation 4 (T8142/T6050): ack/pending words from 0x600, source n in bit n % 32 - * of word n / 32, the controller's fault source 263 acked at 0x620 bit 7. - */ -#include -#include -#include - -typedef uint32_t u32; -#define BIT(n) (1U << (n)) - -#include "spmi-apple-irq.h" - -int main(void) -{ - /* generation 1 */ - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_MASK, 3) == 0x20); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 3) == 0x60); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 40) == 0x64); - assert(apple_spmi_irq_bit(40) == BIT(8)); - - /* generation 4: the PMU alarm source seen on K114c, the hpm2 wake bit macOS acks, the fault source */ - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 2) == 0x600); - assert(apple_spmi_irq_bit(2) == BIT(2)); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 19) == 0x600); - assert(apple_spmi_irq_bit(19) == BIT(19)); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, APPLE_SPMI_GEN4_FAULT_IRQ) == 0x620); - assert(apple_spmi_irq_bit(APPLE_SPMI_GEN4_FAULT_IRQ) == BIT(7)); - /* gen 4 mask bank (measured on K114c, Dj's HV trace writes +0x420), mirrors the ack bank */ - assert(APPLE_SPMI_GEN4_IRQ_MASK == 0x400); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 2) == 0x400); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 263) == 0x420); - assert(APPLE_SPMI_GEN4_IRQ_ACK - APPLE_SPMI_GEN4_IRQ_MASK == 0x200); - /* the last peripheral source is in word 7 */ - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 255) == 0x61c); - - puts("spmi-apple-irq host check: ok"); - return 0; -} diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h index d43dfa1c606cb..4134ef37ff369 100644 --- a/drivers/spmi/spmi-apple-irq.h +++ b/drivers/spmi/spmi-apple-irq.h @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * Apple SPMI controller interrupt register layout, shared with the host check - * (spmi-apple-irq-host-test.c). + * Apple SPMI controller interrupt register layout. * * Peripheral sources 0..255 come first, then the RX FIFO notification (256) and * the controller's own fault sources. Source n sits in bit n % 32 of word n / 32 From 3aa7b99a6fe4aa20df50e3bba977f6c5c0ed3d6c Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:27:53 -0600 Subject: [PATCH 4/5] spmi: apple: drop the unreachable fault drain in the stray-queue loop The stray-queue loop visits ack words 0 to 3 (bytes 0 to 24), while the gen4 fault source lives in word 8 (0x620), which the chained handler already reads and drains before acking. The hunk also compared a word index against byte offsets. It could never fire; remove it. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index b3a1864d142a7..3a1eccb59c099 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -515,14 +515,6 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * pending for its unmask: it isn't a bad interrupt either. */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; - if (stray && !spmi->hw->legacy_irqs && spmi->faults && - offset == (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * sizeof(val) && - (stray & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { - /* Same rule as above: read the queued records first. */ - apple_spmi_drain_faults(spmi->dev, spmi); - stray &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); - handled = true; - } if (stray) { writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); From 36ef4f8b60cf6980fe0dd6bf807aa791f29c08dd Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:09:55 +0000 Subject: [PATCH 5/5] arm64: dts: apple: t6050: wire the PMIC RTC alarm interrupt nub-spmi0 becomes an interrupt controller on AIC 726 (ADT interrupts[1]; inference, not booted) and smc_rtc takes peripheral source 2 as a wake source with the T6030-style rtc_ctrl/rtc_alarm/rtc_alarm_mask cells (abbey 0x2000/0x2008/0x200e). Compile only. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6050-die0.dtsi | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-die0.dtsi b/arch/arm64/boot/dts/apple/t6050-die0.dtsi index fdd2f6bfa746a..32a45704c849d 100644 --- a/arch/arm64/boot/dts/apple/t6050-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-die0.dtsi @@ -138,8 +138,13 @@ /* ADT info-clock_offset [0x2100, 6]: M1-style 32768 Hz ticks, as on T6040. */ smc_rtc: rtc { compatible = "apple,smc-rtc"; - nvmem-cells = <&rtc_offset>; - nvmem-cell-names = "rtc_offset"; + nvmem-cells = <&rtc_offset>, <&rtc_ctrl>, <&rtc_alarm>, + <&rtc_alarm_mask>; + nvmem-cell-names = "rtc_offset", "rtc_ctrl", "rtc_alarm", + "rtc_alarm_mask"; + /* The PMIC's RTC alarm, peripheral interrupt 2 of nub-spmi0 */ + interrupts-extended = <&nub_spmi0 2 IRQ_TYPE_EDGE_RISING>; + wakeup-source; }; }; @@ -220,7 +225,8 @@ }; /* - * /arm-io/nub-spmi0: reg[0] 0x8a014000 +0x4000, generation 4 (no IRQ: the driver refuses one). + * /arm-io/nub-spmi0: reg[0] 0x8a014000 +0x4000, generation 4. ADT interrupts[1] is 726, the line the + * peripheral sources arrive on (inference from macOS's wake trace, not yet booted). * No power-domains: NUB_SPMI0 is critical and on (Aura talks to the PMU here every boot), and * binding the pwrstate driver would write the PS register at probe. */ @@ -229,6 +235,9 @@ reg = <0x2 0x8a014000 0x0 0x4000>; #address-cells = <2>; #size-cells = <0>; + interrupts = ; + interrupt-controller; + #interrupt-cells = <2>; /* spmi-abbeyL1, is-primary: USID 0xe. Read-only use: cells, never a whole-device read. */ pmu: pmic@e { @@ -245,6 +254,19 @@ reg = <0x2001 1>; }; + /* ADT spmi-abbeyL1 RTC cells, as on T6030 */ + rtc_ctrl: rtc-ctrl@2000 { + reg = <0x2000 1>; + }; + + rtc_alarm: rtc-alarm@2008 { + reg = <0x2008 4>; + }; + + rtc_alarm_mask: rtc-alarm-mask@200e { + reg = <0x200e 1>; + }; + rtc_offset: rtc-offset@2100 { reg = <0x2100 6>; /* ADT info-clock_offset */ };