arm-versatile-reboot.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <asm/system_misc.h>
  17. #define REALVIEW_SYS_LOCK_OFFSET 0x20
  18. #define REALVIEW_SYS_LOCK_VAL 0xA05F
  19. #define REALVIEW_SYS_RESETCTL_OFFSET 0x40
  20. /*
  21. * We detect the different syscon types from the compatible strings.
  22. */
  23. enum versatile_reboot {
  24. REALVIEW_REBOOT_EB,
  25. REALVIEW_REBOOT_PB1176,
  26. REALVIEW_REBOOT_PB11MP,
  27. REALVIEW_REBOOT_PBA8,
  28. REALVIEW_REBOOT_PBX,
  29. };
  30. /* Pointer to the system controller */
  31. static struct regmap *syscon_regmap;
  32. static enum versatile_reboot versatile_reboot_type;
  33. static const struct of_device_id versatile_reboot_of_match[] = {
  34. {
  35. .compatible = "arm,realview-eb-syscon",
  36. .data = (void *)REALVIEW_REBOOT_EB,
  37. },
  38. {
  39. .compatible = "arm,realview-pb1176-syscon",
  40. .data = (void *)REALVIEW_REBOOT_PB1176,
  41. },
  42. {
  43. .compatible = "arm,realview-pb11mp-syscon",
  44. .data = (void *)REALVIEW_REBOOT_PB11MP,
  45. },
  46. {
  47. .compatible = "arm,realview-pba8-syscon",
  48. .data = (void *)REALVIEW_REBOOT_PBA8,
  49. },
  50. {
  51. .compatible = "arm,realview-pbx-syscon",
  52. .data = (void *)REALVIEW_REBOOT_PBX,
  53. },
  54. };
  55. static void versatile_reboot(enum reboot_mode mode, const char *cmd)
  56. {
  57. /* Unlock the reset register */
  58. regmap_write(syscon_regmap, REALVIEW_SYS_LOCK_OFFSET,
  59. REALVIEW_SYS_LOCK_VAL);
  60. /* Then hit reset on the different machines */
  61. switch (versatile_reboot_type) {
  62. case REALVIEW_REBOOT_EB:
  63. regmap_write(syscon_regmap,
  64. REALVIEW_SYS_RESETCTL_OFFSET, 0x0008);
  65. break;
  66. case REALVIEW_REBOOT_PB1176:
  67. regmap_write(syscon_regmap,
  68. REALVIEW_SYS_RESETCTL_OFFSET, 0x0100);
  69. break;
  70. case REALVIEW_REBOOT_PB11MP:
  71. case REALVIEW_REBOOT_PBA8:
  72. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  73. 0x0000);
  74. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  75. 0x0004);
  76. break;
  77. case REALVIEW_REBOOT_PBX:
  78. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  79. 0x00f0);
  80. regmap_write(syscon_regmap, REALVIEW_SYS_RESETCTL_OFFSET,
  81. 0x00f4);
  82. break;
  83. }
  84. dsb();
  85. }
  86. static int __init versatile_reboot_probe(void)
  87. {
  88. const struct of_device_id *reboot_id;
  89. struct device_node *np;
  90. np = of_find_matching_node_and_match(NULL, versatile_reboot_of_match,
  91. &reboot_id);
  92. if (!np)
  93. return -ENODEV;
  94. versatile_reboot_type = (enum versatile_reboot)reboot_id->data;
  95. syscon_regmap = syscon_node_to_regmap(np);
  96. if (IS_ERR(syscon_regmap))
  97. return PTR_ERR(syscon_regmap);
  98. arm_pm_restart = versatile_reboot;
  99. pr_info("versatile reboot driver registered\n");
  100. return 0;
  101. }
  102. device_initcall(versatile_reboot_probe);