arm-versatile-reboot.c 4.2 KB

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