cevt-mn10300.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* MN10300 clockevents
  2. *
  3. * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
  4. * Written by Mark Salter (msalter@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/clockchips.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/percpu.h>
  14. #include <linux/smp.h>
  15. #include <asm/timex.h>
  16. #include "internal.h"
  17. #ifdef CONFIG_SMP
  18. #if (CONFIG_NR_CPUS > 2) && !defined(CONFIG_GEENERIC_CLOCKEVENTS_BROADCAST)
  19. #error "This doesn't scale well! Need per-core local timers."
  20. #endif
  21. #else /* CONFIG_SMP */
  22. #define stop_jiffies_counter1()
  23. #define reload_jiffies_counter1(x)
  24. #define TMJC1IRQ TMJCIRQ
  25. #endif
  26. static int next_event(unsigned long delta,
  27. struct clock_event_device *evt)
  28. {
  29. unsigned int cpu = smp_processor_id();
  30. if (cpu == 0) {
  31. stop_jiffies_counter();
  32. reload_jiffies_counter(delta - 1);
  33. } else {
  34. stop_jiffies_counter1();
  35. reload_jiffies_counter1(delta - 1);
  36. }
  37. return 0;
  38. }
  39. static void set_clock_mode(enum clock_event_mode mode,
  40. struct clock_event_device *evt)
  41. {
  42. /* Nothing to do ... */
  43. }
  44. static DEFINE_PER_CPU(struct clock_event_device, mn10300_clockevent_device);
  45. static DEFINE_PER_CPU(struct irqaction, timer_irq);
  46. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  47. {
  48. struct clock_event_device *cd;
  49. unsigned int cpu = smp_processor_id();
  50. if (cpu == 0)
  51. stop_jiffies_counter();
  52. else
  53. stop_jiffies_counter1();
  54. cd = &per_cpu(mn10300_clockevent_device, cpu);
  55. cd->event_handler(cd);
  56. return IRQ_HANDLED;
  57. }
  58. static void event_handler(struct clock_event_device *dev)
  59. {
  60. }
  61. static inline void setup_jiffies_interrupt(int irq,
  62. struct irqaction *action)
  63. {
  64. u16 tmp;
  65. setup_irq(irq, action);
  66. set_intr_level(irq, NUM2GxICR_LEVEL(CONFIG_TIMER_IRQ_LEVEL));
  67. GxICR(irq) |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
  68. tmp = GxICR(irq);
  69. }
  70. int __init init_clockevents(void)
  71. {
  72. struct clock_event_device *cd;
  73. struct irqaction *iact;
  74. unsigned int cpu = smp_processor_id();
  75. cd = &per_cpu(mn10300_clockevent_device, cpu);
  76. if (cpu == 0) {
  77. stop_jiffies_counter();
  78. cd->irq = TMJCIRQ;
  79. } else {
  80. stop_jiffies_counter1();
  81. cd->irq = TMJC1IRQ;
  82. }
  83. cd->name = "Timestamp";
  84. cd->features = CLOCK_EVT_FEAT_ONESHOT;
  85. /* Calculate shift/mult. We want to spawn at least 1 second */
  86. clockevents_calc_mult_shift(cd, MN10300_JCCLK, 1);
  87. /* Calculate the min / max delta */
  88. cd->max_delta_ns = clockevent_delta2ns(TMJCBR_MAX, cd);
  89. cd->min_delta_ns = clockevent_delta2ns(100, cd);
  90. cd->rating = 200;
  91. cd->cpumask = cpumask_of(smp_processor_id());
  92. cd->set_mode = set_clock_mode;
  93. cd->event_handler = event_handler;
  94. cd->set_next_event = next_event;
  95. iact = &per_cpu(timer_irq, cpu);
  96. iact->flags = IRQF_SHARED | IRQF_TIMER;
  97. iact->handler = timer_interrupt;
  98. clockevents_register_device(cd);
  99. #if defined(CONFIG_SMP) && !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
  100. /* setup timer irq affinity so it only runs on this cpu */
  101. {
  102. struct irq_data *data;
  103. data = irq_get_irq_data(cd->irq);
  104. cpumask_copy(data->affinity, cpumask_of(cpu));
  105. iact->flags |= IRQF_NOBALANCING;
  106. }
  107. #endif
  108. if (cpu == 0) {
  109. reload_jiffies_counter(MN10300_JC_PER_HZ - 1);
  110. iact->name = "CPU0 Timer";
  111. } else {
  112. reload_jiffies_counter1(MN10300_JC_PER_HZ - 1);
  113. iact->name = "CPU1 Timer";
  114. }
  115. setup_jiffies_interrupt(cd->irq, iact);
  116. return 0;
  117. }