dc21285-timer.c 3.2 KB

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