st-poweroff.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2014 STMicroelectronics
  4. *
  5. * Power off Restart driver, used in STMicroelectronics devices.
  6. *
  7. * Author: Christophe Kerello <christophe.kerello@st.com>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/reboot.h>
  15. #include <linux/regmap.h>
  16. struct reset_syscfg {
  17. struct regmap *regmap;
  18. /* syscfg used for reset */
  19. unsigned int offset_rst;
  20. unsigned int mask_rst;
  21. /* syscfg used for unmask the reset */
  22. unsigned int offset_rst_msk;
  23. unsigned int mask_rst_msk;
  24. };
  25. /* STiH407 */
  26. #define STIH407_SYSCFG_4000 0x0
  27. #define STIH407_SYSCFG_4008 0x20
  28. static struct reset_syscfg stih407_reset = {
  29. .offset_rst = STIH407_SYSCFG_4000,
  30. .mask_rst = BIT(0),
  31. .offset_rst_msk = STIH407_SYSCFG_4008,
  32. .mask_rst_msk = BIT(0)
  33. };
  34. static struct reset_syscfg *st_restart_syscfg;
  35. static int st_restart(struct notifier_block *this, unsigned long mode,
  36. void *cmd)
  37. {
  38. /* reset syscfg updated */
  39. regmap_update_bits(st_restart_syscfg->regmap,
  40. st_restart_syscfg->offset_rst,
  41. st_restart_syscfg->mask_rst,
  42. 0);
  43. /* unmask the reset */
  44. regmap_update_bits(st_restart_syscfg->regmap,
  45. st_restart_syscfg->offset_rst_msk,
  46. st_restart_syscfg->mask_rst_msk,
  47. 0);
  48. return NOTIFY_DONE;
  49. }
  50. static struct notifier_block st_restart_nb = {
  51. .notifier_call = st_restart,
  52. .priority = 192,
  53. };
  54. static const struct of_device_id st_reset_of_match[] = {
  55. {
  56. .compatible = "st,stih407-restart",
  57. .data = (void *)&stih407_reset,
  58. },
  59. {}
  60. };
  61. static int st_reset_probe(struct platform_device *pdev)
  62. {
  63. struct device_node *np = pdev->dev.of_node;
  64. const struct of_device_id *match;
  65. struct device *dev = &pdev->dev;
  66. match = of_match_device(st_reset_of_match, dev);
  67. if (!match)
  68. return -ENODEV;
  69. st_restart_syscfg = (struct reset_syscfg *)match->data;
  70. st_restart_syscfg->regmap =
  71. syscon_regmap_lookup_by_phandle(np, "st,syscfg");
  72. if (IS_ERR(st_restart_syscfg->regmap)) {
  73. dev_err(dev, "No syscfg phandle specified\n");
  74. return PTR_ERR(st_restart_syscfg->regmap);
  75. }
  76. return register_restart_handler(&st_restart_nb);
  77. }
  78. static struct platform_driver st_reset_driver = {
  79. .probe = st_reset_probe,
  80. .driver = {
  81. .name = "st_reset",
  82. .of_match_table = st_reset_of_match,
  83. },
  84. };
  85. static int __init st_reset_init(void)
  86. {
  87. return platform_driver_register(&st_reset_driver);
  88. }
  89. device_initcall(st_reset_init);
  90. MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
  91. MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
  92. MODULE_LICENSE("GPL v2");