Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Carsten Langgaard, carstenl@mips.com
0004  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
0005  *
0006  *  Setting up the clock on the MIPS boards.
0007  */
0008 
0009 #include <linux/init.h>
0010 #include <linux/kernel_stat.h>
0011 #include <linux/ptrace.h>
0012 #include <linux/sched.h>
0013 #include <linux/spinlock.h>
0014 #include <linux/mc146818rtc.h>
0015 #include <linux/irq.h>
0016 #include <linux/timex.h>
0017 
0018 #include <asm/mipsregs.h>
0019 #include <asm/time.h>
0020 #include <asm/mach-rc32434/rc32434.h>
0021 
0022 extern unsigned int idt_cpu_freq;
0023 
0024 /*
0025  * Figure out the r4k offset, the amount to increment the compare
0026  * register for each time tick. There is no RTC available.
0027  *
0028  * The RC32434 counts at half the CPU *core* speed.
0029  */
0030 static unsigned long __init cal_r4koff(void)
0031 {
0032     mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
0033 
0034     return mips_hpt_frequency / HZ;
0035 }
0036 
0037 void __init plat_time_init(void)
0038 {
0039     unsigned int est_freq;
0040     unsigned long flags, r4k_offset;
0041 
0042     local_irq_save(flags);
0043 
0044     printk(KERN_INFO "calculating r4koff... ");
0045     r4k_offset = cal_r4koff();
0046     printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
0047 
0048     est_freq = 2 * r4k_offset * HZ;
0049     est_freq += 5000;   /* round */
0050     est_freq -= est_freq % 10000;
0051     printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
0052            (est_freq % 1000000) * 100 / 1000000);
0053     local_irq_restore(flags);
0054 }