integrator_ap.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/syscore_ops.h>
  23. #include <linux/amba/bus.h>
  24. #include <linux/io.h>
  25. #include <linux/irqchip.h>
  26. #include <linux/of_irq.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_platform.h>
  29. #include <linux/termios.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include "hardware.h"
  33. #include "cm.h"
  34. #include "common.h"
  35. #include "pci_v3.h"
  36. #include "lm.h"
  37. /* Base address to the AP system controller */
  38. void __iomem *ap_syscon_base;
  39. /* Base address to the external bus interface */
  40. static void __iomem *ebi_base;
  41. /*
  42. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  43. * is the (PA >> 12).
  44. *
  45. * Setup a VA for the Integrator interrupt controller (for header #0,
  46. * just for now).
  47. */
  48. #define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
  49. /*
  50. * Logical Physical
  51. * f1400000 14000000 Interrupt controller
  52. * f1600000 16000000 UART 0
  53. */
  54. static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
  55. {
  56. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  57. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  58. .length = SZ_4K,
  59. .type = MT_DEVICE
  60. }, {
  61. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  62. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  63. .length = SZ_4K,
  64. .type = MT_DEVICE
  65. }
  66. };
  67. static void __init ap_map_io(void)
  68. {
  69. iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
  70. pci_v3_early_init();
  71. }
  72. #ifdef CONFIG_PM
  73. static unsigned long ic_irq_enable;
  74. static int irq_suspend(void)
  75. {
  76. ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
  77. return 0;
  78. }
  79. static void irq_resume(void)
  80. {
  81. /* disable all irq sources */
  82. cm_clear_irqs();
  83. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  84. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  85. writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
  86. }
  87. #else
  88. #define irq_suspend NULL
  89. #define irq_resume NULL
  90. #endif
  91. static struct syscore_ops irq_syscore_ops = {
  92. .suspend = irq_suspend,
  93. .resume = irq_resume,
  94. };
  95. static int __init irq_syscore_init(void)
  96. {
  97. register_syscore_ops(&irq_syscore_ops);
  98. return 0;
  99. }
  100. device_initcall(irq_syscore_init);
  101. /*
  102. * For the PL010 found in the Integrator/AP some of the UART control is
  103. * implemented in the system controller and accessed using a callback
  104. * from the driver.
  105. */
  106. static void integrator_uart_set_mctrl(struct amba_device *dev,
  107. void __iomem *base, unsigned int mctrl)
  108. {
  109. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  110. u32 phybase = dev->res.start;
  111. if (phybase == INTEGRATOR_UART0_BASE) {
  112. /* UART0 */
  113. rts_mask = 1 << 4;
  114. dtr_mask = 1 << 5;
  115. } else {
  116. /* UART1 */
  117. rts_mask = 1 << 6;
  118. dtr_mask = 1 << 7;
  119. }
  120. if (mctrl & TIOCM_RTS)
  121. ctrlc |= rts_mask;
  122. else
  123. ctrls |= rts_mask;
  124. if (mctrl & TIOCM_DTR)
  125. ctrlc |= dtr_mask;
  126. else
  127. ctrls |= dtr_mask;
  128. __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
  129. __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  130. }
  131. struct amba_pl010_data ap_uart_data = {
  132. .set_mctrl = integrator_uart_set_mctrl,
  133. };
  134. void __init ap_init_early(void)
  135. {
  136. }
  137. static void __init ap_init_irq_of(void)
  138. {
  139. cm_init();
  140. irqchip_init();
  141. }
  142. /* For the Device Tree, add in the UART callbacks as AUXDATA */
  143. static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
  144. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
  145. "uart0", &ap_uart_data),
  146. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
  147. "uart1", &ap_uart_data),
  148. { /* sentinel */ },
  149. };
  150. static const struct of_device_id ap_syscon_match[] = {
  151. { .compatible = "arm,integrator-ap-syscon"},
  152. { },
  153. };
  154. static const struct of_device_id ebi_match[] = {
  155. { .compatible = "arm,external-bus-interface"},
  156. { },
  157. };
  158. static void __init ap_init_of(void)
  159. {
  160. unsigned long sc_dec;
  161. struct device_node *syscon;
  162. struct device_node *ebi;
  163. int i;
  164. syscon = of_find_matching_node(NULL, ap_syscon_match);
  165. if (!syscon)
  166. return;
  167. ebi = of_find_matching_node(NULL, ebi_match);
  168. if (!ebi)
  169. return;
  170. ap_syscon_base = of_iomap(syscon, 0);
  171. if (!ap_syscon_base)
  172. return;
  173. ebi_base = of_iomap(ebi, 0);
  174. if (!ebi_base)
  175. return;
  176. of_platform_default_populate(NULL, ap_auxdata_lookup, NULL);
  177. sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
  178. for (i = 0; i < 4; i++) {
  179. struct lm_device *lmdev;
  180. if ((sc_dec & (16 << i)) == 0)
  181. continue;
  182. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  183. if (!lmdev)
  184. continue;
  185. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  186. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  187. lmdev->resource.flags = IORESOURCE_MEM;
  188. lmdev->irq = irq_of_parse_and_map(syscon, i);
  189. lmdev->id = i;
  190. lm_device_register(lmdev);
  191. }
  192. }
  193. static const char * ap_dt_board_compat[] = {
  194. "arm,integrator-ap",
  195. NULL,
  196. };
  197. DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
  198. .reserve = integrator_reserve,
  199. .map_io = ap_map_io,
  200. .init_early = ap_init_early,
  201. .init_irq = ap_init_irq_of,
  202. .init_machine = ap_init_of,
  203. .dt_compat = ap_dt_board_compat,
  204. MACHINE_END