core.c 7.1 KB

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