PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/arm/mach-integrator/integrator_ap.c

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