core.c 5.4 KB

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