timer.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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/sched_clock.h>
  21. #include <mach/hardware.h>
  22. /* Generic stuff */
  23. #include <asm/mach/map.h>
  24. #include <asm/mach/time.h>
  25. #include <asm/mach/irq.h>
  26. /*
  27. * APP side special timer registers
  28. * This timer contains four timers which can fire an interrupt each.
  29. * OS (operating system) timer @ 32768 Hz
  30. * DD (device driver) timer @ 1 kHz
  31. * GP1 (general purpose 1) timer @ 1MHz
  32. * GP2 (general purpose 2) timer @ 1MHz
  33. */
  34. /* Reset OS Timer 32bit (-/W) */
  35. #define U300_TIMER_APP_ROST (0x0000)
  36. #define U300_TIMER_APP_ROST_TIMER_RESET (0x00000000)
  37. /* Enable OS Timer 32bit (-/W) */
  38. #define U300_TIMER_APP_EOST (0x0004)
  39. #define U300_TIMER_APP_EOST_TIMER_ENABLE (0x00000000)
  40. /* Disable OS Timer 32bit (-/W) */
  41. #define U300_TIMER_APP_DOST (0x0008)
  42. #define U300_TIMER_APP_DOST_TIMER_DISABLE (0x00000000)
  43. /* OS Timer Mode Register 32bit (-/W) */
  44. #define U300_TIMER_APP_SOSTM (0x000c)
  45. #define U300_TIMER_APP_SOSTM_MODE_CONTINUOUS (0x00000000)
  46. #define U300_TIMER_APP_SOSTM_MODE_ONE_SHOT (0x00000001)
  47. /* OS Timer Status Register 32bit (R/-) */
  48. #define U300_TIMER_APP_OSTS (0x0010)
  49. #define U300_TIMER_APP_OSTS_TIMER_STATE_MASK (0x0000000F)
  50. #define U300_TIMER_APP_OSTS_TIMER_STATE_IDLE (0x00000001)
  51. #define U300_TIMER_APP_OSTS_TIMER_STATE_ACTIVE (0x00000002)
  52. #define U300_TIMER_APP_OSTS_ENABLE_IND (0x00000010)
  53. #define U300_TIMER_APP_OSTS_MODE_MASK (0x00000020)
  54. #define U300_TIMER_APP_OSTS_MODE_CONTINUOUS (0x00000000)
  55. #define U300_TIMER_APP_OSTS_MODE_ONE_SHOT (0x00000020)
  56. #define U300_TIMER_APP_OSTS_IRQ_ENABLED_IND (0x00000040)
  57. #define U300_TIMER_APP_OSTS_IRQ_PENDING_IND (0x00000080)
  58. /* OS Timer Current Count Register 32bit (R/-) */
  59. #define U300_TIMER_APP_OSTCC (0x0014)
  60. /* OS Timer Terminal Count Register 32bit (R/W) */
  61. #define U300_TIMER_APP_OSTTC (0x0018)
  62. /* OS Timer Interrupt Enable Register 32bit (-/W) */
  63. #define U300_TIMER_APP_OSTIE (0x001c)
  64. #define U300_TIMER_APP_OSTIE_IRQ_DISABLE (0x00000000)
  65. #define U300_TIMER_APP_OSTIE_IRQ_ENABLE (0x00000001)
  66. /* OS Timer Interrupt Acknowledge Register 32bit (-/W) */
  67. #define U300_TIMER_APP_OSTIA (0x0020)
  68. #define U300_TIMER_APP_OSTIA_IRQ_ACK (0x00000080)
  69. /* Reset DD Timer 32bit (-/W) */
  70. #define U300_TIMER_APP_RDDT (0x0040)
  71. #define U300_TIMER_APP_RDDT_TIMER_RESET (0x00000000)
  72. /* Enable DD Timer 32bit (-/W) */
  73. #define U300_TIMER_APP_EDDT (0x0044)
  74. #define U300_TIMER_APP_EDDT_TIMER_ENABLE (0x00000000)
  75. /* Disable DD Timer 32bit (-/W) */
  76. #define U300_TIMER_APP_DDDT (0x0048)
  77. #define U300_TIMER_APP_DDDT_TIMER_DISABLE (0x00000000)
  78. /* DD Timer Mode Register 32bit (-/W) */
  79. #define U300_TIMER_APP_SDDTM (0x004c)
  80. #define U300_TIMER_APP_SDDTM_MODE_CONTINUOUS (0x00000000)
  81. #define U300_TIMER_APP_SDDTM_MODE_ONE_SHOT (0x00000001)
  82. /* DD Timer Status Register 32bit (R/-) */
  83. #define U300_TIMER_APP_DDTS (0x0050)
  84. #define U300_TIMER_APP_DDTS_TIMER_STATE_MASK (0x0000000F)
  85. #define U300_TIMER_APP_DDTS_TIMER_STATE_IDLE (0x00000001)
  86. #define U300_TIMER_APP_DDTS_TIMER_STATE_ACTIVE (0x00000002)
  87. #define U300_TIMER_APP_DDTS_ENABLE_IND (0x00000010)
  88. #define U300_TIMER_APP_DDTS_MODE_MASK (0x00000020)
  89. #define U300_TIMER_APP_DDTS_MODE_CONTINUOUS (0x00000000)
  90. #define U300_TIMER_APP_DDTS_MODE_ONE_SHOT (0x00000020)
  91. #define U300_TIMER_APP_DDTS_IRQ_ENABLED_IND (0x00000040)
  92. #define U300_TIMER_APP_DDTS_IRQ_PENDING_IND (0x00000080)
  93. /* DD Timer Current Count Register 32bit (R/-) */
  94. #define U300_TIMER_APP_DDTCC (0x0054)
  95. /* DD Timer Terminal Count Register 32bit (R/W) */
  96. #define U300_TIMER_APP_DDTTC (0x0058)
  97. /* DD Timer Interrupt Enable Register 32bit (-/W) */
  98. #define U300_TIMER_APP_DDTIE (0x005c)
  99. #define U300_TIMER_APP_DDTIE_IRQ_DISABLE (0x00000000)
  100. #define U300_TIMER_APP_DDTIE_IRQ_ENABLE (0x00000001)
  101. /* DD Timer Interrupt Acknowledge Register 32bit (-/W) */
  102. #define U300_TIMER_APP_DDTIA (0x0060)
  103. #define U300_TIMER_APP_DDTIA_IRQ_ACK (0x00000080)
  104. /* Reset GP1 Timer 32bit (-/W) */
  105. #define U300_TIMER_APP_RGPT1 (0x0080)
  106. #define U300_TIMER_APP_RGPT1_TIMER_RESET (0x00000000)
  107. /* Enable GP1 Timer 32bit (-/W) */
  108. #define U300_TIMER_APP_EGPT1 (0x0084)
  109. #define U300_TIMER_APP_EGPT1_TIMER_ENABLE (0x00000000)
  110. /* Disable GP1 Timer 32bit (-/W) */
  111. #define U300_TIMER_APP_DGPT1 (0x0088)
  112. #define U300_TIMER_APP_DGPT1_TIMER_DISABLE (0x00000000)
  113. /* GP1 Timer Mode Register 32bit (-/W) */
  114. #define U300_TIMER_APP_SGPT1M (0x008c)
  115. #define U300_TIMER_APP_SGPT1M_MODE_CONTINUOUS (0x00000000)
  116. #define U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT (0x00000001)
  117. /* GP1 Timer Status Register 32bit (R/-) */
  118. #define U300_TIMER_APP_GPT1S (0x0090)
  119. #define U300_TIMER_APP_GPT1S_TIMER_STATE_MASK (0x0000000F)
  120. #define U300_TIMER_APP_GPT1S_TIMER_STATE_IDLE (0x00000001)
  121. #define U300_TIMER_APP_GPT1S_TIMER_STATE_ACTIVE (0x00000002)
  122. #define U300_TIMER_APP_GPT1S_ENABLE_IND (0x00000010)
  123. #define U300_TIMER_APP_GPT1S_MODE_MASK (0x00000020)
  124. #define U300_TIMER_APP_GPT1S_MODE_CONTINUOUS (0x00000000)
  125. #define U300_TIMER_APP_GPT1S_MODE_ONE_SHOT (0x00000020)
  126. #define U300_TIMER_APP_GPT1S_IRQ_ENABLED_IND (0x00000040)
  127. #define U300_TIMER_APP_GPT1S_IRQ_PENDING_IND (0x00000080)
  128. /* GP1 Timer Current Count Register 32bit (R/-) */
  129. #define U300_TIMER_APP_GPT1CC (0x0094)
  130. /* GP1 Timer Terminal Count Register 32bit (R/W) */
  131. #define U300_TIMER_APP_GPT1TC (0x0098)
  132. /* GP1 Timer Interrupt Enable Register 32bit (-/W) */
  133. #define U300_TIMER_APP_GPT1IE (0x009c)
  134. #define U300_TIMER_APP_GPT1IE_IRQ_DISABLE (0x00000000)
  135. #define U300_TIMER_APP_GPT1IE_IRQ_ENABLE (0x00000001)
  136. /* GP1 Timer Interrupt Acknowledge Register 32bit (-/W) */
  137. #define U300_TIMER_APP_GPT1IA (0x00a0)
  138. #define U300_TIMER_APP_GPT1IA_IRQ_ACK (0x00000080)
  139. /* Reset GP2 Timer 32bit (-/W) */
  140. #define U300_TIMER_APP_RGPT2 (0x00c0)
  141. #define U300_TIMER_APP_RGPT2_TIMER_RESET (0x00000000)
  142. /* Enable GP2 Timer 32bit (-/W) */
  143. #define U300_TIMER_APP_EGPT2 (0x00c4)
  144. #define U300_TIMER_APP_EGPT2_TIMER_ENABLE (0x00000000)
  145. /* Disable GP2 Timer 32bit (-/W) */
  146. #define U300_TIMER_APP_DGPT2 (0x00c8)
  147. #define U300_TIMER_APP_DGPT2_TIMER_DISABLE (0x00000000)
  148. /* GP2 Timer Mode Register 32bit (-/W) */
  149. #define U300_TIMER_APP_SGPT2M (0x00cc)
  150. #define U300_TIMER_APP_SGPT2M_MODE_CONTINUOUS (0x00000000)
  151. #define U300_TIMER_APP_SGPT2M_MODE_ONE_SHOT (0x00000001)
  152. /* GP2 Timer Status Register 32bit (R/-) */
  153. #define U300_TIMER_APP_GPT2S (0x00d0)
  154. #define U300_TIMER_APP_GPT2S_TIMER_STATE_MASK (0x0000000F)
  155. #define U300_TIMER_APP_GPT2S_TIMER_STATE_IDLE (0x00000001)
  156. #define U300_TIMER_APP_GPT2S_TIMER_STATE_ACTIVE (0x00000002)
  157. #define U300_TIMER_APP_GPT2S_ENABLE_IND (0x00000010)
  158. #define U300_TIMER_APP_GPT2S_MODE_MASK (0x00000020)
  159. #define U300_TIMER_APP_GPT2S_MODE_CONTINUOUS (0x00000000)
  160. #define U300_TIMER_APP_GPT2S_MODE_ONE_SHOT (0x00000020)
  161. #define U300_TIMER_APP_GPT2S_IRQ_ENABLED_IND (0x00000040)
  162. #define U300_TIMER_APP_GPT2S_IRQ_PENDING_IND (0x00000080)
  163. /* GP2 Timer Current Count Register 32bit (R/-) */
  164. #define U300_TIMER_APP_GPT2CC (0x00d4)
  165. /* GP2 Timer Terminal Count Register 32bit (R/W) */
  166. #define U300_TIMER_APP_GPT2TC (0x00d8)
  167. /* GP2 Timer Interrupt Enable Register 32bit (-/W) */
  168. #define U300_TIMER_APP_GPT2IE (0x00dc)
  169. #define U300_TIMER_APP_GPT2IE_IRQ_DISABLE (0x00000000)
  170. #define U300_TIMER_APP_GPT2IE_IRQ_ENABLE (0x00000001)
  171. /* GP2 Timer Interrupt Acknowledge Register 32bit (-/W) */
  172. #define U300_TIMER_APP_GPT2IA (0x00e0)
  173. #define U300_TIMER_APP_GPT2IA_IRQ_ACK (0x00000080)
  174. /* Clock request control register - all four timers */
  175. #define U300_TIMER_APP_CRC (0x100)
  176. #define U300_TIMER_APP_CRC_CLOCK_REQUEST_ENABLE (0x00000001)
  177. #define TICKS_PER_JIFFY ((CLOCK_TICK_RATE + (HZ/2)) / HZ)
  178. #define US_PER_TICK ((1000000 + (HZ/2)) / HZ)
  179. /*
  180. * The u300_set_mode() function is always called first, if we
  181. * have oneshot timer active, the oneshot scheduling function
  182. * u300_set_next_event() is called immediately after.
  183. */
  184. static void u300_set_mode(enum clock_event_mode mode,
  185. struct clock_event_device *evt)
  186. {
  187. switch (mode) {
  188. case CLOCK_EVT_MODE_PERIODIC:
  189. /* Disable interrupts on GPT1 */
  190. writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
  191. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  192. /* Disable GP1 while we're reprogramming it. */
  193. writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
  194. U300_TIMER_APP_VBASE + U300_TIMER_APP_DGPT1);
  195. /*
  196. * Set the periodic mode to a certain number of ticks per
  197. * jiffy.
  198. */
  199. writel(TICKS_PER_JIFFY,
  200. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1TC);
  201. /*
  202. * Set continuous mode, so the timer keeps triggering
  203. * interrupts.
  204. */
  205. writel(U300_TIMER_APP_SGPT1M_MODE_CONTINUOUS,
  206. U300_TIMER_APP_VBASE + U300_TIMER_APP_SGPT1M);
  207. /* Enable timer interrupts */
  208. writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
  209. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  210. /* Then enable the OS timer again */
  211. writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
  212. U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT1);
  213. break;
  214. case CLOCK_EVT_MODE_ONESHOT:
  215. /* Just break; here? */
  216. /*
  217. * The actual event will be programmed by the next event hook,
  218. * so we just set a dummy value somewhere at the end of the
  219. * universe here.
  220. */
  221. /* Disable interrupts on GPT1 */
  222. writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
  223. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  224. /* Disable GP1 while we're reprogramming it. */
  225. writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
  226. U300_TIMER_APP_VBASE + U300_TIMER_APP_DGPT1);
  227. /*
  228. * Expire far in the future, u300_set_next_event() will be
  229. * called soon...
  230. */
  231. writel(0xFFFFFFFF, U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1TC);
  232. /* We run one shot per tick here! */
  233. writel(U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT,
  234. U300_TIMER_APP_VBASE + U300_TIMER_APP_SGPT1M);
  235. /* Enable interrupts for this timer */
  236. writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
  237. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  238. /* Enable timer */
  239. writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
  240. U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT1);
  241. break;
  242. case CLOCK_EVT_MODE_UNUSED:
  243. case CLOCK_EVT_MODE_SHUTDOWN:
  244. /* Disable interrupts on GP1 */
  245. writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
  246. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  247. /* Disable GP1 */
  248. writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
  249. U300_TIMER_APP_VBASE + U300_TIMER_APP_DGPT1);
  250. break;
  251. case CLOCK_EVT_MODE_RESUME:
  252. /* Ignore this call */
  253. break;
  254. }
  255. }
  256. /*
  257. * The app timer in one shot mode obviously has to be reprogrammed
  258. * in EXACTLY this sequence to work properly. Do NOT try to e.g. replace
  259. * the interrupt disable + timer disable commands with a reset command,
  260. * it will fail miserably. Apparently (and I found this the hard way)
  261. * the timer is very sensitive to the instruction order, though you don't
  262. * get that impression from the data sheet.
  263. */
  264. static int u300_set_next_event(unsigned long cycles,
  265. struct clock_event_device *evt)
  266. {
  267. /* Disable interrupts on GPT1 */
  268. writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
  269. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  270. /* Disable GP1 while we're reprogramming it. */
  271. writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
  272. U300_TIMER_APP_VBASE + U300_TIMER_APP_DGPT1);
  273. /* Reset the General Purpose timer 1. */
  274. writel(U300_TIMER_APP_RGPT1_TIMER_RESET,
  275. U300_TIMER_APP_VBASE + U300_TIMER_APP_RGPT1);
  276. /* IRQ in n * cycles */
  277. writel(cycles, U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1TC);
  278. /*
  279. * We run one shot per tick here! (This is necessary to reconfigure,
  280. * the timer will tilt if you don't!)
  281. */
  282. writel(U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT,
  283. U300_TIMER_APP_VBASE + U300_TIMER_APP_SGPT1M);
  284. /* Enable timer interrupts */
  285. writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
  286. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IE);
  287. /* Then enable the OS timer again */
  288. writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
  289. U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT1);
  290. return 0;
  291. }
  292. /* Use general purpose timer 1 as clock event */
  293. static struct clock_event_device clockevent_u300_1mhz = {
  294. .name = "GPT1",
  295. .rating = 300, /* Reasonably fast and accurate clock event */
  296. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  297. .set_next_event = u300_set_next_event,
  298. .set_mode = u300_set_mode,
  299. };
  300. /* Clock event timer interrupt handler */
  301. static irqreturn_t u300_timer_interrupt(int irq, void *dev_id)
  302. {
  303. struct clock_event_device *evt = &clockevent_u300_1mhz;
  304. /* ACK/Clear timer IRQ for the APP GPT1 Timer */
  305. writel(U300_TIMER_APP_GPT1IA_IRQ_ACK,
  306. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT1IA);
  307. evt->event_handler(evt);
  308. return IRQ_HANDLED;
  309. }
  310. static struct irqaction u300_timer_irq = {
  311. .name = "U300 Timer Tick",
  312. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  313. .handler = u300_timer_interrupt,
  314. };
  315. /*
  316. * Override the global weak sched_clock symbol with this
  317. * local implementation which uses the clocksource to get some
  318. * better resolution when scheduling the kernel. We accept that
  319. * this wraps around for now, since it is just a relative time
  320. * stamp. (Inspired by OMAP implementation.)
  321. */
  322. static u32 notrace u300_read_sched_clock(void)
  323. {
  324. return readl(U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT2CC);
  325. }
  326. /*
  327. * This sets up the system timers, clock source and clock event.
  328. */
  329. static void __init u300_timer_init(void)
  330. {
  331. struct clk *clk;
  332. unsigned long rate;
  333. /* Clock the interrupt controller */
  334. clk = clk_get_sys("apptimer", NULL);
  335. BUG_ON(IS_ERR(clk));
  336. clk_enable(clk);
  337. rate = clk_get_rate(clk);
  338. setup_sched_clock(u300_read_sched_clock, 32, rate);
  339. /*
  340. * Disable the "OS" and "DD" timers - these are designed for Symbian!
  341. * Example usage in cnh1601578 cpu subsystem pd_timer_app.c
  342. */
  343. writel(U300_TIMER_APP_CRC_CLOCK_REQUEST_ENABLE,
  344. U300_TIMER_APP_VBASE + U300_TIMER_APP_CRC);
  345. writel(U300_TIMER_APP_ROST_TIMER_RESET,
  346. U300_TIMER_APP_VBASE + U300_TIMER_APP_ROST);
  347. writel(U300_TIMER_APP_DOST_TIMER_DISABLE,
  348. U300_TIMER_APP_VBASE + U300_TIMER_APP_DOST);
  349. writel(U300_TIMER_APP_RDDT_TIMER_RESET,
  350. U300_TIMER_APP_VBASE + U300_TIMER_APP_RDDT);
  351. writel(U300_TIMER_APP_DDDT_TIMER_DISABLE,
  352. U300_TIMER_APP_VBASE + U300_TIMER_APP_DDDT);
  353. /* Reset the General Purpose timer 1. */
  354. writel(U300_TIMER_APP_RGPT1_TIMER_RESET,
  355. U300_TIMER_APP_VBASE + U300_TIMER_APP_RGPT1);
  356. /* Set up the IRQ handler */
  357. setup_irq(IRQ_U300_TIMER_APP_GP1, &u300_timer_irq);
  358. /* Reset the General Purpose timer 2 */
  359. writel(U300_TIMER_APP_RGPT2_TIMER_RESET,
  360. U300_TIMER_APP_VBASE + U300_TIMER_APP_RGPT2);
  361. /* Set this timer to run around forever */
  362. writel(0xFFFFFFFFU, U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT2TC);
  363. /* Set continuous mode so it wraps around */
  364. writel(U300_TIMER_APP_SGPT2M_MODE_CONTINUOUS,
  365. U300_TIMER_APP_VBASE + U300_TIMER_APP_SGPT2M);
  366. /* Disable timer interrupts */
  367. writel(U300_TIMER_APP_GPT2IE_IRQ_DISABLE,
  368. U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT2IE);
  369. /* Then enable the GP2 timer to use as a free running us counter */
  370. writel(U300_TIMER_APP_EGPT2_TIMER_ENABLE,
  371. U300_TIMER_APP_VBASE + U300_TIMER_APP_EGPT2);
  372. /* Use general purpose timer 2 as clock source */
  373. if (clocksource_mmio_init(U300_TIMER_APP_VBASE + U300_TIMER_APP_GPT2CC,
  374. "GPT2", rate, 300, 32, clocksource_mmio_readl_up))
  375. pr_err("timer: failed to initialize U300 clock source\n");
  376. /* Configure and register the clockevent */
  377. clockevents_config_and_register(&clockevent_u300_1mhz, rate,
  378. 1, 0xffffffff);
  379. /*
  380. * TODO: init and register the rest of the timers too, they can be
  381. * used by hrtimers!
  382. */
  383. }
  384. /*
  385. * Very simple system timer that only register the clock event and
  386. * clock source.
  387. */
  388. struct sys_timer u300_timer = {
  389. .init = u300_timer_init,
  390. };