mxc_timer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * mxc_timer.h
  3. *
  4. * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
  5. *
  6. * Platform independent (i.MX1, i.MX2, i.MX3) definition for timer handling.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef __PLAT_MXC_TIMER_H
  23. #define __PLAT_MXC_TIMER_H
  24. #include <linux/clk.h>
  25. #include <mach/hardware.h>
  26. #ifdef CONFIG_ARCH_MX1
  27. #define TIMER_BASE IO_ADDRESS(TIM1_BASE_ADDR)
  28. #define TIMER_INTERRUPT TIM1_INT
  29. #define TCTL_VAL TCTL_CLK_PCLK1
  30. #define TCTL_IRQEN (1<<4)
  31. #define TCTL_FRR (1<<8)
  32. #define TCTL_CLK_PCLK1 (1<<1)
  33. #define TCTL_CLK_PCLK1_4 (2<<1)
  34. #define TCTL_CLK_TIN (3<<1)
  35. #define TCTL_CLK_32 (4<<1)
  36. #define MXC_TCTL 0x00
  37. #define MXC_TPRER 0x04
  38. #define MXC_TCMP 0x08
  39. #define MXC_TCR 0x0c
  40. #define MXC_TCN 0x10
  41. #define MXC_TSTAT 0x14
  42. #define TSTAT_CAPT (1<<1)
  43. #define TSTAT_COMP (1<<0)
  44. static inline void gpt_irq_disable(void)
  45. {
  46. unsigned int tmp;
  47. tmp = __raw_readl(TIMER_BASE + MXC_TCTL);
  48. __raw_writel(tmp & ~TCTL_IRQEN, TIMER_BASE + MXC_TCTL);
  49. }
  50. static inline void gpt_irq_enable(void)
  51. {
  52. __raw_writel(__raw_readl(TIMER_BASE + MXC_TCTL) | TCTL_IRQEN,
  53. TIMER_BASE + MXC_TCTL);
  54. }
  55. static void gpt_irq_acknowledge(void)
  56. {
  57. __raw_writel(0, TIMER_BASE + MXC_TSTAT);
  58. }
  59. #endif /* CONFIG_ARCH_MX1 */
  60. #ifdef CONFIG_ARCH_MX2
  61. #define TIMER_BASE IO_ADDRESS(GPT1_BASE_ADDR)
  62. #define TIMER_INTERRUPT MXC_INT_GPT1
  63. #define MXC_TCTL 0x00
  64. #define TCTL_VAL TCTL_CLK_PCLK1
  65. #define TCTL_CLK_PCLK1 (1<<1)
  66. #define TCTL_CLK_PCLK1_4 (2<<1)
  67. #define TCTL_IRQEN (1<<4)
  68. #define TCTL_FRR (1<<8)
  69. #define MXC_TPRER 0x04
  70. #define MXC_TCMP 0x08
  71. #define MXC_TCR 0x0c
  72. #define MXC_TCN 0x10
  73. #define MXC_TSTAT 0x14
  74. #define TSTAT_CAPT (1<<1)
  75. #define TSTAT_COMP (1<<0)
  76. static inline void gpt_irq_disable(void)
  77. {
  78. unsigned int tmp;
  79. tmp = __raw_readl(TIMER_BASE + MXC_TCTL);
  80. __raw_writel(tmp & ~TCTL_IRQEN, TIMER_BASE + MXC_TCTL);
  81. }
  82. static inline void gpt_irq_enable(void)
  83. {
  84. __raw_writel(__raw_readl(TIMER_BASE + MXC_TCTL) | TCTL_IRQEN,
  85. TIMER_BASE + MXC_TCTL);
  86. }
  87. static void gpt_irq_acknowledge(void)
  88. {
  89. __raw_writel(TSTAT_CAPT | TSTAT_COMP, TIMER_BASE + MXC_TSTAT);
  90. }
  91. #endif /* CONFIG_ARCH_MX2 */
  92. #ifdef CONFIG_ARCH_MX3
  93. #define TIMER_BASE IO_ADDRESS(GPT1_BASE_ADDR)
  94. #define TIMER_INTERRUPT MXC_INT_GPT
  95. #define MXC_TCTL 0x00
  96. #define TCTL_VAL (TCTL_CLK_IPG | TCTL_WAITEN)
  97. #define TCTL_CLK_IPG (1<<6)
  98. #define TCTL_FRR (1<<9)
  99. #define TCTL_WAITEN (1<<3)
  100. #define MXC_TPRER 0x04
  101. #define MXC_TSTAT 0x08
  102. #define TSTAT_OF1 (1<<0)
  103. #define TSTAT_OF2 (1<<1)
  104. #define TSTAT_OF3 (1<<2)
  105. #define TSTAT_IF1 (1<<3)
  106. #define TSTAT_IF2 (1<<4)
  107. #define TSTAT_ROV (1<<5)
  108. #define MXC_IR 0x0c
  109. #define MXC_TCMP 0x10
  110. #define MXC_TCMP2 0x14
  111. #define MXC_TCMP3 0x18
  112. #define MXC_TCR 0x1c
  113. #define MXC_TCN 0x24
  114. static inline void gpt_irq_disable(void)
  115. {
  116. __raw_writel(0, TIMER_BASE + MXC_IR);
  117. }
  118. static inline void gpt_irq_enable(void)
  119. {
  120. __raw_writel(1<<0, TIMER_BASE + MXC_IR);
  121. }
  122. static inline void gpt_irq_acknowledge(void)
  123. {
  124. __raw_writel(TSTAT_OF1, TIMER_BASE + MXC_TSTAT);
  125. }
  126. #endif /* CONFIG_ARCH_MX3 */
  127. #define TCTL_SWR (1<<15)
  128. #define TCTL_CC (1<<10)
  129. #define TCTL_OM (1<<9)
  130. #define TCTL_CAP_RIS (1<<6)
  131. #define TCTL_CAP_FAL (2<<6)
  132. #define TCTL_CAP_RIS_FAL (3<<6)
  133. #define TCTL_CAP_ENA (1<<5)
  134. #define TCTL_TEN (1<<0)
  135. #endif