Skip to content

t8103: PMU RTC wake alarm (M1), on top of #351 - #504

Draft
enriquebv wants to merge 7 commits into
omacom:integration/aurorafrom
enriquebv:t8103-pmu-rtc-alarm
Draft

enriquebv wants to merge 7 commits into
omacom:integration/aurorafrom
enriquebv:t8103-pmu-rtc-alarm

Conversation

@enriquebv

Copy link
Copy Markdown

This makes the PMU's RTC wake alarm work on T8103 (M1): rtcwake, and timed wakes from s2idle. It is two commits on top of #351 (T600x), and needs #351's rtc_alarm_event cell and driver changes. Only the last two commits are new; the five before them are #351. Draft until #351 merges; I'll rebase then.

Patches

  1. spmi: apple: match apple,t8103-spmi to t600x: PMU RTC wake alarm (SPMI notify at 192, Maverick event clear, DT) #351's T6000 data (192 peripheral interrupts) instead of gen1 (256).
  2. arm64: dts: apple: t8103: describe the alarm:
    • nub-spmi as an interrupt controller on AIC 343;
    • the alarm's nvmem cells on the Sera PMU, at the offsets in macOS's device tree: info-rtc_alarm_ctrl 0xd000, info-rtc_alarm_offset 0xd008, info-rtc_alarm_event 0xd00c, info-rtc_irq_mask_offset 0xd00e (enable mask 0x40, as in rtc-macsmc);
    • the rtc node's five cells, its interrupt (peripheral interrupt 2 of nub-spmi) and wakeup-source.

No rtc-macsmc change: #351's driver works as it is.

How the Sera PMU behaves (read back through the nvmem device while testing):

  • Armed, the control byte reads 0x41 and the alarm holds the requested second + 1. The RTC offset on this Mac is unset (fraction 0), so that is t600x: PMU RTC wake alarm (SPMI notify at 192, Maverick event clear, DT) #351's "arm one second later" patch at work.
  • After the alarm fires and the driver handles it, the control byte reads 0x01 and the event byte at 0xd00c reads 0.
  • I did not check by hand which write clears which latch, as was done for Stowe; the driver's sequence leaves both clear.

Testing on J293 (MacBook Pro 13" M1, 2020), linux-aurora 7.2.11.aurora14-1, m1n1-aurora 1.6.1.aurora22-1, Omarchy on Limine (UKI); OS firmware 13.5, system firmware 26.6.2:

  • Setup: rtc-macsmc and spmi-apple-controller from this branch as out-of-tree modules (LLVM, in the initramfs), plus a small module that applies this device-tree description as an of_changeset at boot, before the SPMI controller probes. The t8103-j293.dtb built from this branch matches that live description property by property (phandle numbers aside).
  • Awake: 3 alarms through /sys/class/rtc/rtc0/wakealarm, 3 interrupts, one per alarm; the alarm is disarmed and the event cleared after each.
  • s2idle: 5 of 5 rtcwake -m freeze -s 20 on battery ended on the alarm (back after 22 s; /sys/power/pm_wakeup_irq is the macsmc-rtc interrupt each time, one interrupt per sleep). 1 of 1 at 3600 s with the lid closed.
  • Sleep draw: about 0.8 W in s2idle, from the SMC charge counter charge_counter (mA·s, checked awake against the SMC's Total System Power: 7.009 W both ways):
    • 301.9 s: 22733 mA·s, 75.3 mA at 11.1 V = 0.84 W;
    • 3601.5 s with the lid closed: 254995 mA·s, 70.8 mA at 11.1 V = 0.79 W.
    • Wi-Fi associated, Bluetooth on, nothing attached.
t8103-rtc-alarm-dt: applied (nub-spmi phandle 253, cells 254-257)
macsmc-rtc macsmc-rtc: registered as rtc0
122:  ...  apple_spmi   2 Edge   macsmc-rtc
run 1: rc=0 back after 22s wake_irq=122 alarm_irqs=1
run 5: rc=0 back after 22s wake_irq=122 alarm_irqs=1
DONE alarm_wakes=5/5

Not tested

  • J274, J313, J456 and J457: their device trees compile with the patch (kernel scripts/dtc, no new warnings), nothing more. I have no such Mac.
  • Wake with an external display attached.
  • A full kernel build: the dtb and the modules were built on their own.
  • dt_binding_check / dtbs_check.

Unrelated, noticed while testing: unbinding 23d0d9300.spmi through sysfs with the stock modules leaves the PMU's nvmem device registered with a freed regmap, and macsmc-reboot still bound to it; loading rtc-macsmc again then oopses in regmap_bulk_read. That's why the test applies the description at boot instead of hot-swapping the driver. I can open a separate issue if that's useful.

The patches were written with Claude's help (each carries Assisted-by:); I've reviewed and tested them, and they carry my Signed-off-by.

🤖 Generated with Claude Code

CoreyH and others added 7 commits November 4, 2026 14:26
…rupts

The controller's interrupt words hold the peripheral interrupts first and
the controller's own events after them, "notify" (the RX FIFO is no
longer empty) first. The driver puts notify at 256, after T6030's 256
peripheral interrupts. T6000's nub-spmi0 has 192: macOS's device tree
numbers its events from 0xc0, and with a reply left in the FIFO the
pending bit is 192 (ack word 6, bit 0).

So once a T6000 device tree gives nub-spmi0 its interrupt, the driver
unmasks bit 256 and waits for a notify that never comes: every SPMI
read times out and the PMU becomes unreachable. Take the peripheral
interrupt count from the match data, 192 for apple,t6000-spmi and 256
for the rest, and derive the notify position, the irq domain's bounds,
the handler's scan and the mask/ack setup from it.

Tested on J314s (M1 Pro): with nub-spmi0's interrupt described, SPMI
transfers complete in 40-60 us and the PMU's RTC alarm wakes the system
from s2idle.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Corey Henderson <nuwanda@gmail.com>
The Maverick PMUs (the M1 Pro's and the M2 Pro's) latch a fired alarm in
an event byte as well as in the alarm control byte, and keep the alarm
interrupt silent until the event byte is cleared by writing 1 to it.
Allow a fifth cell, rtc_alarm_event, after the four alarm cells.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Corey Henderson <nuwanda@gmail.com>
…gister

The Maverick PMUs (the M1 Pro's and the M2 Pro's) latch a fired alarm in
two places: bit 1 of the alarm control byte and an interrupt status
byte. Writing the control byte back with bit 1 set, which is how T6030's
PMU acknowledges the event, leaves the bit set here. It clears when it
is written as 0. The status byte clears when 1 is written to it, and
until then the PMU keeps the alarm interrupt silent, so every later
alarm would be lost.

With the optional rtc_alarm_event cell, clear the status byte before
arming and after firing. The control byte's bit 1 then clears where it
is written as 0. Without the cell, nothing changes.

Tested on J314s (M1 Pro): awake alarms fire on their second and leave
both registers clear, and every timed s2idle sleep that nothing else
woke ended on the alarm.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Corey Henderson <nuwanda@gmail.com>
The time is the SMC's CLKM plus a tick offset, but the PMU's alarm
compares against the PMU's own counter, which CLKM lags by a few ms (5.5
to 6.3 ms on J314s, once 14 to 24 ms right after boot). When the tick
offset's fraction is under that lag, the alarm fires while the time
still reads the second before. The RTC core then finds its timer not
yet expired and sets the same second again, the PMU fires again at
once, and so on until the time catches up: five or six interrupts and a
burst of SPMI traffic for one alarm. That is the state after the PMU
loses power, which leaves the offset at 0.

When the offset's fraction is under 1/32 s, arm the alarm one counter
second later. It then fires within the set second, and read_alarm still
reports the time that was set. For fractions between the lag and 1/32 s
the alarm comes up to a second late, which the tick-offset path already
allowed. The seconds-offset path is unchanged.

Tested on J314s (M1 Pro) with the offset's fraction cleared: three awake
alarms raised one interrupt each, where they raised 6, 5 and 5 before.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Corey Henderson <nuwanda@gmail.com>
The Maverick PMU on nub-spmi0 has an RTC alarm (macOS's device tree:
info-rtc_alarm_ctrl 0x1401, info-rtc_alarm_offset 0x140c,
info-rtc_alarm_event 0x14c0, info-rtc_irq_mask_offset 0x14c2). It raises
peripheral interrupt 2 of nub-spmi0, whose own interrupt is AIC 636.
Describe nub-spmi0 as an interrupt controller and the alarm's four
cells, and give the SMC's rtc node the cells, the alarm interrupt and
wakeup-source.

This needs the SPMI controller to put T6000's notify event at 192
(previous patches); without it, describing the interrupt breaks every
SPMI transfer.

Tested on J314s (M1 Pro) with the same description applied to the live
device tree: the alarm fires on its second, and it wakes the system
from s2idle.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Corey Henderson <nuwanda@gmail.com>
T8103's nub-spmi is laid out like T6000's: macOS's device tree numbers
the controller's own events from 0xc0 (its interrupts list 0xc0 and
0xc4-0xdd on the controller itself, next to AIC 343), so notify is bit
192, not 256. apple,t8103-spmi matched the gen1 data with 256 peripheral
interrupts; match it to the T6000 data instead.

With 256, describing nub-spmi's interrupt in a T8103 device tree would
leave the driver waiting at bit 256 for a notify that never comes, as
on T6000 before the previous change.

Tested on J293 (MacBook Pro 13" M1, 2020), 7.2.11.aurora14, with this
driver as an out-of-tree module and the RTC alarm described (next
patch): the PMU is reachable, and its alarm wakes the system from
s2idle.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Enrique Bernabeu <16876988+enriquebv@users.noreply.github.com>
The Sera PMU on nub-spmi has an RTC alarm (macOS's device tree:
info-rtc_alarm_ctrl 0xd000, info-rtc_alarm_offset 0xd008,
info-rtc_alarm_event 0xd00c, info-rtc_irq_mask_offset 0xd00e, enable
mask 0x40). It raises peripheral interrupt 2 of nub-spmi, whose own
interrupt is AIC 343. Describe nub-spmi as an interrupt controller and
the alarm's four cells, and give the SMC's rtc node the cells, the alarm
interrupt and wakeup-source.

This needs the SPMI controller to put T8103's notify event at 192
(previous patch).

macOS describes an event register for Sera too, so the rtc node gets
the rtc_alarm_event cell like the Maverick and Stowe PMUs. With
rtc-macsmc from this series, a fired alarm reads back with the control
byte at 0x01 (enable and event bits clear) and the event byte at 0.

Tested on J293 (MacBook Pro 13" M1, 2020), 7.2.11.aurora14, with
rtc-macsmc and the SPMI driver from this series as out-of-tree modules
and this description applied to the live device tree at boot, before
the SPMI controller probes: awake alarms raise one interrupt each (3 of
3), and every timed s2idle sleep ended on the alarm (5 of 5 at 20 s on
battery, and 1 of 1 at 3600 s with the lid closed). The J274, J313,
J456 and J457 device trees compile with no new warnings; they are not
tested.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Enrique Bernabeu <16876988+enriquebv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants