arm-versatile-reboot.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2014 Linaro Ltd.
  4. *
  5. * Author: Linus Walleij <[email protected]>
  6. */
  7. #include <linux/init.h>
  8. #include <linux/mfd/syscon.h>
  9. #include <linux/reboot.h>
  10. #include <linux/regmap.h>
  11. #include <linux/of.h>
  12. #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
  13. #define INTEGRATOR_HDR_LOCK_OFFSET 0x14
  14. #define INTEGRATOR_CM_CTRL_RESET (1 << 3)
  15. #define VERSATILE_SYS_LOCK_OFFSET 0x20
  16. #define VERSATILE_SYS_RESETCTL_OFFSET 0x40
  17. /* Magic unlocking token used on all Versatile boards */
  18. #define VERSATILE_LOCK_VAL 0xA05F
  19. /*
  20. * We detect the different syscon types from the compatible strings.
  21. */
  22. enum versatile_reboot {
  23. INTEGRATOR_REBOOT_CM,
  24. VERSATILE_REBOOT_CM,
  25. REALVIEW_REBOOT_EB,
  26. REALVIEW_REBOOT_PB1176,
  27. REALVIEW_REBOOT_PB11MP,
  28. REALVIEW_REBOOT_PBA8,
  29. REALVIEW_REBOOT_PBX,
  30. };
  31. /* Pointer to the system controller */
  32. static struct regmap *syscon_regmap;
  33. static enum versatile_reboot versatile_reboot_type;
  34. static const struct of_device_id versatile_reboot_of_match[] = {
  35. {
  36. .compatible = "arm,core-module-integrator",
  37. .data = (void *)INTEGRATOR_REBOOT_CM
  38. },
  39. {
  40. .compatible = "arm,core-module-versatile",
  41. .data = (void *)VERSATILE_REBOOT_CM,
  42. },
  43. {
  44. .compatible = "arm,realview-eb-syscon",
  45. .data = (void *)REALVIEW_REBOOT_EB,
  46. },
  47. {
  48. .compatible = "arm,realview-pb1176-syscon",
  49. .data = (void *)REALVIEW_REBOOT_PB1176,
  50. },
  51. {
  52. .compatible = "arm,realview-pb11mp-syscon",
  53. .data = (void *)REALVIEW_REBOOT_PB11MP,
  54. },
  55. {
  56. .compatible = "arm,realview-pba8-syscon",
  57. .data = (void *)REALVIEW_REBOOT_PBA8,
  58. },
  59. {
  60. .compatible = "arm,realview-pbx-syscon",
  61. .data = (void *)REALVIEW_REBOOT_PBX,
  62. },
  63. {},
  64. };
  65. static int versatile_reboot(struct notifier_block *this, unsigned long mode,
  66. void *cmd)
  67. {
  68. /* Unlock the reset register */
  69. /* Then hit reset on the different machines */
  70. switch (versatile_reboot_type) {
  71. case INTEGRATOR_REBOOT_CM:
  72. regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET,
  73. VERSATILE_LOCK_VAL);
  74. regmap_update_bits(syscon_regmap,
  75. INTEGRATOR_HDR_CTRL_OFFSET,
  76. INTEGRATOR_CM_CTRL_RESET,
  77. INTEGRATOR_CM_CTRL_RESET);
  78. break;
  79. case VERSATILE_REBOOT_CM:
  80. regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
  81. VERSATILE_LOCK_VAL);
  82. regmap_update_bits(syscon_regmap,
  83. VERSATILE_SYS_RESETCTL_OFFSET,
  84. 0x0107,
  85. 0x0105);
  86. regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
  87. 0);
  88. break;
  89. case REALVIEW_REBOOT_EB:
  90. regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
  91. VERSATILE_LOCK_VAL);
  92. regmap_write(syscon_regmap,
  93. VERSATILE_SYS_RESETCTL_OFFSET, 0x0008);
  94. break;
  95. case REALVIEW_REBOOT_PB1176:
  96. regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
  97. VERSATILE_LOCK_VAL);
  98. regmap_write(syscon_regmap,
  99. VERSATILE_SYS_RESETCTL_OFFSET, 0x0100);
  100. break;
  101. case REALVIEW_REBOOT_PB11MP:
  102. case REALVIEW_REBOOT_PBA8:
  103. regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
  104. VERSATILE_LOCK_VAL);
  105. regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
  106. 0x0000);
  107. regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
  108. 0x0004);
  109. break;
  110. case REALVIEW_REBOOT_PBX:
  111. regmap_write(syscon_regmap, VERSATILE_SYS_LOCK_OFFSET,
  112. VERSATILE_LOCK_VAL);
  113. regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
  114. 0x00f0);
  115. regmap_write(syscon_regmap, VERSATILE_SYS_RESETCTL_OFFSET,
  116. 0x00f4);
  117. break;
  118. }
  119. dsb();
  120. return NOTIFY_DONE;
  121. }
  122. static struct notifier_block versatile_reboot_nb = {
  123. .notifier_call = versatile_reboot,
  124. .priority = 192,
  125. };
  126. static int __init versatile_reboot_probe(void)
  127. {
  128. const struct of_device_id *reboot_id;
  129. struct device_node *np;
  130. int err;
  131. np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
  132. &reboot_id);
  133. if (!np)
  134. return -ENODEV;
  135. versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
  136. syscon_regmap = syscon_node_to_regmap(np);
  137. of_node_put(np);
  138. if (IS_ERR(syscon_regmap))
  139. return PTR_ERR(syscon_regmap);
  140. err = register_restart_handler(&versatile_reboot_nb);
  141. if (err)
  142. return err;
  143. pr_info("versatile reboot driver registered\n");
  144. return 0;
  145. }
  146. device_initcall(versatile_reboot_probe);