interrupts.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * (C) Copyright 2007
  3. * Sascha Hauer, Pengutronix
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/arch/mx31-regs.h>
  25. #define TIMER_BASE 0x53f90000 /* General purpose timer 1 */
  26. /* General purpose timers registers */
  27. #define GPTCR __REG(TIMER_BASE) /* Control register */
  28. #define GPTPR __REG(TIMER_BASE + 0x4) /* Prescaler register */
  29. #define GPTSR __REG(TIMER_BASE + 0x8) /* Status register */
  30. #define GPTCNT __REG(TIMER_BASE + 0x24) /* Counter register */
  31. /* General purpose timers bitfields */
  32. #define GPTCR_SWR (1<<15) /* Software reset */
  33. #define GPTCR_FRR (1<<9) /* Freerun / restart */
  34. #define GPTCR_CLKSOURCE_32 (4<<6) /* Clock source */
  35. #define GPTCR_TEN (1) /* Timer enable */
  36. /*
  37. * nothing really to do with interrupts, just starts up a counter.
  38. */
  39. int interrupt_init(void)
  40. {
  41. int i;
  42. /* setup GP Timer 1 */
  43. GPTCR = GPTCR_SWR;
  44. for (i = 0; i < 100; i++) GPTCR = 0; /* We have no udelay by now */
  45. GPTPR = 0; /* 32Khz */
  46. /* Freerun Mode, PERCLK1 input */
  47. GPTCR |= GPTCR_CLKSOURCE_32 | GPTCR_TEN;
  48. return 0;
  49. }
  50. void reset_timer_masked(void)
  51. {
  52. GPTCR = 0;
  53. /* Freerun Mode, PERCLK1 input*/
  54. GPTCR = GPTCR_CLKSOURCE_32 | GPTCR_TEN;
  55. }
  56. ulong get_timer_masked(void)
  57. {
  58. ulong val = GPTCNT;
  59. return val;
  60. }
  61. ulong get_timer(ulong base)
  62. {
  63. return get_timer_masked() - base;
  64. }
  65. void set_timer(ulong t)
  66. {
  67. }
  68. /* delay x useconds AND perserve advance timstamp value */
  69. void udelay(unsigned long usec)
  70. {
  71. ulong tmo, tmp;
  72. if (usec >= 1000) {
  73. /* "big" number, spread normalization to seconds */
  74. /* start to normalize for usec to ticks per sec */
  75. tmo = usec / 1000;
  76. /* find number of "ticks" to wait to achieve target */
  77. tmo *= CFG_HZ;
  78. tmo /= 1000; /* finish normalize. */
  79. } else {
  80. /* else small number, don't kill it prior to HZ multiply */
  81. tmo = usec * CFG_HZ;
  82. tmo /= (1000*1000);
  83. }
  84. tmp = get_timer(0); /* get current timestamp */
  85. if ((tmo + tmp + 1) < tmp)
  86. /* setting this forward will roll time stamp */
  87. /* reset "advancing" timestamp to 0, set lastinc value */
  88. reset_timer_masked();
  89. else
  90. /* else, set advancing stamp wake up time */
  91. tmo += tmp;
  92. while (get_timer_masked() < tmo)/* loop till event */
  93. /*NOP*/;
  94. }
  95. void reset_cpu(ulong addr)
  96. {
  97. __REG16(WDOG_BASE) = 4;
  98. }