st-poweroff.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2014 STMicroelectronics
  3. *
  4. * Power off Restart driver, used in STMicroelectronics devices.
  5. *
  6. * Author: Christophe Kerello <christophe.kerello@st.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2, as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mfd/syscon.h>
  17. #include <linux/regmap.h>
  18. #include <asm/system_misc.h>
  19. struct reset_syscfg {
  20. struct regmap *regmap;
  21. /* syscfg used for reset */
  22. unsigned int offset_rst;
  23. unsigned int mask_rst;
  24. /* syscfg used for unmask the reset */
  25. unsigned int offset_rst_msk;
  26. unsigned int mask_rst_msk;
  27. };
  28. /* STiH415 */
  29. #define STIH415_SYSCFG_11 0x2c
  30. #define STIH415_SYSCFG_15 0x3c
  31. static struct reset_syscfg stih415_reset = {
  32. .offset_rst = STIH415_SYSCFG_11,
  33. .mask_rst = BIT(0),
  34. .offset_rst_msk = STIH415_SYSCFG_15,
  35. .mask_rst_msk = BIT(0)
  36. };
  37. /* STiH416 */
  38. #define STIH416_SYSCFG_500 0x7d0
  39. #define STIH416_SYSCFG_504 0x7e0
  40. static struct reset_syscfg stih416_reset = {
  41. .offset_rst = STIH416_SYSCFG_500,
  42. .mask_rst = BIT(0),
  43. .offset_rst_msk = STIH416_SYSCFG_504,
  44. .mask_rst_msk = BIT(0)
  45. };
  46. /* STiH407 */
  47. #define STIH407_SYSCFG_4000 0x0
  48. #define STIH407_SYSCFG_4008 0x20
  49. static struct reset_syscfg stih407_reset = {
  50. .offset_rst = STIH407_SYSCFG_4000,
  51. .mask_rst = BIT(0),
  52. .offset_rst_msk = STIH407_SYSCFG_4008,
  53. .mask_rst_msk = BIT(0)
  54. };
  55. /* STiD127 */
  56. #define STID127_SYSCFG_700 0x0
  57. #define STID127_SYSCFG_773 0x124
  58. static struct reset_syscfg stid127_reset = {
  59. .offset_rst = STID127_SYSCFG_773,
  60. .mask_rst = BIT(0),
  61. .offset_rst_msk = STID127_SYSCFG_700,
  62. .mask_rst_msk = BIT(8)
  63. };
  64. static struct reset_syscfg *st_restart_syscfg;
  65. static void st_restart(enum reboot_mode reboot_mode, const char *cmd)
  66. {
  67. /* reset syscfg updated */
  68. regmap_update_bits(st_restart_syscfg->regmap,
  69. st_restart_syscfg->offset_rst,
  70. st_restart_syscfg->mask_rst,
  71. 0);
  72. /* unmask the reset */
  73. regmap_update_bits(st_restart_syscfg->regmap,
  74. st_restart_syscfg->offset_rst_msk,
  75. st_restart_syscfg->mask_rst_msk,
  76. 0);
  77. }
  78. static struct of_device_id st_reset_of_match[] = {
  79. {
  80. .compatible = "st,stih415-restart",
  81. .data = (void *)&stih415_reset,
  82. }, {
  83. .compatible = "st,stih416-restart",
  84. .data = (void *)&stih416_reset,
  85. }, {
  86. .compatible = "st,stih407-restart",
  87. .data = (void *)&stih407_reset,
  88. }, {
  89. .compatible = "st,stid127-restart",
  90. .data = (void *)&stid127_reset,
  91. },
  92. {}
  93. };
  94. static int st_reset_probe(struct platform_device *pdev)
  95. {
  96. struct device_node *np = pdev->dev.of_node;
  97. const struct of_device_id *match;
  98. struct device *dev = &pdev->dev;
  99. match = of_match_device(st_reset_of_match, dev);
  100. if (!match)
  101. return -ENODEV;
  102. st_restart_syscfg = (struct reset_syscfg *)match->data;
  103. st_restart_syscfg->regmap =
  104. syscon_regmap_lookup_by_phandle(np, "st,syscfg");
  105. if (IS_ERR(st_restart_syscfg->regmap)) {
  106. dev_err(dev, "No syscfg phandle specified\n");
  107. return PTR_ERR(st_restart_syscfg->regmap);
  108. }
  109. arm_pm_restart = st_restart;
  110. return 0;
  111. }
  112. static struct platform_driver st_reset_driver = {
  113. .probe = st_reset_probe,
  114. .driver = {
  115. .name = "st_reset",
  116. .of_match_table = st_reset_of_match,
  117. },
  118. };
  119. static int __init st_reset_init(void)
  120. {
  121. return platform_driver_register(&st_reset_driver);
  122. }
  123. device_initcall(st_reset_init);
  124. MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
  125. MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
  126. MODULE_LICENSE("GPL v2");