time.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * arch/arm/mach-ns9xxx/time.c
  3. *
  4. * Copyright (C) 2006 by Digi International Inc.
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. #include <linux/jiffies.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/stringify.h>
  15. #include <linux/clocksource.h>
  16. #include <asm/arch-ns9xxx/regs-sys.h>
  17. #include <asm/arch-ns9xxx/clock.h>
  18. #include <asm/arch-ns9xxx/irqs.h>
  19. #include <asm/arch/system.h>
  20. #include "generic.h"
  21. #define TIMERCLOCKSELECT 64
  22. #define TIMER_CLOCKSOURCE 1
  23. static irqreturn_t
  24. ns9xxx_timer_interrupt(int irq, void *dev_id)
  25. {
  26. int timerno = irq - IRQ_TIMER0;
  27. u32 tc;
  28. write_seqlock(&xtime_lock);
  29. timer_tick();
  30. write_sequnlock(&xtime_lock);
  31. /* clear irq */
  32. tc = SYS_TC(timerno);
  33. if (REGGET(tc, SYS_TCx, REN) == SYS_TCx_REN_DIS) {
  34. REGSET(tc, SYS_TCx, TEN, DIS);
  35. SYS_TC(timerno) = tc;
  36. }
  37. REGSET(tc, SYS_TCx, INTC, SET);
  38. SYS_TC(timerno) = tc;
  39. REGSET(tc, SYS_TCx, INTC, UNSET);
  40. SYS_TC(timerno) = tc;
  41. return IRQ_HANDLED;
  42. }
  43. static struct irqaction ns9xxx_timer_irq = {
  44. .name = "NS9xxx Timer Tick",
  45. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  46. .handler = ns9xxx_timer_interrupt,
  47. };
  48. static cycle_t ns9xxx_clocksource_read(void)
  49. {
  50. return SYS_TR(TIMER_CLOCKSOURCE);
  51. }
  52. static struct clocksource ns9xxx_clocksource = {
  53. .name = "ns9xxx-timer" __stringify(TIMER_CLOCKSOURCE),
  54. .rating = 300,
  55. .read = ns9xxx_clocksource_read,
  56. .mask = CLOCKSOURCE_MASK(32),
  57. .shift = 20,
  58. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  59. };
  60. static void __init ns9xxx_timer_init(void)
  61. {
  62. int tc;
  63. /* disable timer */
  64. if ((tc = SYS_TC(0)) & SYS_TCx_TEN)
  65. SYS_TC(0) = tc & ~SYS_TCx_TEN;
  66. SYS_TRC(0) = SH_DIV(ns9xxx_cpuclock(), (TIMERCLOCKSELECT * HZ), 0);
  67. REGSET(tc, SYS_TCx, TEN, EN);
  68. REGSET(tc, SYS_TCx, TLCS, DIV64); /* This must match TIMERCLOCKSELECT */
  69. REGSET(tc, SYS_TCx, INTS, EN);
  70. REGSET(tc, SYS_TCx, UDS, DOWN);
  71. REGSET(tc, SYS_TCx, TDBG, STOP);
  72. REGSET(tc, SYS_TCx, TSZ, 32);
  73. REGSET(tc, SYS_TCx, REN, EN);
  74. SYS_TC(0) = tc;
  75. setup_irq(IRQ_TIMER0, &ns9xxx_timer_irq);
  76. tc = SYS_TC(TIMER_CLOCKSOURCE);
  77. if (REGGET(tc, SYS_TCx, TEN)) {
  78. REGSET(tc, SYS_TCx, TEN, DIS);
  79. SYS_TC(TIMER_CLOCKSOURCE) = tc;
  80. }
  81. SYS_TRC(TIMER_CLOCKSOURCE) = 0;
  82. REGSET(tc, SYS_TCx, TEN, EN);
  83. REGSET(tc, SYS_TCx, TDBG, STOP);
  84. REGSET(tc, SYS_TCx, TLCS, CPU);
  85. REGSET(tc, SYS_TCx, TM, IEE);
  86. REGSET(tc, SYS_TCx, INTS, DIS);
  87. REGSET(tc, SYS_TCx, UDS, UP);
  88. REGSET(tc, SYS_TCx, TSZ, 32);
  89. REGSET(tc, SYS_TCx, REN, EN);
  90. SYS_TC(TIMER_CLOCKSOURCE) = tc;
  91. ns9xxx_clocksource.mult = clocksource_hz2mult(ns9xxx_cpuclock(),
  92. ns9xxx_clocksource.shift);
  93. clocksource_register(&ns9xxx_clocksource);
  94. }
  95. struct sys_timer ns9xxx_timer = {
  96. .init = ns9xxx_timer_init,
  97. };