time.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * arch/arm/plat-iop/time.c
  3. *
  4. * Timer code for IOP32x and IOP33x based systems
  5. *
  6. * Author: Deepak Saxena <dsaxena@mvista.com>
  7. *
  8. * Copyright 2002-2003 MontaVista Software Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/time.h>
  18. #include <linux/init.h>
  19. #include <linux/timex.h>
  20. #include <asm/hardware.h>
  21. #include <asm/io.h>
  22. #include <asm/irq.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/mach/irq.h>
  25. #include <asm/mach/time.h>
  26. #ifdef CONFIG_ARCH_IOP32X
  27. #define IRQ_IOP3XX_TIMER0 IRQ_IOP32X_TIMER0
  28. #else
  29. #ifdef CONFIG_ARCH_IOP33X
  30. #define IRQ_IOP3XX_TIMER0 IRQ_IOP33X_TIMER0
  31. #endif
  32. #endif
  33. static unsigned long ticks_per_jiffy;
  34. static unsigned long ticks_per_usec;
  35. static unsigned long next_jiffy_time;
  36. unsigned long iop3xx_gettimeoffset(void)
  37. {
  38. unsigned long offset;
  39. offset = next_jiffy_time - *IOP3XX_TU_TCR1;
  40. return offset / ticks_per_usec;
  41. }
  42. static irqreturn_t
  43. iop3xx_timer_interrupt(int irq, void *dev_id)
  44. {
  45. write_seqlock(&xtime_lock);
  46. iop3xx_cp6_enable();
  47. asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (1));
  48. iop3xx_cp6_disable();
  49. while ((signed long)(next_jiffy_time - *IOP3XX_TU_TCR1)
  50. >= ticks_per_jiffy) {
  51. timer_tick();
  52. next_jiffy_time -= ticks_per_jiffy;
  53. }
  54. write_sequnlock(&xtime_lock);
  55. return IRQ_HANDLED;
  56. }
  57. static struct irqaction iop3xx_timer_irq = {
  58. .name = "IOP3XX Timer Tick",
  59. .handler = iop3xx_timer_interrupt,
  60. .flags = IRQF_DISABLED | IRQF_TIMER,
  61. };
  62. void __init iop3xx_init_time(unsigned long tick_rate)
  63. {
  64. u32 timer_ctl;
  65. ticks_per_jiffy = (tick_rate + HZ/2) / HZ;
  66. ticks_per_usec = tick_rate / 1000000;
  67. next_jiffy_time = 0xffffffff;
  68. timer_ctl = IOP3XX_TMR_EN | IOP3XX_TMR_PRIVILEGED |
  69. IOP3XX_TMR_RELOAD | IOP3XX_TMR_RATIO_1_1;
  70. /*
  71. * We use timer 0 for our timer interrupt, and timer 1 as
  72. * monotonic counter for tracking missed jiffies.
  73. */
  74. iop3xx_cp6_enable();
  75. asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (ticks_per_jiffy - 1));
  76. asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl));
  77. asm volatile("mcr p6, 0, %0, c5, c1, 0" : : "r" (0xffffffff));
  78. asm volatile("mcr p6, 0, %0, c1, c1, 0" : : "r" (timer_ctl));
  79. iop3xx_cp6_disable();
  80. setup_irq(IRQ_IOP3XX_TIMER0, &iop3xx_timer_irq);
  81. }