dc21285-timer.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * linux/arch/arm/mach-footbridge/dc21285-timer.c
  3. *
  4. * Copyright (C) 1998 Russell King.
  5. * Copyright (C) 1998 Phil Blundell
  6. */
  7. #include <linux/clockchips.h>
  8. #include <linux/clocksource.h>
  9. #include <linux/init.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/irq.h>
  12. #include <linux/sched_clock.h>
  13. #include <asm/irq.h>
  14. #include <asm/hardware/dec21285.h>
  15. #include <asm/mach/time.h>
  16. #include <asm/system_info.h>
  17. #include "common.h"
  18. static cycle_t cksrc_dc21285_read(struct clocksource *cs)
  19. {
  20. return cs->mask - *CSR_TIMER2_VALUE;
  21. }
  22. static int cksrc_dc21285_enable(struct clocksource *cs)
  23. {
  24. *CSR_TIMER2_LOAD = cs->mask;
  25. *CSR_TIMER2_CLR = 0;
  26. *CSR_TIMER2_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;
  27. return 0;
  28. }
  29. static void cksrc_dc21285_disable(struct clocksource *cs)
  30. {
  31. *CSR_TIMER2_CNTL = 0;
  32. }
  33. static struct clocksource cksrc_dc21285 = {
  34. .name = "dc21285_timer2",
  35. .rating = 200,
  36. .read = cksrc_dc21285_read,
  37. .enable = cksrc_dc21285_enable,
  38. .disable = cksrc_dc21285_disable,
  39. .mask = CLOCKSOURCE_MASK(24),
  40. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  41. };
  42. static int ckevt_dc21285_set_next_event(unsigned long delta,
  43. struct clock_event_device *c)
  44. {
  45. *CSR_TIMER1_CLR = 0;
  46. *CSR_TIMER1_LOAD = delta;
  47. *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;
  48. return 0;
  49. }
  50. static void ckevt_dc21285_set_mode(enum clock_event_mode mode,
  51. struct clock_event_device *c)
  52. {
  53. switch (mode) {
  54. case CLOCK_EVT_MODE_RESUME:
  55. case CLOCK_EVT_MODE_PERIODIC:
  56. *CSR_TIMER1_CLR = 0;
  57. *CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ);
  58. *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD |
  59. TIMER_CNTL_DIV16;
  60. break;
  61. case CLOCK_EVT_MODE_ONESHOT:
  62. case CLOCK_EVT_MODE_UNUSED:
  63. case CLOCK_EVT_MODE_SHUTDOWN:
  64. *CSR_TIMER1_CNTL = 0;
  65. break;
  66. }
  67. }
  68. static struct clock_event_device ckevt_dc21285 = {
  69. .name = "dc21285_timer1",
  70. .features = CLOCK_EVT_FEAT_PERIODIC |
  71. CLOCK_EVT_FEAT_ONESHOT,
  72. .rating = 200,
  73. .irq = IRQ_TIMER1,
  74. .set_next_event = ckevt_dc21285_set_next_event,
  75. .set_mode = ckevt_dc21285_set_mode,
  76. };
  77. static irqreturn_t timer1_interrupt(int irq, void *dev_id)
  78. {
  79. struct clock_event_device *ce = dev_id;
  80. *CSR_TIMER1_CLR = 0;
  81. /* Stop the timer if in one-shot mode */
  82. if (ce->mode == CLOCK_EVT_MODE_ONESHOT)
  83. *CSR_TIMER1_CNTL = 0;
  84. ce->event_handler(ce);
  85. return IRQ_HANDLED;
  86. }
  87. static struct irqaction footbridge_timer_irq = {
  88. .name = "dc21285_timer1",
  89. .handler = timer1_interrupt,
  90. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  91. .dev_id = &ckevt_dc21285,
  92. };
  93. /*
  94. * Set up timer interrupt.
  95. */
  96. void __init footbridge_timer_init(void)
  97. {
  98. struct clock_event_device *ce = &ckevt_dc21285;
  99. unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16);
  100. clocksource_register_hz(&cksrc_dc21285, rate);
  101. setup_irq(ce->irq, &footbridge_timer_irq);
  102. ce->cpumask = cpumask_of(smp_processor_id());
  103. clockevents_config_and_register(ce, rate, 0x4, 0xffffff);
  104. }
  105. static u32 notrace footbridge_read_sched_clock(void)
  106. {
  107. return ~*CSR_TIMER3_VALUE;
  108. }
  109. void __init footbridge_sched_clock(void)
  110. {
  111. unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16);
  112. *CSR_TIMER3_LOAD = 0;
  113. *CSR_TIMER3_CLR = 0;
  114. *CSR_TIMER3_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;
  115. setup_sched_clock(footbridge_read_sched_clock, 24, rate);
  116. }