st-poweroff.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/reboot.h>
  18. #include <linux/regmap.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 int st_restart(struct notifier_block *this, unsigned long mode,
  66. void *cmd)
  67. {
  68. /* reset syscfg updated */
  69. regmap_update_bits(st_restart_syscfg->regmap,
  70. st_restart_syscfg->offset_rst,
  71. st_restart_syscfg->mask_rst,
  72. 0);
  73. /* unmask the reset */
  74. regmap_update_bits(st_restart_syscfg->regmap,
  75. st_restart_syscfg->offset_rst_msk,
  76. st_restart_syscfg->mask_rst_msk,
  77. 0);
  78. return NOTIFY_DONE;
  79. }
  80. static struct notifier_block st_restart_nb = {
  81. .notifier_call = st_restart,
  82. .priority = 192,
  83. };
  84. static const struct of_device_id st_reset_of_match[] = {
  85. {
  86. .compatible = "st,stih415-restart",
  87. .data = (void *)&stih415_reset,
  88. }, {
  89. .compatible = "st,stih416-restart",
  90. .data = (void *)&stih416_reset,
  91. }, {
  92. .compatible = "st,stih407-restart",
  93. .data = (void *)&stih407_reset,
  94. }, {
  95. .compatible = "st,stid127-restart",
  96. .data = (void *)&stid127_reset,
  97. },
  98. {}
  99. };
  100. static int st_reset_probe(struct platform_device *pdev)
  101. {
  102. struct device_node *np = pdev->dev.of_node;
  103. const struct of_device_id *match;
  104. struct device *dev = &pdev->dev;
  105. match = of_match_device(st_reset_of_match, dev);
  106. if (!match)
  107. return -ENODEV;
  108. st_restart_syscfg = (struct reset_syscfg *)match->data;
  109. st_restart_syscfg->regmap =
  110. syscon_regmap_lookup_by_phandle(np, "st,syscfg");
  111. if (IS_ERR(st_restart_syscfg->regmap)) {
  112. dev_err(dev, "No syscfg phandle specified\n");
  113. return PTR_ERR(st_restart_syscfg->regmap);
  114. }
  115. return register_restart_handler(&st_restart_nb);
  116. }
  117. static struct platform_driver st_reset_driver = {
  118. .probe = st_reset_probe,
  119. .driver = {
  120. .name = "st_reset",
  121. .of_match_table = st_reset_of_match,
  122. },
  123. };
  124. static int __init st_reset_init(void)
  125. {
  126. return platform_driver_register(&st_reset_driver);
  127. }
  128. device_initcall(st_reset_init);
  129. MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
  130. MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
  131. MODULE_LICENSE("GPL v2");