Repository navigation
apple-pmu-charger: Add shared adaptive charging and iPad 3 D1974 support - #139
Conversation
Record live 64 GB iPad3,3 (J2A) test results for Dialog D1974 USB charging control (OrchardLinux/linux#139) and H4ISP front/rear cameras (OrchardLinux/linux#140) in devices/j2a/device.toml and devices/j1/device.toml, keeping their states missing/untested until the kernel changes (and H4ISPFIRMWARE recipe) land in orchard's build. Regenerated docs/devices/{j1,j2a}.md via ./tools/catalog/generate matrix. Signed-off-by: Alistair <alistair.reay@gmail.com>
|
Thank you @alistairreay — getting the iPad 3 to raise its own input limit, with the measurements to back it up, is real progress. Before we merge, we need charging to be adaptive, the way iOS does it. Every device gets the same bar here (see the same request on #136). Today the driver asks every source for 1000 mA and backs off only when VBUS sags. That treats a computer port, a hub, a generic USB-A charger and an Apple 10/12 W iPad charger the same:
What we'd like the driver to do:
Small cleanups while you're there: read the chip-ID register only on the D1974, update the Kconfig help and header comment that still say "iPad mini 1 only", and use your full name in the sign-off. If the D+/D− part turns out bigger than you'd like to take on, say so and we'll work out together how to split it. Thanks again! |
3522307 to
86367bd
Compare
|
@henrikklee Thanks for the clear review! I've reworked this into the full shared adaptive charging stack and force-pushed the updated 5-commit series: What changed
Live test results on 64 GB iPad 3 (
|
| Source | D+/D− / Host Observation | usb_type |
current_max |
input_current_limit |
Battery |
|---|---|---|---|---|---|
| Mac direct USB-C port | D+ 53 mV, D− 61 mV; Apple 0x40 grant extra 1900 mA → 2400 mA |
[SDP] |
2400 mA |
2400 mA |
Charging +857 mA (full brightness) |
| USB 2.0 hub | D+ 40 mV, D− 40 mV; SET_CONFIGURATION → 500 mA; suspend → 2 mA (100 mA floor) |
[SDP] |
500 mA |
500 mA (100 mA suspended) |
Discharging -502 mA (zero sag/loop) |
| Anker PowerIQ USB-A adapter | Apple BrickID 5 (D+ 2631..2684 mV, D− 2619..2679 mV) |
[BrickID] |
2400 mA |
2400 mA |
Charging +768..+922 mA |
Generic 5V 1000mA USB-A brick |
Apple BrickID 4 (D+ 2449 mV, D− 1746 mV, ratio 0.713) |
[BrickID] |
2100 mA |
2100 mA |
Charging +656 mA |
| Hot-unplug & replug (Mac USB-C) | VBUS off: dropping 0x3e to 0x02; replug re-identifies, enumerates once, re-grants 2400 mA in ~445 ms |
[Unknown] → [SDP] |
0 → 2400 mA |
100 → 2400 mA |
Charging +838 mA |
Two caveats to note transparently:
- The generic
5V 1000mAwall brick I tested actually wires Apple 2.1 A (BrickID 4) resistor dividers on D+/D−, and I don't have a plain shorted-D+/D− non-Apple-divider BC1.2 DCP charger on hand, so the 1.5 s shorted-D+/D− BC1.2 fallback path is compile-checked only. - D1946 (iPad mini 1) hardware was not physically tested here; existing D1946 DT wiring and behavior are preserved and compile-checked.
86367bd to
6aff874
Compare
macOS, and Windows with Apple's device support, grant an Apple device more than the USB 2.0 500 mA with a zero-length vendor request (bmRequestType 0x40, bRequest 0x40). wIndex carries the extra active current and wValue the suspend current, both signed mA. iOS stores both and resolves the allowance as 500 mA plus the extra while the bus is active; on a Mac this gives the iPad 2400 mA. The host sends it only to Apple devices it knows. Answer the request in the composite core when the gadget presents Apple's vendor ID, and report the result through usb_gadget_vbus_draw() like any other configuration change, so the UDC passes it on to its PHY or power supply. A bus reset, a disconnect or a suspend ends the grant; set_config keeps it, since the host may send it before SET_CONFIGURATION. Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com> [Orchard: from brkosebay/linux e44a80b and 0dd7ae0 (J71t ledger 6.7, 6.8, 7.4); reworked onto the existing vbus_draw path instead of a new UDC core budget, notifier and query API; gated on the Apple vendor ID instead of a DT opt-in; no board cap in the core (the charger caps at its board maximum); OUT request only] Co-developed-by: Henrik Klee <henrik@goat-code.com> Signed-off-by: Henrik Klee <henrik@goat-code.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit fda0098) Signed-off-by: Henrik Klee <henrik@goat-code.com>
The extra current an Apple host grants must not be drawn while the bus is suspended. reset_config() could apply it during suspend, because the suspended flag was cleared only at the end of composite_resume(). Skip the extra current while suspended and clear the flag before the configuration is applied again on resume. [Orchard: from orchard PR OrchardLinux#108, commit 0674e1db; unchanged] Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com> Link: OrchardLinux/orchard#231 (comment) (cherry picked from commit e4ff533) Signed-off-by: Henrik Klee <henrik@goat-code.com>
…ction Accept the Apple vendor current-limit request whether the host sets the IN or OUT direction bit, and log the grant it carries. [Orchard: from orchard PR OrchardLinux#103, commit 190bb139b293] Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com> Link: OrchardLinux/orchard#231 (comment) (cherry picked from commit 4ef6c32) Signed-off-by: Henrik Klee <henrik@goat-code.com>
A peripheral-only controller with a role switch and no role-switch-default-mode starts with no session and waits for a connector driver to set the role. If that driver is missing, its probe defers forever or it hangs, the gadget never connects. If no role has been set through the switch 1 s after it was registered, set the device role. A role set by the connector driver at any time before or after takes precedence. Assisted-by: LLM (cherry picked from commit 54ef2ea) Signed-off-by: Henrik Klee <henrik@goat-code.com>
A peripheral-only controller with a role switch and no role-switch-default-mode forced its B-valid session signal low through the OTG override until a role was set. On the Apple A10 (iPad 6) that left an interrupt pending which nothing cleared: as soon as binding the gadget re-enabled interrupts, CPU 0 stayed in the interrupt handler (RCU stall in dwc2_hsotg_udc_start) and USB never came up. Such a controller now leaves the override alone. Without the device role its pull-up stays off (DCTL.SFTDISCON): pullup() does not connect while held, and setting the device role connects it. No role or the fallback work behaves as before from the host's side. Assisted-by: LLM (cherry picked from commit c1e4b67) Signed-off-by: Henrik Klee <henrik@goat-code.com>
dwc2's vbus_draw only reaches a legacy usb_phy. Controllers with a generic PHY have nowhere to report what the host allows, so a charger behind the port never learns about a configuration, a suspend or a host grant above the USB 2.0 default. Do what dwc3 does: with usb-psy-name set and no usb_phy, store the current and pass it from a work item to that power supply as its input current limit. The supply is looked up when the work runs, so the charger may bind after the controller; without it the call does nothing. J71t ledger 6.8 (gadget current reported through vbus_draw instead of a new UDC core budget API). Reported-by: Berkay Kösebay <brkosebay@users.noreply.github.com> Signed-off-by: Henrik Klee <henrik@goat-code.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit d5eb4ba) Signed-off-by: Henrik Klee <henrik@goat-code.com>
An iPad can log a 2400 mA Apple host grant at boot while its charger stays at 500 mA with no current allowance. A source event invalidates the report without necessarily ending the USB session; an early report can also arrive before the charger accepts the attachment. No further host request is guaranteed. The Lightning charger notifies its power supply when its source epoch or the attachment's readiness changes. On that notification, have DWC2 re-report its current live draw to its named power supply. Compare the allowance rather than the ramped input limit to avoid notification feedback. End the composite session on a soft-role hold so an earlier attachment cannot retain a grant. Suspend, reset and disconnect still replace the live draw, and notifier cleanup drains its work. Affects: Apple A9/A10 DWC2 controllers using a named TriStar power supply Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com> Link: OrchardLinux/orchard#231 (comment) (cherry picked from commit 4b21826) Signed-off-by: Henrik Klee <henrik@goat-code.com>
The 32-bit Apple charger holds the pull-up off on every plug-in, unplug and fast swap while it identifies the source, then releases it. Make the soft role switch act only on a change of the hold: - On a new hold, end the gadget session first, with the pull-up still on, then disconnect the core. - On release, reinitialise the core as disconnected and re-enable ACG before connecting, so the session starts from a clean controller state after the charger's detection window. - Keep the pull-up off in dwc2_hsotg_core_connect() while a hold is set, so no other path connects during detection. [Orchard: split out of Alistair's armv7 backport of the dwc2 series in linux#139; the series itself is cherry-picked with its original authors] Signed-off-by: Alistair Reay <alistair.reay@gmail.com> Signed-off-by: Henrik Klee <henrik@goat-code.com>
Export apple_s5l_usbphy_set_dmon() to control the otgphyctrl +0x48 analog monitor mux (bits 0x7e06) used by AppleS5L8930XUSBPhy and iBEC for USB charger source detection: - D+ (0x0002) and D- (0x0004) on all S5L8940X/8942X/8945X/8950X/8955X PHYs - BC1.2 DCD (0x6602) and Primary (0x1e04) on phy-version >= 4 PHYs (S5L8950X/S5L8955X), returning -EOPNOTSUPP on older PHYs. Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Extend apple-pmu-charger with per-PMU match data (Dialog D1946 and D1974, extensible to D1972) and shared adaptive USB source detection: - Per-PMU match data holds status0/VBUS mask, ilim register, log registers, hard ceiling, current-to-code/code-to-current tables, D1974-only chip revision read (reg 0x00), and PMU 12-bit ADC layout. - On probe, plug-in, unplug, or fast swap, park the input limit at 100 mA (0x02) and hold USB pull-up off via usb-role-switch while sampling D-/D+ through the S5L USB PHY DMON mux and PMU ADC. - Classify Apple BrickID chargers (500/1000/2100/2400 mA), hardware BC1.2 primary ports on phy-version >= 4 (1500 mA), USB hosts via dwc2 vbus_draw (100/500 mA SDP, 2 mA suspend, and Apple host 0x40 grants), shorted-D+/D- BC1.2 DCP chargers (1500 mA when no USB host enumerates within 1.5 s), and unidentified sources (500 mA fallback). - Cap grants at DT input-current-limit-microamp (or chip max), keep 100 mA / 10 ms stepped ramping, VBUS sag backoff, and battery thermal derating, and expose USB_TYPE, CURRENT_MAX, and actual INPUT_CURRENT_LIMIT properties. Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Add the D1974 USB charger child node (charger@3e) to s5l8945x-ipad3.dtsi with its 2400 mA board limit (ADT usb-input-limit-max 0x960), otgphy0 DMON PHY handle, and usb-role-switch graph link to dwc2, and set usb-psy-name = "apple-pmu-usb" on dwc2 so USB host vbus_draw reports (including Apple host 0x40 grants) reach the charger. Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
… wiring The iPad 2 (K93 family) and the iPad mini 1 (P105/P107) describe the D1946 charger without a data monitor PHY or a USB link. Source detection cannot run there, so every source reached the 1.5 s "no USB host" check and ended at the 500 mA fallback, half of the 1000 mA these boards have had so far on every source (iBEC's value for a charger it does not know; a Mac's port gives it without a sag). When the board has no "dmon" PHY (or the PMU has no ADC to read it), keep that fixed 1000 mA target, still capped by the board maximum and max_input_ma, with the same sag backoff as before. A USB host report on such a board raises the limit above it but no longer lowers it. The choice follows the device tree, not a board check: a board that gains the wiring gets detection. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
…t session When the PMU drops the input limit back to 0x02 in steady state, the driver re-identified the source, which holds the USB pull-up off while it measures D+/D-. On a computer or hub port the re-identified source is a host again with no source current of its own, so no backoff applied: the limit ramped back up, sagged again, and the USB link went down and came back on every round, taking USB serial and SSH with it. During a USB host session an unplug ends the session through vbus_draw(0) before the poll sees the drop, so a drop there is a sag. Step the limit down 8 codes and keep that ceiling until unplug, as on the boards without detection wiring, and leave the USB link alone. Re-identification stays for dedicated sources, where USB carries no session. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
6aff874 to
e5e33c1
Compare
|
Thanks a lot, @alistairreay, for the adaptive rework! The charger now works out what's plugged in instead of applying one fixed limit: it recognises Apple chargers by their D+/D- dividers, gives computer and hub ports the current their host allows (including the extra current a Mac grants an Apple device), and reports the source type through the standard What we changed on your branch (your own commits are otherwise untouched):
Nothing was left out. Open points:
|
Summary
Adds shared adaptive USB source detection and charging to
apple-pmu-charger(per-PMU match data for Dialog D1946/D1974 and extensible to D1972) and wires the Dialog D1974 adaptive charger into the shared iPad 3 device tree (s5l8945x-ipad3.dtsi, covering J1, J2, and J2A).Split into five commits:
usb: gadget: composite: Report an Apple host's current grant— backport of OrchardmainApple vendor0x40extra-current request handling so USB gadget drivers report Mac high-current grants (e.g.500 + 1900 = 2400 mA).usb: dwc2: Report VBUS draw to power supply and support soft-role pull-up hold— backport of Orchardmainusb-psy-namevbus_drawreporting and soft-roleusb-role-switch(DCTL.SFTDISCONhold + clean core re-init on release, withrole_sw_holdguard indwc2_hsotg_core_connect()).phy: apple-s5l-usb: Export USB data monitor (DMON) helper— addsapple_s5l_usbphy_set_dmon()onotgphyctrl + 0x48(mask0x7e06) to route USBD+/D-(and hardware BC1.2 primary detection onphy-version >= 4) to the PMU ADC.power: supply: apple-pmu-charger: Add D1974 and shared adaptive charging— per-PMU match data (apple,pmu-d1946-chargerandapple,pmu-d1974-charger), D1974-only chip-ID0x00read, PMU 12-bit ADC ch 6 D+/D− measurement, Apple BrickID classifier (500 / 1000 / 2100 / 2400 mA), hardware BC1.2 primary detection (phy-version >= 4) + shorted-D+/D− BC1.2 DCP fallback after 1.5 s without USB host enumeration, USB hostvbus_drawenforcement (100 mA before enumeration, 500 mA after, 2 mA suspend → 100 mA floor, up to 2400 mA on Apple host grant), 100 mA conservative attach start, 100 mA/10 ms ramp, VBUS sag backoff & fast-swap re-identification, thermal guard (45 °C / 40 °C), DTinput-current-limit-microamp, and standardusb_type/current_max/input_current_limitreporting. Also updates the Kconfig help text and file header comment.ARM: dts: apple: ipad3: Wire D1974 adaptive USB charger— addscharger@3e(input-current-limit-microamp = <2400000>,phys = <&otgphy 0>, OF graphusb-role-switchlink todwc2) andusb-psy-name = "apple-pmu-usb"ondwc2.Testing
orchard_applearmv7_defconfigwithW=1across all 5 modified.ofiles (composite.o,drd.o,gadget.o,phy-apple-s5l-usb.o,apple-pmu-charger.o), fullzImage, ands5l8945x-{j1,j2a}.dtb,s5l8942x-p105.dtb,s5l8940x-k93.dtb— zero warnings.iPad3,3/ J2A) with Orchard's configfs05ac:1014(MaxPower=500) gadget:usb_typecurrent_max/input_current_limitD+ 53 mV, D− 61 mV; Apple0x40grantextra 1900 mA→2400 mA[SDP]2400 mA/2400 mACharging +857 mA(full brightness)D+ 40 mV, D− 40 mV;SET_CONFIGURATION→500 mA; bus suspend →2 mA(100 mAfloor)[SDP]500 mA/500 mA(100 mAon suspend)Discharging -502 mA(no sag/loop)Apple BrickID 5(D+ 2631..2684 mV, D− 2619..2679 mV)[BrickID]2400 mA/2400 mACharging +768..+922 mA5V 1000mAUSB-A brickApple BrickID 4divider (D+ 2449 mV, D− 1746 mV, ratio0.713)[BrickID]2100 mA/2100 mACharging +656 mAVBUS off: dropping 0x3e to 0x02; replug re-identifies, enumerates once, re-grants2400 mAin ~445 ms[Unknown]→[SDP]0→2400 mACharging +838 mA5V 1000mAbrick carries Apple 2.1 A divider resistors), so the 1.5 s shorted-D+/D− BC1.2 fallback path is compile-tested only. D1946 (iPad mini 1) and D1972 (iPhone 5) hardware were not physically tested (existing D1946 compatibility and DTBs are preserved and compile-checked).