time.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. *
  7. * Galileo Technology chip interrupt handler
  8. */
  9. #include <linux/interrupt.h>
  10. #include <linux/kernel.h>
  11. #include <linux/sched.h>
  12. #include <linux/kernel_stat.h>
  13. #include <asm/irq_regs.h>
  14. #include <asm/gt64120.h>
  15. /*
  16. * These are interrupt handlers for the GT on-chip interrupts. They all come
  17. * in to the MIPS on a single interrupt line, and have to be handled and ack'ed
  18. * differently than other MIPS interrupts.
  19. */
  20. static irqreturn_t gt64120_irq(int irq, void *dev_id)
  21. {
  22. unsigned int irq_src, int_high_src, irq_src_mask, int_high_src_mask;
  23. int handled = 0;
  24. irq_src = GT_READ(GT_INTRCAUSE_OFS);
  25. irq_src_mask = GT_READ(GT_INTRMASK_OFS);
  26. int_high_src = GT_READ(GT_HINTRCAUSE_OFS);
  27. int_high_src_mask = GT_READ(GT_HINTRMASK_OFS);
  28. irq_src = irq_src & irq_src_mask;
  29. int_high_src = int_high_src & int_high_src_mask;
  30. if (irq_src & 0x00000800) { /* Check for timer interrupt */
  31. handled = 1;
  32. irq_src &= ~0x00000800;
  33. do_timer(1);
  34. #ifndef CONFIG_SMP
  35. update_process_times(user_mode(get_irq_regs()));
  36. #endif
  37. }
  38. GT_WRITE(GT_INTRCAUSE_OFS, 0);
  39. GT_WRITE(GT_HINTRCAUSE_OFS, 0);
  40. return IRQ_HANDLED;
  41. }
  42. /*
  43. * Initializes timer using galileo's built in timer.
  44. */
  45. #ifdef CONFIG_SYSCLK_100
  46. #define Sys_clock (100 * 1000000) // 100 MHz
  47. #endif
  48. #ifdef CONFIG_SYSCLK_83
  49. #define Sys_clock (83.333 * 1000000) // 83.333 MHz
  50. #endif
  51. #ifdef CONFIG_SYSCLK_75
  52. #define Sys_clock (75 * 1000000) // 75 MHz
  53. #endif
  54. /*
  55. * This will ignore the standard MIPS timer interrupt handler that is passed in
  56. * as *irq (=irq0 in ../kernel/time.c). We will do our own timer interrupt
  57. * handling.
  58. */
  59. void __init plat_timer_setup(struct irqaction *irq)
  60. {
  61. static struct irqaction timer;
  62. /* Disable timer first */
  63. GT_WRITE(GT_TC_CONTROL_OFS, 0);
  64. /* Load timer value for 100 Hz */
  65. GT_WRITE(GT_TC3_OFS, Sys_clock / HZ);
  66. /*
  67. * Create the IRQ structure entry for the timer. Since we're too early
  68. * in the boot process to use the "request_irq()" call, we'll hard-code
  69. * the values to the correct interrupt line.
  70. */
  71. timer.handler = gt64120_irq;
  72. timer.flags = IRQF_SHARED | IRQF_DISABLED;
  73. timer.name = "timer";
  74. timer.dev_id = NULL;
  75. timer.next = NULL;
  76. timer.mask = CPU_MASK_NONE;
  77. irq_desc[GT_TIMER].action = &timer;
  78. enable_irq(GT_TIMER);
  79. /* Enable timer ints */
  80. GT_WRITE(GT_TC_CONTROL_OFS, 0xc0);
  81. /* clear Cause register first */
  82. GT_WRITE(GT_INTRCAUSE_OFS, 0x0);
  83. /* Unmask timer int */
  84. GT_WRITE(GT_INTRMASK_OFS, 0x800);
  85. /* Clear High int register */
  86. GT_WRITE(GT_HINTRCAUSE_OFS, 0x0);
  87. /* Mask All interrupts at High cause interrupt */
  88. GT_WRITE(GT_HINTRMASK_OFS, 0x0);
  89. }