Skip to content

max77705: S9 charger guard for iOS 16.5 (max77705_chg=, off by default): Samsung's 5 V limits, temperature bands, SIOP - #421

Merged
claudiusthebot merged 2 commits into
mainfrom
max77705-chg-guard
Nov 27, 2026
Merged

claudiusthebot merged 2 commits into
mainfrom
max77705-chg-guard

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

What

The iOS 16.5 kernel's MAX77705 driver only read the S9's charger (plus the watchdog kick with max77705_wdt=1), so the phone charged at whatever S-Boot left. This adds a charger guard, off by default:

  • max77705_chg=1: read only. Logs what it would write.
  • max77705_chg=2: writes Samsung's own S9 limits at 5 V, with the temperature rules.
  • max77705_siop=0: turns off the in-use limit. It is on by default when the guard is on.

The rules are the existing hakios.max77705_charge.h, the same rules the iOS 27 guard uses (#415). This PR adds the iOS 16.5 caller (hakios.max77705_guard.h) and two caps that only lower the limits. AFC (9 V) is not in this PR. It will come later as its own off-by-default boot-arg.

Registers written (max77705_chg=2), charger at I2C 0x69

reg bits values source (S9 DTS exynos9810-starlte_eur_open_26.dts)
CNFG_09 0xC0 [6:0] input limit SDP 475 (0x12), CDP 1500 (0x3B), DCP 1800 (0x47), unknown 500 (0x13); SIOP 1200 (0x2F); host 1500 cable-info current groups; siop_input_limit_current
CNFG_02 0xB9 [5:0] charge current SDP 550 (0x0B), CDP 1500 (0x1E), DCP 2100 (0x2A), unknown 500 (0x0A); ≤15 °C 700 (0x0E); SIOP 1000 (0x14) same groups; swelling_low_temp_current; siop_charging_limit_current
CNFG_00 0xB7 bit 0 only, and only in mode 4/5 off at ≥41.0 °C (on at 39.0), ≤5.0 °C (on at 10.0), no thermistor reading, full (recharge 4280 mV/98 %), session time over; latched off at 45 °C, on a chip fault, float >4350 mV, or a read-back mismatch swelling_*, recharge_condition_*, *_charging_total_time
CNFG_06 0xBD [1:0] WDTCLR=01 the watchdog kicked every poll while WDTEN is on Samsung max77705_chg_set_wdtmr_kick()

Each register is written only when its value differs, only the named bits change, and every write is read back. Nothing is written when CHGPROT is locked, without VBUS, or after a failed read. Never written: the float voltage, the timers, CHGPROT, the MUIC (no AFC, the D+/D- switch untouched), the gauge, and anything non-volatile. It runs on the S9 only; on star2lte and crownlte it says it is for the S9 and does nothing.

Taken from Jesvi-iOS (jesvi-eulah, with the owner's approval)

Ideas only, no code copied. The values are the S9's own, not the S20's.

  • SIOP ("in use") limit: docs/devices/x1slte/charging-samsung.md (fc07d1b).
  • A computer configured on the USB link means a computer port, whatever the MUIC detected: cap at 1500 mA (3a4db07, fb882cf). No 9 V request with a host on the link (a57b321). Here the cap is the S9's CDP limit, 1500/1500, and ask_9v is cleared.

Jesvi-iOS is credited in NOTICE and in docs/devices/starlte-charging.md.

Other changes

  • hakios_panel_level() in hakios.backlight.cpp (the panel's last level, -1 if unknown).
  • hakios_usb_gadget_host() in hakios.dwc3.c, with a stub that returns false when the gadget isn't built.
  • Host tests: tools/max77705-charge-test.sh now also checks that the caps only ever lower, across every input/charge value (871 213 checks, 0 failures).
  • tools/arch-size.allow: hakios.max77705.c goes 1125→1130 (+5: the guard's hooks; the guard itself is split out into hakios.max77705_guard.h), and hakios.dwc3.c goes 2298→2302 (+4: the new accessor).
  • Generated catalogues regenerated (boot-args, symbols, common_defconfig, reference/drivers).

The checks run locally all pass: hakios-config-test, boot-args-test/--check, drivers-check, arch-check, hakios-device check, docs-gen --check, docs-check, max77705-charge-test, provenance. The guard logic was also compiled and run on the host against a fake register file under ASan/UBSan, and clang reported no warnings with -Wconversion -Wshorten-64-to-32. The kernel build itself is left to CI (xnu-linux, starlte_defconfig).

Test plan (S9, iOS 16.5 image from this branch)

Full plan: docs/devices/starlte-charging.md.

  1. Boot with max77705_chg=1. Look for max77705: chg: the charger guard, read only…, then lines like max77705: chg: a wall charger at 5 V (DCP); charging allowed; on, input … mA …; battery NN.N C. The battery temperature must be plausible, never NOT READ, and the type must match the charger.
  2. Boot with max77705_chg=2 on a Samsung wall charger:
    • screen off: expect input limit (CNFG_09): … -> 0x47, read back 0x47 and charge current (CNFG_02): … -> 0x2a, read back 0x2a;
    • screen on: expect 0x2f / 0x14.
      Every 5 min the summary should read … 0 failed, 0 read back differently, 0 refused.
  3. On the Mac's port, once the USB console is configured, the log says a computer on the link, and the limits never go above 1500/1500.
  4. Unplug and send the log on DIFFERS, FAILED, 45 C or more, a fault, or a hot phone.

Revert: drop max77705_chg= (or set it to 0). Every register written is volatile: S-Boot sets its own again on the next boot.

Unverified: none of this has run on a phone yet. Two things in particular are untested: whether iOS sets the panel to level 0 when the screen locks (if it does not, SIOP stays on, which only means slower charging), and what S-Boot sets on a DCP.

Not merging: the owner merges after a phone test.

🤖 Generated with Claude Code

…default): Samsung's 5 V limits, temperature bands, SIOP

The iOS 16.5 kernel's MAX77705 driver only read the charger (and kicked its watchdog with max77705_wdt=1), so the S9
charged at whatever S-Boot left. With max77705_chg=2 the driver now applies the rules of hakios.max77705_charge.h (the
same rules as the iOS 27 guard, Samsung's numbers for the S9 from exynos9810-starlte_eur_open_26.dts):

- CNFG_09 [6:0] input limit and CNFG_02 [5:0] charge current to Samsung's S9 values for the BC 1.2 type, at 5 V:
  SDP 475/550, CDP 1500/1500, DCP 1800/2100, unknown 500/500 mA; 700 mA charge at 15.0 C and down;
- CNFG_00 bit 0: charging off at 41.0 C (on at 39.0), 5.0 C (on at 10.0), without a thermistor reading, when full
  (recharge at 4280 mV / 98 %), after the session time; latched off at 45 C, on a chip fault, a float above 4350 mV or
  a read-back that differs; only while the mode is 4 or 5;
- CNFG_06 WDTCLR kicked every poll.
Each written only when different, only its bits, read back; nothing while CHGPROT is locked, without VBUS or after a
failed read. Never written: the float, the timers, CHGPROT, the MUIC (no AFC), the gauge, anything non-volatile.
max77705_chg=1 only says what it would write.

On top, only lowering: SIOP, Samsung's in-use limit (siop_input_limit_current 1200, siop_charging_limit_current 1000
of the S9's DTS) while the panel is lit or its level unknown (max77705_siop=0 turns it off); and a computer on the USB
link (hakios_usb_gadget_host(), the gadget configured) holds the CDP's 1500/1500 mA and never asks 9 V.

Both ideas come from Jesvi-iOS (jesvi-eulah, iOS 16.5 on the Galaxy S20): SIOP from
docs/devices/x1slte/charging-samsung.md (fc07d1b), the computer-port cap and no 9 V with a host from
redwood_max77705.c's charging commits 3a4db07, fb882cf and a57b321. No code is copied; the values are the S9's.
Credited in NOTICE.

S9 only (refused on the S9+ and the Note9). Not yet run on a phone; host tests extended
(tools/max77705-charge-test.sh: the caps only ever lower). docs/devices/starlte-charging.md: registers, values,
sources, test plan.
@claudiusthebot

Copy link
Copy Markdown
Collaborator Author

CI: GitHub Actions is disabled on this repository, so I ran this repo's own workflows (check, xnu-linux) in a temporary private repo. It held one squashed snapshot commit of this branch's tree, no history, and has since been deleted.

  • check: green on the head (519503c). The first run failed only on docs-gen --check, because I had hand-edited the generated docs/devices/starlte.md; 519503c reverts that edit.
  • xnu-linux (tree of 66d6496; 519503c changes only that doc): the bcm2837 kernel linked; each SoC table linked; starlte_defconfig: linked (34 drivers); no error: / undefined symbols.
    Still not run on a phone.

@claudiusthebot

Copy link
Copy Markdown
Collaborator Author

Phone regression of current main, phone 2 (Galaxy S9, iOS 27.2.1), 28 Nov 2026 — PASS.

Built: scion-kernel main adbb15d6 (this PR and #398 #408 #416 #418 #419 #420 #421 #422 all in) + Scion-Project/xnu scion/xnu-12377 head f2f59dd (xnu#70), with the recipe of the previous phone runs (gpupass-1124 kbuild.sh, rc 0; kernel f36b080a), image = that kernel + the same loader and the boot line phone 2 already runs (no new boot-args): BOOT 0edca00b…, flash read back. Root: phone 2's own as found, nothing written to USERDATA.

boot SpringBoard Wi-Fi assoc BT (BlueTool / 0xfe3b) panic idle all-CPU (of 800) crashes big core
M1b 21 s after flash +8 s up / answered none 16 % chronod 1 42.1 C
M1c 21 s after flash +8 s up / answered none 17 % locationd 2, chronod 1 43.0 C

Home screen drawn on both (icons, widgets, dock, Wi-Fi + charging). Crash set = the earlier baselines' (locationd, chronod); no new crash loop. The S9's charger guard as before (sweetchg=2 sweetafc=1: the guard).

#421 (max77705_chg=) and #422 (sdcard=) are iOS 16.5 kernel drivers, off by default, and not in this iOS 27 kernel; #421 was not enabled (live charging tests need Dylan beside the phone); #422 not run on phone 2: no microSD card in it.

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