vt8500.c 4.3 KB

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