Skip to content

t602x: PMU RTC wake alarm (M2 Pro/Max/Ultra), on top of #351 - #522

Draft
unTanana wants to merge 6 commits into
omacom:integration/aurorafrom
unTanana:t602x-rtc-alarm
Draft

unTanana wants to merge 6 commits into
omacom:integration/aurorafrom
unTanana:t602x-rtc-alarm

Conversation

@unTanana

Copy link
Copy Markdown

This makes the PMU's RTC wake alarm work on T602x (M2 Pro/Max/Ultra): rtcwake, and timed wakes from s2idle. It is one device-tree commit on top of #351 (T600x), and needs #351's rtc_alarm_event cell and driver change. Only the last commit is new; the five before it are #351, rebased unchanged onto the current integration/aurora (it applied without conflicts). Draft until #351 merges; I'll rebase then.

Patch

arm64: dts: apple: t602x: in t602x-die0.dtsi, describe the alarm:

  • nub-spmi0 as an interrupt controller on AIC 724;
  • the alarm's nvmem cells on the Maverick PMU, at the same offsets as T600x: info-rtc_alarm_ctrl 0x1401, info-rtc_alarm_offset 0x140c, info-rtc_alarm_event 0x14c0, info-rtc_irq_mask_offset 0x14c2;
  • the rtc node's five cells, its interrupt (peripheral interrupt 2 of nub-spmi0) and wakeup-source.

No driver change beyond #351: T6020's SPMI controller uses the apple,t8103-spmi layout (256 peripheral interrupts, notify at 256), and SPMI transfers and the alarm work with it.

How the PMU behaves on J414c (read through the nvmem device)

  • As macOS left it: control byte 0x41 (armed), alarm parked near the end of 32-bit time.
  • After rtc-macsmc's probe: control 0x01, mask 0x01 (disarmed).
  • Armed: control 0x41, mask 0x00. On the alarm's second, before the driver services it: control 0x03 (enable cleared, event set) and the event byte at 0x14c0 reads 1.
  • After the stock driver services it: control 0x01, but 0x14c0 stays 1, and the next alarm did not fire (2 of 2) until 1 was written to 0x14c0. This is the Maverick behaviour t600x: PMU RTC wake alarm (SPMI notify at 192, Maverick event clear, DT) #351 handles.

Testing on J414c (MacBook Pro 14" M2 Max), linux-aurora 7.2.11.aurora14, m1n1-aurora 1.6.1.aurora22, os-fw 13.5, Omarchy 4.5 (omarchy-mac 0.2.3):

  • Setup: the same description as a boot-time overlay through omarchy-mac-boot's dtb-overlays, the stock rtc-macsmc (without t600x: PMU RTC wake alarm (SPMI notify at 192, Maverick event clear, DT) #351), and 0x14c0 cleared by hand before each alarm. The device tree built from this patch has the same properties and cells as the live one; only phandle numbers differ.
  • Awake: 3 alarms through /sys/class/rtc/rtc0/wakealarm, 3 interrupts on apple_spmi 2 Edge macsmc-rtc, each on its second.
  • s2idle: rtcwake -m freeze -s 30 ended on the alarm 3 of 3 times (back after 31.4–31.9 s, /sys/power/pm_wakeup_irq = the macsmc-rtc interrupt each time), and 1 of 1 at 1800 s.
  • Lid closed: 7 of 7 alarm wakes from a lid-closed suspend (1 at 150 s, 6 at 60 s). After a wake with the lid still closed, logind suspended again after its 30 s holdoff. The panel lit for about 20 s behind the closed lid before the compositor turned it off.
  • Sleep draw: about 2.8 W in s2idle (about 1820 s; charge_counter fell by 418521 mA·s, 230 mA average at 12.15 V; lid open, Wi-Fi down by NetworkManager, nothing attached; one sample).
  • Build: all eight T602x device trees (J414s, J416s, J474s, J414c, J416c, J475c, J180d, J475d) compile with the kernel's dtc, with the same warnings as without the patch.

Not tested

Credit: JJRPF found the T6020 register map and AIC 724 on a J414s (JJRPF/Aurora-DeepIdle). #351 and #454 are the pattern this follows.

🤖 Generated with Claude Code

CoreyH and others added 6 commits November 24, 2026 21:50
…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>
The Maverick PMU on nub-spmi0 has its RTC alarm at the same offsets as
on T600x (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 724. 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.

T6020's SPMI controller uses the apple,t8103-spmi layout (256
peripheral interrupts, notify at 256), and SPMI transfers and the alarm
work with it, so the SPMI driver needs no change.

As on T600x, a fired alarm stays latched in the event byte until 1 is
written to it, and no later alarm fires until then. So the rtc node
needs the rtc_alarm_event cell from this series.

Tested on J414c (MacBook Pro 14" M2 Max), 7.2.11.aurora14 with the
stock rtc-macsmc and the same description applied as a boot-time device
tree overlay, clearing the event byte by hand before each alarm. Awake
alarms fire on their second (3 of 3; without the clear, the second one
did not fire). Timed s2idle sleeps end on the alarm: 3 of 3 at 30 s,
1 of 1 at 1800 s, and 7 of 7 with the lid closed (60 s and 150 s).
The J414s, J416s, J474s, J416c, J475c, J180d and J475d device trees
compile; they are not tested.

JJRPF found the register map and AIC 724 on a J414s (Aurora-DeepIdle).

Signed-off-by: El Miez <22821635+unTanana@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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