timer.c 1.9 KB

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