core.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/memblock.h>
  18. #include <linux/sched.h>
  19. #include <linux/smp.h>
  20. #include <linux/termios.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/amba/serial.h>
  23. #include <linux/io.h>
  24. #include <linux/clkdev.h>
  25. #include <mach/hardware.h>
  26. #include <mach/platform.h>
  27. #include <asm/irq.h>
  28. #include <mach/cm.h>
  29. #include <asm/system.h>
  30. #include <asm/leds.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/time.h>
  33. #include <asm/pgtable.h>
  34. static struct amba_pl010_data integrator_uart_data;
  35. static struct amba_device rtc_device = {
  36. .dev = {
  37. .init_name = "mb:15",
  38. },
  39. .res = {
  40. .start = INTEGRATOR_RTC_BASE,
  41. .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
  42. .flags = IORESOURCE_MEM,
  43. },
  44. .irq = { IRQ_RTCINT, NO_IRQ },
  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. };
  58. static struct amba_device uart1_device = {
  59. .dev = {
  60. .init_name = "mb:17",
  61. .platform_data = &integrator_uart_data,
  62. },
  63. .res = {
  64. .start = INTEGRATOR_UART1_BASE,
  65. .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
  66. .flags = IORESOURCE_MEM,
  67. },
  68. .irq = { IRQ_UARTINT1, NO_IRQ },
  69. };
  70. static struct amba_device kmi0_device = {
  71. .dev = {
  72. .init_name = "mb:18",
  73. },
  74. .res = {
  75. .start = KMI0_BASE,
  76. .end = KMI0_BASE + SZ_4K - 1,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. .irq = { IRQ_KMIINT0, NO_IRQ },
  80. };
  81. static struct amba_device kmi1_device = {
  82. .dev = {
  83. .init_name = "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. };
  92. static struct amba_device *amba_devs[] __initdata = {
  93. &rtc_device,
  94. &uart0_device,
  95. &uart1_device,
  96. &kmi0_device,
  97. &kmi1_device,
  98. };
  99. /*
  100. * These are fixed clocks.
  101. */
  102. static struct clk clk24mhz = {
  103. .rate = 24000000,
  104. };
  105. static struct clk uartclk = {
  106. .rate = 14745600,
  107. };
  108. static struct clk dummy_apb_pclk;
  109. static struct clk_lookup lookups[] = {
  110. { /* Bus clock */
  111. .con_id = "apb_pclk",
  112. .clk = &dummy_apb_pclk,
  113. }, {
  114. /* Integrator/AP timer frequency */
  115. .dev_id = "ap_timer",
  116. .clk = &clk24mhz,
  117. }, { /* UART0 */
  118. .dev_id = "mb:16",
  119. .clk = &uartclk,
  120. }, { /* UART1 */
  121. .dev_id = "mb:17",
  122. .clk = &uartclk,
  123. }, { /* KMI0 */
  124. .dev_id = "mb:18",
  125. .clk = &clk24mhz,
  126. }, { /* KMI1 */
  127. .dev_id = "mb:19",
  128. .clk = &clk24mhz,
  129. }, { /* MMCI - IntegratorCP */
  130. .dev_id = "mb:1c",
  131. .clk = &uartclk,
  132. }
  133. };
  134. void __init integrator_init_early(void)
  135. {
  136. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  137. }
  138. static int __init integrator_init(void)
  139. {
  140. int i;
  141. /*
  142. * The Integrator/AP lacks necessary AMBA PrimeCell IDs, so we need to
  143. * hard-code them. The Integator/CP and forward have proper cell IDs.
  144. * Else we leave them undefined to the bus driver can autoprobe them.
  145. */
  146. if (machine_is_integrator()) {
  147. rtc_device.periphid = 0x00041030;
  148. uart0_device.periphid = 0x00041010;
  149. uart1_device.periphid = 0x00041010;
  150. kmi0_device.periphid = 0x00041050;
  151. kmi1_device.periphid = 0x00041050;
  152. }
  153. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  154. struct amba_device *d = amba_devs[i];
  155. amba_device_register(d, &iomem_resource);
  156. }
  157. return 0;
  158. }
  159. arch_initcall(integrator_init);
  160. /*
  161. * On the Integrator platform, the port RTS and DTR are provided by
  162. * bits in the following SC_CTRLS register bits:
  163. * RTS DTR
  164. * UART0 7 6
  165. * UART1 5 4
  166. */
  167. #define SC_CTRLC IO_ADDRESS(INTEGRATOR_SC_CTRLC)
  168. #define SC_CTRLS IO_ADDRESS(INTEGRATOR_SC_CTRLS)
  169. static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
  170. {
  171. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  172. if (dev == &uart0_device) {
  173. rts_mask = 1 << 4;
  174. dtr_mask = 1 << 5;
  175. } else {
  176. rts_mask = 1 << 6;
  177. dtr_mask = 1 << 7;
  178. }
  179. if (mctrl & TIOCM_RTS)
  180. ctrlc |= rts_mask;
  181. else
  182. ctrls |= rts_mask;
  183. if (mctrl & TIOCM_DTR)
  184. ctrlc |= dtr_mask;
  185. else
  186. ctrls |= dtr_mask;
  187. __raw_writel(ctrls, SC_CTRLS);
  188. __raw_writel(ctrlc, SC_CTRLC);
  189. }
  190. static struct amba_pl010_data integrator_uart_data = {
  191. .set_mctrl = integrator_uart_set_mctrl,
  192. };
  193. #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_CTRL)
  194. static DEFINE_RAW_SPINLOCK(cm_lock);
  195. /**
  196. * cm_control - update the CM_CTRL register.
  197. * @mask: bits to change
  198. * @set: bits to set
  199. */
  200. void cm_control(u32 mask, u32 set)
  201. {
  202. unsigned long flags;
  203. u32 val;
  204. raw_spin_lock_irqsave(&cm_lock, flags);
  205. val = readl(CM_CTRL) & ~mask;
  206. writel(val | set, CM_CTRL);
  207. raw_spin_unlock_irqrestore(&cm_lock, flags);
  208. }
  209. EXPORT_SYMBOL(cm_control);
  210. /*
  211. * We need to stop things allocating the low memory; ideally we need a
  212. * better implementation of GFP_DMA which does not assume that DMA-able
  213. * memory starts at zero.
  214. */
  215. void __init integrator_reserve(void)
  216. {
  217. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  218. }
  219. /*
  220. * To reset, we hit the on-board reset register in the system FPGA
  221. */
  222. void integrator_restart(char mode, const char *cmd)
  223. {
  224. cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
  225. }