timer.c 17 KB

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