system-controller.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. static void __iomem *system_controller_base;
  31. struct mvebu_system_controller {
  32. u32 rstoutn_mask_offset;
  33. u32 system_soft_reset_offset;
  34. u32 rstoutn_mask_reset_out_en;
  35. u32 system_soft_reset;
  36. u32 resume_boot_addr;
  37. };
  38. static struct mvebu_system_controller *mvebu_sc;
  39. static const struct mvebu_system_controller armada_370_xp_system_controller = {
  40. .rstoutn_mask_offset = 0x60,
  41. .system_soft_reset_offset = 0x64,
  42. .rstoutn_mask_reset_out_en = 0x1,
  43. .system_soft_reset = 0x1,
  44. };
  45. static const struct mvebu_system_controller armada_375_system_controller = {
  46. .rstoutn_mask_offset = 0x54,
  47. .system_soft_reset_offset = 0x58,
  48. .rstoutn_mask_reset_out_en = 0x1,
  49. .system_soft_reset = 0x1,
  50. .resume_boot_addr = 0xd4,
  51. };
  52. static const struct mvebu_system_controller orion_system_controller = {
  53. .rstoutn_mask_offset = 0x108,
  54. .system_soft_reset_offset = 0x10c,
  55. .rstoutn_mask_reset_out_en = 0x4,
  56. .system_soft_reset = 0x1,
  57. };
  58. static const struct of_device_id of_system_controller_table[] = {
  59. {
  60. .compatible = "marvell,orion-system-controller",
  61. .data = (void *) &orion_system_controller,
  62. }, {
  63. .compatible = "marvell,armada-370-xp-system-controller",
  64. .data = (void *) &armada_370_xp_system_controller,
  65. }, {
  66. .compatible = "marvell,armada-375-system-controller",
  67. .data = (void *) &armada_375_system_controller,
  68. },
  69. { /* end of list */ },
  70. };
  71. void mvebu_restart(enum reboot_mode mode, const char *cmd)
  72. {
  73. if (!system_controller_base) {
  74. pr_err("Cannot restart, system-controller not available: check the device tree\n");
  75. } else {
  76. /*
  77. * Enable soft reset to assert RSTOUTn.
  78. */
  79. writel(mvebu_sc->rstoutn_mask_reset_out_en,
  80. system_controller_base +
  81. mvebu_sc->rstoutn_mask_offset);
  82. /*
  83. * Assert soft reset.
  84. */
  85. writel(mvebu_sc->system_soft_reset,
  86. system_controller_base +
  87. mvebu_sc->system_soft_reset_offset);
  88. }
  89. while (1)
  90. ;
  91. }
  92. #ifdef CONFIG_SMP
  93. void mvebu_system_controller_set_cpu_boot_addr(void *boot_addr)
  94. {
  95. BUG_ON(system_controller_base == NULL);
  96. BUG_ON(mvebu_sc->resume_boot_addr == 0);
  97. writel(virt_to_phys(boot_addr), system_controller_base +
  98. mvebu_sc->resume_boot_addr);
  99. }
  100. #endif
  101. static int __init mvebu_system_controller_init(void)
  102. {
  103. const struct of_device_id *match;
  104. struct device_node *np;
  105. np = of_find_matching_node_and_match(NULL, of_system_controller_table,
  106. &match);
  107. if (np) {
  108. system_controller_base = of_iomap(np, 0);
  109. mvebu_sc = (struct mvebu_system_controller *)match->data;
  110. of_node_put(np);
  111. }
  112. return 0;
  113. }
  114. early_initcall(mvebu_system_controller_init);