dmtimer.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * arch/arm/plat-omap/include/mach/dmtimer.h
  3. *
  4. * OMAP Dual-Mode Timers
  5. *
  6. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  7. * Tarun Kanti DebBarma <tarun.kanti@ti.com>
  8. * Thara Gopinath <thara@ti.com>
  9. *
  10. * Platform device conversion and hwmod support.
  11. *
  12. * Copyright (C) 2005 Nokia Corporation
  13. * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
  14. * PWM and clock framwork support by Timo Teras.
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the
  18. * Free Software Foundation; either version 2 of the License, or (at your
  19. * option) any later version.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  24. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * You should have received a copy of the GNU General Public License along
  31. * with this program; if not, write to the Free Software Foundation, Inc.,
  32. * 675 Mass Ave, Cambridge, MA 02139, USA.
  33. */
  34. #ifndef __ASM_ARCH_DMTIMER_H
  35. #define __ASM_ARCH_DMTIMER_H
  36. /* clock sources */
  37. #define OMAP_TIMER_SRC_SYS_CLK 0x00
  38. #define OMAP_TIMER_SRC_32_KHZ 0x01
  39. #define OMAP_TIMER_SRC_EXT_CLK 0x02
  40. /* timer interrupt enable bits */
  41. #define OMAP_TIMER_INT_CAPTURE (1 << 2)
  42. #define OMAP_TIMER_INT_OVERFLOW (1 << 1)
  43. #define OMAP_TIMER_INT_MATCH (1 << 0)
  44. /* trigger types */
  45. #define OMAP_TIMER_TRIGGER_NONE 0x00
  46. #define OMAP_TIMER_TRIGGER_OVERFLOW 0x01
  47. #define OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE 0x02
  48. /*
  49. * IP revision identifier so that Highlander IP
  50. * in OMAP4 can be distinguished.
  51. */
  52. #define OMAP_TIMER_IP_VERSION_1 0x1
  53. struct omap_dm_timer;
  54. extern struct omap_dm_timer *gptimer_wakeup;
  55. struct clk;
  56. int omap_dm_timer_init(void);
  57. struct omap_dm_timer *omap_dm_timer_request(void);
  58. struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id);
  59. void omap_dm_timer_free(struct omap_dm_timer *timer);
  60. void omap_dm_timer_enable(struct omap_dm_timer *timer);
  61. void omap_dm_timer_disable(struct omap_dm_timer *timer);
  62. int omap_dm_timer_get_irq(struct omap_dm_timer *timer);
  63. u32 omap_dm_timer_modify_idlect_mask(u32 inputmask);
  64. struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer);
  65. void omap_dm_timer_trigger(struct omap_dm_timer *timer);
  66. void omap_dm_timer_start(struct omap_dm_timer *timer);
  67. void omap_dm_timer_stop(struct omap_dm_timer *timer);
  68. int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source);
  69. void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, unsigned int value);
  70. void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, unsigned int value);
  71. void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, unsigned int match);
  72. void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, int toggle, int trigger);
  73. void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler);
  74. void omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, unsigned int value);
  75. unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer);
  76. void omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value);
  77. unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer);
  78. void omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value);
  79. int omap_dm_timers_active(void);
  80. /*
  81. * Do not use the defines below, they are not needed. They should be only
  82. * used by dmtimer.c and sys_timer related code.
  83. */
  84. /* register offsets */
  85. #define _OMAP_TIMER_ID_OFFSET 0x00
  86. #define _OMAP_TIMER_OCP_CFG_OFFSET 0x10
  87. #define _OMAP_TIMER_SYS_STAT_OFFSET 0x14
  88. #define _OMAP_TIMER_STAT_OFFSET 0x18
  89. #define _OMAP_TIMER_INT_EN_OFFSET 0x1c
  90. #define _OMAP_TIMER_WAKEUP_EN_OFFSET 0x20
  91. #define _OMAP_TIMER_CTRL_OFFSET 0x24
  92. #define OMAP_TIMER_CTRL_GPOCFG (1 << 14)
  93. #define OMAP_TIMER_CTRL_CAPTMODE (1 << 13)
  94. #define OMAP_TIMER_CTRL_PT (1 << 12)
  95. #define OMAP_TIMER_CTRL_TCM_LOWTOHIGH (0x1 << 8)
  96. #define OMAP_TIMER_CTRL_TCM_HIGHTOLOW (0x2 << 8)
  97. #define OMAP_TIMER_CTRL_TCM_BOTHEDGES (0x3 << 8)
  98. #define OMAP_TIMER_CTRL_SCPWM (1 << 7)
  99. #define OMAP_TIMER_CTRL_CE (1 << 6) /* compare enable */
  100. #define OMAP_TIMER_CTRL_PRE (1 << 5) /* prescaler enable */
  101. #define OMAP_TIMER_CTRL_PTV_SHIFT 2 /* prescaler value shift */
  102. #define OMAP_TIMER_CTRL_POSTED (1 << 2)
  103. #define OMAP_TIMER_CTRL_AR (1 << 1) /* auto-reload enable */
  104. #define OMAP_TIMER_CTRL_ST (1 << 0) /* start timer */
  105. #define _OMAP_TIMER_COUNTER_OFFSET 0x28
  106. #define _OMAP_TIMER_LOAD_OFFSET 0x2c
  107. #define _OMAP_TIMER_TRIGGER_OFFSET 0x30
  108. #define _OMAP_TIMER_WRITE_PEND_OFFSET 0x34
  109. #define WP_NONE 0 /* no write pending bit */
  110. #define WP_TCLR (1 << 0)
  111. #define WP_TCRR (1 << 1)
  112. #define WP_TLDR (1 << 2)
  113. #define WP_TTGR (1 << 3)
  114. #define WP_TMAR (1 << 4)
  115. #define WP_TPIR (1 << 5)
  116. #define WP_TNIR (1 << 6)
  117. #define WP_TCVR (1 << 7)
  118. #define WP_TOCR (1 << 8)
  119. #define WP_TOWR (1 << 9)
  120. #define _OMAP_TIMER_MATCH_OFFSET 0x38
  121. #define _OMAP_TIMER_CAPTURE_OFFSET 0x3c
  122. #define _OMAP_TIMER_IF_CTRL_OFFSET 0x40
  123. #define _OMAP_TIMER_CAPTURE2_OFFSET 0x44 /* TCAR2, 34xx only */
  124. #define _OMAP_TIMER_TICK_POS_OFFSET 0x48 /* TPIR, 34xx only */
  125. #define _OMAP_TIMER_TICK_NEG_OFFSET 0x4c /* TNIR, 34xx only */
  126. #define _OMAP_TIMER_TICK_COUNT_OFFSET 0x50 /* TCVR, 34xx only */
  127. #define _OMAP_TIMER_TICK_INT_MASK_SET_OFFSET 0x54 /* TOCR, 34xx only */
  128. #define _OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET 0x58 /* TOWR, 34xx only */
  129. /* register offsets with the write pending bit encoded */
  130. #define WPSHIFT 16
  131. #define OMAP_TIMER_ID_REG (_OMAP_TIMER_ID_OFFSET \
  132. | (WP_NONE << WPSHIFT))
  133. #define OMAP_TIMER_OCP_CFG_REG (_OMAP_TIMER_OCP_CFG_OFFSET \
  134. | (WP_NONE << WPSHIFT))
  135. #define OMAP_TIMER_SYS_STAT_REG (_OMAP_TIMER_SYS_STAT_OFFSET \
  136. | (WP_NONE << WPSHIFT))
  137. #define OMAP_TIMER_STAT_REG (_OMAP_TIMER_STAT_OFFSET \
  138. | (WP_NONE << WPSHIFT))
  139. #define OMAP_TIMER_INT_EN_REG (_OMAP_TIMER_INT_EN_OFFSET \
  140. | (WP_NONE << WPSHIFT))
  141. #define OMAP_TIMER_WAKEUP_EN_REG (_OMAP_TIMER_WAKEUP_EN_OFFSET \
  142. | (WP_NONE << WPSHIFT))
  143. #define OMAP_TIMER_CTRL_REG (_OMAP_TIMER_CTRL_OFFSET \
  144. | (WP_TCLR << WPSHIFT))
  145. #define OMAP_TIMER_COUNTER_REG (_OMAP_TIMER_COUNTER_OFFSET \
  146. | (WP_TCRR << WPSHIFT))
  147. #define OMAP_TIMER_LOAD_REG (_OMAP_TIMER_LOAD_OFFSET \
  148. | (WP_TLDR << WPSHIFT))
  149. #define OMAP_TIMER_TRIGGER_REG (_OMAP_TIMER_TRIGGER_OFFSET \
  150. | (WP_TTGR << WPSHIFT))
  151. #define OMAP_TIMER_WRITE_PEND_REG (_OMAP_TIMER_WRITE_PEND_OFFSET \
  152. | (WP_NONE << WPSHIFT))
  153. #define OMAP_TIMER_MATCH_REG (_OMAP_TIMER_MATCH_OFFSET \
  154. | (WP_TMAR << WPSHIFT))
  155. #define OMAP_TIMER_CAPTURE_REG (_OMAP_TIMER_CAPTURE_OFFSET \
  156. | (WP_NONE << WPSHIFT))
  157. #define OMAP_TIMER_IF_CTRL_REG (_OMAP_TIMER_IF_CTRL_OFFSET \
  158. | (WP_NONE << WPSHIFT))
  159. #define OMAP_TIMER_CAPTURE2_REG (_OMAP_TIMER_CAPTURE2_OFFSET \
  160. | (WP_NONE << WPSHIFT))
  161. #define OMAP_TIMER_TICK_POS_REG (_OMAP_TIMER_TICK_POS_OFFSET \
  162. | (WP_TPIR << WPSHIFT))
  163. #define OMAP_TIMER_TICK_NEG_REG (_OMAP_TIMER_TICK_NEG_OFFSET \
  164. | (WP_TNIR << WPSHIFT))
  165. #define OMAP_TIMER_TICK_COUNT_REG (_OMAP_TIMER_TICK_COUNT_OFFSET \
  166. | (WP_TCVR << WPSHIFT))
  167. #define OMAP_TIMER_TICK_INT_MASK_SET_REG \
  168. (_OMAP_TIMER_TICK_INT_MASK_SET_OFFSET | (WP_TOCR << WPSHIFT))
  169. #define OMAP_TIMER_TICK_INT_MASK_COUNT_REG \
  170. (_OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET | (WP_TOWR << WPSHIFT))
  171. struct omap_dm_timer {
  172. unsigned long phys_base;
  173. int irq;
  174. #ifdef CONFIG_ARCH_OMAP2PLUS
  175. struct clk *iclk, *fclk;
  176. #endif
  177. void __iomem *io_base;
  178. unsigned reserved:1;
  179. unsigned enabled:1;
  180. unsigned posted:1;
  181. };
  182. #endif /* __ASM_ARCH_DMTIMER_H */