time.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2001-2006 Storlink, Corp.
  3. * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. */
  10. #include <linux/interrupt.h>
  11. #include <linux/irq.h>
  12. #include <linux/io.h>
  13. #include <mach/hardware.h>
  14. #include <mach/global_reg.h>
  15. #include <asm/mach/time.h>
  16. /*
  17. * Register definitions for the timers
  18. */
  19. #define TIMER_COUNT(BASE_ADDR) (BASE_ADDR + 0x00)
  20. #define TIMER_LOAD(BASE_ADDR) (BASE_ADDR + 0x04)
  21. #define TIMER_MATCH1(BASE_ADDR) (BASE_ADDR + 0x08)
  22. #define TIMER_MATCH2(BASE_ADDR) (BASE_ADDR + 0x0C)
  23. #define TIMER_CR(BASE_ADDR) (BASE_ADDR + 0x30)
  24. #define TIMER_1_CR_ENABLE (1 << 0)
  25. #define TIMER_1_CR_CLOCK (1 << 1)
  26. #define TIMER_1_CR_INT (1 << 2)
  27. #define TIMER_2_CR_ENABLE (1 << 3)
  28. #define TIMER_2_CR_CLOCK (1 << 4)
  29. #define TIMER_2_CR_INT (1 << 5)
  30. #define TIMER_3_CR_ENABLE (1 << 6)
  31. #define TIMER_3_CR_CLOCK (1 << 7)
  32. #define TIMER_3_CR_INT (1 << 8)
  33. /*
  34. * IRQ handler for the timer
  35. */
  36. static irqreturn_t gemini_timer_interrupt(int irq, void *dev_id)
  37. {
  38. timer_tick();
  39. return IRQ_HANDLED;
  40. }
  41. static struct irqaction gemini_timer_irq = {
  42. .name = "Gemini Timer Tick",
  43. .flags = IRQF_DISABLED | IRQF_TIMER,
  44. .handler = gemini_timer_interrupt,
  45. };
  46. /*
  47. * Set up timer interrupt, and return the current time in seconds.
  48. */
  49. void __init gemini_timer_init(void)
  50. {
  51. unsigned int tick_rate, reg_v;
  52. reg_v = __raw_readl(IO_ADDRESS(GEMINI_GLOBAL_BASE + GLOBAL_STATUS));
  53. tick_rate = REG_TO_AHB_SPEED(reg_v) * 1000000;
  54. printk(KERN_INFO "Bus: %dMHz", tick_rate / 1000000);
  55. tick_rate /= 6; /* APB bus run AHB*(1/6) */
  56. switch(reg_v & CPU_AHB_RATIO_MASK) {
  57. case CPU_AHB_1_1:
  58. printk(KERN_CONT "(1/1)\n");
  59. break;
  60. case CPU_AHB_3_2:
  61. printk(KERN_CONT "(3/2)\n");
  62. break;
  63. case CPU_AHB_24_13:
  64. printk(KERN_CONT "(24/13)\n");
  65. break;
  66. case CPU_AHB_2_1:
  67. printk(KERN_CONT "(2/1)\n");
  68. break;
  69. }
  70. /*
  71. * Make irqs happen for the system timer
  72. */
  73. setup_irq(IRQ_TIMER2, &gemini_timer_irq);
  74. /* Start the timer */
  75. __raw_writel(tick_rate / HZ, TIMER_COUNT(IO_ADDRESS(GEMINI_TIMER2_BASE)));
  76. __raw_writel(tick_rate / HZ, TIMER_LOAD(IO_ADDRESS(GEMINI_TIMER2_BASE)));
  77. __raw_writel(TIMER_2_CR_ENABLE | TIMER_2_CR_INT, TIMER_CR(IO_ADDRESS(GEMINI_TIMER_BASE)));
  78. }