timer.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <time.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. static ulong get_timer_masked (void)
  35. {
  36. return TCN1;
  37. }
  38. ulong get_timer (ulong base)
  39. {
  40. return get_timer_masked() - base;
  41. }
  42. void __udelay (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. /*
  52. * This function is derived from PowerPC code (read timebase as long long).
  53. * On ARM it just returns the timer value.
  54. */
  55. unsigned long long get_ticks(void)
  56. {
  57. return get_timer(0);
  58. }
  59. /*
  60. * This function is derived from PowerPC code (timebase clock frequency).
  61. * On ARM it returns the number of timer ticks per second.
  62. */
  63. ulong get_tbclk (void)
  64. {
  65. return CONFIG_SYS_HZ;
  66. }
  67. /*
  68. * Reset the cpu by setting up the watchdog timer and let him time out
  69. */
  70. void reset_cpu (ulong ignored)
  71. {
  72. /* Disable watchdog and set Time-Out field to 0 */
  73. WCR = 0x00000000;
  74. /* Write Service Sequence */
  75. WSR = 0x00005555;
  76. WSR = 0x0000AAAA;
  77. /* Enable watchdog */
  78. WCR = 0x00000001;
  79. while (1);
  80. /*NOTREACHED*/
  81. }
  82. #endif /* defined (CONFIG_IMX) */