interrupts.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * (C) Copyright 2004-2005, Greg Ungerer <greg.ungerer@opengear.com>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <asm/arch/platform.h>
  24. /*
  25. * Handy KS8695 register access functions.
  26. */
  27. #define ks8695_read(a) *((volatile ulong *) (KS8695_IO_BASE + (a)))
  28. #define ks8695_write(a,v) *((volatile ulong *) (KS8695_IO_BASE + (a))) = (v)
  29. int timer_inited;
  30. ulong timer_ticks;
  31. int interrupt_init (void)
  32. {
  33. /* nothing happens here - we don't setup any IRQs */
  34. return (0);
  35. }
  36. /*
  37. * Initial timer set constants. Nothing complicated, just set for a 1ms
  38. * tick.
  39. */
  40. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_1)
  41. #define TIMER_COUNT (TIMER_INTERVAL / 2)
  42. #define TIMER_PULSE TIMER_COUNT
  43. void reset_timer_masked(void)
  44. {
  45. /* Set the hadware timer for 1ms */
  46. ks8695_write(KS8695_TIMER1, TIMER_COUNT);
  47. ks8695_write(KS8695_TIMER1_PCOUNT, TIMER_PULSE);
  48. ks8695_write(KS8695_TIMER_CTRL, 0x2);
  49. timer_ticks = 0;
  50. timer_inited++;
  51. }
  52. void reset_timer(void)
  53. {
  54. reset_timer_masked();
  55. }
  56. ulong get_timer_masked(void)
  57. {
  58. /* Check for timer wrap */
  59. if (ks8695_read(KS8695_INT_STATUS) & KS8695_INTMASK_TIMERINT1) {
  60. /* Clear interrupt condition */
  61. ks8695_write(KS8695_INT_STATUS, KS8695_INTMASK_TIMERINT1);
  62. timer_ticks++;
  63. }
  64. return timer_ticks;
  65. }
  66. ulong get_timer(ulong base)
  67. {
  68. return (get_timer_masked() - base);
  69. }
  70. void set_timer(ulong t)
  71. {
  72. timer_ticks = t;
  73. }
  74. void udelay(ulong usec)
  75. {
  76. ulong start = get_timer_masked();
  77. ulong end;
  78. if (!timer_inited)
  79. reset_timer();
  80. /* Only 1ms resolution :-( */
  81. end = usec / 1000;
  82. while (get_timer(start) < end)
  83. ;
  84. }
  85. void reset_cpu (ulong ignored)
  86. {
  87. ulong tc;
  88. /* Set timer0 to watchdog, and let it timeout */
  89. tc = ks8695_read(KS8695_TIMER_CTRL) & 0x2;
  90. ks8695_write(KS8695_TIMER_CTRL, tc);
  91. ks8695_write(KS8695_TIMER0, ((10 << 8) | 0xff));
  92. ks8695_write(KS8695_TIMER_CTRL, (tc | 0x1));
  93. /* Should only wait here till watchdog resets */
  94. for (;;)
  95. ;
  96. }