Repository navigation
ARM: apple: iPhone 5 (A6) and its watchdog, ready for the iPad 4 (A6X) too - #88
Merged
Merged
Conversation
The A6 (S5L8950X, iPhone 5) has two Apple Swift ARMv7s cores, the A5's PMGR core control and the same AIC. Add it to the S5L machine: - apple.c: match "apple,s5l8950x". The A5 boards' memblock carve-out under iBoot's scanout (0x9f600000..0x9f6fc000) is skipped on the A6, where that address is ordinary RAM; the A6 boards reserve their scanout in the DT. - headsmp.S: run the Cortex-A9 errata fixups and the SCU tag invalidation only on a Cortex-A9 (MIDR part 0xc09). Swift has an integrated L2 and no A9 SCU, CBAR or diagnostic register. - platsmp.c: look up "apple,s5l8950x-pmgr" first. Its core control registers sit at the A5's offsets (+0x1210 stop, +0x1214 start, +0x1220 run; iOS 8.4.1 AppleS5L8950XPerformanceController). On a core that is not a Cortex-A9, power down by switching the D-cache off and cleaning L1, without the A9's ACTLR.SMP write. The A5 boards run the same code as before. Tested on an iPhone5,2: both cores come up and the USB shell is reached. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…RM PMU
The A6's Swift cores are Apple's own (MIDR 0x613f0001, implementer
'a') and have no ARM PMU. time_init enabled the Cortex-A9 cycle counter
unconditionally, and its first CP15 c9 write (PMUSERENR) was an
undefined instruction: the iPhone 5 panicked at time 0 ("Attempted to
kill the idle task").
Use the cycle counter, its calibration and the PMU overflow tick only on
a Cortex-A9 (the A5). Other cores get the 24 MHz watchdog counter as
clocksource and sched_clock, and the AIC timer as the tick. The USB SOF
tick no longer reads the cycle counter before its checks.
With this the iPhone 5 boots to /init in 5.4 s.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Three differences on the A6 watchdog: - WDT_CUR_TIME only counts while WDT_CTRL bit 3 (enable) is set. If the boot loader left CTRL at 0, set bit 3 without the reset enable, so the counter runs; a watchdog the boot loader armed (0xc) is left alone. The calibration loop is bounded, so a counter that never moves cannot hang the boot. - A reset needs enable and reset enable together (0xc), programmed the way iBEC's wdt_enable() does: CTRL 0, bite time, count, CTRL 0xc, count 0. The restart handler and the reboot notifier do that on the S5L8950X. - The A6 skips the CPU calibration (no cycle counter), which was the only place that mapped the counter, so the clocksource found nothing mapped and the phone ran on jiffies. Map the counter in a helper that both call. The A5 boards keep their sequence. Tested on an iPhone5,2: the watchdog counter is the clocksource, and panic=10 and reboot reset the phone through the watchdog. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
On the iPhone 5 the only clockevent was the AIC timer of CPU0. CPU1 got
the dummy clockevent, and with no broadcast device it never ticked:
with idle=poll RCU stalled on it ("timer wakeup didn't happen"), and
with WFI idle the whole system froze at about 10.8 s, the first time
something waited for a timer on CPU1.
The AIC timer is a per-core register: the 0x2000 window is banked by
the accessing core, like WHOAMI, EVENT/IACK and IPI_SEND, and the timer
fires as a local event (type 7) in that core's EVENT. iOS 10.3.4 on the
N42 does not use it (XNU ticks each core from the Swift generic timer),
but iBoot runs on it, and so does Linux on CPU0.
On the A6, once a secondary core is online (CPUHP_AP_ONLINE_DYN,
interrupts on), arm a 10 ms shot in its banked window, then in its
explicit window (0x5000 + (cpu << 7)), and wait up to 200 ms of AIC
timebase for the event on that core. The first window that fires
becomes the core's oneshot clockevent, rating 400, which replaces the
dummy. A failed test disarms through the core's explicit window only,
so it cannot stop CPU0's tick, and logs FAIL. Per-CPU timer event
counts are in /sys/module/aic1/parameters/timer_events.
There is no offline teardown: going offline, the core's timer stays its
tick device until the tick code lets go of it, and
apple_aic1_secondary_init() quiesces the window before the core comes
back.
The A5 (P105, J1) keeps its PMU tick and CPU0-only AIC timer: the
online state is installed only on "apple,s5l8950x".
Tested on an iPhone5,2: "PASS -- CPU1 has its own clockevent", and a
two-core boot reaches the USB shell with no nohlt or irqaffinity.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
aic1_irq_unmask() routes every line to CPU0 (TARGET = BIT(0)) and the chip has no irq_set_affinity, so no device interrupt ever reaches another core. The IRQ core did not know that: /proc/irq/N claimed affinity 0-1, and irqaffinity=0 on the command line only changed what it claimed. Set the affinity and effective affinity of each line to CPU0 when it is mapped, mark it single-target and exclude it from balancing. Routing is unchanged, on the A5 as well; irqaffinity=0 is no longer needed. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6 (S5L8950X, iPhone 5) has the A5's OTG and HSIC PHY with other PMGR offsets and tuning values, so it gets its own compatible and no S5L8940X fallback. On the S5L8950X the PHY can also take the PMGR gates of the OTG block (UPERF, USB-OTG, USBREG) as clocks, after the reference clock, and holds them from probe. Allow up to four clocks, named in that order. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6's OTG PHY is the A5's, with its PMGR power states at other offsets: UPERF +0x1084, USB-OTG +0x1088, USB-EHCI +0x108c, USB-OHCI0 +0x1094 and USBREG +0x109c. Its tuning differs too: uotgtune1 is 0x749. Move the gate offsets and the tuning values into per-SoC match data and add "apple,s5l8950x-otgphy" (iPhone5,2 iOS 8.4.1 iBEC and ADT). The S5L8940X and S5L8942X entries carry the values the driver used before. Tested on an iPhone5,2: the dwc2 gadget comes up with CDC ACM and networking. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The A6's OTG controller is the A5's dwc2 and runs with the S5L8942X quirks and parameters. Add "apple,s5l8950x-dwc2" in front of the S5L8942X and S5L8940X compatibles, and require the PHY like theirs. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
s5l8950x.dtsi describes the A6 as the iPhone5,2 iOS 8.4.1 (12H321) ADT, iBEC and kernelcache give it: two Swift cores started through PMGR, the AIC, the 24 MHz watchdog counter, PMGR, GPIO (232 pins), UART1-6, the OTG PHY and the dwc2 gadget, and simple-framebuffer over iBoot's 640x1136 scanout. The boot loader fills memory and framebuffer. Every PMGR gate is disabled in the SoC file and enabled by the board next to its consumer. A registered gate that nobody holds is switched off by clk_disable_unused, and iBoot leaves most of them on. When the SoC file registered the CDMA, SPI1, UART1-5 and I2C0-2 gates with no consumer, the N42 booted into clk: Disabling unused clocks phy-apple-s5l-usb 36000000.phy: PHY reference clock selection did not latch udc 36100000.usb: failed to start ...: -5 although no USB gate is among them. A gate that is not registered keeps the state iBoot left. CDMA has no Linux consumer and stays unregistered. s5l8950x-5.dtsi holds what the N41 and N42 share; so far UART6, the debug port. The two boards differ in cellular bands, which Linux does not drive. The N41 is untested. Tested on an iPhone5,2: both cores, the framebuffer console and the USB gadget. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The N42's otgphyctrl is PHY version 4. Besides uotgtune1 = 0x749 and uotgtune2 = 0x2ff3, its ADT node has hsic-tuning-val = 0xa30a3a3, which AppleS5L8930XUSBPhy writes to +0x5c (iPhone5,2 iOS 10.3.4). Add it to the per-SoC data and write it with the other tuning values on a cold start, and on its own when the PHY was left running. HSIC port 4 carries the BCM4334 Wi-Fi. The other SoCs have no HSIC tuning value and write nothing new. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The OTG PHY switched UPERF, USB-OTG and USBREG on with raw PMGR writes
in phy_init, behind the clock framework's back. Describe the three as
PMGR gate clocks in s5l8950x.dtsi (+0x1084, +0x1088, +0x109c; ADT
device-clocks ids 0x04, 0x35, 0x06) and give them to the PHY, which
switches them on at probe in the order the boot loader uses and keeps
them on, the way the H2FMI driver holds its gates. The gadget is the
console and the network, so nothing switches them off again: not a
failed probe, not an unbind, and with the enable count held not
clk_disable_unused either.
The clocks are optional and looked up by name ("uperf", "otg",
"usbreg"). P105, J1 and the other trees name only "ref", get none, and
run the code they ran before; phy_init's register checks stay for them
and are a no-op on the A6 once the gates are held.
The host side's USB-EHCI and USB-OHCI0 gates stay with the host PHY's
power-on and are not clocks, so nothing at late_initcall reaches them
either. When the reference clock selection does not latch, the error
now says what OPHYCLK, OPHYPWR and the three gate registers read.
Tested on an iPhone5,2: the gadget comes up without clk_ignore_unused.
Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…t SoC The per-CPU AIC timer for secondary cores was switched on only for boards compatible with "apple,s5l8950x". What decides it is the core, not the board: the A5's Cortex-A9 has the ARM PMU whose tick serves the other core, and Apple's Swift cores have none. The A6X (S5L8955X) uses Swift cores and the same "aic,1" controller, so key the choice on the boot CPU's part number, as pmccntr.c already does, and every Swift board gets a tick on each core it brings up. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
The watchdog counter of the A6 runs only while WDT_CTRL_ENABLE is set, and its bite needs ENABLE together with RESET_EN; that was decided by the "apple,s5l8950x" board compatible alone. The A6X (S5L8955X) is of the same family (its ADT pmgr lists "pmgr,s5l8950x" after its own) with the same wdt-version 1 block, and having no cycle counter it relies on this counter for all its time. Put the check in one helper that names both chips, so the A6X's clocksource ticks and its restart bites as the A6's do. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
Register the wdt-version 1 watchdog (the 24 MHz counter that is already the clocksource) as a watchdog device, so a hung system is reset within the timeout and a healthy one runs for ever: the kernel pets it from boot until userspace (systemd's RuntimeWatchdogSec=) opens /dev/watchdog. A ping moves BITE_TIME to CUR_TIME + timeout; CUR_TIME is never written, being the clocksource. The comparator fires when the counter reaches BITE_TIME, not while it is above it (iBoot enables RESET_EN with CUR_TIME at 0x80000000 and a small BITE_TIME), so a bite past the 32-bit wrap is correct and timeouts go up to 178 s. On the A6, ENABLE stays set: the counter only runs with it. It is started at boot whatever the boot loader armed, with no way out: this hardware has no power off, so a halt ends in the bite as well. The restart path keeps its own bite. apple_wdt_timeout= (60 s) sets the timeout; 0 leaves the watchdog as the boot loader left it. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
The board has no way to cut its own power, so a power off halted and waited for the watchdog's timeout. A phone booted from iOS that powers off belongs back in iOS: restart through the watchdog at once, as a low-priority power-off handler that a real one would replace. Halt and power off also get the 10 s net the reboot notifier arms for a restart. For the flights, a ping whose bite lies past the counter's 32-bit wrap is logged, and debugfs apple-wdt/state shows the counter, the bite and CTRL. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…og core The watchdog that Linux now keeps armed set WDT_CTRL_ENABLE only on boards named "apple,s5l8950x". The A6X's counter needs the same bit to run, so use the A6-family helper the clocksource and restart paths use: on the A6X, starting or stopping the watchdog would otherwise stop its only clock. The watchdog registers with the watchdog core from code built into every S5L kernel, but nothing asked for that core: it was only there because unrelated watchdog drivers in the defconfig select it. Select WATCHDOG and WATCHDOG_CORE from ARCH_APPLE_S5L, so a configuration without those drivers still links. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
This was referenced Dec 2, 2026
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.
The iPhone 5 (A6) boots Linux through m1n1 on the shared 32-bit kernel, and the iPad 4 (A6X) gets the same core support once its device trees land. Every 32-bit board also gets a watchdog that recovers a hung system by itself.
What the iPhone 5 (N41, N42) gets
s5l8950x.dtsi), the shared iPhone 5 file, and the N41 and N42 boards.What every 32-bit board gets (A5, A5X, A6, A6X)
apple_wdt_timeout=changes it). The kernel pets it until systemd takes over/dev/watchdog. If the system hangs, the device resets on its own within the timeout, with no button pressed.Carried unchanged
This branch carries Berkay Kösebay's (
brkosebay) linux#57 and linux#58 exactly as they are, plus the two watchdog commits of linux#64 (not the PRs between #58 and #64). His authorship and sign-offs are kept.Three fixes on top, so the A6X works too
For the iPad 4 PR (#80)
#80 and this branch both turn the USB PHY's fixed addresses into a per-chip table, with different field names. Whichever lands second needs that table merged by hand. The A6X's USB gate addresses are the A6's, and only one tuning value differs. The other overlaps (the device-tree list, the startup checks for the A9 core, and the machine's chip list) are one-line merges.