From 82d7f19cd501e0e0214cdbfa57f993b39688bbeb Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 13:57:51 +0100 Subject: [PATCH] soc: apple: sep: calibrate the Touch ID sensor again after a system sleep 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 --- drivers/soc/apple/pm.rs | 1 + drivers/soc/apple/sbio.rs | 16 ++++++++++++++++ drivers/soc/apple/sep.rs | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/soc/apple/pm.rs b/drivers/soc/apple/pm.rs index e18e84bb1986a..c611654b382cc 100644 --- a/drivers/soc/apple/pm.rs +++ b/drivers/soc/apple/pm.rs @@ -237,6 +237,7 @@ unsafe extern "C" fn pm_wake() { } // SAFETY: as in `pm_event`. let sep = unsafe { as ForeignOwnable>::borrow(ptr) }; + sep.sensor_after_sleep(); if sep.sleep_exit() { // The enclave slept and is back: report the accessory service online // again, as macOS does right after the wake. diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 0c3b733941936..a8f46d8451e74 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -2255,12 +2255,14 @@ impl SepData { None }; + let mut recalibrated = false; if !self.sensor_calibrated.load(Relaxed) { if !self.calibrate_sensor() { diag::sensor_brought_up(bind, false); return false; } self.sensor_calibrated.store(true, Relaxed); + recalibrated = self.sensor_recalibrate.xchg(false, Relaxed); if parameters.is_none() { let Some(reloaded_patch) = self.wake_sensor() else { diag::sensor_brought_up(bind, false); @@ -2278,6 +2280,20 @@ impl SepData { Some(parameters) => self.finish_sensor_setup(patch, parameters), None => self.complete_bringup(patch), }; + // On a sensor with a nonce session the calibration takes effect only + // in a session made after it: on J813 the capture on the session that + // carried the calibration after a deep sleep never scanned (3V0 rail + // at 1 mA, not 3 mA) and saw no finger, while the next bring-up's did. + // At boot the attach-time bring-up calibrates and the first verify + // brings the sensor up again; after a sleep do that second bring-up + // here, before the capture. + if ok && recalibrated && self.profile.nonce_session { + dev_info_ratelimited!( + self.dev, + "sensor: calibrated again after a system sleep; bringing it up once more for the capture\n" + ); + return self.bring_sensor_online(); + } diag::sensor_brought_up(bind, ok); // The sensor is patched and idle here -- the only safe moment to // configure the data-ready interrupt, which is then left alone for the diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 02fcc78b25564..4a6d31eea7574 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -709,6 +709,8 @@ struct SepData { cold_restore_candidate: Atomic, sensor_calibrated: Atomic, + // Set by a system sleep: the next calibration is a recalibration. + sensor_recalibrate: Atomic, sensor_key_loaded: Atomic, enrol_open: Atomic, @@ -1208,6 +1210,7 @@ impl SepData { xart_refusal_logged: Atomic::new(false), capture_refusal_logged: Atomic::new(false), sensor_calibrated: Atomic::new(false), + sensor_recalibrate: Atomic::new(false), sensor_key_loaded: Atomic::new(false), templates_restored: Atomic::new(false), cold_restore_candidate: Atomic::new(false), @@ -1620,6 +1623,17 @@ impl SepData { } } + /// After a system sleep the sensor is neither kept nor calibrated: its + /// suspend powered it off, and a deep sleep also put the enclave to sleep. + /// On J813 every capture after a deep sleep then ended without a frame + /// until the next boot. The next bring-up calibrates the sensor again, as + /// the first one after boot does. + pub(crate) fn sensor_after_sleep(&self) { + self.sensor_kept.store(false, Relaxed); + self.sensor_calibrated.store(false, Relaxed); + self.sensor_recalibrate.store(true, Relaxed); + } + /// A refused precommit attempt was never sent; reopen normal admission. /// A sent request can be restarted only after actual physical sleep/wake. /// Returns whether the enclave came back from a sleep it was told of.