xref: /openbmc/linux/arch/mips/rb532/time.c (revision 41173abc)
141173abcSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
273b4390fSRalf Baechle /*
373b4390fSRalf Baechle  * Carsten Langgaard, carstenl@mips.com
473b4390fSRalf Baechle  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
573b4390fSRalf Baechle  *
673b4390fSRalf Baechle  *  Setting up the clock on the MIPS boards.
773b4390fSRalf Baechle  */
873b4390fSRalf Baechle 
973b4390fSRalf Baechle #include <linux/init.h>
1073b4390fSRalf Baechle #include <linux/kernel_stat.h>
1173b4390fSRalf Baechle #include <linux/ptrace.h>
1273b4390fSRalf Baechle #include <linux/sched.h>
1373b4390fSRalf Baechle #include <linux/spinlock.h>
1473b4390fSRalf Baechle #include <linux/mc146818rtc.h>
1573b4390fSRalf Baechle #include <linux/irq.h>
1673b4390fSRalf Baechle #include <linux/timex.h>
1773b4390fSRalf Baechle 
1873b4390fSRalf Baechle #include <asm/mipsregs.h>
1973b4390fSRalf Baechle #include <asm/time.h>
2073b4390fSRalf Baechle #include <asm/mach-rc32434/rc32434.h>
2173b4390fSRalf Baechle 
2273b4390fSRalf Baechle extern unsigned int idt_cpu_freq;
2373b4390fSRalf Baechle 
2473b4390fSRalf Baechle /*
2573b4390fSRalf Baechle  * Figure out the r4k offset, the amount to increment the compare
2673b4390fSRalf Baechle  * register for each time tick. There is no RTC available.
2773b4390fSRalf Baechle  *
2873b4390fSRalf Baechle  * The RC32434 counts at half the CPU *core* speed.
2973b4390fSRalf Baechle  */
cal_r4koff(void)3073b4390fSRalf Baechle static unsigned long __init cal_r4koff(void)
3173b4390fSRalf Baechle {
3273b4390fSRalf Baechle 	mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
3373b4390fSRalf Baechle 
3473b4390fSRalf Baechle 	return mips_hpt_frequency / HZ;
3573b4390fSRalf Baechle }
3673b4390fSRalf Baechle 
plat_time_init(void)3773b4390fSRalf Baechle void __init plat_time_init(void)
3873b4390fSRalf Baechle {
398b32d6d0SAdrian Bunk 	unsigned int est_freq;
408b32d6d0SAdrian Bunk 	unsigned long flags, r4k_offset;
4173b4390fSRalf Baechle 
4273b4390fSRalf Baechle 	local_irq_save(flags);
4373b4390fSRalf Baechle 
4473b4390fSRalf Baechle 	printk(KERN_INFO "calculating r4koff... ");
4573b4390fSRalf Baechle 	r4k_offset = cal_r4koff();
4673b4390fSRalf Baechle 	printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
4773b4390fSRalf Baechle 
4873b4390fSRalf Baechle 	est_freq = 2 * r4k_offset * HZ;
4973b4390fSRalf Baechle 	est_freq += 5000;	/* round */
5073b4390fSRalf Baechle 	est_freq -= est_freq % 10000;
5173b4390fSRalf Baechle 	printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
5273b4390fSRalf Baechle 	       (est_freq % 1000000) * 100 / 1000000);
5373b4390fSRalf Baechle 	local_irq_restore(flags);
5473b4390fSRalf Baechle }
55