vt8500.c 4.8 KB

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