timer.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #if defined (CONFIG_IMX)
  17. #include <asm/arch/imx-regs.h>
  18. int timer_init (void)
  19. {
  20. int i;
  21. /* setup GP Timer 1 */
  22. TCTL1 = TCTL_SWR;
  23. for ( i=0; i<100; i++) TCTL1 = 0; /* We have no udelay by now */
  24. TPRER1 = get_PERCLK1() / 1000000; /* 1 MHz */
  25. TCTL1 |= TCTL_FRR | (1<<1); /* Freerun Mode, PERCLK1 input */
  26. /* Reset the timer */
  27. TCTL1 &= ~TCTL_TEN;
  28. TCTL1 |= TCTL_TEN; /* Enable timer */
  29. return (0);
  30. }
  31. /*
  32. * timer without interrupts
  33. */
  34. ulong get_timer (ulong base)
  35. {
  36. return get_timer_masked() - base;
  37. }
  38. ulong get_timer_masked (void)
  39. {
  40. return TCN1;
  41. }
  42. void udelay_masked (unsigned long usec)
  43. {
  44. ulong endtime = get_timer_masked() + usec;
  45. signed long diff;
  46. do {
  47. ulong now = get_timer_masked ();
  48. diff = endtime - now;
  49. } while (diff >= 0);
  50. }
  51. void __udelay (unsigned long usec)
  52. {
  53. udelay_masked(usec);
  54. }
  55. /*
  56. * This function is derived from PowerPC code (read timebase as long long).
  57. * On ARM it just returns the timer value.
  58. */
  59. unsigned long long get_ticks(void)
  60. {
  61. return get_timer(0);
  62. }
  63. /*
  64. * This function is derived from PowerPC code (timebase clock frequency).
  65. * On ARM it returns the number of timer ticks per second.
  66. */
  67. ulong get_tbclk (void)
  68. {
  69. ulong tbclk;
  70. tbclk = CONFIG_SYS_HZ;
  71. return tbclk;
  72. }
  73. /*
  74. * Reset the cpu by setting up the watchdog timer and let him time out
  75. */
  76. void reset_cpu (ulong ignored)
  77. {
  78. /* Disable watchdog and set Time-Out field to 0 */
  79. WCR = 0x00000000;
  80. /* Write Service Sequence */
  81. WSR = 0x00005555;
  82. WSR = 0x0000AAAA;
  83. /* Enable watchdog */
  84. WCR = 0x00000001;
  85. while (1);
  86. /*NOTREACHED*/
  87. }
  88. #endif /* defined (CONFIG_IMX) */