msp_time.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Setting up the clock on MSP SOCs. No RTC typically.
  3. *
  4. * Carsten Langgaard, carstenl@mips.com
  5. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  6. *
  7. * ########################################################################
  8. *
  9. * This program is free software; you can distribute it and/or modify it
  10. * under the terms of the GNU General Public License (Version 2) as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  21. *
  22. * ########################################################################
  23. */
  24. #include <linux/init.h>
  25. #include <linux/kernel_stat.h>
  26. #include <linux/sched.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/ptrace.h>
  29. #include <asm/cevt-r4k.h>
  30. #include <asm/mipsregs.h>
  31. #include <asm/time.h>
  32. #include <msp_prom.h>
  33. #include <msp_int.h>
  34. #include <msp_regs.h>
  35. #define get_current_vpe() \
  36. ((read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE)
  37. static struct irqaction timer_vpe1;
  38. static int tim_installed;
  39. void __init plat_time_init(void)
  40. {
  41. char *endp, *s;
  42. unsigned long cpu_rate = 0;
  43. if (cpu_rate == 0) {
  44. s = prom_getenv("clkfreqhz");
  45. cpu_rate = simple_strtoul(s, &endp, 10);
  46. if (endp != NULL && *endp != 0) {
  47. printk(KERN_ERR
  48. "Clock rate in Hz parse error: %s\n", s);
  49. cpu_rate = 0;
  50. }
  51. }
  52. if (cpu_rate == 0) {
  53. s = prom_getenv("clkfreq");
  54. cpu_rate = 1000 * simple_strtoul(s, &endp, 10);
  55. if (endp != NULL && *endp != 0) {
  56. printk(KERN_ERR
  57. "Clock rate in MHz parse error: %s\n", s);
  58. cpu_rate = 0;
  59. }
  60. }
  61. if (cpu_rate == 0) {
  62. #if defined(CONFIG_PMC_MSP7120_EVAL) \
  63. || defined(CONFIG_PMC_MSP7120_GW)
  64. cpu_rate = 400000000;
  65. #elif defined(CONFIG_PMC_MSP7120_FPGA)
  66. cpu_rate = 25000000;
  67. #else
  68. cpu_rate = 150000000;
  69. #endif
  70. printk(KERN_ERR
  71. "Failed to determine CPU clock rate, "
  72. "assuming %ld hz ...\n", cpu_rate);
  73. }
  74. printk(KERN_WARNING "Clock rate set to %ld\n", cpu_rate);
  75. /* timer frequency is 1/2 clock rate */
  76. mips_hpt_frequency = cpu_rate/2;
  77. }
  78. unsigned int get_c0_compare_int(void)
  79. {
  80. /* MIPS_MT modes may want timer for second VPE */
  81. if ((get_current_vpe()) && !tim_installed) {
  82. memcpy(&timer_vpe1, &c0_compare_irqaction, sizeof(timer_vpe1));
  83. setup_irq(MSP_INT_VPE1_TIMER, &timer_vpe1);
  84. tim_installed++;
  85. }
  86. return get_current_vpe() ? MSP_INT_VPE1_TIMER : MSP_INT_VPE0_TIMER;
  87. }