sead3-time.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/irqchip/mips-gic.h>
  10. #include <asm/cpu.h>
  11. #include <asm/setup.h>
  12. #include <asm/time.h>
  13. #include <asm/irq.h>
  14. #include <asm/mips-boards/generic.h>
  15. static void __iomem *status_reg = (void __iomem *)0xbf000410;
  16. /*
  17. * Estimate CPU frequency. Sets mips_hpt_frequency as a side-effect.
  18. */
  19. static unsigned int __init estimate_cpu_frequency(void)
  20. {
  21. unsigned int prid = read_c0_prid() & (PRID_COMP_MASK | PRID_IMP_MASK);
  22. unsigned int tick = 0;
  23. unsigned int freq;
  24. unsigned int orig;
  25. unsigned long flags;
  26. local_irq_save(flags);
  27. orig = readl(status_reg) & 0x2; /* get original sample */
  28. /* wait for transition */
  29. while ((readl(status_reg) & 0x2) == orig)
  30. ;
  31. orig = orig ^ 0x2; /* flip the bit */
  32. write_c0_count(0);
  33. /* wait 1 second (the sampling clock transitions every 10ms) */
  34. while (tick < 100) {
  35. /* wait for transition */
  36. while ((readl(status_reg) & 0x2) == orig)
  37. ;
  38. orig = orig ^ 0x2; /* flip the bit */
  39. tick++;
  40. }
  41. freq = read_c0_count();
  42. local_irq_restore(flags);
  43. mips_hpt_frequency = freq;
  44. /* Adjust for processor */
  45. if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
  46. (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
  47. freq *= 2;
  48. freq += 5000; /* rounding */
  49. freq -= freq%10000;
  50. return freq ;
  51. }
  52. void read_persistent_clock(struct timespec *ts)
  53. {
  54. ts->tv_sec = 0;
  55. ts->tv_nsec = 0;
  56. }
  57. int get_c0_perfcount_int(void)
  58. {
  59. if (gic_present)
  60. return gic_get_c0_perfcount_int();
  61. if (cp0_perfcount_irq >= 0)
  62. return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
  63. return -1;
  64. }
  65. unsigned int get_c0_compare_int(void)
  66. {
  67. if (gic_present)
  68. return gic_get_c0_compare_int();
  69. return MIPS_CPU_IRQ_BASE + cp0_compare_irq;
  70. }
  71. void __init plat_time_init(void)
  72. {
  73. unsigned int est_freq;
  74. est_freq = estimate_cpu_frequency();
  75. pr_debug("CPU frequency %d.%02d MHz\n", (est_freq / 1000000),
  76. (est_freq % 1000000) * 100 / 1000000);
  77. mips_scroll_message();
  78. }