Repository navigation
Conversation
The charger charges whenever the input allows it; userspace can neither stop at a charge level nor lower the charge current. iOS 15.8.8's AppleSN2400ChargerFunction (iPhone 6s Plus kernelcache) writes 0x0d = min(mA, 2550) / 10 from AppleARMPMUCharger's chargeLimit, which is capped at the ADT charge-limits[0] (1924 mA on the n66; the monitored battery's constant-charge-current-max on all six A9 iPhones). A chargeLimit of 0 writes 0x0d = 0 and leaves the input on: that is how iOS stops charging for IsCharging false, PredictiveChargingInhibit (optimized charging at 80 %) and its PoSM state-of-charge hold, which stops at an upper threshold until the charge falls to a lower one. Turning the input off (0x10 OFF, 0x09 = 0) is iOS's separate inflow inhibit. In control mode without apple,keep-charge-limit: - constant_charge_current (100 mA up to the battery's constant-charge-current-max, 10 mA steps) caps 0x0d; - charge_behaviour inhibit-charge writes 0x0d = 0, force-discharge also turns the input off as the temperature guard does; - the gauge's battery gets charge_control_end_threshold and start_threshold (and charge_behaviour) as a power-supply extension: charging stops at the end threshold and resumes below the start threshold, or 5 % below the end without one. The driver reads the gauge's capacity on the temperature guard's 5 s poll, only while charge control is in use. Without a capacity younger than a minute, or at 10 % and below, it charges as normal. The temperature guard still turns the input off or reduces it. Asleep the work does not run, so the suspend handler also stops charging from the start threshold up; force-discharge keeps the input off. jiffies stand still in s2idle, so resume reads the gauge again before deciding. 0x0d is written again after every cable change and read back while charging is held. Remove and shutdown restore the full limit: a 0 would survive into iBoot and the next boot. A panic or an emergency restart skips shutdown, and the I2C controller cannot write from a restart handler, so probe restores a 0 it finds, also with apple,keep-charge-limit, and warns that a crashed kernel left it. The charger's status bit stays set while 0x0d is 0, so the USB supply reports Not charging while the charge is held and Discharging with force-discharge. Every board whose SN2400 node is in control mode gets this: the A9 iPhones (s800x-iphone.dtsi), the iPhone 6 (N61) and the iPhone 7 and 7 Plus (t8010-7.dtsi). Read-only and apple,keep-charge-limit nodes keep their attributes read-only and register no extension. Tested on an iPhone 6s Plus (N66), RAM-booted, on a Mac's USB port (2026-11-25): inhibit-charge writes 0x0d = 0 and holds the battery at 0 A while the phone runs from the cable (IBUS 270-350 mA), with usb/status Not charging; auto charges again within a second. constant_charge_current 500000 gives 0x0d = 0x32, 123456 rounds to 120000, and values above the battery's limit or below 100 mA are refused. An end threshold below the charge stops charging within 7 s; force-discharge turns the input off (IBUS 0, battery -0.36 A). 0x0d stays 0 across an unplug and replug, and a clean reboot while held hands iOS a charger that charges. The current cap at a wall adapter, the thresholds across suspend and a crash while held were not tested, nor were the N61 and the iPhone 7. Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFMaVf5sMxs7xEyPFZWGEj
ricktav
force-pushed
the
n66/charge-control
branch
from
December 2, 2026 21:32
94e9c6d to
5c502af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets userspace limit charging on the SN2400 charger, the way iOS does it: a charge-current cap, "don't charge" while the phone keeps running from the cable, and a charge-level hold (end and start thresholds) where UPower, GNOME, KDE and TLP look for it.
Draft: four on-device checks are still open (see below).
What
On the
usbsupply (SN2400), in control mode withoutapple,keep-charge-limit:constant_charge_current(rw): 100 mA up to the monitored battery'sconstant-charge-current-max, in 10 mA steps, written to 0x0d. That maximum is iOS's own ceiling (ADTcharge-limits[0]), so a write can never exceed what iOS asks.charge_behaviour(rw):auto,inhibit-charge(0x0d = 0, input on: the phone runs from the cable),force-discharge(also turns the input off, through the temperature guard's path).On the gauge's
battery, as a power-supply extension:charge_control_end_threshold(20..100, 100 = off) andcharge_control_start_threshold: charging stops at the end and resumes below the start (or 5 % below the end).charge_behaviour: the same state as onusb.The driver applies the thresholds itself, on the temperature guard's existing 5 s gauge poll, so no daemon is needed and a crashed daemon cannot leave charging off.
Why this way
iOS 15.8.8's AppleSN2400ChargerFunction writes 0x0d = min(mA, 2550) / 10 from AppleARMPMUCharger's chargeLimit. A chargeLimit of 0 (IsCharging false, PredictiveChargingInhibit, i.e. Optimized Battery Charging at 80 %, and the PoSM state-of-charge hold) writes 0x0d = 0 and leaves the input on. Turning the input off is iOS's separate inflow inhibit. This driver maps
inhibit-chargeto the first andforce-dischargeto the second.Safety
apple,keep-charge-limit) and warns.apple,keep-charge-limitnodes: no writable attribute, no extension.Which boards
The driver change applies to every board whose SN2400 node is in control mode: the A9 iPhones (
s800x-iphone.dtsi: N66, N66m, N71, N71m, N69, N69u), the iPhone 6 (N61,t7000-n61.dts, since #18) and the iPhone 7 / 7 Plus (t8010-7.dtsi). Each one's ceiling is its own DT battery'sconstant-charge-current-max. Only the N66 was tested.Tested
On an iPhone 6s Plus (N66), RAM-booted, on a Mac's USB port, on 2026-11-25. The kernel was built from the pre-migration Orchard patch tree, with this patch as
drivers/power/0074. The driver file on current main is unchanged since that tree (#18 changed only the N61 device tree), and this commit applies without conflicts, byte-identical to the tested patch.battery, 0x0d = 0xc0 (1920000 µA), thresholds 0/100.inhibit-chargesets 0x0d = 0x00 and 0x0e = 0x00. The battery holds at 0 A, IBUS is 270–350 mA from the cable,usb/onlineis 1 andusb/statusis "Not charging".autocharges again within about 1 s (0x0d 0xc0, +0.18 A).current_max0, 0x10 = 0x0c), battery −0.36 A,usb/status"Discharging".autowith end 90 at 100 % stays held; end 100 charges again.reboot -finto iOS, which shows the charging bolt.Local checks on this branch:
scripts/checkpatch.pl --strict: 0 problems in the code. It flags only the missingSigned-off-byand theCo-Authored-Bytrailer spelling.drivers/power/supply/apple_sn2400_charger.obuilds withW=1(orchard_apple16k_defconfig, aarch64 gcc 12) without warnings.Not tested (why this is a draft)
These need a boot at 60 % charge or more. Also not tested:
Known gaps
Commits
constant_charge_currentandcharge_behaviouron the USB supply, end and start thresholds on the gauge's battery, applied in the driver, with the crash and suspend safeguards above.🤖 Generated with Claude Code
https://claude.ai/code/session_01SFMaVf5sMxs7xEyPFZWGEj