Skip to content

iPod touch 6 (N102): battery status from the D2186 PMIC - #202

Draft
brkosebay wants to merge 19 commits into
OrchardLinux:mainfrom
brkosebay:pr/n102-battery
Draft

brkosebay wants to merge 19 commits into
OrchardLinux:mainfrom
brkosebay:pr/n102-battery

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

Stacked on #201 (Wi-Fi). Review only the last 3 commits. Draft until the latest power/0042 revision has run on the device.

The iPod touch 6 has no fuel gauge. iOS reads the battery through the Dialog D2186 PMIC's housekeeping ADC and charger status registers. These drivers do the same, and they only read.

Commits

  • kernel: battery status on the iPod touch 6 from the D2186.

    • iio/0010-0011: apple-d2186-adc, a polled 12-bit ADC exposed as IIO channels: battery and bus voltage, charge and bus current, battery thermistor, and the PMIC's factory current calibration.
    • power/0040-0041: apple_d2186_battery, a battery and USB power_supply built from those channels and the status registers 0x60 and 0x62. It never writes a charger register.
    • devices/t7000/0019: the nodes on the N102.
    • Configs: CONFIG_APPLE_D2186_ADC=m and CONFIG_BATTERY_APPLE_D2186=m on apple-4k. apple-16k leaves both off, because no A9 or later board has a D2186.
  • kernel: apple_d2186_battery: estimate the charge as iOS does (power/0042, devices/t7000/0020). It follows AppleARMPMUCharger for battery family 6:

    • its OCV table, averaged samples, and IR and load compensation;
    • a median over recent estimates and coulomb counting while charging;
    • _smoothSOC's rate limit: the reading only rises while charging, only falls on battery, and stays at 99% until the charger ends.

    When the charge-current channel reads 0 while charging, the driver falls back to the PMIC's averaged charge current.

  • devices: n102: battery status works. Battery is set to working. The catalog counts apple_d2186_battery as a battery driver, and the matrix is regenerated. Charging stays missing, because nothing sets the charge current.

Tested (iPod touch 6)

  • With power/0040-0041 only, in a RAM boot on a charger: 3.77 V, 28 %, 28 °C, Charging; USB online at 5.19 V and 219 mA. The charge-current channel read 0 while charging.
  • The installed system ran the first revision of power/0042. This revision was refined from that system's logs: the median ring, the strict 0x62 charging rule and the averaged-current fallback for the zero reading above. It is built but has not run on the device yet.

Open

  • The OCV curve has not been checked against a full charge and discharge.
  • Charge current control (charging, charging_control).

Proposed changelog line: "iPod touch 6 (N102): battery status."

🤖 Generated with Claude Code

The A8's GX6450 runs the same family of firmware as the A9's, so it
becomes a variant of the S8003 chip file rather than a new driver
(drivers/gpu/0063-0073):

- 0063-0064: the S8003 chip described in a variant table, and chip
  hooks for its own GPU ID read and heap table. These touch the A9 and
  A10 paths; their values and functions are unchanged.
- 0065: dt-bindings for apple,t7000-gpu.
- 0066: a GPU node without power domains, and the failing probe step
  named (shared powervr code; nodes with power domains are unchanged).
- 0067-0069: the A8's firmware boot and power up and down in Apple's
  order, compute jobs, and TA/3D render jobs with the parameter-manager
  pool (a8_pm_blocks, a8_pm_grow) and the region-header ring kept in
  the HWRT data set.
- 0070: fault and hang reports and recovery.
- 0071: completion checks in the firmware interrupt's thread, the
  re-check after an early interrupt, a publish that cannot leave a
  failed job in the firmware's ring, Apple's doorbell.
- 0072: a fragment job submitted behind its geometry job, with two
  alternating 3D records (a8_joint, off by default).
- 0073: statistics and the A8's job timeline in debugfs apple_jobs,
  last. It also points the firmware's TA and 3D time words at the
  channel's times; the series without it has not run on the device.

Config: CONFIG_DRM_POWERVR_APPLE goes from unset to =y on apple-4k, as
on apple-16k, so the A8 gets powervr's Apple glue. It builds into the
powervr module on every A7, A8 and A8X kernel; only boards whose device
tree enables an apple,t7000-gpu node bind it.

Assisted-by: LLM
The iPod touch 6 RAM-boots through checkm8, PongoOS and m1n1 to the USB
serial shell. Its descriptor, boot assets and firmware recipe pin the
public iOS 12.5.8 IPSW.

devices/t7000/0011 describes the A8's GPU in t7000.dtsi (the Rogue core,
Fender, the power manager and GPU bridge registers, five interrupts,
the firmware name) and enables it on the N102, where powervr's A8
variant runs Vulkan and OpenGL ES (through Zink) jobs.

Orchard's feature list has no GPU entry and the chip's [gpu] table
records dEQP results, which the A8 does not have yet, so the GPU state
is in devices/n102/README.md. docs/compatibility.md is regenerated.

Assisted-by: LLM
The iPad mini 4 (J96, J97) and the iPhone 6 and 6 Plus (N61, N56) have
the iPod touch 6's A8 GPU. devices/t7000/0012 enables the GPU node in
their shared board files (t7000-mini4.dtsi, t7000-6.dtsi) so people with
these boards can test it; the driver has run only on the iPod touch 6.
Each board's README asks for the probe and ladder results. The A8X
(T7001) has a different GPU and is unchanged.

Assisted-by: LLM
minimal-boot with a constant USB serial number, the kernel's modules,
the GPU firmware and a8-gpu-drm-test, which loads powervr and checks the
probe, Mesa's Vulkan path and two DRM-level replays, each step under a
hardware watchdog with its kernel lines saved. It builds for every A8
board (n102, j96, j97, n61, n56).

tools/extract-fw.py writes the GPU firmware and its border colour table
from Apple's public iPod touch 6 iOS 12.4 IPSW, read over HTTP ranges
with orchard's own IPSW and kernelcache code, or from another IPSW or
kernelcache. Nothing from Apple is in the repository, and everything
build.sh stages is git-ignored.

Assisted-by: LLM
a8-vk-smoke (Vulkan probe, compute, a triangle) and a8-vk-ladder, a set
of Vulkan tests from one clear to vkmark's scenes with every pixel or
value checked on the CPU, both MIT. vk/make-bundle.sh builds them with a
Mesa build of the A8 branch into the self-contained /opt/a8vk bundle
that build.sh's A8_VK_DIR stages, with vkmark when it is installed.

Assisted-by: LLM
The iPod touch 6 keeps its flash behind ANS1 like the iPad Air 2, but
its ANS firmware (iOS 12.4) speaks RTKit 10.2, where the storage
endpoint is 6 instead of 0x20.

- soc-apple/0028: RTKit 10 firmware sends its minor version in the
  HELLO's minimum-version field and wants it back; keep it, answer with
  it and let drivers read the protocol version. RTKit 11 and later are
  unchanged.
- block/0003: asp takes its storage endpoint from the protocol version
  (6 on 10.2, 0x20 on 11 and later); 10.0 is refused by name.
- devices/t7000/0013: the ANS nodes, as Nick Chan wrote them.
- devices/t7000/0014: enabled on the N102 only, ps_ans kept on as the
  boot loader leaves it.

The iPad Air 2 (J81, RTKit 12) runs the same rtkit and asp code; its
path is meant to be unchanged and was not retested.

Assisted-by: LLM
ANS1's write unlock opens the whole controller, so only the driver keeps
writes off the auxiliary namespaces (LLB, firmware, NVRAM, SysCfg with
the factory calibration, ...). Check each command against the ones the
driver uses (identify, the user area's read, write and flush, the write
unlock and the auxiliary reads) before it is queued; anything else,
auxiliary writes and format commands included, is refused.

Shared with the iPad Air 2 (J81), which uses only those commands; not
retested there.

Assisted-by: LLM
With ANS1 on the iPod touch 6, Orchard installs to its user area
(asp0n1) next to a shrunk iOS: storage_read and storage_write are
working. The board now meets every install requirement.

The catalog gets the board's drivers (it had none yet). The ANS1
driver is not one the catalog looks for, so the matrix lists storage as
working with no driver binding, as for the iPad Air 2.

Assisted-by: LLM
The N102's N1 touchscreen on apple_z2, as AppleMultitouchSPIN102 drives
it: the N1 protocol with its C1F58,1 personality and clock settings, its
core supply from a D2186 regulator instead of a GPIO LDO
(input/0030-0031), and the SPI2 node with the Chestnut and D2186
supplies, the touch clock and the calibration alias
(devices/t7000/0015).

Other apple_z2 boards keep their match data; not retested.

Assisted-by: LLM
The N102's DWI backlight drives an LM3534 whose outputs are switched on
over I2C (register 0x10 bit 0, then 600 us), as AppleLMBacklight does
(backlight/0007-0008, devices/t7000/0016). On the T7000 the DWI starts a
transfer with 0x71 in the channel control register, without the extra
send bit (backlight/0006).

backlight/0006 changes the DWI transfer on every T7000 board (iPad mini
4, iPhone 6 and 6 Plus); it was run on the iPod touch 6 only.

Assisted-by: LLM
The firmware recipe makes the touchscreen's firmware
(apple/n102-fwstart.z2fw) from N102.mtprops in the pinned IPSW, with
the C1F58,1 personality and the unit's calibration.

Touch, backlight, the four buttons and the display were seen working on
the iPod touch 6. It has no Touch ID and no cellular modem: none, not
missing.

Assisted-by: LLM
The iPod touch 6's Dialog D2186 PMIC drives Wi-Fi REG_ON (GPIO 10) and
Bluetooth power (GPIO 8). apple-d2365 gets the D2186 as match data: 21
lines with their configuration at 0x400 + 2n and input levels at 0x63,
as AppleD2186PMU reads them. Its PMU event block is not wired, so it is
no interrupt controller, like the D2333.

Other PMICs keep their match data.

Assisted-by: LLM
The N102 has a BCM4345B1 combo module ("bacchus"): Wi-Fi on PCIe port 1,
Bluetooth on UART1.

- wifi/0011-0012: brcmfmac matches the BCM4345 on PCIe (14e4:43ab),
  names its firmware brcmfmac4345-pcie with a CLM blob and reads its OTP
  as iOS does; a missing Apple OTP record falls back to the board type.
- pci/0041: pwrctrl-apple-wifi powers it up like the A8/A8X BCM4350.
- bluetooth/0008-0009: hci_bcm matches the BCM4345B1 at 115200 baud, as
  for the iPad Air 2's BCM4350C2, and knows the TDK module vendor ("t").
- devices/t7000/0017-0018: UART1 for the A8, and the N102's Wi-Fi and
  Bluetooth nodes from its ADT, with REG_ON and Bluetooth power on D2186
  GPIOs 10 and 8.

Other boards' brcmfmac, pwrctrl and hci_bcm matches are unchanged; the
iPad Air 2 (BCM4350) was not retested.

Assisted-by: LLM
The iPod touch 6's BCM4345B1 (rev 5) firmware never started: "FW failed
to initialize". brcmfmac loads every BCM4345 at 0x198000, which is right
for rev 6 and later (43455/43456) but 96 KiB below the rev 5's RAM, which
starts at 0x1b0000 (iOS's AppleBCMWLANChipManagerPCIe4345 and the
firmware's own link addresses agree).

- wifi/0013: 0x1b0000 for BCM4345 below rev 6; 0x198000 otherwise.
- wifi/0014: the 256-byte random seed and 0xfeedc0de footer before the
  NVRAM, which Apple's downloader writes and the firmware's start-up code
  looks for.

The BCM43455/43456 (rev 6 and later) keep 0x198000.

Assisted-by: LLM
The firmware recipe adds the BCM4345B1 module's Wi-Fi firmware, NVRAM,
CLM and TX-cap blobs from the pinned IPSW, and the Bluetooth patchram of
each module vendor (Murata, TDK, USI) from BlueTool.

Wi-Fi was seen working on the iPod touch 6: firmware 7.63.79.4 starts,
it scans 2.4 and 5 GHz and an installed system joins a network.
Bluetooth's controller comes up with the USI patchram; with nothing
paired yet, Bluetooth input and audio stay untested.

Assisted-by: LLM
The iPod touch 6 has no fuel gauge: iOS reads the battery through its
Dialog D2186 PMIC. Two read-only drivers do the same:

- iio/0010-0011: apple-d2186-adc, the PMIC's 12-bit housekeeping ADC as
  IIO channels (battery and bus voltage, charge and bus current, battery
  thermistor), polled, with the PMIC's factory current calibration.
- power/0040-0041: apple_d2186_battery, a power_supply for the battery
  and USB from those channels and the charger status registers 0x60 and
  0x62. It never writes a charger register.
- devices/t7000/0019: the ADC and battery nodes on the N102, with the
  1080 mAh design capacity and 3400 mV shutdown voltage of its ADT.

Configs: CONFIG_APPLE_D2186_ADC and CONFIG_BATTERY_APPLE_D2186 are =m on
apple-4k for the N102; apple-16k leaves both off, as no A9 or later board
has a D2186.

Assisted-by: LLM
A single voltage sample on a made-up curve jumped with every load
change. Follow AppleARMPMUCharger for battery family 6 instead, still
read-only:

- power/0042: its 100-point OCV table, ten averaged samples per update,
  IR compensation while charging and load compensation while
  discharging, a median over recent estimates, coulomb counting while
  charging, and _smoothSOC's rate limit: the reported charge only rises
  while charging (0x62 bits 1:0 or USB present), only falls on battery,
  and stays at 99% until the charger ends. When the charge-current ADC
  channel reads 0 while charging, it falls back to the PMIC's averaged
  charge current (0x4e2).
- devices/t7000/0020: the N102's battery node with key points of that
  curve and the 200 mOhm internal resistance.

Assisted-by: LLM
The D2186 battery driver was seen reporting on the iPod touch 6: battery
voltage, charge, temperature and status, and USB online with its bus
voltage and current. The catalog counts apple_d2186_battery as a battery
driver.

Charging stays missing: the driver only reads, and the PMIC charges at
the limit the boot loader left.

Assisted-by: LLM
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