timer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Alex Zuepke <azu@sysgo.de>
  9. *
  10. * (C) Copyright 2002
  11. * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. #include <common.h>
  32. #if defined (CONFIG_IMX)
  33. #include <asm/arch/imx-regs.h>
  34. int timer_init (void)
  35. {
  36. int i;
  37. /* setup GP Timer 1 */
  38. TCTL1 = TCTL_SWR;
  39. for ( i=0; i<100; i++) TCTL1 = 0; /* We have no udelay by now */
  40. TPRER1 = get_PERCLK1() / 1000000; /* 1 MHz */
  41. TCTL1 |= TCTL_FRR | (1<<1); /* Freerun Mode, PERCLK1 input */
  42. reset_timer_masked();
  43. return (0);
  44. }
  45. /*
  46. * timer without interrupts
  47. */
  48. void reset_timer (void)
  49. {
  50. reset_timer_masked ();
  51. }
  52. ulong get_timer (ulong base)
  53. {
  54. return get_timer_masked() - base;
  55. }
  56. void reset_timer_masked (void)
  57. {
  58. TCTL1 &= ~TCTL_TEN;
  59. TCTL1 |= TCTL_TEN; /* Enable timer */
  60. }
  61. ulong get_timer_masked (void)
  62. {
  63. return TCN1;
  64. }
  65. void udelay_masked (unsigned long usec)
  66. {
  67. ulong endtime = get_timer_masked() + usec;
  68. signed long diff;
  69. do {
  70. ulong now = get_timer_masked ();
  71. diff = endtime - now;
  72. } while (diff >= 0);
  73. }
  74. void __udelay (unsigned long usec)
  75. {
  76. udelay_masked(usec);
  77. }
  78. /*
  79. * This function is derived from PowerPC code (read timebase as long long).
  80. * On ARM it just returns the timer value.
  81. */
  82. unsigned long long get_ticks(void)
  83. {
  84. return get_timer(0);
  85. }
  86. /*
  87. * This function is derived from PowerPC code (timebase clock frequency).
  88. * On ARM it returns the number of timer ticks per second.
  89. */
  90. ulong get_tbclk (void)
  91. {
  92. ulong tbclk;
  93. tbclk = CONFIG_SYS_HZ;
  94. return tbclk;
  95. }
  96. /*
  97. * Reset the cpu by setting up the watchdog timer and let him time out
  98. */
  99. void reset_cpu (ulong ignored)
  100. {
  101. /* Disable watchdog and set Time-Out field to 0 */
  102. WCR = 0x00000000;
  103. /* Write Service Sequence */
  104. WSR = 0x00005555;
  105. WSR = 0x0000AAAA;
  106. /* Enable watchdog */
  107. WCR = 0x00000001;
  108. while (1);
  109. /*NOTREACHED*/
  110. }
  111. #endif /* defined (CONFIG_IMX) */