[PATCH 5/6] mach-mpc85xx: speed: add fsl_set_timebase_clock() override

Ahmad Fatoum
2026-02-09T09:15:46Z

Some platforms (e.g. QEMU) don't implement the GUTS PORPLLSR register,
so the register-based timebase frequency calculation returns 0. Add
fsl_set_timebase_clock() that allows board code to provide the correct
timebase frequency before initcalls run, bypassing the register read.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/powerpc/mach-mpc85xx/include/mach/clock.h | 1 +
arch/powerpc/mach-mpc85xx/speed.c | 10 ++++++++++
2 files changed, 11 insertions(+)

diff --git a/arch/powerpc/mach-mpc85xx/include/mach/clock.h b/arch/powerpc/mach-mpc85xx/include/mach/clock.h
index bfd9cf4d8ecd..2d0f079f5c68 100644
--- a/arch/powerpc/mach-mpc85xx/include/mach/clock.h
+++ b/arch/powerpc/mach-mpc85xx/include/mach/clock.h
@@ -14,6 +14,7 @@ struct sys_info {

unsigned long fsl_get_bus_freq(ulong dummy);
unsigned long fsl_get_ddr_freq(ulong dummy);
+void fsl_set_timebase_clock(unsigned long freq);
unsigned long fsl_get_timebase_clock(void);
unsigned long fsl_get_i2c_freq(void);
void fsl_get_sys_info(struct sys_info *sysInfo);
diff --git a/arch/powerpc/mach-mpc85xx/speed.c b/arch/powerpc/mach-mpc85xx/speed.c
index 4a69de3dc81a..8018132874ba 100644
--- a/arch/powerpc/mach-mpc85xx/speed.c
+++ b/arch/powerpc/mach-mpc85xx/speed.c
@@ -104,10 +104,20 @@ unsigned long fsl_get_ddr_freq(ulong dummy)
return sys_info.freqDDRBus;
}

+static unsigned long timebase_clock_override;
+
+void fsl_set_timebase_clock(unsigned long freq)
+{
+ timebase_clock_override = freq;
+}
+
unsigned long fsl_get_timebase_clock(void)
{
struct sys_info sysinfo;

+ if (timebase_clock_override)
+ return timebase_clock_override;
+
fsl_get_sys_info(&sysinfo);

return (sysinfo.freqSystemBus + 4UL)/8UL;
--
2.47.3