commandProcessing.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. *
  3. * arch/arm/mach-u300/timer.c
  4. *
  5. *
  6. * Copyright (C) 2007-2009 ST-Ericsson AB
  7. * License terms: GNU General Public License (GPL) version 2
  8. * Timer COH 901 328, runs the OS timer interrupt.
  9. * Author: Linus Walleij <linus.walleij@stericsson.com>
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/time.h>
  13. #include <linux/timex.h>
  14. #include <linux/clockchips.h>
  15. #include <linux/clocksource.h>
  16. #include <linux/types.h>
  17. #include <linux/io.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/irq.h>
  21. #include <mach/hardware.h>
  22. #include <mach/irqs.h>
  23. /* Generic stuff */
  24. #include <asm/sched_clock.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/mach/time.h>
  27. #include "timer.h"
  28. /*
  29. * APP side special timer registers
  30. * This timer contains four timers which can fire an interrupt each.
  31. * OS (operating system) timer @ 32768 Hz
  32. * DD (device driver) timer @ 1 kHz
  33. * GP1 (general purpose 1) timer @ 1MHz
  34. * GP2 (general purpose 2) timer @ 1MHz
  35. */
  36. /* Reset OS Timer 32bit (-/W) */
  37. #define U300_TIMER_APP_ROST (0x0000)
  38. #define U300_TIMER_APP_ROST_TIMER_RESET (0x00000000)
  39. /* Enable OS Timer 32bit (-/W) */
  40. #define U300_TIMER_APP_EOST (0x0004)
  41. #define U300_TIMER_APP_EOST_TIMER_ENABLE (0x00000000)
  42. /* Disable OS Timer 32bit (-/W) */
  43. #define U300_TIMER_APP_DOST (0x0008)
  44. #define U300_TIMER_APP_DOST_TIMER_DISABLE (0x00000000)
  45. /* OS Timer Mode Register 32bit (-/W) */
  46. #define U300_TIMER_APP_SOSTM (0x000c)
  47. #define U300_TIMER_APP_SOSTM_MODE_CONTINUOUS (0x00000000)
  48. #define U300_TIMER_APP_SOSTM_MODE_ONE_SHOT (0x00000001)
  49. /* OS Timer Status Register 32bit (R/-) */
  50. #define U300_TIMER_APP_OSTS (0x0010)
  51. #define U300_TIMER_APP_OSTS_TIMER_STATE_MASK (0x0000000F)
  52. #define U300_TIMER_APP_OSTS_TIMER_STATE_IDLE (0x00000001)
  53. #define U300_TIMER_APP_OSTS_TIMER_STATE_ACTIVE (0x00000002)
  54. #define U300_TIMER_APP_OSTS_ENABLE_IND (0x00000010)
  55. #define U300_TIMER_APP_OSTS_MODE_MASK (0x00000020)
  56. #define U300_TIMER_APP_OSTS_MODE_CONTINUOUS (0x00000000)
  57. #define U300_TIMER_APP_OSTS_MODE_ONE_SHOT (0x00000020)
  58. #define U300_TIMER_APP_OSTS_IRQ_ENABLED_IND (0x00000040)
  59. #define U300_TIMER_APP_OSTS_IRQ_PENDING_IND (0x00000080)
  60. /* OS Timer Current Count Register 32bit (R/-) */
  61. #define U300_TIMER_APP_OSTCC (0x0014)
  62. /* OS Timer Terminal Count Register 32bit (R/W) */
  63. #define U300_TIMER_APP_OSTTC (0x0018)
  64. /* OS Timer Interrupt Enable Register 32bit (-/W) */
  65. #define U300_TIMER_APP_OSTIE (0x001c)
  66. #define U300_TIMER_APP_OSTIE_IRQ_DISABLE (0x00000000)
  67. #define U300_TIMER_APP_OSTIE_IRQ_ENABLE (0x00000001)
  68. /* OS Timer Interrupt Acknowledge Register 32bit (-/W) */
  69. #define U300_TIMER_APP_OSTIA (0x0020)
  70. #define U300_TIMER_APP_OSTIA_IRQ_ACK (0x00000080)
  71. /* Reset DD Timer 32bit (-/W) */
  72. #define U300_TIMER_APP_RDDT (0x0040)
  73. #define U300_TIMER_APP_RDDT_TIMER_RESET (0x00000000)
  74. /* Enable DD Timer 32bit (-/W) */
  75. #define U300_TIMER_APP_EDDT (0x0044)
  76. #define U300_TIMER_APP_EDDT_TIMER_ENABLE (0x00000000)
  77. /* Disable DD Timer 32bit (-/W) */
  78. #define U300_TIMER_APP_DDDT (0x0048)
  79. #define U300_TIMER_APP_DDDT_TIMER_DISABLE (0x00000000)
  80. /* DD Timer Mode Register 32bit (-/W) */
  81. #define U300_TIMER_APP_SDDTM (0x004c)
  82. #define U300_TIMER_APP_SDDTM_MODE_CONTINUOUS (0x00000000)
  83. #define U300_TIMER_APP_SDDTM_MODE_ONE_SHOT (0x00000001)
  84. /* DD Timer Status Register 32bit (R/-) */
  85. #define U300_TIMER_APP_DDTS (0x0050)
  86. #define U300_TIMER_APP_DDTS_TIMER_STATE_MASK (0x0000000F)
  87. #define U300_TIMER_APP_DDTS_TIMER_STATE_IDLE (0x00000001)
  88. #define U300_TIMER_APP_DDTS_TIMER_STATE_ACTIVE (0x00000002)
  89. #define U300_TIMER_APP_DDTS_ENABLE_IND (0x00000010)
  90. #define U300_TIMER_APP_DDTS_MODE_MASK (0x00000020)
  91. #define U300_TIMER_APP_DDTS_MODE_CONTINUOUS (0x00000000)
  92. #define U300_TIMER_APP_DDTS_MODE_ONE_SHOT (0x00000020)
  93. #define U300_TIMER_APP_DDTS_IRQ_ENABLED_IND (0x00000040)
  94. #define U300_TIMER_APP_DDTS_IRQ_PENDING_IND (0x00000080)
  95. /* DD Timer Current Count Register 32bit (R/-) */
  96. #define U300_TIMER_APP_DDTCC (0x0054)
  97. /* DD Timer Terminal Count Register 32bit (R/W) */
  98. #define U300_TIMER_APP_DDTTC (0x0058)
  99. /* DD Timer Interrupt Enable Register 32bit (-/W) */
  100. #define U300_TIMER_APP_DDTIE (0x005c)
  101. #define U300_TIMER_APP_DDTIE_IRQ_DISABLE (0x00000000)
  102. #define U300_TIMER_APP_DDTIE_IRQ_ENABLE (0x00000001)
  103. /* DD Timer Interrupt Acknowledge Register 32bit (-/W) */
  104. #define U300_TIMER_APP_DDTIA (0x0060)
  105. #define U300_TIMER_APP_DDTIA_IRQ_ACK (0x00000080)
  106. /* Reset GP1 Timer 32bit (-/W) */
  107. #define U300_TIMER_APP_RGPT1 (0x0080)
  108. #define U300_TIMER_APP_RGPT1_TIMER_RESET (0x00000000)
  109. /* Enable GP1 Timer 32bit (-/W) */
  110. #define U300_TIMER_APP_EGPT1 (0x0084)
  111. #define U300_TIMER_APP_EGPT1_TIMER_ENABLE (0x00000000)
  112. /* Disable GP1 Timer 32bit (-/W) */
  113. #define U300_TIMER_APP_DGPT1 (0x0088)
  114. #define U300_TIMER_APP_DGPT1_TIMER_DISABLE (0x00000000)
  115. /* GP1 Timer Mode Register 32bit (-/W) */
  116. #define U300_TIMER_APP_SGPT1M (0x008c)
  117. #define U300_TIMER_APP_SGPT1M_MODE_CONTINUOUS (0x00000000)
  118. #define U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT (0x00000001)
  119. /* GP1 Timer Status Register 32bit (R/-) */
  120. #define U300_TIMER_APP_GPT1S (0x0090)
  121. #define U300_TIMER_APP_GPT1S_TIMER_STATE_MASK (0x0000000F)
  122. #define U300_TIMER_APP_GPT1S_TIMER_STATE_IDLE (0x00000001)
  123. #define U300_TIMER_APP_GPT1S_TIMER_STATE_ACTIVE (0x00000002)
  124. #define U300_TIMER_APP_GPT1S_ENABLE_IND (0x00000010)
  125. #define U300_TIMER_APP_GPT1S_MODE_MASK (0x00000020)
  126. #define U300_TIMER_APP_GPT1S_MODE_CONTINUOUS (0x00000000)
  127. #define U300_TIMER_APP_GPT1S_MODE_ONE_SHOT (0x00000020)
  128. #define U300_TIMER_APP_GPT1S_IRQ_ENABLED_IND (0x00000040)
  129. #define U300_TIMER_APP_GPT1S_IRQ_PENDING_IND (0x00000080)
  130. /* GP1 Timer Current Count Register 32bit (R/-) */
  131. #define U300_TIMER_APP_GPT1CC (0x0094)
  132. /* GP1 Timer Terminal Count Register 32bit (R/W) */
  133. #define U300_TIMER_APP_GPT1TC (0x0098)
  134. /* GP1 Timer Interrupt Enable Register 32bit (-/W) */
  135. #define U300_TIMER_APP_GPT1IE (0x009c)
  136. #define U300_TIMER_APP_GPT1IE_IRQ_DISABLE (0x00000000)
  137. #define U300_TIMER_APP_GPT1IE_IRQ_ENABLE (0x00000001)
  138. /* GP1 Timer Interrupt Acknowledge Register 32bit (-/W) */
  139. #define U300_TIMER_APP_GPT1IA (0x00a0)
  140. #define U300_TIMER_APP_GPT1IA_IRQ_ACK (0x00000080)
  141. /* Reset GP2 Timer 32bit (-/W) */
  142. #define U300_TIMER_APP_RGPT2 (0x00c0)
  143. #define U300_TIMER_APP_RGPT2_TIMER_RESET (0x00000000)
  144. /* Enable GP2 Timer 32bit (-/W) */
  145. #define U300_TIMER_APP_EGPT2 (0x00c4)
  146. #define U300_TIMER_APP_EGPT2_TIMER_ENABLE (0x00000000)
  147. /* Disable GP2 Timer 32bit (-/W) */
  148. #define U300_TIMER_APP_DGPT2 (0x00c8)
  149. #define U300_TIMER_APP_DGPT2_TIMER_DISABLE (0x00000000)
  150. /* GP2 Timer Mode Register 32bit (-/W) */
  151. #define U300_TIMER_APP_SGPT2M (0x00cc)
  152. #define U300_TIMER_APP_SGPT2M_MODE_CONTINUOUS (0x00000000)
  153. #define U300_TIMER_APP_SGPT2M_MODE_ONE_SHOT (0x00000001)
  154. /* GP2 Timer Status Register 32bit (R/-) */
  155. #define U300_TIMER_APP_GPT2S (0x00d0)
  156. #define U300_TIMER_APP_GPT2S_TIMER_STATE_MASK (0x0000000F)
  157. #define U300_TIMER_APP_GPT2S_TIMER_STATE_IDLE (0x00000001)
  158. #define U300_TIMER_APP_GPT2S_TIMER_STATE_ACTIVE (0x00000002)
  159. #define U300_TIMER_APP_GPT2S_ENABLE_IND (0x00000010)
  160. #define U300_TIMER_APP_GPT2S_MODE_MASK (0x00000020)
  161. #define U300_TIMER_APP_GPT2S_MODE_CONTINUOUS (0x00000000)
  162. #define U300_TIMER_APP_GPT2S_MODE_ONE_SHOT (0x00000020)
  163. #define U300_TIMER_APP_GPT2S_IRQ_ENABLED_IND (0x00000040)
  164. #define U300_TIMER_APP_GPT2S_IRQ_PENDING_IND (0x00000080)
  165. /* GP2 Timer Current Count Register 32bit (R/-) */
  166. #define U300_TIMER_APP_GPT2CC (0x00d4)
  167. /* GP2 Timer Terminal Count Register 32bit (R/W) */
  168. #define U300_TIMER_APP_GPT2TC (0x00d8)
  169. /* GP2 Timer Interrupt Enable Register 32bit (-/W) */
  170. #define U300_TIMER_APP_GPT2IE (0x00dc)
  171. #define U300_TIMER_APP_GPT2IE_IRQ_DISABLE (0x00000000)
  172. #define U300_TIMER_APP_GPT2IE_IRQ_ENABLE (0x00000001)
  173. /* GP2 Timer Interrupt Acknowledge Register 32bit (-/W) */
  174. #define U300_TIMER_APP_GPT2IA (0x00e0)
  175. #define U300_TIMER_APP_GPT2IA_IRQ_ACK (0x00000080)
  176. /* Clock request control register - all four timers */
  177. #define U300_TIMER_APP_CRC (0x100)
  178. #define U300_TIMER_APP_CRC_CLOCK_REQUEST_ENABLE (0x00000001)
  179. #define TICKS_PER_JIFFY ((CLOCK_TICK_RATE + (HZ/2)) / HZ)
  180. #define US_PER_TICK ((1000000 + (HZ/2)) / HZ)
  181. /*
  182. * The u300_set_mode() function is always called first, if we
  183. * have oneshot timer active, the oneshot scheduling function
  184. * u300_set_next_event() is called immediately after.
  185. */
  186. static void u300_set_mode(enum clock_event_mode mode,
  187. struct clock_event_device *evt)
  188. {
  189. switch (mode) {
  190. case CLOCK_EVT_MODE_PERIODIC:
  191. /* Disable interrupts on GPT1 */
  192. writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
  193. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  194. /* Disable GP1 while we're reprogramming it. */
  195. writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
  196. U300_TIMER_APP_VBASE + U300_TIMER_APP_DGPT1);
  197. /*
  198. * Set the periodic mode to a certain number of ticks per
  199. * jiffy.
  200. */
  201. writel(TICKS_PER_JIFFY,
  202. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1TC);
  203. /*
  204. * Set continuous mode, so the timer keeps triggering
  205. * interrupts.
  206. */
  207. writel(U300_TIMER_APP_SGPT1M_MODE_CONTINUOUS,
  208. U300_TIMER_APP_VBASE + U300_TIMER_APP_SGPT1M);
  209. /* Enable timer interrupts */
  210. writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
  211. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  212. /* Then enable the OS timer again */
  213. writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
  214. U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT1);
  215. break;
  216. case CLOCK_EVT_MODE_ONESHOT:
  217. /* Just break; here? */
  218. /*
  219. * The actual event will be programmed by the next event hook,
  220. * so we just set a dummy value somewhere at the end of the
  221. * universe here.