system-controller.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * System controller support for Armada 370, 375 and XP platforms.
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Lior Amsalem <alior@marvell.com>
  7. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  8. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. *
  14. * The Armada 370, 375 and Armada XP SoCs have a range of
  15. * miscellaneous registers, that do not belong to a particular device,
  16. * but rather provide system-level features. This basic
  17. * system-controller driver provides a device tree binding for those
  18. * registers, and implements utility functions offering various
  19. * features related to those registers.
  20. *
  21. * For now, the feature set is limited to restarting the platform by a
  22. * soft-reset, but it might be extended in the future.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/of_address.h>
  27. #include <linux/io.h>
  28. #include <linux/reboot.h>
  29. #include "common.h"
  30. #include "mvebu-soc-id.h"
  31. #include "pmsu.h"
  32. #define ARMADA_375_CRYPT0_ENG_TARGET 41
  33. #define ARMADA_375_CRYPT0_ENG_ATTR 1
  34. static void __iomem *system_controller_base;
  35. static phys_addr_t system_controller_phys_base;
  36. struct mvebu_system_controller {
  37. u32 rstoutn_mask_offset;
  38. u32 system_soft_reset_offset;
  39. u32 rstoutn_mask_reset_out_en;
  40. u32 system_soft_reset;
  41. u32 resume_boot_addr;
  42. u32 dev_id;
  43. u32 rev_id;
  44. };
  45. static struct mvebu_system_controller *mvebu_sc;
  46. static const struct mvebu_system_controller armada_370_xp_system_controller = {
  47. .rstoutn_mask_offset = 0x60,
  48. .system_soft_reset_offset = 0x64,
  49. .rstoutn_mask_reset_out_en = 0x1,
  50. .system_soft_reset = 0x1,
  51. .dev_id = 0x38,
  52. .rev_id = 0x3c,
  53. };
  54. static const struct mvebu_system_controller armada_375_system_controller = {
  55. .rstoutn_mask_offset = 0x54,
  56. .system_soft_reset_offset = 0x58,
  57. .rstoutn_mask_reset_out_en = 0x1,
  58. .system_soft_reset = 0x1,
  59. .resume_boot_addr = 0xd4,
  60. .dev_id = 0x38,
  61. .rev_id = 0x3c,
  62. };
  63. static const struct mvebu_system_controller orion_system_controller = {
  64. .rstoutn_mask_offset = 0x108,
  65. .system_soft_reset_offset = 0x10c,
  66. .rstoutn_mask_reset_out_en = 0x4,
  67. .system_soft_reset = 0x1,
  68. };
  69. static const struct of_device_id of_system_controller_table[] = {
  70. {
  71. .compatible = "marvell,orion-system-controller",
  72. .data = (void *) &orion_system_controller,
  73. }, {
  74. .compatible = "marvell,armada-370-xp-system-controller",
  75. .data = (void *) &armada_370_xp_system_controller,
  76. }, {
  77. .compatible = "marvell,armada-375-system-controller",
  78. .data = (void *) &armada_375_system_controller,
  79. },
  80. { /* end of list */ },
  81. };
  82. void mvebu_restart(enum reboot_mode mode, const char *cmd)
  83. {
  84. if (!system_controller_base) {
  85. pr_err("Cannot restart, system-controller not available: check the device tree\n");
  86. } else {
  87. /*
  88. * Enable soft reset to assert RSTOUTn.
  89. */
  90. writel(mvebu_sc->rstoutn_mask_reset_out_en,
  91. system_controller_base +
  92. mvebu_sc->rstoutn_mask_offset);
  93. /*
  94. * Assert soft reset.
  95. */
  96. writel(mvebu_sc->system_soft_reset,
  97. system_controller_base +
  98. mvebu_sc->system_soft_reset_offset);
  99. }
  100. while (1)
  101. ;
  102. }
  103. int mvebu_system_controller_get_soc_id(u32 *dev, u32 *rev)
  104. {
  105. if (of_machine_is_compatible("marvell,armada380") &&
  106. system_controller_base) {
  107. *dev = readl(system_controller_base + mvebu_sc->dev_id) >> 16;
  108. *rev = (readl(system_controller_base + mvebu_sc->rev_id) >> 8)
  109. & 0xF;
  110. return 0;
  111. } else
  112. return -ENODEV;
  113. }
  114. #if defined(CONFIG_SMP) && defined(CONFIG_MACH_MVEBU_V7)
  115. static void mvebu_armada375_smp_wa_init(void)
  116. {
  117. u32 dev, rev;
  118. phys_addr_t resume_addr_reg;
  119. if (mvebu_get_soc_id(&dev, &rev) != 0)
  120. return;
  121. if (rev != ARMADA_375_Z1_REV)
  122. return;
  123. resume_addr_reg = system_controller_phys_base +
  124. mvebu_sc->resume_boot_addr;
  125. mvebu_setup_boot_addr_wa(ARMADA_375_CRYPT0_ENG_TARGET,
  126. ARMADA_375_CRYPT0_ENG_ATTR,
  127. resume_addr_reg);
  128. }
  129. void mvebu_system_controller_set_cpu_boot_addr(void *boot_addr)
  130. {
  131. BUG_ON(system_controller_base == NULL);
  132. BUG_ON(mvebu_sc->resume_boot_addr == 0);
  133. if (of_machine_is_compatible("marvell,armada375"))
  134. mvebu_armada375_smp_wa_init();
  135. writel(__pa_symbol(boot_addr), system_controller_base +
  136. mvebu_sc->resume_boot_addr);
  137. }
  138. #endif
  139. static int __init mvebu_system_controller_init(void)
  140. {
  141. const struct of_device_id *match;
  142. struct device_node *np;
  143. np = of_find_matching_node_and_match(NULL, of_system_controller_table,
  144. &match);
  145. if (np) {
  146. struct resource res;
  147. system_controller_base = of_iomap(np, 0);
  148. of_address_to_resource(np, 0, &res);
  149. system_controller_phys_base = res.start;
  150. mvebu_sc = (struct mvebu_system_controller *)match->data;
  151. of_node_put(np);
  152. }
  153. return 0;
  154. }
  155. early_initcall(mvebu_system_controller_init);