integrator_ap.c 5.6 KB

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