Convert MediaTek GPT timers to OF probing
Status from this message: The following commit has been merged into the timers/drivers/next branch of clocksource:
Get series with b4
b4 am [email protected]Versions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | clocksource/drivers/timer-mediatek: Fix random crash at bootdrivers/ | +3 | 0 replies | |
| 2/3 | clocksource/drivers/timer-mediatek: Convert to OF probingdrivers/ | +31 | 1 reply | |
| 3/3 | clocksource/drivers/timer-mediatek: Request and enable the bus clockdrivers/ | +10 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/3] Convert MediaTek GPT timers to OF probing
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.
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!
Luca Leonardo Scorcia (3):
clocksource/drivers/timer-mediatek: Fix random crash at boot clocksource/drivers/timer-mediatek: Convert to OF probing clocksource/drivers/timer-mediatek: Request and enable the bus clock
drivers/clocksource/timer-mediatek.c | 47 +++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0