dc21285-timer.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 int ckevt_dc21285_shutdown(struct clock_event_device *c)
  51. {
  52. *CSR_TIMER1_CNTL = 0;
  53. return 0;
  54. }
  55. static int ckevt_dc21285_set_periodic(struct clock_event_device *c)
  56. {
  57. *CSR_TIMER1_CLR = 0;
  58. *CSR_TIMER1_LOAD = (mem_fclk_21285 + 8 * HZ) / (16 * HZ);
  59. *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_AUTORELOAD |
  60. TIMER_CNTL_DIV16;
  61. return 0;
  62. }
  63. static struct clock_event_device ckevt_dc21285 = {
  64. .name = "dc21285_timer1",
  65. .features = CLOCK_EVT_FEAT_PERIODIC |
  66. CLOCK_EVT_FEAT_ONESHOT,
  67. .rating = 200,
  68. .irq = IRQ_TIMER1,
  69. .set_next_event = ckevt_dc21285_set_next_event,
  70. .set_state_shutdown = ckevt_dc21285_shutdown,
  71. .set_state_periodic = ckevt_dc21285_set_periodic,
  72. .set_state_oneshot = ckevt_dc21285_shutdown,
  73. .tick_resume = ckevt_dc21285_set_periodic,
  74. };
  75. static irqreturn_t timer1_interrupt(int irq, void *dev_id)
  76. {
  77. struct clock_event_device *ce = dev_id;
  78. *CSR_TIMER1_CLR = 0;
  79. /* Stop the timer if in one-shot mode */
  80. if (clockevent_state_oneshot(ce))
  81. *CSR_TIMER1_CNTL = 0;
  82. ce->event_handler(ce);
  83. return IRQ_HANDLED;
  84. }
  85. static struct irqaction footbridge_timer_irq = {
  86. .name = "dc21285_timer1",
  87. .handler = timer1_interrupt,
  88. .flags = IRQF_TIMER | IRQF_IRQPOLL,
  89. .dev_id = &ckevt_dc21285,
  90. };
  91. /*
  92. * Set up timer interrupt.
  93. */
  94. void __init footbridge_timer_init(void)
  95. {
  96. struct clock_event_device *ce = &ckevt_dc21285;
  97. unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16);
  98. clocksource_register_hz(&cksrc_dc21285, rate);
  99. setup_irq(ce->irq, &footbridge_timer_irq);
  100. ce->cpumask = cpumask_of(smp_processor_id());
  101. clockevents_config_and_register(ce, rate, 0x4, 0xffffff);
  102. }
  103. static u64 notrace footbridge_read_sched_clock(void)
  104. {
  105. return ~*CSR_TIMER3_VALUE;
  106. }
  107. void __init footbridge_sched_clock(void)
  108. {
  109. unsigned rate = DIV_ROUND_CLOSEST(mem_fclk_21285, 16);
  110. *CSR_TIMER3_LOAD = 0;
  111. *CSR_TIMER3_CLR = 0;
  112. *CSR_TIMER3_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV16;
  113. sched_clock_register(footbridge_read_sched_clock, 24, rate);
  114. }