time.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Carsten Langgaard, [email protected]
  4. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  5. *
  6. * Setting up the clock on the MIPS boards.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/kernel_stat.h>
  10. #include <linux/ptrace.h>
  11. #include <linux/sched.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/mc146818rtc.h>
  14. #include <linux/irq.h>
  15. #include <linux/timex.h>
  16. #include <asm/mipsregs.h>
  17. #include <asm/time.h>
  18. #include <asm/mach-rc32434/rc32434.h>
  19. extern unsigned int idt_cpu_freq;
  20. /*
  21. * Figure out the r4k offset, the amount to increment the compare
  22. * register for each time tick. There is no RTC available.
  23. *
  24. * The RC32434 counts at half the CPU *core* speed.
  25. */
  26. static unsigned long __init cal_r4koff(void)
  27. {
  28. mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
  29. return mips_hpt_frequency / HZ;
  30. }
  31. void __init plat_time_init(void)
  32. {
  33. unsigned int est_freq;
  34. unsigned long flags, r4k_offset;
  35. local_irq_save(flags);
  36. printk(KERN_INFO "calculating r4koff... ");
  37. r4k_offset = cal_r4koff();
  38. printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
  39. est_freq = 2 * r4k_offset * HZ;
  40. est_freq += 5000; /* round */
  41. est_freq -= est_freq % 10000;
  42. printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
  43. (est_freq % 1000000) * 100 / 1000000);
  44. local_irq_restore(flags);
  45. }