core.c 7.3 KB

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