system-controller.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * System controller support for Armada 370 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 and Armada XP SoCs both 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. static void __iomem *system_controller_base;
  30. struct mvebu_system_controller {
  31. u32 rstoutn_mask_offset;
  32. u32 system_soft_reset_offset;
  33. u32 rstoutn_mask_reset_out_en;
  34. u32 system_soft_reset;
  35. };
  36. static struct mvebu_system_controller *mvebu_sc;
  37. const struct mvebu_system_controller armada_370_xp_system_controller = {
  38. .rstoutn_mask_offset = 0x60,
  39. .system_soft_reset_offset = 0x64,
  40. .rstoutn_mask_reset_out_en = 0x1,
  41. .system_soft_reset = 0x1,
  42. };
  43. const struct mvebu_system_controller orion_system_controller = {
  44. .rstoutn_mask_offset = 0x108,
  45. .system_soft_reset_offset = 0x10c,
  46. .rstoutn_mask_reset_out_en = 0x4,
  47. .system_soft_reset = 0x1,
  48. };
  49. static struct of_device_id of_system_controller_table[] = {
  50. {
  51. .compatible = "marvell,orion-system-controller",
  52. .data = (void *) &orion_system_controller,
  53. }, {
  54. .compatible = "marvell,armada-370-xp-system-controller",
  55. .data = (void *) &armada_370_xp_system_controller,
  56. },
  57. { /* end of list */ },
  58. };
  59. void mvebu_restart(enum reboot_mode mode, const char *cmd)
  60. {
  61. if (!system_controller_base) {
  62. pr_err("Cannot restart, system-controller not available: check the device tree\n");
  63. } else {
  64. /*
  65. * Enable soft reset to assert RSTOUTn.
  66. */
  67. writel(mvebu_sc->rstoutn_mask_reset_out_en,
  68. system_controller_base +
  69. mvebu_sc->rstoutn_mask_offset);
  70. /*
  71. * Assert soft reset.
  72. */
  73. writel(mvebu_sc->system_soft_reset,
  74. system_controller_base +
  75. mvebu_sc->system_soft_reset_offset);
  76. }
  77. while (1)
  78. ;
  79. }
  80. static int __init mvebu_system_controller_init(void)
  81. {
  82. struct device_node *np;
  83. np = of_find_matching_node(NULL, of_system_controller_table);
  84. if (np) {
  85. const struct of_device_id *match =
  86. of_match_node(of_system_controller_table, np);
  87. BUG_ON(!match);
  88. system_controller_base = of_iomap(np, 0);
  89. mvebu_sc = (struct mvebu_system_controller *)match->data;
  90. of_node_put(np);
  91. }
  92. return 0;
  93. }
  94. arch_initcall(mvebu_system_controller_init);