timer.c 17 KB

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