timer-gp.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/arm/mach-omap2/timer-gp.c
  3. *
  4. * OMAP2 GP timer support.
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Author: Paul Mundt <paul.mundt@nokia.com>
  8. * Juha Yrjölä <juha.yrjola@nokia.com>
  9. *
  10. * Some parts based off of TI's 24xx code:
  11. *
  12. * Copyright (C) 2004 Texas Instruments, Inc.
  13. *
  14. * Roughly modelled after the OMAP1 MPU timer code.
  15. *
  16. * This file is subject to the terms and conditions of the GNU General Public
  17. * License. See the file "COPYING" in the main directory of this archive
  18. * for more details.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/time.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/err.h>
  24. #include <linux/clk.h>
  25. #include <asm/mach/time.h>
  26. #include <asm/delay.h>
  27. #include <asm/io.h>
  28. #define OMAP2_GP_TIMER1_BASE 0x48028000
  29. #define OMAP2_GP_TIMER2_BASE 0x4802a000
  30. #define OMAP2_GP_TIMER3_BASE 0x48078000
  31. #define OMAP2_GP_TIMER4_BASE 0x4807a000
  32. #define GP_TIMER_TIDR 0x00
  33. #define GP_TIMER_TISR 0x18
  34. #define GP_TIMER_TIER 0x1c
  35. #define GP_TIMER_TCLR 0x24
  36. #define GP_TIMER_TCRR 0x28
  37. #define GP_TIMER_TLDR 0x2c
  38. #define GP_TIMER_TSICR 0x40
  39. #define OS_TIMER_NR 1 /* GP timer 2 */
  40. static unsigned long timer_base[] = {
  41. IO_ADDRESS(OMAP2_GP_TIMER1_BASE),
  42. IO_ADDRESS(OMAP2_GP_TIMER2_BASE),
  43. IO_ADDRESS(OMAP2_GP_TIMER3_BASE),
  44. IO_ADDRESS(OMAP2_GP_TIMER4_BASE),
  45. };
  46. static inline unsigned int timer_read_reg(int nr, unsigned int reg)
  47. {
  48. return __raw_readl(timer_base[nr] + reg);
  49. }
  50. static inline void timer_write_reg(int nr, unsigned int reg, unsigned int val)
  51. {
  52. __raw_writel(val, timer_base[nr] + reg);
  53. }
  54. /* Note that we always enable the clock prescale divider bit */
  55. static inline void omap2_gp_timer_start(int nr, unsigned long load_val)
  56. {
  57. unsigned int tmp;
  58. tmp = 0xffffffff - load_val;
  59. timer_write_reg(nr, GP_TIMER_TLDR, tmp);
  60. timer_write_reg(nr, GP_TIMER_TCRR, tmp);
  61. timer_write_reg(nr, GP_TIMER_TIER, 1 << 1);
  62. timer_write_reg(nr, GP_TIMER_TCLR, (1 << 5) | (1 << 1) | 1);
  63. }
  64. static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id,
  65. struct pt_regs *regs)
  66. {
  67. write_seqlock(&xtime_lock);
  68. timer_write_reg(OS_TIMER_NR, GP_TIMER_TISR, 1 << 1);
  69. timer_tick(regs);
  70. write_sequnlock(&xtime_lock);
  71. return IRQ_HANDLED;
  72. }
  73. static struct irqaction omap2_gp_timer_irq = {
  74. .name = "gp timer",
  75. .flags = SA_INTERRUPT,
  76. .handler = omap2_gp_timer_interrupt,
  77. };
  78. static void __init omap2_gp_timer_init(void)
  79. {
  80. struct clk * sys_ck;
  81. u32 tick_period = 120000;
  82. u32 l;
  83. /* Reset clock and prescale value */
  84. timer_write_reg(OS_TIMER_NR, GP_TIMER_TCLR, 0);
  85. sys_ck = clk_get(NULL, "sys_ck");
  86. if (IS_ERR(sys_ck))
  87. printk(KERN_ERR "Could not get sys_ck\n");
  88. else {
  89. clk_enable(sys_ck);
  90. tick_period = clk_get_rate(sys_ck) / 100;
  91. clk_put(sys_ck);
  92. }
  93. tick_period /= 2; /* Minimum prescale divider is 2 */
  94. tick_period -= 1;
  95. l = timer_read_reg(OS_TIMER_NR, GP_TIMER_TIDR);
  96. printk(KERN_INFO "OMAP2 GP timer (HW version %d.%d)\n",
  97. (l >> 4) & 0x0f, l & 0x0f);
  98. setup_irq(38, &omap2_gp_timer_irq);
  99. omap2_gp_timer_start(OS_TIMER_NR, tick_period);
  100. }
  101. struct sys_timer omap_timer = {
  102. .init = omap2_gp_timer_init,
  103. };