Skip to content

soc: apple: sep: calibrate the Touch ID sensor again after a system sleep - #2202

Closed
sithglan wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
sithglan:thomas/sep-touchid-recalibrate-after-sleep
Closed

sithglan wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
sithglan:thomas/sep-touchid-recalibrate-after-sleep

Conversation

@sithglan

@sithglan sithglan commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

On hold (draft): gig3m's J813 matches after deep sleeps on the unmodified driver (see the comments). I'm testing the unmodified driver again, with the IIDR channel.

On J813 (MacBook Air 13" M5, T8142) Touch ID stopped seeing fingers after the first deep sleep, until the next reboot. The sensor came back after the wake: its registration (PLATFORM_IDENTITY, REGISTER_SENSOR, CLEAR_STATE, serial, nonce, SESSION_SHARE/COMMIT) and the enclave's match operation succeeded, and its data-ready line still fired during the bring-up. But every capture ended with "the capture ended without a frame". Before the sleep, the same boot had enrolled a finger and matched it, with a power cycle of the sensor for every verify.

The SMC's current on the sensor's 3V0 rail showed what was different. The key is IIDR, from the ADT's monitor-current-3v0, which I added as a temporary hwmon channel. During a capture, before a sleep, the rail goes 0 → 1 mA at the bring-up and to 3 mA while the sensor scans for a finger; it reaches about 20 mA while it images one. After a deep sleep it stayed at 1 mA: the sensor never scanned.

Cause

  • The calibration (the enclave's module challenge and the per-device blob) runs once, in the attach-time bring-up, and sensor_calibrated then stays set. A deep sleep puts the enclave to sleep, and the calibration does not survive it.
  • With only sensor_calibrated cleared on resume, the first capture after each wake still stayed at 1 mA; the next bring-up's capture scanned and matched. On a profile with a nonce session the calibration takes effect only in a session made after it. At boot this never shows, because the bring-up that calibrates is the attach-time one, which no capture uses.
  • The sensor's sleep command before the suspend's power-off makes no difference: the same with and without it.

Change

  • pm_wake() calls the new SepData::sensor_after_sleep(). It clears sensor_kept and sensor_calibrated and marks the next calibration as one that a sleep caused.
  • bring_sensor_online(): after such a recalibration, on a profile with a nonce session, it brings the sensor up once more before the capture. That is one extra power cycle and registration, about 0.2 s, once per wake.

Tested on J813

The kernel was this repository's consolidated J813 stack (#2135 plus #2142's USB4), the J813 DT part of #1732 and CONFIG_SPI_APPLE=m. The SEP ran with the driver defaults and xart_guard=1.

  • Before: on one boot, after two 8 s deep sleeps, a touch during the third fresh bring-up after the wakes wasn't seen. The finger had been enrolled on that boot. There is no IIDR reading for the unmodified driver: every reading below was taken with a candidate of this change.
  • With only the flag cleared: after each of 2 sleeps, the first capture stayed at 1 mA and the second and third scanned at 3 mA.
  • With this change: across 4 deep sleeps (8 s PMU alarm), the first capture after each wake scanned at 3 mA, and the log shows "calibrated again after a system sleep; bringing it up once more for the capture".
  • Matches after a wake: fprintd matched after a sleep, and swaylock (pam_fprintd) unlocked with a touch after another one.
  • No regressions seen: no guard refusals, no xarm failures, and the enrolment survived reboots.

This commit is the same patch, cherry-picked onto integration/aurora 0abc2f3. It builds there (Image and modules, LLVM 22), and checkpatch --strict is clean. Other SoCs were not tested: they now recalibrate once after a system sleep, and only nonce-session profiles take the extra bring-up.

cc @Acelogic @DjDeveloperr @RyanTheTide @LiamRay10

…leep

After a deep sleep on J813 every Touch ID capture ended without a frame
until the next boot. The sensor came back, its registration and the
enclave's match operation succeeded, but it never scanned: the SMC's
current on its 3V0 rail (IIDR) stayed at 1 mA during a capture, where it
is 3 mA before a sleep and about 20 mA while it images a finger.

The calibration (the enclave's module challenge and the per-device blob)
runs once, at the attach-time bring-up, and sensor_calibrated then stays
set. A deep sleep puts the enclave to sleep, and that calibration does not
survive it. Clear sensor_calibrated and sensor_kept when the SEP resumes,
so the next bring-up calibrates the sensor again.

On a sensor with a nonce session the calibration only takes effect in a
session made after it: with the recalibration alone, the first capture
after each wake still stayed at 1 mA and the next bring-up's scanned. At
boot this never shows, because the attach-time bring-up that calibrates
is not used for a capture. After a recalibration that a sleep caused,
bring the sensor up once more before the capture.

Tested on J813: after deep sleeps the first capture scans (3 mA) and a
touch matches.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@gig3m

gig3m commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

My J813 doesn't show this, on the same SEP driver. Over four boots and 82 deep sleeps, Touch ID matched 13 times after a wake. The driver never logged "the capture ended without a frame". I can't measure the 3V0 rail, so all I have is the journal.

Same driver. All four kernels are #2135's merged head 408e27268fd6 with a few PRs on top. In all of them, drivers/soc/apple/{sep,sbio,pm,profile}.rs are identical to 408e27268fd6 (empty git diff --stat). For the havok18 tree I also compared them with integration/aurora 0abc2f3, the base of this PR, and they're identical. What's on top:

None of these touch the SEP driver. Nothing there clears sensor_calibrated after it is first set, and T8142 has nonce_session: true (from T8132). pm_wake(), sleep_exit(), sleep_prepare()/sleep_finished(), wake_sensor() and the registration stage resets all leave the flag alone.

Setup:

  • macOS 27.2 / 26B123 stub, EL2 aura 8b9c92ea.
  • CONFIG_SPI_APPLE=m and CONFIG_APPLE_SEP=m, both loaded.
  • mesacal-j813.bin and msrk-j813.bin built by aurora-touchid-setup (11-12). One enrolled finger ("identity count 1").
  • options apple_sep xart_writes=1 provision_keybag=1 xart_guard=1. The diag policy reads xart_writes=1 provision_keybag=1 xart_guard=1 trusted_keys=1 filevault_api=1 xarm_trace=0 refkey_v2=0 identity_override=0 identity_source=dt, and xart_guard_refusals is 0.
  • Boot arguments: appledrm.s2r_untested=1 apple_sleep.deep=1 nvme_apple.sleep_untested=1 apple_centauri.alpha_sleep_untested=1 idle=nop arm64.nowfxt apple_sleep.untested_commit=1 apple_sleep.t8142_wake_s=0 (the first boots used the alarm for test sleeps), and systemd MemorySleepMode=deep.
  • Hyprland with Omarchy's lock screen (quickshell PAM through pam_fprintd). The lock opens a match as soon as the machine wakes, and fprintd is restarted on each resume.

Matches after a deep sleep. Every sleep here logged PM: suspend entry (deep) and "the enclave is back from its sleep request". The SEP attached once per boot, so SepData was never recreated across these sleeps.

Kernel (boot) Deep sleeps Matches (time: number of the sleep on that boot, wake source)
#2135 head + #1732 DT, #2019, #2142, palms, XRGB (11-17 14:12) 72 14:19 #1, 14:23 #2, 15:30 #4, 17:31 #6, 18:10 #7, 18:36 #26, 19:11 #61 (lid); 20:19 #63 (SMC.OutboxNotEmpty, lid opened 3 s later); 06:18 #72 (lid)
+ #2192/#2193/#2195 (11-18 06:38) 6 06:52 #5, 06:54 #6 (lid)
+ #2199/#1906 (11-18 07:30) 2 07:40 #2 (NUB.SPMI0.SW3, a 30 s alarm sleep)
same (11-18 07:46) 2 15:41 #2 (lid)
  • Sleep lengths: from 4 s to 7 h 50 min.
    • The 18:36 match followed a 5 s sleep.
    • The 06:18 match followed a 48 min sleep, the last of a night with an alarm wake every hour.
    • The 15:41 match followed a single 7 h 50 min sleep with no wakes, the second sleep of that boot.
  • First match after each wake: twelve of the 13 matches were the first match operation opened after their wake, 1-6 s after the lid opened. The exception is 07:40: the operation opened at that wake was cancelled with nobody touching, and a new one matched 5 min 46 s later.
  • Unmatched operations:
    • The rest of the operations on these boots that ended without a match were mostly on test alarm wakes with nobody there. The lock cancelled them after 14-30 s.
    • Two were on lid wakes. 11-17 18:12 ended after 5 s; I don't know whether a finger was on the sensor. 18:23 ended at once because I typed my password.
    • None of the unmatched operations logged "the capture ended without a frame".
  • Bring-ups: each boot logged exactly one "registering sensor at bring-up stage 0", at attach. Some bring-ups after wakes logged stage 2: 11 of the 72 sleeps on the first boot (it's a ratelimited message). Since the flag is never cleared, I read this as the sensor calibrated once per boot and never again, yet scanning after these sleeps.
  • Template updates: every match was followed by "template update persisted (user, then master)", 13 of 13.

Today's boot, after the 7 h 50 min sleep:

15:41:31 apple-sleep: back from sleep, boot object resumes 1 -> 2
15:41:31 apple-sleep: wake source: MTP.DOCK.CHANNELS.AP0.IRQ
15:41:31 apple_sep: the enclave is back from its sleep request
15:41:31 apple_sep: sbio: registering sensor at bring-up stage 2
15:41:31 apple_sep: verify: match operation opened (OPERATION_DEVICE_LIST, 1 device(s))
15:41:34 apple_sep: verify: enclave matched identity 87 7c 8a 47 ... (host index present)
15:41:34 apple_sep: sbio: background result (after a match result): TemplatesUpdated
15:41:34 apple_sep: sbio: template update persisted (user, then master)

Differences from your test that I can see:

  • Sleep length: my sleeps include short ones (4-7 s) like your 8 s alarms, but most were lid sleeps of minutes to hours.
  • Userspace: the match opens right at the wake, and fprintd restarts on each resume. Neither should reach sensor_calibrated.
  • The Mac itself: sensor unit and factory calibration records.

I can't tell which of those matters. If it helps, I can run a build with your temporary IIDR hwmon channel on this Mac and log the 3V0 rail before and after a deep sleep.

🤖 Generated with Claude Code

@sithglan

Copy link
Copy Markdown
Contributor Author

Thanks. This is a careful comparison, and it shows a gap in my evidence.

I went back through my logs. Every 3V0 (IIDR) reading in the description was taken with my first candidate (only sensor_calibrated cleared on resume) or its diag builds. None was taken with the unmodified driver. With that candidate, the first capture after a wake stayed at 1 mA and the next ones scanned. That fits "the enclave loses the calibration in its sleep". It fits just as well "a session that carries a calibration doesn't scan", and then the recalibration itself caused it. At boot that session is the attach-time one, which no capture uses.

My only failure on the unmodified driver is one boot. The finger was enrolled on that boot. Then came two 8 s alarm sleeps, and a touch during the third fresh bring-up after the wakes wasn't seen. I have no IIDR for it, and its kernel journal didn't survive. So "Before: every capture stayed at 1 mA" in the description is wrong as written. I'll correct it.

Your 13 first-operation matches without any recalibration point the other way. Next on my side: the unmodified module of the kernel I run, with the IIDR channel, and no enrolment on that boot. I'll take one capture before a sleep, then the first three after an 8 s alarm sleep, and again after a longer sleep. That needs no finger. I'm moving #2202 to draft until then.

And yes, please run IIDR on your Mac. The channel is DT only:

&smc {
	hwmon {
		current-IIDR {
			apple,key-id = "IIDR";
			label = "Touch ID 3V0 Current";
		};
	};
};

Readings: 0 = off, 1 mA = up but not scanning, 3 mA = scanning for a finger, about 20 mA = imaging one. Since your lock opens a match at the wake, a background log across a lid sleep measures exactly your flow:

f=$(grep -l "Touch ID 3V0" /sys/class/hwmon/hwmon*/curr*_label | sed 's/_label$/_input/')
while :; do echo "$(date +%T.%N | cut -c1-12) $(cat "$f")"; sleep 0.5; done > iidr.log

The most useful parts are the lock's first operation after a wake, before you touch, and a capture before the sleep for comparison.

@sithglan
sithglan marked this pull request as draft November 18, 2026 22:13
@sithglan

Copy link
Copy Markdown
Contributor Author

Result: on my J813 the unmodified driver scans after a deep sleep too.

I used the same kernel and DT as before, plus the IIDR channel, with the unmodified SEP module. No finger was enrolled on that boot. The sensor's 3V0 current over each capture's first 6 s:

  • Before a sleep: 3 mA on both captures.
  • After an 8 s alarm deep sleep: 3 mA on the first, second and third capture.
  • After a 60 s deep sleep: the same.

So here too the enclave keeps the calibration across a deep sleep, as on your Mac, and the premise of this PR is wrong. The 1 mA first capture after a wake came from my first candidate: it recalibrated on that bring-up, and a session that carries a calibration doesn't scan. The extra bring-up in the second commit only undid what the first broke. I'm closing this. Thanks for checking it so thoroughly.

The one failure on the unmodified driver is still unexplained. After two 8 s sleeps, a touch wasn't seen, on the same boot as the enrolment. If I can reproduce it with IIDR readings, I'll open an issue for that instead.

@sithglan sithglan closed this Nov 18, 2026
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