timer-gp.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * OMAP Dual-mode timer framework support by Timo Teras
  10. *
  11. * Some parts based off of TI's 24xx code:
  12. *
  13. * Copyright (C) 2004 Texas Instruments, Inc.
  14. *
  15. * Roughly modelled after the OMAP1 MPU timer code.
  16. *
  17. * This file is subject to the terms and conditions of the GNU General Public
  18. * License. See the file "COPYING" in the main directory of this archive
  19. * for more details.
  20. */
  21. #include <linux/init.h>
  22. #include <linux/time.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/err.h>
  25. #include <linux/clk.h>
  26. #include <linux/delay.h>
  27. #include <linux/irq.h>
  28. #include <asm/mach/time.h>
  29. #include <asm/arch/dmtimer.h>
  30. static struct omap_dm_timer *gptimer;
  31. static inline void omap2_gp_timer_start(unsigned long load_val)
  32. {
  33. omap_dm_timer_set_load(gptimer, 1, 0xffffffff - load_val);
  34. omap_dm_timer_set_int_enable(gptimer, OMAP_TIMER_INT_OVERFLOW);
  35. omap_dm_timer_start(gptimer);
  36. }
  37. static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id)
  38. {
  39. write_seqlock(&xtime_lock);
  40. omap_dm_timer_write_status(gptimer, OMAP_TIMER_INT_OVERFLOW);
  41. timer_tick();
  42. write_sequnlock(&xtime_lock);
  43. return IRQ_HANDLED;
  44. }
  45. static struct irqaction omap2_gp_timer_irq = {
  46. .name = "gp timer",
  47. .flags = IRQF_DISABLED | IRQF_TIMER,
  48. .handler = omap2_gp_timer_interrupt,
  49. };
  50. static void __init omap2_gp_timer_init(void)
  51. {
  52. u32 tick_period;
  53. omap_dm_timer_init();
  54. gptimer = omap_dm_timer_request_specific(1);
  55. BUG_ON(gptimer == NULL);
  56. omap_dm_timer_set_source(gptimer, OMAP_TIMER_SRC_SYS_CLK);
  57. tick_period = clk_get_rate(omap_dm_timer_get_fclk(gptimer)) / HZ;
  58. tick_period -= 1;
  59. setup_irq(omap_dm_timer_get_irq(gptimer), &omap2_gp_timer_irq);
  60. omap2_gp_timer_start(tick_period);
  61. }
  62. struct sys_timer omap_timer = {
  63. .init = omap2_gp_timer_init,
  64. };