Skip to content

A7 charger: resume the D2089 input and restart its charge timer, as iOS 12 does - #228

Closed
ricktav wants to merge 1 commit into
OrchardLinux:mainfrom
ricktav:a7/charge-suspend
Closed

ricktav wants to merge 1 commit into
OrchardLinux:mainfrom
ricktav:a7/charge-suspend

Conversation

@ricktav

@ricktav ricktav commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

An iPad Air (J71) on main's charger code did not charge from a near-empty
battery. At 1 % it was plugged into a Mac's USB-C port (identified as a CDP)
and into a 30 W USB-C charger. Both times the driver identified the source and
set the D2089's input limit (0x4c0) to 1500 mA, but the battery kept
discharging at -224 to -565 mA and went from 1 % to 0 %. After iBoot had
charged it to 7 % while powered off, the same kernel charged it at +823 mA
on the CDP.

I don't know the root cause. No register dump was taken while it failed at
1 %. The only read-only dump is from the charging state at 7 %: 0x10 = 00,
0x4c0..0x4cf = 72 02 c2 72 0e d4 3f 3f f7 3f 0e 00 e1 2d 3f 07,
0x60..0x6c = 0d 03 42 20 3e 00 00 00 00 00 00 00 03. So this PR does what iOS
12 does on the D2089 in two places where main's driver does nothing, and
it logs when either case happens so the next failing run shows which one it was.

What iOS 12 does (AppleD2089PMUPowerSource, J85 12.5.8 kernelcache, static analysis)

  • setInputCurrentLimit writes 0x4c0 = (mA - 75) / 12.5. Before each write,
    a helper read-modify-writes bit 2 of PMIC register 0x10: set for a limit
    below 75 mA, cleared otherwise.
  • "resetting charge TO": when the charger state 0x62 reports an expired
    charge timer (bit 4) and the battery is below 90 %, at most every 300 s,
    it reads 0x4c8, writes back only its bit 3, then writes the value it read.

Changes

  • Driver (apple_tristar_charger): three new fields in struct tristar_pmic
    (input_suspend, timeout and charge_timer), set only for the D2089.
    • Before every input-limit write (write_limit, including the unlocked
      withdrawal from the event handler), bit 2 of the "input" register is set
      or cleared as iOS does it. The driver never writes less than 75 mA, so in
      practice this clears the bit. The first time the bit is found set it
      logs a dev_info ("charger input was suspended ... resuming it").
    • In the poll, with a source attached: if 0x62 bit 4 is set and the
      battery reads below 90 %, the charge timer is pulsed through 0x4c8 as
      above. This happens at most every 300 s per attachment and logs a
      dev_info each time. If the battery charge can't be read, the timer is
      left alone.
  • Binding: an optional fourth register range, input, required for
    apple,d2089-tristar-charger and not allowed for the other compatibles.
  • DT (s5l8960x-air1.dtsi, s5l8960x-mini2.dtsi): <0x10 0x01> as
    input, and the control range grows from <0x4c0 0x01> to
    <0x4c0 0x09> so it reaches 0x4c8.
  • The D2207, D2365 and D2355 are unchanged: nothing is known about the same
    registers on them.
  • devices/j71/device.toml: the charging note records the J71 results above.
    It stays untested. CHANGELOG entry under Unreleased.

The charge current register 0x4c6 (0x3f from iBoot) is left alone.

Testing

  • This exact series has not run on an iPad yet. Next step: plug the J71 in at
    1-2 % and look for the two new log lines and the battery current.
  • orchard build examples/minimal-boot --device j85, --device j71,
    --device j81: built. The J71 and J85 DTBs have the new range. The driver
    also compiles cleanly with W=1.
  • kernel/audit-patches.py --device j85, j81, j71b, j71t, j71: PASS.
  • tools/catalog/generate matrix --check: clean.
  • Unit tests: 927 run, the same 1 failure and 4 errors as on main eab974c
    (test_cascadia_loader, test_ram CLI tests); nothing new.

🤖 Generated with Claude Code

…OS 12

The A7 iPads' Lightning charger now does two things iOS 12
AppleD2089PMUPowerSource does on the D2089:
- with every input-limit write, bit 2 of PMIC register 0x10 is set below
  75 mA and cleared otherwise (setInputCurrentLimit); the driver never
  writes less than 75 mA, so it clears the bit, logging the first time it
  found it set;
- when the charger state 0x62 reports an expired charge timer (bit 4)
  while a source is attached and the battery is below 90 %, the timer is
  restarted through 0x4c8 (the value with only bit 3, then the value),
  at most every 300 s.

The binding gains an "input" register range for 0x10, required on the
D2089; the iPad Air's and iPad mini 2's shared files give it and extend
the control range to 0x4c8. The D2207, D2365 and D2355 are unchanged.

An iPad Air at 1 % kept discharging on a charger while one at 7 %
charged; this series has not run on an iPad yet.

Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ricktav

ricktav commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing this: the register dumps show it isn't the cause.

I caught the failure twice more on the J71 today, at 1–2 % (about 3.65 V, screen on). Once it was on a Mac CDP, once on an Apple USB-C charger, and both times the battery discharged at -270 to -540 mA. A read-only dump in the failing state was identical to the charging state:

  • 0x10 = 00: input not suspended.
  • 0x4c0 = 72: 1500 mA.
  • 0x4c6/0x4c7/0x4ce = 3f.
  • 0x62 = 42: charging, no timeout, not at end of charge.
  • 0x6c = 03.

iOS's restart sequence didn't help either: 0x10 bit 2 set, then cleared, then 0x4c0 rewritten.

At 3.70 V the same kernel charged at +845 to +948 mA from the same sources. So this looks like low-battery behaviour of the D2089 (precharge, or a system-load priority below some VBAT), not the input suspend or the charge timer. Powered off on a charger, it recovers. I'll look into what iOS does at low VBAT and open a new PR if that finds the cause.

@ricktav ricktav closed this Nov 24, 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.

1 participant