arm-versatile-reboot.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 REALVIEW_SYS_LOCK_OFFSET 0x20
  20. #define REALVIEW_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. REALVIEW_REBOOT_EB,
  29. REALVIEW_REBOOT_PB1176,
  30. REALVIEW_REBOOT_PB11MP,
  31. REALVIEW_REBOOT_PBA8,
  32. REALVIEW_REBOOT_PBX,
  33. };
  34. /* Pointer to the system controller */
  35. static struct regmap *syscon_regmap;
  36. static enum versatile_reboot versatile_reboot_type;
  37. static const struct of_device_id versatile_reboot_of_match[] = {
  38. {
  39. .compatible = "arm,core-module-integrator",
  40. .data = (void *)INTEGRATOR_REBOOT_CM
  41. },
  42. {
  43. .compatible = "arm,realview-eb-syscon",
  44. .data = (void *)REALVIEW_REBOOT_EB,
  45. },
  46. {
  47. .compatible = "arm,realview-pb1176-syscon",
  48. .data = (void *)REALVIEW_REBOOT_PB1176,
  49. },
  50. {
  51. .compatible = "arm,realview-pb11mp-syscon",
  52. .data = (void *)REALVIEW_REBOOT_PB11MP,
  53. },
  54. {
  55. .compatible = "arm,realview-pba8-syscon",
  56. .data = (void *)REALVIEW_REBOOT_PBA8,
  57. },
  58. {
  59. .compatible = "arm,realview-pbx-syscon",
  60. .data = (void *)REALVIEW_REBOOT_PBX,
  61. },
  62. {},
  63. };
  64. static int versatile_reboot(struct notifier_block *this, unsigned long mode,
  65. void *cmd)
  66. {
  67. /* Unlock the reset register */
  68. /* Then hit reset on the different machines */
  69. switch (versatile_reboot_type) {
  70. case INTEGRATOR_REBOOT_CM:
  71. regmap_write(syscon_regmap, INTEGRATOR_HDR_LOCK_OFFSET,
  72. VERSATILE_LOCK_VAL);
  73. regmap_update_bits(syscon_regmap,
  74. INTEGRATOR_HDR_CTRL_OFFSET,
  75. INTEGRATOR_CM_CTRL_RESET,
  76. INTEGRATOR_CM_CTRL_RESET);
  77. break;
  78. case REALVIEW_REBOOT_EB:
  79. regmap_write(syscon_regmap, REALVIEW_SYS_LOCK_OFFSET,
  80. VERSATILE_LOCK_VAL);
  81. regmap_write(syscon_regmap,
  82. REALVIEW_SYS_RESETCTL_OFFSET, 0x0008);
  83. break;
  84. case REALVIEW_REBOOT_PB1176:
  85. regmap_write(syscon_regmap, REALVIEW_SYS_LOCK_OFFSET,
  86. VERSATILE_LOCK_VAL);
  87. regmap_write(syscon_regmap,
  88. REALVIEW_SYS_RESETCTL_OFFSET, 0x0100);
  89. break;
  90. case REALVIEW_REBOOT_PB11MP:
  91. case REALVIEW_REBOOT_PBA8:
  92. regmap_write(syscon_regmap, REALVIEW_SYS_LOCK_OFFSET,
  93. VERSATILE_LOCK_VAL);
  94. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  95. 0x0000);
  96. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  97. 0x0004);
  98. break;
  99. case REALVIEW_REBOOT_PBX:
  100. regmap_write(syscon_regmap, REALVIEW_SYS_LOCK_OFFSET,
  101. VERSATILE_LOCK_VAL);
  102. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  103. 0x00f0);
  104. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  105. 0x00f4);
  106. break;
  107. }
  108. dsb();
  109. return NOTIFY_DONE;
  110. }
  111. static struct notifier_block versatile_reboot_nb = {
  112. .notifier_call = versatile_reboot,
  113. .priority = 192,
  114. };
  115. static int __init versatile_reboot_probe(void)
  116. {
  117. const struct of_device_id *reboot_id;
  118. struct device_node *np;
  119. int err;
  120. np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
  121. &reboot_id);
  122. if (!np)
  123. return -ENODEV;
  124. versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
  125. syscon_regmap = syscon_node_to_regmap(np);
  126. if (IS_ERR(syscon_regmap))
  127. return PTR_ERR(syscon_regmap);
  128. err = register_restart_handler(&versatile_reboot_nb);
  129. if (err)
  130. return err;
  131. pr_info("versatile reboot driver registered\n");
  132. return 0;
  133. }
  134. device_initcall(versatile_reboot_probe);