cevt-mn10300.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 DEFINE_PER_CPU(struct clock_event_device, mn10300_clockevent_device);
  40. static DEFINE_PER_CPU(struct irqaction, timer_irq);
  41. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  42. {
  43. struct clock_event_device *cd;
  44. unsigned int cpu = smp_processor_id();
  45. if (cpu == 0)
  46. stop_jiffies_counter();
  47. else
  48. stop_jiffies_counter1();
  49. cd = &per_cpu(mn10300_clockevent_device, cpu);
  50. cd->event_handler(cd);
  51. return IRQ_HANDLED;
  52. }
  53. static void event_handler(struct clock_event_device *dev)
  54. {
  55. }
  56. static inline void setup_jiffies_interrupt(int irq,
  57. struct irqaction *action)
  58. {
  59. u16 tmp;
  60. setup_irq(irq, action);
  61. set_intr_level(irq, NUM2GxICR_LEVEL(CONFIG_TIMER_IRQ_LEVEL));
  62. GxICR(irq) |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
  63. tmp = GxICR(irq);
  64. }
  65. int __init init_clockevents(void)
  66. {
  67. struct clock_event_device *cd;
  68. struct irqaction *iact;
  69. unsigned int cpu = smp_processor_id();
  70. cd = &per_cpu(mn10300_clockevent_device, cpu);
  71. if (cpu == 0) {
  72. stop_jiffies_counter();
  73. cd->irq = TMJCIRQ;
  74. } else {
  75. stop_jiffies_counter1();
  76. cd->irq = TMJC1IRQ;
  77. }
  78. cd->name = "Timestamp";
  79. cd->features = CLOCK_EVT_FEAT_ONESHOT;
  80. /* Calculate shift/mult. We want to spawn at least 1 second */
  81. clockevents_calc_mult_shift(cd, MN10300_JCCLK, 1);
  82. /* Calculate the min / max delta */
  83. cd->max_delta_ns = clockevent_delta2ns(TMJCBR_MAX, cd);
  84. cd->min_delta_ns = clockevent_delta2ns(100, cd);
  85. cd->rating = 200;
  86. cd->cpumask = cpumask_of(smp_processor_id());
  87. cd->event_handler = event_handler;
  88. cd->set_next_event = next_event;
  89. iact = &per_cpu(timer_irq, cpu);
  90. iact->flags = IRQF_SHARED | IRQF_TIMER;
  91. iact->handler = timer_interrupt;
  92. clockevents_register_device(cd);
  93. #if defined(CONFIG_SMP) && !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
  94. /* setup timer irq affinity so it only runs on this cpu */
  95. {
  96. struct irq_data *data;
  97. data = irq_get_irq_data(cd->irq);
  98. cpumask_copy(irq_data_get_affinity_mask(data), cpumask_of(cpu));
  99. iact->flags |= IRQF_NOBALANCING;
  100. }
  101. #endif
  102. if (cpu == 0) {
  103. reload_jiffies_counter(MN10300_JC_PER_HZ - 1);
  104. iact->name = "CPU0 Timer";
  105. } else {
  106. reload_jiffies_counter1(MN10300_JC_PER_HZ - 1);
  107. iact->name = "CPU1 Timer";
  108. }
  109. setup_jiffies_interrupt(cd->irq, iact);
  110. return 0;
  111. }