core.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * linux/arch/arm/mach-integrator/core.c
  3. *
  4. * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2, as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/sched.h>
  17. #include <linux/smp.h>
  18. #include <asm/hardware.h>
  19. #include <asm/irq.h>
  20. #include <asm/io.h>
  21. #include <asm/hardware/amba.h>
  22. #include <asm/arch/cm.h>
  23. #include <asm/system.h>
  24. #include <asm/leds.h>
  25. #include <asm/mach/time.h>
  26. #include "common.h"
  27. static struct amba_device rtc_device = {
  28. .dev = {
  29. .bus_id = "mb:15",
  30. },
  31. .res = {
  32. .start = INTEGRATOR_RTC_BASE,
  33. .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. .irq = { IRQ_RTCINT, NO_IRQ },
  37. .periphid = 0x00041030,
  38. };
  39. static struct amba_device uart0_device = {
  40. .dev = {
  41. .bus_id = "mb:16",
  42. },
  43. .res = {
  44. .start = INTEGRATOR_UART0_BASE,
  45. .end = INTEGRATOR_UART0_BASE + SZ_4K - 1,
  46. .flags = IORESOURCE_MEM,
  47. },
  48. .irq = { IRQ_UARTINT0, NO_IRQ },
  49. .periphid = 0x0041010,
  50. };
  51. static struct amba_device uart1_device = {
  52. .dev = {
  53. .bus_id = "mb:17",
  54. },
  55. .res = {
  56. .start = INTEGRATOR_UART1_BASE,
  57. .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
  58. .flags = IORESOURCE_MEM,
  59. },
  60. .irq = { IRQ_UARTINT1, NO_IRQ },
  61. .periphid = 0x0041010,
  62. };
  63. static struct amba_device kmi0_device = {
  64. .dev = {
  65. .bus_id = "mb:18",
  66. },
  67. .res = {
  68. .start = KMI0_BASE,
  69. .end = KMI0_BASE + SZ_4K - 1,
  70. .flags = IORESOURCE_MEM,
  71. },
  72. .irq = { IRQ_KMIINT0, NO_IRQ },
  73. .periphid = 0x00041050,
  74. };
  75. static struct amba_device kmi1_device = {
  76. .dev = {
  77. .bus_id = "mb:19",
  78. },
  79. .res = {
  80. .start = KMI1_BASE,
  81. .end = KMI1_BASE + SZ_4K - 1,
  82. .flags = IORESOURCE_MEM,
  83. },
  84. .irq = { IRQ_KMIINT1, NO_IRQ },
  85. .periphid = 0x00041050,
  86. };
  87. static struct amba_device *amba_devs[] __initdata = {
  88. &rtc_device,
  89. &uart0_device,
  90. &uart1_device,
  91. &kmi0_device,
  92. &kmi1_device,
  93. };
  94. static int __init integrator_init(void)
  95. {
  96. int i;
  97. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  98. struct amba_device *d = amba_devs[i];
  99. amba_device_register(d, &iomem_resource);
  100. }
  101. return 0;
  102. }
  103. arch_initcall(integrator_init);
  104. #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
  105. static DEFINE_SPINLOCK(cm_lock);
  106. /**
  107. * cm_control - update the CM_CTRL register.
  108. * @mask: bits to change
  109. * @set: bits to set
  110. */
  111. void cm_control(u32 mask, u32 set)
  112. {
  113. unsigned long flags;
  114. u32 val;
  115. spin_lock_irqsave(&cm_lock, flags);
  116. val = readl(CM_CTRL) & ~mask;
  117. writel(val | set, CM_CTRL);
  118. spin_unlock_irqrestore(&cm_lock, flags);
  119. }
  120. EXPORT_SYMBOL(cm_control);
  121. /*
  122. * Where is the timer (VA)?
  123. */
  124. #define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
  125. #define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
  126. #define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
  127. #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
  128. /*
  129. * How long is the timer interval?
  130. */
  131. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  132. #if TIMER_INTERVAL >= 0x100000
  133. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  134. #elif TIMER_INTERVAL >= 0x10000
  135. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  136. #else
  137. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  138. #endif
  139. /*
  140. * What does it look like?
  141. */
  142. typedef struct TimerStruct {
  143. unsigned long TimerLoad;
  144. unsigned long TimerValue;
  145. unsigned long TimerControl;
  146. unsigned long TimerClear;
  147. } TimerStruct_t;
  148. static unsigned long timer_reload;
  149. /*
  150. * Returns number of ms since last clock interrupt. Note that interrupts
  151. * will have been disabled by do_gettimeoffset()
  152. */
  153. unsigned long integrator_gettimeoffset(void)
  154. {
  155. volatile TimerStruct_t *timer1 = (TimerStruct_t *)TIMER1_VA_BASE;
  156. unsigned long ticks1, ticks2, status;
  157. /*
  158. * Get the current number of ticks. Note that there is a race
  159. * condition between us reading the timer and checking for
  160. * an interrupt. We get around this by ensuring that the
  161. * counter has not reloaded between our two reads.
  162. */
  163. ticks2 = timer1->TimerValue & 0xffff;
  164. do {
  165. ticks1 = ticks2;
  166. status = __raw_readl(VA_IC_BASE + IRQ_RAW_STATUS);
  167. ticks2 = timer1->TimerValue & 0xffff;
  168. } while (ticks2 > ticks1);
  169. /*
  170. * Number of ticks since last interrupt.
  171. */
  172. ticks1 = timer_reload - ticks2;
  173. /*
  174. * Interrupt pending? If so, we've reloaded once already.
  175. */
  176. if (status & (1 << IRQ_TIMERINT1))
  177. ticks1 += timer_reload;
  178. /*
  179. * Convert the ticks to usecs
  180. */
  181. return TICKS2USECS(ticks1);
  182. }
  183. /*
  184. * IRQ handler for the timer
  185. */
  186. static irqreturn_t
  187. integrator_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  188. {
  189. volatile TimerStruct_t *timer1 = (volatile TimerStruct_t *)TIMER1_VA_BASE;
  190. write_seqlock(&xtime_lock);
  191. /*
  192. * clear the interrupt
  193. */
  194. timer1->TimerClear = 1;
  195. /*
  196. * the clock tick routines are only processed on the
  197. * primary CPU
  198. */
  199. if (hard_smp_processor_id() == 0) {
  200. timer_tick(regs);
  201. #ifdef CONFIG_SMP
  202. smp_send_timer();
  203. #endif
  204. }
  205. #ifdef CONFIG_SMP
  206. /*
  207. * this is the ARM equivalent of the APIC timer interrupt
  208. */
  209. update_process_times(user_mode(regs));
  210. #endif /* CONFIG_SMP */
  211. write_sequnlock(&xtime_lock);
  212. return IRQ_HANDLED;
  213. }
  214. static struct irqaction integrator_timer_irq = {
  215. .name = "Integrator Timer Tick",
  216. .flags = SA_INTERRUPT,
  217. .handler = integrator_timer_interrupt
  218. };
  219. /*
  220. * Set up timer interrupt, and return the current time in seconds.
  221. */
  222. void __init integrator_time_init(unsigned long reload, unsigned int ctrl)
  223. {
  224. volatile TimerStruct_t *timer0 = (volatile TimerStruct_t *)TIMER0_VA_BASE;
  225. volatile TimerStruct_t *timer1 = (volatile TimerStruct_t *)TIMER1_VA_BASE;
  226. volatile TimerStruct_t *timer2 = (volatile TimerStruct_t *)TIMER2_VA_BASE;
  227. unsigned int timer_ctrl = 0x80 | 0x40; /* periodic */
  228. timer_reload = reload;
  229. timer_ctrl |= ctrl;
  230. if (timer_reload > 0x100000) {
  231. timer_reload >>= 8;
  232. timer_ctrl |= 0x08; /* /256 */
  233. } else if (timer_reload > 0x010000) {
  234. timer_reload >>= 4;
  235. timer_ctrl |= 0x04; /* /16 */
  236. }
  237. /*
  238. * Initialise to a known state (all timers off)
  239. */
  240. timer0->TimerControl = 0;
  241. timer1->TimerControl = 0;
  242. timer2->TimerControl = 0;
  243. timer1->TimerLoad = timer_reload;
  244. timer1->TimerValue = timer_reload;
  245. timer1->TimerControl = timer_ctrl;
  246. /*
  247. * Make irqs happen for the system timer
  248. */
  249. setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
  250. }