integrator_ap.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * linux/arch/arm/mach-integrator/integrator_ap.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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <linux/string.h>
  27. #include <linux/syscore_ops.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/amba/kmi.h>
  30. #include <linux/io.h>
  31. #include <linux/irqchip.h>
  32. #include <linux/platform_data/clk-integrator.h>
  33. #include <linux/of_irq.h>
  34. #include <linux/of_address.h>
  35. #include <linux/of_platform.h>
  36. #include <linux/stat.h>
  37. #include <linux/termios.h>
  38. #include <asm/setup.h>
  39. #include <asm/param.h> /* HZ */
  40. #include <asm/mach-types.h>
  41. #include <asm/mach/arch.h>
  42. #include <asm/mach/irq.h>
  43. #include <asm/mach/map.h>
  44. #include <asm/mach/time.h>
  45. #include "hardware.h"
  46. #include "cm.h"
  47. #include "common.h"
  48. #include "pci_v3.h"
  49. #include "lm.h"
  50. /* Base address to the AP system controller */
  51. void __iomem *ap_syscon_base;
  52. /* Base address to the external bus interface */
  53. static void __iomem *ebi_base;
  54. /*
  55. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  56. * is the (PA >> 12).
  57. *
  58. * Setup a VA for the Integrator interrupt controller (for header #0,
  59. * just for now).
  60. */
  61. #define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
  62. /*
  63. * Logical Physical
  64. * ef000000 Cache flush
  65. * f1100000 11000000 System controller registers
  66. * f1300000 13000000 Counter/Timer
  67. * f1400000 14000000 Interrupt controller
  68. * f1600000 16000000 UART 0
  69. * f1700000 17000000 UART 1
  70. * f1a00000 1a000000 Debug LEDs
  71. * f1b00000 1b000000 GPIO
  72. */
  73. static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
  74. {
  75. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  76. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  77. .length = SZ_4K,
  78. .type = MT_DEVICE
  79. }, {
  80. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  81. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  82. .length = SZ_4K,
  83. .type = MT_DEVICE
  84. }, {
  85. .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
  86. .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
  87. .length = SZ_4K,
  88. .type = MT_DEVICE
  89. }, {
  90. .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
  91. .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
  92. .length = SZ_4K,
  93. .type = MT_DEVICE
  94. }
  95. };
  96. static void __init ap_map_io(void)
  97. {
  98. iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
  99. pci_v3_early_init();
  100. }
  101. #ifdef CONFIG_PM
  102. static unsigned long ic_irq_enable;
  103. static int irq_suspend(void)
  104. {
  105. ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
  106. return 0;
  107. }
  108. static void irq_resume(void)
  109. {
  110. /* disable all irq sources */
  111. cm_clear_irqs();
  112. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  113. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  114. writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
  115. }
  116. #else
  117. #define irq_suspend NULL
  118. #define irq_resume NULL
  119. #endif
  120. static struct syscore_ops irq_syscore_ops = {
  121. .suspend = irq_suspend,
  122. .resume = irq_resume,
  123. };
  124. static int __init irq_syscore_init(void)
  125. {
  126. register_syscore_ops(&irq_syscore_ops);
  127. return 0;
  128. }
  129. device_initcall(irq_syscore_init);
  130. /*
  131. * For the PL010 found in the Integrator/AP some of the UART control is
  132. * implemented in the system controller and accessed using a callback
  133. * from the driver.
  134. */
  135. static void integrator_uart_set_mctrl(struct amba_device *dev,
  136. void __iomem *base, unsigned int mctrl)
  137. {
  138. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  139. u32 phybase = dev->res.start;
  140. if (phybase == INTEGRATOR_UART0_BASE) {
  141. /* UART0 */
  142. rts_mask = 1 << 4;
  143. dtr_mask = 1 << 5;
  144. } else {
  145. /* UART1 */
  146. rts_mask = 1 << 6;
  147. dtr_mask = 1 << 7;
  148. }
  149. if (mctrl & TIOCM_RTS)
  150. ctrlc |= rts_mask;
  151. else
  152. ctrls |= rts_mask;
  153. if (mctrl & TIOCM_DTR)
  154. ctrlc |= dtr_mask;
  155. else
  156. ctrls |= dtr_mask;
  157. __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
  158. __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  159. }
  160. struct amba_pl010_data ap_uart_data = {
  161. .set_mctrl = integrator_uart_set_mctrl,
  162. };
  163. void __init ap_init_early(void)
  164. {
  165. }
  166. static void __init ap_init_irq_of(void)
  167. {
  168. cm_init();
  169. irqchip_init();
  170. }
  171. /* For the Device Tree, add in the UART callbacks as AUXDATA */
  172. static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
  173. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_RTC_BASE,
  174. "rtc", NULL),
  175. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
  176. "uart0", &ap_uart_data),
  177. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
  178. "uart1", &ap_uart_data),
  179. OF_DEV_AUXDATA("arm,primecell", KMI0_BASE,
  180. "kmi0", NULL),
  181. OF_DEV_AUXDATA("arm,primecell", KMI1_BASE,
  182. "kmi1", NULL),
  183. { /* sentinel */ },
  184. };
  185. static const struct of_device_id ap_syscon_match[] = {
  186. { .compatible = "arm,integrator-ap-syscon"},
  187. { },
  188. };
  189. static const struct of_device_id ebi_match[] = {
  190. { .compatible = "arm,external-bus-interface"},
  191. { },
  192. };
  193. static void __init ap_init_of(void)
  194. {
  195. unsigned long sc_dec;
  196. struct device_node *syscon;
  197. struct device_node *ebi;
  198. int i;
  199. syscon = of_find_matching_node(NULL, ap_syscon_match);
  200. if (!syscon)
  201. return;
  202. ebi = of_find_matching_node(NULL, ebi_match);
  203. if (!ebi)
  204. return;
  205. ap_syscon_base = of_iomap(syscon, 0);
  206. if (!ap_syscon_base)
  207. return;
  208. ebi_base = of_iomap(ebi, 0);
  209. if (!ebi_base)
  210. return;
  211. of_platform_default_populate(NULL, ap_auxdata_lookup, NULL);
  212. sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
  213. for (i = 0; i < 4; i++) {
  214. struct lm_device *lmdev;
  215. if ((sc_dec & (16 << i)) == 0)
  216. continue;
  217. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  218. if (!lmdev)
  219. continue;
  220. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  221. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  222. lmdev->resource.flags = IORESOURCE_MEM;
  223. lmdev->irq = irq_of_parse_and_map(syscon, i);
  224. lmdev->id = i;
  225. lm_device_register(lmdev);
  226. }
  227. }
  228. static const char * ap_dt_board_compat[] = {
  229. "arm,integrator-ap",
  230. NULL,
  231. };
  232. DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
  233. .reserve = integrator_reserve,
  234. .map_io = ap_map_io,
  235. .init_early = ap_init_early,
  236. .init_irq = ap_init_irq_of,
  237. .init_machine = ap_init_of,
  238. .dt_compat = ap_dt_board_compat,
  239. MACHINE_END