integrator_ap.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/mtd/physmap.h>
  33. #include <linux/platform_data/clk-integrator.h>
  34. #include <linux/of_irq.h>
  35. #include <linux/of_address.h>
  36. #include <linux/of_platform.h>
  37. #include <linux/stat.h>
  38. #include <linux/termios.h>
  39. #include <asm/hardware/arm_timer.h>
  40. #include <asm/setup.h>
  41. #include <asm/param.h> /* HZ */
  42. #include <asm/mach-types.h>
  43. #include <asm/mach/arch.h>
  44. #include <asm/mach/irq.h>
  45. #include <asm/mach/map.h>
  46. #include <asm/mach/time.h>
  47. #include "hardware.h"
  48. #include "cm.h"
  49. #include "common.h"
  50. #include "pci_v3.h"
  51. #include "lm.h"
  52. /* Base address to the AP system controller */
  53. void __iomem *ap_syscon_base;
  54. /* Base address to the external bus interface */
  55. static void __iomem *ebi_base;
  56. /*
  57. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  58. * is the (PA >> 12).
  59. *
  60. * Setup a VA for the Integrator interrupt controller (for header #0,
  61. * just for now).
  62. */
  63. #define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
  64. /*
  65. * Logical Physical
  66. * ef000000 Cache flush
  67. * f1100000 11000000 System controller registers
  68. * f1300000 13000000 Counter/Timer
  69. * f1400000 14000000 Interrupt controller
  70. * f1600000 16000000 UART 0
  71. * f1700000 17000000 UART 1
  72. * f1a00000 1a000000 Debug LEDs
  73. * f1b00000 1b000000 GPIO
  74. */
  75. static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
  76. {
  77. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  78. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  79. .length = SZ_4K,
  80. .type = MT_DEVICE
  81. }, {
  82. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  83. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  84. .length = SZ_4K,
  85. .type = MT_DEVICE
  86. }, {
  87. .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
  88. .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
  89. .length = SZ_4K,
  90. .type = MT_DEVICE
  91. }, {
  92. .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
  93. .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
  94. .length = SZ_4K,
  95. .type = MT_DEVICE
  96. }
  97. };
  98. static void __init ap_map_io(void)
  99. {
  100. iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
  101. pci_v3_early_init();
  102. }
  103. #ifdef CONFIG_PM
  104. static unsigned long ic_irq_enable;
  105. static int irq_suspend(void)
  106. {
  107. ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
  108. return 0;
  109. }
  110. static void irq_resume(void)
  111. {
  112. /* disable all irq sources */
  113. cm_clear_irqs();
  114. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  115. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  116. writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
  117. }
  118. #else
  119. #define irq_suspend NULL
  120. #define irq_resume NULL
  121. #endif
  122. static struct syscore_ops irq_syscore_ops = {
  123. .suspend = irq_suspend,
  124. .resume = irq_resume,
  125. };
  126. static int __init irq_syscore_init(void)
  127. {
  128. register_syscore_ops(&irq_syscore_ops);
  129. return 0;
  130. }
  131. device_initcall(irq_syscore_init);
  132. /*
  133. * Flash handling.
  134. */
  135. static int ap_flash_init(struct platform_device *dev)
  136. {
  137. u32 tmp;
  138. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
  139. ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  140. tmp = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) |
  141. INTEGRATOR_EBI_WRITE_ENABLE;
  142. writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
  143. if (!(readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET)
  144. & INTEGRATOR_EBI_WRITE_ENABLE)) {
  145. writel(0xa05f, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
  146. writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
  147. writel(0, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
  148. }
  149. return 0;
  150. }
  151. static void ap_flash_exit(struct platform_device *dev)
  152. {
  153. u32 tmp;
  154. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
  155. ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  156. tmp = readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) &
  157. ~INTEGRATOR_EBI_WRITE_ENABLE;
  158. writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
  159. if (readl(ebi_base + INTEGRATOR_EBI_CSR1_OFFSET) &
  160. INTEGRATOR_EBI_WRITE_ENABLE) {
  161. writel(0xa05f, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
  162. writel(tmp, ebi_base + INTEGRATOR_EBI_CSR1_OFFSET);
  163. writel(0, ebi_base + INTEGRATOR_EBI_LOCK_OFFSET);
  164. }
  165. }
  166. static void ap_flash_set_vpp(struct platform_device *pdev, int on)
  167. {
  168. if (on)
  169. writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
  170. ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
  171. else
  172. writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
  173. ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  174. }
  175. static struct physmap_flash_data ap_flash_data = {
  176. .width = 4,
  177. .init = ap_flash_init,
  178. .exit = ap_flash_exit,
  179. .set_vpp = ap_flash_set_vpp,
  180. };
  181. /*
  182. * For the PL010 found in the Integrator/AP some of the UART control is
  183. * implemented in the system controller and accessed using a callback
  184. * from the driver.
  185. */
  186. static void integrator_uart_set_mctrl(struct amba_device *dev,
  187. void __iomem *base, unsigned int mctrl)
  188. {
  189. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  190. u32 phybase = dev->res.start;
  191. if (phybase == INTEGRATOR_UART0_BASE) {
  192. /* UART0 */
  193. rts_mask = 1 << 4;
  194. dtr_mask = 1 << 5;
  195. } else {
  196. /* UART1 */
  197. rts_mask = 1 << 6;
  198. dtr_mask = 1 << 7;
  199. }
  200. if (mctrl & TIOCM_RTS)
  201. ctrlc |= rts_mask;
  202. else
  203. ctrls |= rts_mask;
  204. if (mctrl & TIOCM_DTR)
  205. ctrlc |= dtr_mask;
  206. else
  207. ctrls |= dtr_mask;
  208. __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
  209. __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  210. }
  211. struct amba_pl010_data ap_uart_data = {
  212. .set_mctrl = integrator_uart_set_mctrl,
  213. };
  214. void __init ap_init_early(void)
  215. {
  216. }
  217. static void __init ap_init_irq_of(void)
  218. {
  219. cm_init();
  220. irqchip_init();
  221. }
  222. /* For the Device Tree, add in the UART callbacks as AUXDATA */
  223. static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
  224. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_RTC_BASE,
  225. "rtc", NULL),
  226. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
  227. "uart0", &ap_uart_data),
  228. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
  229. "uart1", &ap_uart_data),
  230. OF_DEV_AUXDATA("arm,primecell", KMI0_BASE,
  231. "kmi0", NULL),
  232. OF_DEV_AUXDATA("arm,primecell", KMI1_BASE,
  233. "kmi1", NULL),
  234. OF_DEV_AUXDATA("cfi-flash", INTEGRATOR_FLASH_BASE,
  235. "physmap-flash", &ap_flash_data),
  236. { /* sentinel */ },
  237. };
  238. static const struct of_device_id ap_syscon_match[] = {
  239. { .compatible = "arm,integrator-ap-syscon"},
  240. { },
  241. };
  242. static const struct of_device_id ebi_match[] = {
  243. { .compatible = "arm,external-bus-interface"},
  244. { },
  245. };
  246. static void __init ap_init_of(void)
  247. {
  248. unsigned long sc_dec;
  249. struct device_node *syscon;
  250. struct device_node *ebi;
  251. int i;
  252. syscon = of_find_matching_node(NULL, ap_syscon_match);
  253. if (!syscon)
  254. return;
  255. ebi = of_find_matching_node(NULL, ebi_match);
  256. if (!ebi)
  257. return;
  258. ap_syscon_base = of_iomap(syscon, 0);
  259. if (!ap_syscon_base)
  260. return;
  261. ebi_base = of_iomap(ebi, 0);
  262. if (!ebi_base)
  263. return;
  264. of_platform_populate(NULL, of_default_bus_match_table,
  265. ap_auxdata_lookup, NULL);
  266. sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
  267. for (i = 0; i < 4; i++) {
  268. struct lm_device *lmdev;
  269. if ((sc_dec & (16 << i)) == 0)
  270. continue;
  271. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  272. if (!lmdev)
  273. continue;
  274. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  275. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  276. lmdev->resource.flags = IORESOURCE_MEM;
  277. lmdev->irq = irq_of_parse_and_map(syscon, i);
  278. lmdev->id = i;
  279. lm_device_register(lmdev);
  280. }
  281. }
  282. static const char * ap_dt_board_compat[] = {
  283. "arm,integrator-ap",
  284. NULL,
  285. };
  286. DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
  287. .reserve = integrator_reserve,
  288. .map_io = ap_map_io,
  289. .init_early = ap_init_early,
  290. .init_irq = ap_init_irq_of,
  291. .init_machine = ap_init_of,
  292. .dt_compat = ap_dt_board_compat,
  293. MACHINE_END