core.c 6.0 KB

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