core.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  134. clkdev_add(&lookups[i]);
  135. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  136. struct amba_device *d = amba_devs[i];
  137. amba_device_register(d, &iomem_resource);
  138. }
  139. return 0;
  140. }
  141. arch_initcall(integrator_init);
  142. /*
  143. * On the Integrator platform, the port RTS and DTR are provided by
  144. * bits in the following SC_CTRLS register bits:
  145. * RTS DTR
  146. * UART0 7 6
  147. * UART1 5 4
  148. */
  149. #define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
  150. #define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
  151. static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
  152. {
  153. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  154. if (dev == &uart0_device) {
  155. rts_mask = 1 << 4;
  156. dtr_mask = 1 << 5;
  157. } else {
  158. rts_mask = 1 << 6;
  159. dtr_mask = 1 << 7;
  160. }
  161. if (mctrl & TIOCM_RTS)
  162. ctrlc |= rts_mask;
  163. else
  164. ctrls |= rts_mask;
  165. if (mctrl & TIOCM_DTR)
  166. ctrlc |= dtr_mask;
  167. else
  168. ctrls |= dtr_mask;
  169. __raw_writel(ctrls, SC_CTRLS);
  170. __raw_writel(ctrlc, SC_CTRLC);
  171. }
  172. static struct amba_pl010_data integrator_uart_data = {
  173. .set_mctrl = integrator_uart_set_mctrl,
  174. };
  175. #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
  176. static DEFINE_SPINLOCK(cm_lock);
  177. /**
  178. * cm_control - update the CM_CTRL register.
  179. * @mask: bits to change
  180. * @set: bits to set
  181. */
  182. void cm_control(u32 mask, u32 set)
  183. {
  184. unsigned long flags;
  185. u32 val;
  186. spin_lock_irqsave(&cm_lock, flags);
  187. val = readl(CM_CTRL) & ~mask;
  188. writel(val | set, CM_CTRL);
  189. spin_unlock_irqrestore(&cm_lock, flags);
  190. }
  191. EXPORT_SYMBOL(cm_control);
  192. /*
  193. * Where is the timer (VA)?
  194. */
  195. #define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
  196. #define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
  197. #define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
  198. #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
  199. /*
  200. * How long is the timer interval?
  201. */
  202. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  203. #if TIMER_INTERVAL >= 0x100000
  204. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  205. #elif TIMER_INTERVAL >= 0x10000
  206. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  207. #else
  208. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  209. #endif
  210. static unsigned long timer_reload;
  211. /*
  212. * Returns number of ms since last clock interrupt. Note that interrupts
  213. * will have been disabled by do_gettimeoffset()
  214. */
  215. unsigned long integrator_gettimeoffset(void)
  216. {
  217. unsigned long ticks1, ticks2, status;
  218. /*
  219. * Get the current number of ticks. Note that there is a race
  220. * condition between us reading the timer and checking for
  221. * an interrupt. We get around this by ensuring that the
  222. * counter has not reloaded between our two reads.
  223. */
  224. ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
  225. do {
  226. ticks1 = ticks2;
  227. status = __raw_readl(VA_IC_BASE + IRQ_RAW_STATUS);
  228. ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
  229. } while (ticks2 > ticks1);
  230. /*
  231. * Number of ticks since last interrupt.
  232. */
  233. ticks1 = timer_reload - ticks2;
  234. /*
  235. * Interrupt pending? If so, we've reloaded once already.
  236. */
  237. if (status & (1 << IRQ_TIMERINT1))
  238. ticks1 += timer_reload;
  239. /*
  240. * Convert the ticks to usecs
  241. */
  242. return TICKS2USECS(ticks1);
  243. }
  244. /*
  245. * IRQ handler for the timer
  246. */
  247. static irqreturn_t
  248. integrator_timer_interrupt(int irq, void *dev_id)
  249. {
  250. /*
  251. * clear the interrupt
  252. */
  253. writel(1, TIMER1_VA_BASE + TIMER_INTCLR);
  254. timer_tick();
  255. return IRQ_HANDLED;
  256. }
  257. static struct irqaction integrator_timer_irq = {
  258. .name = "Integrator Timer Tick",
  259. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  260. .handler = integrator_timer_interrupt,
  261. };
  262. /*
  263. * Set up timer interrupt, and return the current time in seconds.
  264. */
  265. void __init integrator_time_init(unsigned long reload, unsigned int ctrl)
  266. {
  267. unsigned int timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
  268. timer_reload = reload;
  269. timer_ctrl |= ctrl;
  270. if (timer_reload > 0x100000) {
  271. timer_reload >>= 8;
  272. timer_ctrl |= TIMER_CTRL_DIV256;
  273. } else if (timer_reload > 0x010000) {
  274. timer_reload >>= 4;
  275. timer_ctrl |= TIMER_CTRL_DIV16;
  276. }
  277. /*
  278. * Initialise to a known state (all timers off)
  279. */
  280. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  281. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  282. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  283. writel(timer_reload, TIMER1_VA_BASE + TIMER_LOAD);
  284. writel(timer_reload, TIMER1_VA_BASE + TIMER_VALUE);
  285. writel(timer_ctrl, TIMER1_VA_BASE + TIMER_CTRL);
  286. /*
  287. * Make irqs happen for the system timer
  288. */
  289. setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
  290. }