cevt-gt641xx.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * GT641xx clockevent routines.
  3. *
  4. * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/clockchips.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/irq.h>
  25. #include <asm/gt64120.h>
  26. #include <asm/time.h>
  27. static DEFINE_RAW_SPINLOCK(gt641xx_timer_lock);
  28. static unsigned int gt641xx_base_clock;
  29. void gt641xx_set_base_clock(unsigned int clock)
  30. {
  31. gt641xx_base_clock = clock;
  32. }
  33. int gt641xx_timer0_state(void)
  34. {
  35. if (GT_READ(GT_TC0_OFS))
  36. return 0;
  37. GT_WRITE(GT_TC0_OFS, gt641xx_base_clock / HZ);
  38. GT_WRITE(GT_TC_CONTROL_OFS, GT_TC_CONTROL_ENTC0_MSK);
  39. return 1;
  40. }
  41. static int gt641xx_timer0_set_next_event(unsigned long delta,
  42. struct clock_event_device *evt)
  43. {
  44. u32 ctrl;
  45. raw_spin_lock(&gt641xx_timer_lock);
  46. ctrl = GT_READ(GT_TC_CONTROL_OFS);
  47. ctrl &= ~(GT_TC_CONTROL_ENTC0_MSK | GT_TC_CONTROL_SELTC0_MSK);
  48. ctrl |= GT_TC_CONTROL_ENTC0_MSK;
  49. GT_WRITE(GT_TC0_OFS, delta);
  50. GT_WRITE(GT_TC_CONTROL_OFS, ctrl);
  51. raw_spin_unlock(&gt641xx_timer_lock);
  52. return 0;
  53. }
  54. static int gt641xx_timer0_shutdown(struct clock_event_device *evt)
  55. {
  56. u32 ctrl;
  57. raw_spin_lock(&gt641xx_timer_lock);
  58. ctrl = GT_READ(GT_TC_CONTROL_OFS);
  59. ctrl &= ~(GT_TC_CONTROL_ENTC0_MSK | GT_TC_CONTROL_SELTC0_MSK);
  60. GT_WRITE(GT_TC_CONTROL_OFS, ctrl);
  61. raw_spin_unlock(&gt641xx_timer_lock);
  62. return 0;
  63. }
  64. static int gt641xx_timer0_set_oneshot(struct clock_event_device *evt)
  65. {
  66. u32 ctrl;
  67. raw_spin_lock(&gt641xx_timer_lock);
  68. ctrl = GT_READ(GT_TC_CONTROL_OFS);
  69. ctrl &= ~GT_TC_CONTROL_SELTC0_MSK;
  70. ctrl |= GT_TC_CONTROL_ENTC0_MSK;
  71. GT_WRITE(GT_TC_CONTROL_OFS, ctrl);
  72. raw_spin_unlock(&gt641xx_timer_lock);
  73. return 0;
  74. }
  75. static int gt641xx_timer0_set_periodic(struct clock_event_device *evt)
  76. {
  77. u32 ctrl;
  78. raw_spin_lock(&gt641xx_timer_lock);
  79. ctrl = GT_READ(GT_TC_CONTROL_OFS);
  80. ctrl |= GT_TC_CONTROL_ENTC0_MSK | GT_TC_CONTROL_SELTC0_MSK;
  81. GT_WRITE(GT_TC_CONTROL_OFS, ctrl);
  82. raw_spin_unlock(&gt641xx_timer_lock);
  83. return 0;
  84. }
  85. static void gt641xx_timer0_event_handler(struct clock_event_device *dev)
  86. {
  87. }
  88. static struct clock_event_device gt641xx_timer0_clockevent = {
  89. .name = "gt641xx-timer0",
  90. .features = CLOCK_EVT_FEAT_PERIODIC |
  91. CLOCK_EVT_FEAT_ONESHOT,
  92. .irq = GT641XX_TIMER0_IRQ,
  93. .set_next_event = gt641xx_timer0_set_next_event,
  94. .set_state_shutdown = gt641xx_timer0_shutdown,
  95. .set_state_periodic = gt641xx_timer0_set_periodic,
  96. .set_state_oneshot = gt641xx_timer0_set_oneshot,
  97. .tick_resume = gt641xx_timer0_shutdown,
  98. .event_handler = gt641xx_timer0_event_handler,
  99. };
  100. static irqreturn_t gt641xx_timer0_interrupt(int irq, void *dev_id)
  101. {
  102. struct clock_event_device *cd = &gt641xx_timer0_clockevent;
  103. cd->event_handler(cd);
  104. return IRQ_HANDLED;
  105. }
  106. static struct irqaction gt641xx_timer0_irqaction = {
  107. .handler = gt641xx_timer0_interrupt,
  108. .flags = IRQF_PERCPU | IRQF_TIMER,
  109. .name = "gt641xx_timer0",
  110. };
  111. static int __init gt641xx_timer0_clockevent_init(void)
  112. {
  113. struct clock_event_device *cd;
  114. if (!gt641xx_base_clock)
  115. return 0;
  116. GT_WRITE(GT_TC0_OFS, gt641xx_base_clock / HZ);
  117. cd = &gt641xx_timer0_clockevent;
  118. cd->rating = 200 + gt641xx_base_clock / 10000000;
  119. clockevent_set_clock(cd, gt641xx_base_clock);
  120. cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd);
  121. cd->min_delta_ns = clockevent_delta2ns(0x300, cd);
  122. cd->cpumask = cpumask_of(0);
  123. clockevents_register_device(&gt641xx_timer0_clockevent);
  124. return setup_irq(GT641XX_TIMER0_IRQ, &gt641xx_timer0_irqaction);
  125. }
  126. arch_initcall(gt641xx_timer0_clockevent_init);