time.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * Setting up the clock on the MIPS boards.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/kernel_stat.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/sched.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/mc146818rtc.h>
  26. #include <linux/irq.h>
  27. #include <linux/timex.h>
  28. #include <asm/mipsregs.h>
  29. #include <asm/debug.h>
  30. #include <asm/time.h>
  31. #include <asm/mach-rc32434/rc32434.h>
  32. extern unsigned int idt_cpu_freq;
  33. /*
  34. * Figure out the r4k offset, the amount to increment the compare
  35. * register for each time tick. There is no RTC available.
  36. *
  37. * The RC32434 counts at half the CPU *core* speed.
  38. */
  39. static unsigned long __init cal_r4koff(void)
  40. {
  41. mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
  42. return mips_hpt_frequency / HZ;
  43. }
  44. void __init plat_time_init(void)
  45. {
  46. unsigned int est_freq;
  47. unsigned long flags, r4k_offset;
  48. local_irq_save(flags);
  49. printk(KERN_INFO "calculating r4koff... ");
  50. r4k_offset = cal_r4koff();
  51. printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
  52. est_freq = 2 * r4k_offset * HZ;
  53. est_freq += 5000; /* round */
  54. est_freq -= est_freq % 10000;
  55. printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
  56. (est_freq % 1000000) * 100 / 1000000);
  57. local_irq_restore(flags);
  58. }