vt8500.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/arm/mach-vt8500/vt8500.c
  4. *
  5. * Copyright (C) 2012 Tony Prisk <[email protected]>
  6. */
  7. #include <linux/io.h>
  8. #include <linux/pm.h>
  9. #include <linux/reboot.h>
  10. #include <asm/mach-types.h>
  11. #include <asm/mach/arch.h>
  12. #include <asm/mach/time.h>
  13. #include <asm/mach/map.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_irq.h>
  17. #define LEGACY_GPIO_BASE 0xD8110000
  18. #define LEGACY_PMC_BASE 0xD8130000
  19. /* Registers in GPIO Controller */
  20. #define VT8500_GPIO_MUX_REG 0x200
  21. /* Registers in Power Management Controller */
  22. #define VT8500_HCR_REG 0x12
  23. #define VT8500_PMSR_REG 0x60
  24. static void __iomem *pmc_base;
  25. static void vt8500_restart(enum reboot_mode mode, const char *cmd)
  26. {
  27. if (pmc_base)
  28. writel(1, pmc_base + VT8500_PMSR_REG);
  29. }
  30. static struct map_desc vt8500_io_desc[] __initdata = {
  31. /* SoC MMIO registers */
  32. [0] = {
  33. .virtual = 0xf8000000,
  34. .pfn = __phys_to_pfn(0xd8000000),
  35. .length = 0x00390000, /* max of all chip variants */
  36. .type = MT_DEVICE
  37. },
  38. };
  39. static void __init vt8500_map_io(void)
  40. {
  41. iotable_init(vt8500_io_desc, ARRAY_SIZE(vt8500_io_desc));
  42. }
  43. static void vt8500_power_off(void)
  44. {
  45. local_irq_disable();
  46. writew(5, pmc_base + VT8500_HCR_REG);
  47. asm("mcr p15, 0, %0, c7, c0, 4" : : "r" (0));
  48. }
  49. static void __init vt8500_init(void)
  50. {
  51. struct device_node *np;
  52. #if defined(CONFIG_FB_VT8500) || defined(CONFIG_FB_WM8505)
  53. struct device_node *fb;
  54. void __iomem *gpio_base;
  55. #endif
  56. #ifdef CONFIG_FB_VT8500
  57. fb = of_find_compatible_node(NULL, NULL, "via,vt8500-fb");
  58. if (fb) {
  59. np = of_find_compatible_node(NULL, NULL, "via,vt8500-gpio");
  60. if (np) {
  61. gpio_base = of_iomap(np, 0);
  62. if (!gpio_base)
  63. pr_err("%s: of_iomap(gpio_mux) failed\n",
  64. __func__);
  65. of_node_put(np);
  66. } else {
  67. gpio_base = ioremap(LEGACY_GPIO_BASE, 0x1000);
  68. if (!gpio_base)
  69. pr_err("%s: ioremap(legacy_gpio_mux) failed\n",
  70. __func__);
  71. }
  72. if (gpio_base) {
  73. writel(readl(gpio_base + VT8500_GPIO_MUX_REG) | 1,
  74. gpio_base + VT8500_GPIO_MUX_REG);
  75. iounmap(gpio_base);
  76. } else
  77. pr_err("%s: Could not remap GPIO mux\n", __func__);
  78. of_node_put(fb);
  79. }
  80. #endif
  81. #ifdef CONFIG_FB_WM8505
  82. fb = of_find_compatible_node(NULL, NULL, "wm,wm8505-fb");
  83. if (fb) {
  84. np = of_find_compatible_node(NULL, NULL, "wm,wm8505-gpio");
  85. if (!np)
  86. np = of_find_compatible_node(NULL, NULL,
  87. "wm,wm8650-gpio");
  88. if (np) {
  89. gpio_base = of_iomap(np, 0);
  90. if (!gpio_base)
  91. pr_err("%s: of_iomap(gpio_mux) failed\n",
  92. __func__);
  93. of_node_put(np);
  94. } else {
  95. gpio_base = ioremap(LEGACY_GPIO_BASE, 0x1000);
  96. if (!gpio_base)
  97. pr_err("%s: ioremap(legacy_gpio_mux) failed\n",
  98. __func__);
  99. }
  100. if (gpio_base) {
  101. writel(readl(gpio_base + VT8500_GPIO_MUX_REG) |
  102. 0x80000000, gpio_base + VT8500_GPIO_MUX_REG);
  103. iounmap(gpio_base);
  104. } else
  105. pr_err("%s: Could not remap GPIO mux\n", __func__);
  106. of_node_put(fb);
  107. }
  108. #endif
  109. np = of_find_compatible_node(NULL, NULL, "via,vt8500-pmc");
  110. if (np) {
  111. pmc_base = of_iomap(np, 0);
  112. if (!pmc_base)
  113. pr_err("%s:of_iomap(pmc) failed\n", __func__);
  114. of_node_put(np);
  115. } else {
  116. pmc_base = ioremap(LEGACY_PMC_BASE, 0x1000);
  117. if (!pmc_base)
  118. pr_err("%s:ioremap(power_off) failed\n", __func__);
  119. }
  120. if (pmc_base)
  121. pm_power_off = &vt8500_power_off;
  122. else
  123. pr_err("%s: PMC Hibernation register could not be remapped, not enabling power off!\n", __func__);
  124. }
  125. static const char * const vt8500_dt_compat[] = {
  126. "via,vt8500",
  127. "wm,wm8650",
  128. "wm,wm8505",
  129. "wm,wm8750",
  130. "wm,wm8850",
  131. NULL
  132. };
  133. DT_MACHINE_START(WMT_DT, "VIA/Wondermedia SoC (Device Tree Support)")
  134. .dt_compat = vt8500_dt_compat,
  135. .map_io = vt8500_map_io,
  136. .init_machine = vt8500_init,
  137. .restart = vt8500_restart,
  138. MACHINE_END