integrator_ap.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 <linux/mfd/syscon.h>
  31. #include <linux/regmap.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/map.h>
  34. #include "hardware.h"
  35. #include "cm.h"
  36. #include "common.h"
  37. #include "pci_v3.h"
  38. #include "lm.h"
  39. /* Regmap to the AP system controller */
  40. static struct regmap *ap_syscon_map;
  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. int ret;
  112. if (phybase == INTEGRATOR_UART0_BASE) {
  113. /* UART0 */
  114. rts_mask = 1 << 4;
  115. dtr_mask = 1 << 5;
  116. } else {
  117. /* UART1 */
  118. rts_mask = 1 << 6;
  119. dtr_mask = 1 << 7;
  120. }
  121. if (mctrl & TIOCM_RTS)
  122. ctrlc |= rts_mask;
  123. else
  124. ctrls |= rts_mask;
  125. if (mctrl & TIOCM_DTR)
  126. ctrlc |= dtr_mask;
  127. else
  128. ctrls |= dtr_mask;
  129. ret = regmap_write(ap_syscon_map,
  130. INTEGRATOR_SC_CTRLS_OFFSET,
  131. ctrls);
  132. if (ret)
  133. pr_err("MODEM: unable to write PL010 UART CTRLS\n");
  134. ret = regmap_write(ap_syscon_map,
  135. INTEGRATOR_SC_CTRLC_OFFSET,
  136. ctrlc);
  137. if (ret)
  138. pr_err("MODEM: unable to write PL010 UART CRTLC\n");
  139. }
  140. struct amba_pl010_data ap_uart_data = {
  141. .set_mctrl = integrator_uart_set_mctrl,
  142. };
  143. void __init ap_init_early(void)
  144. {
  145. }
  146. static void __init ap_init_irq_of(void)
  147. {
  148. cm_init();
  149. irqchip_init();
  150. }
  151. /* For the Device Tree, add in the UART callbacks as AUXDATA */
  152. static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
  153. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
  154. "uart0", &ap_uart_data),
  155. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
  156. "uart1", &ap_uart_data),
  157. { /* sentinel */ },
  158. };
  159. static const struct of_device_id ap_syscon_match[] = {
  160. { .compatible = "arm,integrator-ap-syscon"},
  161. { },
  162. };
  163. static void __init ap_init_of(void)
  164. {
  165. u32 sc_dec;
  166. struct device_node *syscon;
  167. int ret;
  168. int i;
  169. of_platform_default_populate(NULL, ap_auxdata_lookup, NULL);
  170. syscon = of_find_matching_node(NULL, ap_syscon_match);
  171. if (!syscon)
  172. return;
  173. ap_syscon_map = syscon_node_to_regmap(syscon);
  174. if (IS_ERR(ap_syscon_map)) {
  175. pr_crit("could not find Integrator/AP system controller\n");
  176. return;
  177. }
  178. ret = regmap_read(ap_syscon_map,
  179. INTEGRATOR_SC_DEC_OFFSET,
  180. &sc_dec);
  181. if (ret) {
  182. pr_crit("could not read from Integrator/AP syscon\n");
  183. return;
  184. }
  185. for (i = 0; i < 4; i++) {
  186. struct lm_device *lmdev;
  187. if ((sc_dec & (16 << i)) == 0)
  188. continue;
  189. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  190. if (!lmdev)
  191. continue;
  192. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  193. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  194. lmdev->resource.flags = IORESOURCE_MEM;
  195. lmdev->irq = irq_of_parse_and_map(syscon, i);
  196. lmdev->id = i;
  197. lm_device_register(lmdev);
  198. }
  199. }
  200. static const char * ap_dt_board_compat[] = {
  201. "arm,integrator-ap",
  202. NULL,
  203. };
  204. DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
  205. .reserve = integrator_reserve,
  206. .map_io = ap_map_io,
  207. .init_early = ap_init_early,
  208. .init_irq = ap_init_irq_of,
  209. .init_machine = ap_init_of,
  210. .dt_compat = ap_dt_board_compat,
  211. MACHINE_END