Re: [PATCH 0/3] Convert MediaTek GPT timers to OF probing
From: Roman Vivchar
Date: Fri Oct 02 2026 - 03:57:38 EST
Hi,
On Friday, October 2nd, 2026 at 10:21 AM, Luca Leonardo Scorcia <l.scorcia@xxxxxxxxx> wrote:
> While chasing a kernel freeze on the Lenovo Tab E7 TB-7104F (mt8167), I
> stumbled on the MediaTek GPT timer driver. This driver is currently early
> loaded via TIMER_OF_DECLARE. I noticed that on mt8167 (and I guess mt8516
> too), this driver actually fails to probe because its device tree
> declaration depends on two HW clocks, CLK_TOP_CLK26M_D2 (13 MHz) and
> CLK_TOP_APXGPT (bus clock). However the driver providing those clocks is
> loaded later in the boot process, leading TIMER_OF_DECLARE to fail with
> -EDEFER.
>
> Patch #2 converts this driver to OF probe, fixing this initial issue.
>
> I noticed that other devices avoid this by connecting the timer to
> fixed clocks instead of referring to an actual clock. This approach
> may work on mt8167 too, but I think referring to the actual clock is
> cleaner.
>
> Once the driver probed successfully I noticed that even if it was enabled
> by the boot loader, the kernel would quickly turn off its bus clock as
> the driver wasn't actually requesting it.
>
> Patch #3 enables it and attaches it to the timer device. I wondered how
> other platforms made it actually work, and noticed that mt6735 declares it
> as a critical clock. This approach might work for mt8167 too, but same
> reasoning as before applies.
Most mt67xx and their 81xx siblings are feeding arch timer from cpuxgpt timers.
These are usually turned on by the firmware at EL3, so in general you can
disable both apxgpt and syst in the devicetree (unless 8167 feeds arch timer
from the gpt6 like 65xx...)
>
> After those fixes the driver probes and works correctly, but I would
> occasionally notice a crash at boot inside the timer interrupt handler.
> It turned out to be a side effect of the bootloader enabling the GPT
> timer at boot: an interrupt may arrive and be handled while the driver is
> not completely initialized.
>
> Patch #1 fixes it by requesting the IRQ but keeping it disabled and
> enabling it after the clock source initialization completes. I sorted this
> patch before the others because it's actually independent of the latter
> two and may fix (rare) random crashes on other devices.
>
> Please note that all the changes apply both to GPT timers and the SYST
> timers, but I have no device to test the SYST ones.
>
> The series was tested on the Sony PlayStation Classic Mini (mt8167).
>
> Re: patch #1, credits for issue discovery and suggested fix go to
> matemiller992 on postmarketOS forums. I am submitting it upstream with
> permission. Not adding Reported-by or Suggested-by tags because it was
> requested not to share real name.
>
> Unfortunately, this series did not fix the tablet randomly freezing during
> boot. Any idea on how to better troubleshoot this is more than welcome!
Have you tried to add {clk,regulator,pd}_ignore_unused? If that doesn't help,
try turning off cpufreq. On mt6595 I had to mark CPU regulator as always-on
(although it should be safe to disable) to avoid system freeze at the boot.
Otherwise start adding status = "disabled" to the devicetree nodes until it
properly boots.
Best regards,
Roman