timer.c 1.9 KB

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