interrupts.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * (C) Copyright 2006
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * (C) Copyright 2002
  10. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  11. * Alex Zuepke <azu@sysgo.de>
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. #include <common.h>
  32. #include <asm/arch/ixp425.h>
  33. #ifdef CONFIG_USE_IRQ
  34. #include <asm/proc-armv/ptrace.h>
  35. /*
  36. * When interrupts are enabled, use timer 2 for time/delay generation...
  37. */
  38. #define FREQ 66666666
  39. #define CLOCK_TICK_RATE (((FREQ / CONFIG_SYS_HZ & ~IXP425_OST_RELOAD_MASK) + 1) * CONFIG_SYS_HZ)
  40. #define LATCH ((CLOCK_TICK_RATE + CONFIG_SYS_HZ/2) / CONFIG_SYS_HZ) /* For divider */
  41. struct _irq_handler {
  42. void *m_data;
  43. void (*m_func)( void *data);
  44. };
  45. static struct _irq_handler IRQ_HANDLER[N_IRQS];
  46. static volatile ulong timestamp;
  47. static void default_isr(void *data)
  48. {
  49. printf("default_isr(): called for IRQ %d, Interrupt Status=%x PR=%x\n",
  50. (int)data, *IXP425_ICIP, *IXP425_ICIH);
  51. }
  52. static int next_irq(void)
  53. {
  54. return (((*IXP425_ICIH & 0x000000fc) >> 2) - 1);
  55. }
  56. static void timer_isr(void *data)
  57. {
  58. unsigned int *pTime = (unsigned int *)data;
  59. (*pTime)++;
  60. /*
  61. * Reset IRQ source
  62. */
  63. *IXP425_OSST = IXP425_OSST_TIMER_2_PEND;
  64. }
  65. ulong get_timer (ulong base)
  66. {
  67. return timestamp - base;
  68. }
  69. void reset_timer (void)
  70. {
  71. timestamp = 0;
  72. }
  73. #endif /* #ifdef CONFIG_USE_IRQ */
  74. #ifdef CONFIG_USE_IRQ
  75. void do_irq (struct pt_regs *pt_regs)
  76. {
  77. int irq = next_irq();
  78. IRQ_HANDLER[irq].m_func(IRQ_HANDLER[irq].m_data);
  79. }
  80. #endif
  81. int interrupt_init (void)
  82. {
  83. #ifdef CONFIG_USE_IRQ
  84. int i;
  85. /* install default interrupt handlers */
  86. for (i = 0; i < N_IRQS; i++) {
  87. IRQ_HANDLER[i].m_data = (void *)i;
  88. IRQ_HANDLER[i].m_func = default_isr;
  89. }
  90. /* install interrupt handler for timer */
  91. IRQ_HANDLER[IXP425_TIMER_2_IRQ].m_data = (void *)&timestamp;
  92. IRQ_HANDLER[IXP425_TIMER_2_IRQ].m_func = timer_isr;
  93. /* setup the Timer counter value */
  94. *IXP425_OSRT2 = (LATCH & ~IXP425_OST_RELOAD_MASK) | IXP425_OST_ENABLE;
  95. /* configure interrupts for IRQ mode */
  96. *IXP425_ICLR = 0x00000000;
  97. /* enable timer irq */
  98. *IXP425_ICMR = (1 << IXP425_TIMER_2_IRQ);
  99. #endif
  100. return (0);
  101. }